Bitwardenのオンプレミス環境へのインストール
自分用にBitwardenのオンプレミス環境を作ってみたので,念のためメモとして残しておく。やったのはBitwardenをAWSのEC2インスタンスにインストールして自分のデバイスからアクセスする方法である。
<meta charSet="utf-8"/>ie=edgewidth=device-width, initial-scale=1, shrink-to-fit=noGatsby 5.11.0Bitwarden makes it easy for businesses and individuals to securely generate, store, and share passwords from any location, browser, or device. Create your free Bitwarden account today.password manager, credential manager, password security, open source password manager, self host password manager, business password manager, family password manager, team password manager, passkey security, passwordless authentication, browser password managerBitwardenThe password manager trusted by millions | BitwardenBitwarden makes it easy for businesses and individuals to securely generate, store, and share passwords from any location, browser, or device. Create your free Bitwarden account today.https://bitwarden.com/_gatsby/file/3f0bfa47d7a430e28ca9f4f1f7be835e/bitwarden-og-alt.png?eu=d7dc04b2b5ccfdd20c60a3876c726260e33806a3fc5137d26864e1fe4cad96d524a14b56289d2ee77d610c8ad5e347e96ec471331dbfd68fc2e818f6bf31f90f01d252ed61b57300542ac7a8e2f406176acf4809a58ac80ca23b2087e5e2e27910571673ec3ef8c2e6b62a3dedd27867a9a8f56a3393e83bb5561d4a954d35e363f9ce8d7544ef98b842a8e1f1aa518ffa9a5f593ea6a96920051f1f2fb476c8f3f1036e6d7f400a379aaf09c26694b5681c60250b5b52a13368d054a8393096e3ada155c62822a5ef987324d39db3dfba07fd7632f98f79fehttps://bitwarden.com/websiteen_USja_JPde_DEsummary_large_image@bitwardenen-USUS#175ddc インストール方法だが,以下にやり方が書いてる。ここで記載するのも基本そのままであり,あえて書くほどのハマりどころはない。重ねて書くが,あくまで自分用のメモである。
https://help.bitwarden.com/article/install-on-premise/
準備
AWSでbitwardenを使うに当たり必要になるのは以下3点。
- AWSのEC2インスタンス (メモリ2GB (=small) 以上)
→1GBだとMSSQLが起動しない - 当該ホストのDNSエントリ (Route 53で良い)
→Let’s Encryptの鍵生成時のホストの真正確認で必要 - メール送信用のSMTP接続情報 (Simple Email Serviceでよい)
→インストール時点では不要だが,利用の際はアカウント作成時にメールを送信するので,ないと実質使えない
EC2のインスタンスの作成
まずAWSのEC2にてインスタンスを作成する。2GBのメモリが必要とのことで,その中でも一番安いと思われるt3a.smallインスタンスを作成。ディスクは8GBにした。
インスタンスが作成されたらec2インスタンスにログイン。ログインしたらとりあえずパッケージの最新化を行っておく。
> ssh -i ~/.ssh/keys/****.pem ec2-user@xxx.xxx.xxx.xxx
$ sudo su -
# yum update
DNSエントリの作成
インスタンスが作成しIPアドレスが決まったら,Route 53あたりで手持ちのドメインで作成したインスタンスに対するDNSエントリを作成する。なぜ作る必要があるかというとcompute.amazonaws.comドメインのままだとインストール時に実行されるLet’s Encryptの鍵作成が受け付けてくれないからである。
xxx.xxx.xxx.xxx -> bitwarden.example.jp
SESの設定
Simple Email Service (SES) でメールが送信できるようにしておく。以前,設定した情報を今回はそのまま流用。具体的な手順は今回は省略する。
パラメータ | 値 |
---|---|
Server Name | email-smtp.us-east-1.amazonaws.com |
Port | 25, 465 or 587 |
Use Transport Layer Security (TLS) | Yes |
Authentication | (省略) |
インストール
Dockerのインストール
Dockerを用いてインストールするので,DockerとDocker Composeをインストールする。インストールしたらDockerを起動する。
# yum install docker
# sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# sudo chmod +x /usr/local/bin/docker-compose
# systemctl start docker
# systemctl enable docker
Bitwardenのインストール
次に,bitwardenのスクリプトをダウンロードし,インストールを実行する。
# mkdir -p /docker/bitwarden
# cd /docker/bitwarden/
# curl -Lso bitwarden.sh https://go.btwrdn.co/bw-sh \
&& chmod +x bitwarden.sh
# ./bitwarden.sh install
質問に対して自分の環境に応じた適当な値を設定していく。
Installation idとkeyは説明のとおり,https://bitwarden.com/host にアクセスし,利用者のメールアドレスを入力すれば取得することができる。
(蛇足だが,Do you want to use Let’s Encrypt to generate a free SSL certificate? に大文字の [Y] を入力して,鍵が設定されずnginxコンテナが起動しない罠にはまったのは内緒だ)
(!) Enter the domain name for your Bitwarden instance (ex. bitwarden.example.com): bitwarden.example.jp
(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): y
(!) Enter your email address (Let's Encrypt will send you certificate expiration reminders): user@example.jp
Using default tag: latest
latest: Pulling from certbot/certbot
Digest: sha256:d908a5d08108feac2a3a479b1bc7d3f33ff4648bc2dbfcde9d4510a57b3cc296
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
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for bitwarden.example.jp
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/bitwarden.example.jp/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/bitwarden.example.jp/privkey.pem
Your cert will expire on 2020-07-25. 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.33.1: Pulling from bitwarden/setup
68ced04f60ab: Pull complete
4ddb1a571238: Pull complete
94b78a0446e2: Pull complete
b48f8e1b0b06: Pull complete
a41ea3d79519: Pull complete
273fb6c3f096: Pull complete
2951cb34aa8c: Pull complete
70fc1c8b3720: Pull complete
ab76805e25d2: Pull complete
9ce92a8c0f20: Pull complete
Digest: sha256:ceaaa30350dca9dac12bf43e888947cec87633da4f0ab125e89a3e6f9d64ecdb
Status: Downloaded newer image for bitwarden/setup:1.33.1
docker.io/bitwarden/setup:1.33.1
(!) Enter your installation id (get at https://bitwarden.com/host): ********-****-****-****-************
(!) Enter your installation key: ********************
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`

Installation ID&Key取得 (1)

Installation ID&Key取得 (2)
設定変更・起動
これでインストールは完了。あとは動かすだけ。
動かすだけならほぼデフォルトで動くが,利用する上でメール送信が必要になるので,メールサーバの設定だけはやっておく。設定ファイルの変更でできるので,以下の通りの手順でパラメータを変更しておく。
vi bwdata/env/global.override.env
SMTP設定でREPLACEとなっているあたりを中心に,SMSの情報を設定する。
globalSettings__mail__smtp__host=email-smtp.us-east-1.amazonaws.com
globalSettings__mail__smtp__port=587
globalSettings__mail__smtp__ssl=false
globalSettings__mail__smtp__username=********
globalSettings__mail__smtp__password=********
これで準備完了のため,実際に起動し確認する。
# ./bitwarden.sh start
_ _ _ _
| |__ (_) |___ ____ _ _ __ __| | ___ _ __
| '_ \| | __\ \ /\ / / _` | '__/ _` |/ _ \ '_ \
| |_) | | |_ \ V V / (_| | | | (_| | __/ | | |
|_.__/|_|\__| \_/\_/ \__,_|_| \__,_|\___|_| |_|
Open source password management solutions
Copyright 2015-2020, 8bit Solutions LLC
https://bitwarden.com, https://github.com/bitwarden
===================================================
Docker version 19.03.6-ce, build 369ce74
docker-compose version 1.25.5, build 8a1c60f6
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 admin ... done
Pulling icons ... done
Pulling notifications ... done
Pulling events ... done
Pulling nginx ... done
Using default tag: latest
latest: Pulling from certbot/certbot
c9b1b535fdd9: Pull complete
2cc5ad85d9ab: Pull complete
756a868c4378: Pull complete
444b2fc9a129: Pull complete
ea15f1150254: Pull complete
2966bb4c2979: Pull complete
bef055e88bc6: Pull complete
12a9fc86916b: Pull complete
41db5b0d58d8: Pull complete
bc6b91fbba74: Pull complete
852b5bc6112d: Pull complete
Digest: sha256:d908a5d08108feac2a3a479b1bc7d3f33ff4648bc2dbfcde9d4510a57b3cc296
Status: Downloaded newer image for certbot/certbot:latest
docker.io/certbot/certbot:latest
Saving debug log to /etc/letsencrypt/logs/letsencrypt.logs
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
No renewals were attempted.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Creating network "docker_default" with the default driver
Creating network "docker_public" with the default driver
Creating bitwarden-events ... done
Creating bitwarden-icons ... done
Creating bitwarden-attachments ... done
Creating bitwarden-api ... done
Creating bitwarden-mssql ... done
Creating bitwarden-web ... done
Creating bitwarden-identity ... done
Creating bitwarden-notifications ... done
Creating bitwarden-admin ... done
Creating bitwarden-nginx ... done
1.33.1: Pulling from bitwarden/setup
Digest: sha256:ceaaa30350dca9dac12bf43e888947cec87633da4f0ab125e89a3e6f9d64ecdb
Status: Image is up to date for bitwarden/setup:1.33.1
docker.io/bitwarden/setup:1.33.1
Bitwarden is up and running!
===================================================
visit https://bitwarden.example.jp
to update, run `./bitwarden.sh updateself` and then `./bitwarden.sh update`
起動後,ブラウザでアクセスしてみるとこんな感じでログイン画面が表示される。あとは,ユーザーを作成し実際に使うだけ。

ログイン画面
蛇足
この状態でのディスク使用量は4.5G程度,使用メモリは1GB強。うーん,運用コストの関係でなんとかt3a.microインスタンスで動かしたいが,やはりMSSQLがネックになり,起動しない。なにかいい方法はないものか。