You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.7 KiB
Markdown

5 years ago
# Bitwarden_rs in docker
###### guide by example
5 years ago
![logo](https://i.imgur.com/tT3FQLJ.png)
5 years ago
4 years ago
# Purpose
5 years ago
Password manager. RS version is simpler and lighter than the official bitwarden.
* [Official site](https://bitwarden.com/)
* [Github](https://github.com/dani-garcia/bitwarden_rs)
5 years ago
* [DockerHub](https://hub.docker.com/r/bitwardenrs/server)
5 years ago
4 years ago
# Files and directory structure
5 years ago
```
/home
└── ~
└── docker
└── bitwarden
├── 🗁 bitwarden-data
├── 🗋 .env
├── 🗋 docker-compose.yml
└── 🗋 bitwarden-backup-script.sh
```
4 years ago
# docker-compose
5 years ago
[Documentation](https://github.com/dani-garcia/bitwarden_rs/wiki/Using-Docker-Compose) on compose.
`docker-compose.yml`
```
version: "3"
services:
bitwarden:
image: bitwardenrs/server
hostname: bitwarden
container_name: bitwarden
restart: unless-stopped
5 years ago
env_file: .env
5 years ago
volumes:
- ./bitwarden-data/:/data/
networks:
default:
external:
name: $DEFAULT_NETWORK
```
`.env`
```
# GENERAL
MY_DOMAIN=blabla.org
DEFAULT_NETWORK=caddy_net
TZ=Europe/Prague
# BITWARDEN
ADMIN_TOKEN=YdLo1TM4MYEQ948GOVZ29IF4fABSrZMpk9
4 years ago
SIGNUPS_ALLOWED=false
4 years ago
WEBSOCKET_ENABLED=true
5 years ago
# USING SENDGRID FOR SENDING EMAILS
5 years ago
DOMAIN=https://passwd.blabla.org
5 years ago
SMTP_SSL=true
SMTP_EXPLICIT_TLS=true
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=465
SMTP_USERNAME=apikey
SMTP_PASSWORD=SG.MOQQegA3bgfodRN4IG2Wqwe.s23Ld4odqhOQQegf4466A4
SMTP_FROM=admin@blabla.org
```
5 years ago
**All containers must be on the same network**.</br>
If one does not exist yet: `docker network create caddy_net`
4 years ago
# Reverse proxy
5 years ago
4 years ago
Caddy v2 is used, details [here.](https://github.com/DoTheEvo/Caddy-v2-docker-example-setup)</br>
5 years ago
Bitwarden_rs documentation has a [section on reverse proxy.](https://github.com/dani-garcia/bitwarden_rs/wiki/Proxy-examples)
`Caddyfile`
```
{
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
passwd.{$MY_DOMAIN} {
5 years ago
header / {
X-XSS-Protection "1; mode=block"
X-Frame-Options "DENY"
X-Robots-Tag "none"
-Server
}
5 years ago
encode gzip
reverse_proxy /notifications/hub/negotiate bitwarden:80
reverse_proxy /notifications/hub bitwarden:3012
reverse_proxy bitwarden:80
}
```
4 years ago
# Forward port 3012 TCP on your router
5 years ago
4 years ago
[WebSocket](https://youtu.be/2Nt-ZrNP22A) protocol is used for notifications,
so that all web based clients can immediatly sync when a change happens on server.
5 years ago
4 years ago
* Enviromental variable `WEBSOCKET_ENABLED=true` needs to be set.</br>
* Reverse proxy needs to route `/notifications/hub` to port 3012.</br>
* Router needs to **forward port 3012** to docker host,
4 years ago
same as port 80 and 443 are forwarded.
To test if websocket works, have the desktop app open
and make changes through browser extension, or through the website.
Changes should immediatly appear in the desktop app. If it is not working,
you need to manually sync for changes to appear.
4 years ago
# Extra info
5 years ago
4 years ago
**bitwarden can be managed** at `<url>/admin` and entering `ADMIN_TOKEN`
set in the `.env` file. Especially if signups are disabled it is the only way
to invite users.
5 years ago
4 years ago
**push notifications**
5 years ago
---
5 years ago
![interface-pic](https://i.imgur.com/5LxEUsA.png)
4 years ago
# Update
5 years ago
5 years ago
* [watchtower](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/watchtower) updates the image automaticly
5 years ago
* manual image update</br>
`docker-compose pull`</br>
`docker-compose up -d`</br>
`docker image prune`
4 years ago
# Backup and restore
5 years ago
5 years ago
* **backup** using [borgbackup setup](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
that makes daily snapshot of the entire directory
5 years ago
* **restore**</br>
down the bitwarden container `docker-compose down`</br>
delete the entire bitwarden directory</br>
from the backup copy back the bitwarden directortory</br>
start the container `docker-compose up -d`
4 years ago
# Backup of just user data
5 years ago
4 years ago
User-data daily export using the [official procedure.](https://github.com/dani-garcia/bitwarden_rs/wiki/Backing-up-your-vault)</br>
4 years ago
For bitwarden_rs it means sqlite database dump and backing up `attachments` directory.</br>
4 years ago
Daily run of [borg backup](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
takes care of backing up the directory.
So only database dump is needed.
The created backup sqlite3 file is overwriten on every run of the script,
but that's ok since borg backup is making daily snapshots.
5 years ago
5 years ago
* **create a backup script**</br>
5 years ago
placed inside `bitwarden` directory on the host
5 years ago
`bitwarden-backup-script.sh`
5 years ago
```
5 years ago
#!/bin/bash
5 years ago
# CREATE SQLITE BACKUP
5 years ago
docker container exec bitwarden sqlite3 /data/db.sqlite3 ".backup '/data/BACKUP.bitwarden.db.sqlite3'"
5 years ago
```
5 years ago
the script must be **executabe** - `chmod +x bitwarden-backup-script.sh`
5 years ago
* **cronjob** on the host</br>
`crontab -e` - add new cron job</br>
`0 2 * * * /home/bastard/docker/bitwarden/bitwarden-backup-script.sh` - run it [at 02:00](https://crontab.guru/#0_2_*_*_*)</br>
`crontab -l` - list cronjobs
4 years ago
# Restore the user data
5 years ago
5 years ago
Assuming clean start.
* start the bitwarden container: `docker-compose up -d`
* let it run so it creates its file structure
* down the container `docker-compose down`
* in `bitwarden/bitwarden-data/`</br>
5 years ago
replace `db.sqlite3` with the backup one `BACKUP.bitwarden.db.sqlite3`</br>
4 years ago
replace `attachments` directory with the one from the borg backup repository
5 years ago
* start the container `docker-compose up -d`
5 years ago