Repository navigation
Operations
Running a deployment day to day: secrets, updates, backups, log growth and the checks that tell you when something has stopped.
Everything here runs on the instance, in /mnt/disks/bwgc/bitwarden_gcloud, unless it says otherwise:
gcloud compute ssh $INSTANCE --zone $ZONE
cd /mnt/disks/bwgc/bitwarden_gcloud
. ~/.bwgc-compose.sh
docker-compose is a shell function from that file, not a binary: Container-Optimized OS ships no compose. Non-interactive shells and ssh --command have to source it explicitly.
On a data-disk deployment bwgc-supervise.timer restarts stopped containers every five minutes. Stop it before any procedure that stops a container on purpose, as several below do.
.env holds SMTP credentials, the admin token, the backup encryption key and, on the tunnel path, the tunnel token.
Restrict it after you create it:
$ chmod 600 .env
The backup container mounts it read-only.
.env.template ships BACKUP_ENV=true, so .env is inside every archive along
with the admin token, the SMTP password and, on the tunnel path, the tunnel
token. Either set BACKUP_ENCRYPTION_KEY, or set BACKUP_ENV=false and accept
that a restore will not bring your settings back.
watchtower runs by default. Every Sunday at 03:00 (WATCHTOWER_SCHEDULE in
.env) it pulls new images and recreates the containers that use them.¹
It updates within the tag each image follows, and never changes the tag. The
project's own images (bwgc_backup, bwgc_caddy, bwgc_countryblock) follow
their major version, such as :1, from v3.1.0, so a rebuild or a compatible
change reaches you and a breaking one waits for a release here that moves the
tag.² Deployments on v3.0.0 follow :master, which
is still rebuilt for security fixes but also gets every merge to the image
repositories, released or not. Update to the newest release to move onto :1.
To have it report updates without applying them, set this in .env and bring
the stack up again:
WATCHTOWER_MONITOR_ONLY=true
Then apply updates yourself:
docker-compose pull && docker-compose up -d
Restore overwrites bitwarden/db.sqlite3 in place. Stop the vault first.
The backup container does not mount the Docker socket, so it cannot stop
bitwarden for you and cannot confirm that you have. It refuses to run rather
than overwrite a live database. RESTORE_FORCE=true is how you assert the vault
is stopped.
sudo systemctl stop bwgc-supervise.timer
docker-compose stop bitwarden
docker exec -it -e RESTORE_FORCE=true backup backup restore /data/backups/<backup-file>
docker-compose start bitwarden
sudo systemctl start bwgc-supervise.timer
Backups do not need the vault stopped. make_backup uses the SQLite online
backup API (sqlite3 .backup) so it can snapshot a live database while writes
are in progress, and it makes no Docker calls at all.
Container-Optimized OS has no cron. Instances built before the data-disk layout
apply staged updates through a GCE startup-script that runs
utilities/reboot-on-update.sh at every boot; the timer replaces it, and
migrate-to-data-disk.sh removes that metadata key.
Instances created by the current Installation page already have the timer, as
part of their user-data. Confirm rather than install:
gcloud compute ssh $INSTANCE --zone $ZONE --command 'systemctl list-timers cos-update-reboot.timer --no-pager'
To add it to an older instance, run this from Cloud Shell in the directory you
downloaded the scripts to. It prints a cloud-config and the gcloud command to
apply it, and installs nothing itself:
$ ~/bwgc/install-cos-update-reboot.sh
See utilities/README-cos-updates.md, which also explains why this does not move the host across COS milestones.
Moving to a newer milestone is a rebuild rather than an update, because a running instance never changes milestone on its own. The wiki page Upgrading Container-Optimized OS covers that, including moving the vault onto its own persistent disk so later upgrades are a disk reattach rather than a data migration.
Every service sets mem_limit and pids_limit, sized for an e2-micro with no
swap. They are ceilings, not reservations. If a container is killed under load,
raise its limit rather than removing it, and check usage with:
docker stats --no-stream
Caddy path only. On the tunnel path fail2ban does not run, because its bans
are iptables rules and no attacker packet reaches this host's network stack. See
fail2ban on the tunnel path.
The fail2ban container runs two jails against the vault log, bitwarden and
bitwarden-admin. Both read /bitwarden/bitwarden.log, which is mounted
separately and read-only.
Do not add a jail with backend = systemd. The image is Alpine-based and ships
no python systemd module, so such a jail cannot initialize, and fail2ban
aborts the whole server rather than skipping it. On one host this took the two
working vault jails down with it, leaving the login and admin pages without
brute-force protection for as long as the container crash-looped. The container
reports Restarting (255) in that state, and the reason appears only in
docker logs fail2ban.
Mounting the journal socket does not help, because the missing piece is the
python module rather than the socket. Container-Optimized OS also logs sshd
to journald, so there is no file for a polling backend to read. An sshd jail is
not achievable in this container. See the next section instead.
Check which jails are actually running:
docker exec fail2ban fail2ban-client status
docker exec fail2ban fail2ban-client status bitwarden
A new GCE instance allows tcp:22 from 0.0.0.0/0. The container changes in
this repository do not address that, and for the reasons above fail2ban cannot
either.
Two approaches, which combine:
-
Identity-Aware Proxy. Restrict
tcp:22to35.235.240.0/20, IAP's forwarding range, and connect withgcloud compute ssh INSTANCE --tunnel-through-iap. Port 22 stops being reachable from the public internet, access is authorised by IAM identity rather than by source address, and each tunnel is recorded in Cloud Audit Logs. Because it does not depend on where you connect from, it keeps working when your own address changes. -
Source address allowlist. Restrict
tcp:22to a known static address. Simpler, and sufficient if that address never moves. It locks you out when it does.
Whichever you choose, confirm the new path works from a second terminal while your existing session is still open, and only then remove the broad rule. The serial console is the recovery path if that ordering goes wrong.
vaultwarden writes to bitwarden/bitwarden.log on both paths. It has no log
rotation, and at its default info level it logs a request/response pair for
every HTTP call, so the file grows without bound. One deployment reached 595 MB
across 5.8 million lines before anyone noticed.
LOG_LEVEL now defaults to warn, which drops roughly 92% of the volume. Every
line the fail2ban filters match is logged at ERROR, so warn still matches
them on the Caddy path.
[error][ERROR] Username or password is incorrect. Try again. IP: ...
[vaultwarden::api::admin][ERROR] Invalid admin token. IP: ...
Set LOG_LEVEL=info in .env when you need request logging for debugging.
An existing oversized log is not truncated by this change. Clear it with the vault stopped, so vaultwarden reopens the file cleanly:
sudo systemctl stop bwgc-supervise.timer
docker-compose stop bitwarden
: > bitwarden/bitwarden.log
docker-compose start bitwarden
sudo systemctl start bwgc-supervise.timer
This reduces growth rather than bounding it. Bounding it properly needs a
logrotate sidecar using copytruncate, since vaultwarden does not reopen its
log file on rename.
Two failures in this stack produce no signal. An unsupported COS milestone keeps running and keeps looking healthy while receiving no security patches, and the in-milestone update timer correctly finds nothing. A backup that stops running raises no error, because cron discards script output.
The backup container checks both once a week and e-mails you through the
existing SMTP settings when either is wrong:
docker exec backup ash /backup.sh check
INFO: Newest backup is within 8 days: bw_backup_YYYY-MM-DD-HHMMSS.tar.gz.aes256
Container-Optimized OS milestone 109 is no longer supported.
...
A newer LTS milestone is available: cos-129-lts (currently on 109).
Support is determined by asking whether cos-<milestone>-lts still resolves.
Google withdraws the family pointer at end of support, so a 404 is the signal.
Note that this deliberately ignores image deprecation, which is set on every
individual build as a newer one supersedes it within a perfectly healthy
family, and would report live milestones as dead.
The check reads the Compute API through the instance's service account and needs
the compute.readonly scope. Instances created by the current Installation page
have it, from --scopes compute-ro. Adding it to an older instance requires
stopping it first, because scopes cannot be changed while it runs.
Configure with CHECK_SCHEDULE and BACKUP_MAX_AGE_DAYS in .env, or set
CHECK_SCHEDULE=disabled to turn it off. Repeat alerts are suppressed until
the situation changes.
Check that an archive decrypts and contains the database rather than assuming it does:
docker exec backup sh -c 'openssl enc -d -aes256 -salt -pbkdf2 \
-pass pass:"$BACKUP_ENCRYPTION_KEY" \
-in /data/backups/<backup-file> | tar tzf - | grep -v attachments/'
Expect db.sqlite3, the four rsa_key.* files, and .env when
BACKUP_ENV=true.
Run the scheduled job by hand to confirm delivery works end to end:
docker exec backup ash /backup.sh local
The method argument is required. Invoking backup with no argument creates the
archive but attempts no delivery and reports All backup methods failed, which
reads as a fault but is not one.
A backup container whose script fails to parse produces no backups and no
console error, because cron discards the output. One deployment ran eight
months that way after a syntax error was introduced into a locally built image.
Set BACKUP_EMAIL_NOTIFY=true, and check the newest timestamp in
bitwarden/backups/ from time to time:
$ ls -laht bitwarden/backups/ | head -3
1. This is how security rebuilds reach a deployment nobody logs into. The cost is trust: watchtower holds the Docker socket and deploys whatever a publisher pushes, unreviewed, so a compromised upstream image would reach the host.
2. Third-party images follow their publishers' floating tags (vaultwarden/server:latest-alpine, crazymax/fail2ban:latest, linuxserver/ddclient, and cloudflare/cloudflared:latest on the tunnel path), so those publishers decide what reaches you. watchtower itself is pinned to a release and moves only when this project's docker-compose.yml does.
- Installation
- Configuration
- Backup, required
- Email Providers, required
- DDNS, required on the Caddy path
- Countryblock (Caddy path)
- Fail2ban (Caddy path)
- Automatic Restarts
- Maintenance