それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

bitwardenのインストール

bitwardenを動かしてみる。

構成、Ubuntu 20.04 に lxc コンテナを用意し、lxc コンテナ内部に docker インストール、docker 上に bitwarden を入れた

bitwarden on docker on lxc on ubuntu 20.04 です

lxc の準備

snap install lxc 

LXC 仮想マシン準備

name=bitwarden
lxc launch ubuntu:20.04 $name --storage bt01
lxc config set $name security.privileged true
lxc config set $name security.nesting true
lxc restart $name
lxc shell $name

docker 準備

apt update 
apt upgrade -y 
apt install docker-compose -y
docker run --rm hello-world

作業用ディレクト

cd 
mkdir sample 
cd sample

bitwarden サーバー

curl -s -o bitwarden.sh \    https://raw.githubusercontent.com/bitwarden/server/master/scripts/bitwarden.sh \
    && chmod +x bitwarden.sh
./bitwarden.sh install
./bitwarden.sh start

インストールID

https://bitwarden.com/hostにアクセス

  • Installation Id: a5dd017f-ca06-xxxxx
  • Installation Key: mPYQiuxxxx

インストールIDを生成してインストールを認証して持らう。

再インストール

再インストールや失敗時にやり直す場合は、先にbwdataを除去しておく。

rm -rf bwdata
./bitwarden.sh install

バックアップ

./biwarden stop
rclone bwdata xx:/backup

証明書

証明書は、letsencrypt を certbot するけど、自動取得がNAT内部だと動かないので、最初は自己署名証明書にしておくのがベター

自分インストールの物を使う。

Chromeの拡張で自分のサーバーを使うには、次のボタンを押す。

インストールのログ

root@bitwarden:~/sample# ./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.42.3
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1
docker-compose version 1.25.0, build unknown

(!) Enter the domain name for your Bitwarden instance (ex. bitwarden.example.com): bit.exampmle.com

(!) Do you want to use Let's Encrypt to generate a free SSL certificate? (y/n): n

(!) Enter the database name for your Bitwarden instance (ex. vault):

1.42.3: Pulling from bitwarden/setup
Digest: sha256:a85998defed50c28dcd477c1b196df9282e0f46c18dfb5d0f5378833fe02f81e
Status: Image is up to date for bitwarden/setup:1.42.3
docker.io/bitwarden/setup:1.42.3

(!) Enter your installation id (get at https://bitwarden.com/host): a5dd017f-ca06-xxx-xxx-xxxxxxxx

(!) Enter your installation key: mPYQiuHnxxxxxxxxx

(!) Do you have a SSL certificate to use? (y/n): n

(!) Do you want to generate a self-signed SSL certificate? (y/n): y

Generating self signed SSL certificate.
Generating a RSA private key
..................++++
...........................................................................................................................................................................................................................................................................++++
writing new private key to '/bitwarden/ssl/self/bit.example.com/private.key'
-----
Generating key for IdentityServer.
Generating a RSA private key
...................................++++
.........................................++++
writing new private key to 'identity.key'
-----

!!!!!!!!!! WARNING !!!!!!!!!!
You are using an untrusted SSL certificate. This certificate will not be
trusted by Bitwarden client applications. You must add this certificate to
the trusted store on each device or else you will receive errors when trying
to connect to your installation.

Building nginx config.
Building docker environment files.
Building docker environment override files.
Building FIDO U2F app id.
Building Asset Links For Fido2.
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`

起動チェック

起動したら、IPアドレスへアクセスする。 http://docker-nginx.local:8080/ にアクセスして起動チェックする。

ポートフォワーディング

docker コンテナへのポートフォワーディングを設定する。

リッスンするポートをここで指定する。

bitwarden/bwdata/config.yml

url: https://mybitwarden.example.tld
generate_compose_config: true
generate_nginx_config: true
http_port: 11080
https_port: 11443
compose_version:
captcha: false
ssl: false

ssl は letsencrypt でできるが、証明書の管理は面倒くさいので、cloudflareで受けるか、自前のnginxでSSLリバースプロキシを構成した。

管理者メールとメール設定

ログインと新規登録、パスワード紛失時のリカバリにメールを使うのでSMTPサーバーを設定する。

管理者ログイン(といってもユーザーの削除くらいしかできない、ユーザーのデータを見ることは出来ない)

bitwarden/bwdata/env/global.override.env

globalSettings__mail__replyToEmail=mybitwarden@example.tld
globalSettings__mail__smtp__host=smtp.example.tld
globalSettings__mail__smtp__port=465
globalSettings__mail__smtp__ssl=true
globalSettings__mail__smtp__username=mybitwarden@example.tld
globalSettings__mail__smtp__password=XXX_smtp_password_XXX
globalSettings__disableUserRegistration=true
globalSettings__hibpApiKey=REPLACE
adminSettings__admins=admin-user@example.tld

ドメイン名+SSL経由でアクセスする

あとは、リバースプロキシを設置してドメイン名でアクセスできるように設定する。

これは、インストールではないので、割愛。

bitwarden self-hostedの制限事項

organization ( 組織 ) は作れない。この点を除けば通常の利用とほぼ同じである。

ファイルの添付もできないが、ほとんど困らない。キャッシュカード、マイナンバーカードや、免許証などは、写真で添付せずに番号を入れておけばいいだけだ。