2024.11.14
いまさらNode.jsを知ろう~環境構築も~
2021.05.17
インフラパスワード管理ツール Bitwarden をAWSで構築してみる(環境構築編)
こんにちは。HMです。
前回から日にちが開いてしまいましたが、続きの環境構築編を書いていきたいと思います。
前回↓
https://www.tcmobile.jp/dev_blog/devtool/%e3%83%91%e3%82%b9%e3%83%af%e3%83%bc%e3%83%89%e7%ae%a1%e7%90%86%e3%83%84%e3%83%bc%e3%83%ab-bitwarden-%e3%82%92aws%e3%81%a7%e6%a7%8b%e7%af%89%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b/
1.サーバの準備
2.Docker インストール
3.Bitwarden インストール
https://bitwarden.com/help/article/install-on-premise/
公式のこちらのドキュメントを参考に構築していきます。
■システム要求
プロセッサー:x64、2GHzデュアルコア
メモリ:4 GB RAM(システムメモリ)
ストレージ:25 GB
Docker:Engine19以降およびCompose1.24以降
AWSにて上記スペックのAmazonLinux2インスタンスを準備しました。
下記の準備方法につきましては今回は省きます。
・AWSでのインスタンス作成
・ネットワーク設定(80ポートと443ポートのinを開ける)
・ドメイン準備、DNS設定(本ブログではbitwarden.example.jpで書いています)
Dockerをyumでインストールし、起動します。
yum install -y docker service docker start
ユーザをdockerグループに所属させます。
usermod -a -G docker ec2-user cat /etc/group | grep docker # docker:x:497:ec2-user
反映のため、ログアウトし、再度ログインする
# 追加確認 docker info # Containers: 0 # Running: 0 # Paused: 0 # Stopped: 0 # Images: 0 # ・・・・・ # Registry: https://index.docker.io/v1/
Docker Compose をインストール
# Docker ComposeをDLする curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # 実行権限を設定 chmod +x /usr/local/bin/docker-compose # バージョンを確認できたらインストールOK docker-compose --version # [root@ip-172-31-23-251 ~]# docker-compose --version # docker-compose version 1.24.0, build 0aa59064
※前提条件
80ポートと443ポートのinが開いていること
今回は証明書にLets encryptを設定します。
Bitwardenインストール前の準備をします
# bitwardenユーザーを作成 adduser bitwarden passwd bitwarden # bitwardenユーザーをdockerグループに追加(dockerグループがなければ作成する) usermod -aG docker bitwarden # bitwardenディレクトリを作成 mkdir /opt/bitwarden chmod -R 700 /opt/bitwarden chown -R bitwarden:bitwarden /opt/bitwarden
ここからBitwardenをインストールしていきます。
まず、https://bitwarden.com/host にブラウザでアクセスし、メールアドレスを送信してインストールIDとキーを取得しておきます。(※1)
bitwardenディレクトリを作成し、Bitwardenインストールスクリプトをダウンロードします。
cd /opt/bitwarden curl -Lso bitwarden.sh https://go.btwrdn.co/bw-sh chmod 700 bitwarden.sh
Bitwardenをインストールします
# [root@bitwarden bitwarden]# ./bitwarden.sh install # _ _ _ _ # | |__ (_) |___ ____ _ _ __ __| | ___ _ __ # | '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \ # | |_) | | |_ \ V V / (_| | | | (_| | __/ | | | # |_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_| # # Open source password management solutions # Copyright 2015-2021, 8bit Solutions LLC # https://bitwarden.com, https://github.com/bitwarden # # =================================================== # # bitwarden.sh version 1.38.4 # Docker version 19.03.13-ce, build 4484c46 # docker-compose version 1.27.4, build 40524192 # # (!) Enter the domain name for your Bitwarden instance (ex. bitwarden.example.com): bitwarden.tmlab.jp ★ドメインを入力 # # (!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): y ★今回はLets encryptを使うので「y」 # # (!) Enter your email address (Let's Encrypt will send you certificate expiration reminders): hoge@example.jp ★管理用のメールアドレスを入力 # # Using default tag: latest # latest: Pulling from certbot/certbot # Digest: sha256:ab08b65a2ed5a07496eab811a10220461cf71919f122a931b0a0ad2aeceab7c5 # Status: Image is up to date for certbot/certbot:latest # docker.io/certbot/certbot:latest # Saving debug log to /etc/letsencrypt/logs/letsencrypt.log # Plugins selected: Authenticator standalone, Installer None # Requesting a certificate for bitwarden.tmlab.jp # Performing the following challenges: # http-01 challenge for bitwarden.tmlab.jp # Waiting for verification... # Cleaning up challenges # # IMPORTANT NOTES: # - Congratulations! Your certificate and chain have been saved at: # /etc/letsencrypt/live/bitwarden.tmlab.jp/fullchain.pem # Your key file has been saved at: # /etc/letsencrypt/live/bitwarden.tmlab.jp/privkey.pem # Your cert will expire on 2021-04-04. To obtain a new or tweaked # version of this certificate in the future, simply run certbot # again. To non-interactively renew *all* of your certificates, run # "certbot renew" # - If you like Certbot, please consider supporting our work by: # # Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate # Donating to EFF: https://eff.org/donate-le # # 1.38.4: Pulling from bitwarden/setup # 6ec7b7d162b2: Pull complete # f48adbf33222: Pull complete # 0caf687f11cc: Pull complete # 31f7e18202e6: Pull complete # b2b381c9c354: Pull complete # e8fd15aa109a: Pull complete # 142f9a45d3a4: Pull complete # 583693ef2d6d: Pull complete # 7822ec538888: Pull complete # e3d143c86e1f: Pull complete # Digest: sha256:d982b81ac6fdb95b0da8744b30b965045b3176201f48903526c3c04d4c6cf972 # Status: Downloaded newer image for bitwarden/setup:1.38.4 # docker.io/bitwarden/setup:1.38.4 # # (!) Enter your installation id (get at https://bitwarden.com/host): ★(※1)で取得したインストールIDを入力 # # (!) Enter your installation key: ★(※1)で取得したインストールキーを入力 # # Generating DH parameters, 2048 bit long safe prime, generator 2 # This is going to take a long time # .............+................+...............................+................................................................................................................................+........................+.....................................+......................................................................................+...........+...............................................................................................................................+................................................................................................................................................+..............................................................................................+....................................................................................+....+....................................................+............................................+...........................................................+........................................................................................................+..................................................................................................................................................................................+......................+......................................................................................+..................................................+................................................+........................................................................................................................+.........................................+......................................................................................+............+................................................................+..........................................................+.........................................................................................................................................................................................+....................+...........................+...............................................................................................................................................................................................................+....................................................................................................................................................................+...............................................................................................................................................................................................................................................+.....................................................................+..............................+....................................................................................................................+.................................................................................................................................................................................................................................................................................................................................+.................................................................................................................................................................................+........................................+.......+........................+.................+..................+..........................+.............................................................+..............................................................................................................................................+...............................................................................................+............................................................+............................................................................................................+........................++*++*++*++* # Generating key for IdentityServer. # Generating a RSA private key # ........................................................++++ # ....................................................................................................++++ # writing new private key to 'identity.key' # ----- # # Building nginx config. # Building docker environment files. # Building docker environment override files. # Building FIDO U2F app id. # Building docker-compose.yml. # # Installation complete # # If you need to make additional configuration changes, you can modify # the settings in `./bwdata/config.yml` and then run: # `./bitwarden.sh rebuild` or `./bitwarden.sh update` # # Next steps, run: # `./bitwarden.sh start`
## bitwardenを起動 ./bitwarden.sh start # [root@bitwarden bitwarden]# ./bitwarden.sh start # _ _ _ _ # | |__ (_) |___ ____ _ _ __ __| | ___ _ __ # | '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \ # | |_) | | |_ \ V V / (_| | | | (_| | __/ | | | # |_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_| # # Open source password management solutions # Copyright 2015-2021, 8bit Solutions LLC # https://bitwarden.com, https://github.com/bitwarden # # =================================================== # # bitwarden.sh version 1.38.4 # Docker version 19.03.13-ce, build 4484c46 # docker-compose version 1.27.4, build 40524192 # # Removing network docker_default # WARNING: Network docker_default not found. # Removing network docker_public # WARNING: Network docker_public not found. # Pulling mssql ... done # Pulling web ... done # Pulling attachments ... done # Pulling api ... done # Pulling identity ... done # Pulling sso ... done # Pulling admin ... done # Pulling portal ... done # Pulling icons ... done # Pulling notifications ... done # Pulling events ... done # Pulling nginx ... done # Using default tag: latest # latest: Pulling from certbot/certbot # Digest: sha256:ab08b65a2ed5a07496eab811a10220461cf71919f122a931b0a0ad2aeceab7c5 # Status: Image is up to date for certbot/certbot:latest # docker.io/certbot/certbot:latest # Saving debug log to /etc/letsencrypt/logs/letsencrypt.log # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Processing /etc/letsencrypt/renewal/bitwarden.tmlab.jp.conf # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Cert not yet due for renewal # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # The following certs are not due for renewal yet: # /etc/letsencrypt/live/bitwarden.tmlab.jp/fullchain.pem expires on 2021-04-04 (skipped) # No renewals were attempted. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Creating directory /opt/bitwarden/bwdata/core # Creating directory /opt/bitwarden/bwdata/core/attachments # Creating directory /opt/bitwarden/bwdata/logs # Creating directory /opt/bitwarden/bwdata/logs/admin # Creating directory /opt/bitwarden/bwdata/logs/api # Creating directory /opt/bitwarden/bwdata/logs/events # Creating directory /opt/bitwarden/bwdata/logs/icons # Creating directory /opt/bitwarden/bwdata/logs/identity # Creating directory /opt/bitwarden/bwdata/logs/mssql # Creating directory /opt/bitwarden/bwdata/logs/nginx # Creating directory /opt/bitwarden/bwdata/logs/notifications # Creating directory /opt/bitwarden/bwdata/logs/sso # Creating directory /opt/bitwarden/bwdata/logs/portal # Creating directory /opt/bitwarden/bwdata/mssql/backups # Creating directory /opt/bitwarden/bwdata/mssql/data # Creating network "docker_default" with the default driver # Creating network "docker_public" with the default driver # Creating bitwarden-notifications ... done # Creating bitwarden-attachments ... done # Creating bitwarden-identity ... done # Creating bitwarden-mssql ... done # Creating bitwarden-web ... done # Creating bitwarden-api ... done # Creating bitwarden-sso ... done # Creating bitwarden-icons ... done # Creating bitwarden-events ... done # Creating bitwarden-admin ... done # Creating bitwarden-portal ... done # Creating bitwarden-nginx ... done # 1.38.4: Pulling from bitwarden/setup # Digest: sha256:d982b81ac6fdb95b0da8744b30b965045b3176201f48903526c3c04d4c6cf972 # Status: Image is up to date for bitwarden/setup:1.38.4 # docker.io/bitwarden/setup:1.38.4 # # # Bitwarden is up and running! # =================================================== # # visit https://bitwarden.tmlab.jp # to update, run `./bitwarden.sh updateself` and then `./bitwarden.sh update`
サービスはコンテナを使用していますので、下記のように確認できます。
## コンテナ稼働確認 # [root@bitwarden bitwarden]# docker ps# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES # 0d7bd8578399 bitwarden/nginx:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 80/tcp, 0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp bitwarden-nginx # 49de573564d3 bitwarden/admin:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-admin # 91e2e7bc0f05 bitwarden/portal:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-portal # 711cb222e009 bitwarden/events:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-events # 9c4fc01f440a bitwarden/icons:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-icons # 1750c0242e76 bitwarden/sso:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-sso # 1d34a4bcb65c bitwarden/mssql:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) bitwarden-mssql # dd96e06d4781 bitwarden/web:2.17.1 "/entrypoint.sh" About a minute ago Up About a minute (healthy) bitwarden-web # b9bb5c4221a2 bitwarden/api:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-api # da98f8ba0e4e bitwarden/identity:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp bitwarden-identity # 31b9be47363b bitwarden/attachments:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) bitwarden-attachments # 021130e9dd5f bitwarden/notifications:1.38.4 "/entrypoint.sh" About a minute ago Up About a minute (healthy) 5000/tcp
https://bitwarden.example.jp にブラウザでアクセス。ログインページが表示されるはずです。
環境変数設定で、メールの設定をします。
## 環境変数設定(メール) vi bwdata/env/global.override.env # globalSettings__yubico__clientId=REPLACE # globalSettings__yubico__key=REPLACE # globalSettings__mail__replyToEmail=no-reply@bitwarden.example.jp # globalSettings__mail__smtp__host=mail.example.jp # globalSettings__mail__smtp__port=587 # globalSettings__mail__smtp__ssl=false # globalSettings__mail__smtp__username=hoge@example.jp # globalSettings__mail__smtp__password=[hoge@example.jpのパスワード] # globalSettings__disableUserRegistration=false
最後に
・ネットワーク設定(80ポートと443ポートのinを開ける)
設定を環境に合わせたものに設定しなおす
完成!
【記事への感想募集中!】
記事への感想・ご意見がありましたら、ぜひフォームからご投稿ください!【テクノデジタルではエンジニア/デザイナーを積極採用中です!】
下記項目に1つでも当てはまる方は是非、詳細ページへ!Qangaroo(カンガルー)
【テクノデジタルのインフラサービス】
当社では、多数のサービスの開発実績を活かし、
アプリケーションのパフォーマンスを最大限に引き出すインフラ設計・構築を行います。
AWSなどへのクラウド移行、既存インフラの監視・運用保守も承りますので、ぜひご相談ください。
詳細は下記ページをご覧ください。
最近の記事
タグ検索