Self-Hosting Vaultwarden Without Trusting the Defaults
Executive Summary
Vaultwarden, the Rust-based implementation of the Bitwarden server API, offers a low-footprint alternative to the official C++ server. While its ease of deployment is a primary attraction, the default configuration prioritizes convenience over security, particularly regarding organizational structure and data isolation. In a self-hosted homelab environment, the default allowance for public organization creation transforms a personal password manager into an unauthenticated public registry. This guide details the hardening of Vaultwarden using Docker Compose, focusing on disabling public registration, enforcing strict network boundaries, and implementing robust backup strategies. We address the critical distinction between user accounts and organizations, ensuring that the infrastructure remains private by default. The approach leverages environment variables for configuration, avoiding mutable file systems where possible, and utilizes SQLite WAL mode for performance without compromising data integrity.
Implementation
The deployment strategy relies on a single docker-compose.yml file that encapsulates the application, database, and reverse proxy integration. The core security measure is the SIGNUPS_ALLOWED environment variable, which must be explicitly set to false. Without this, any individual with network access can create an organization and invite others, effectively bypassing the intended single-user or closed-group model.
We utilize SQLite with Write-Ahead Logging (WAL) enabled. This provides concurrency benefits over the default journal mode while maintaining the simplicity of a single file. The database file is persisted in a named volume to survive container restarts.
version: '3.8'
services:
vaultwarden:
image: vaultwarden/server:latest
container_name: vaultwarden
restart: unless-stopped
environment:
# CRITICAL: Disable public signups and org creation
SIGNUPS_ALLOWED: "false"
ADMIN_TOKEN: "<GENERATE_SECURE_RANDOM_STRING_HERE>"
# Enable WAL for better concurrency and crash recovery
DATABASE_URL: "/data/db.sqlite3"
# Optional: Set a specific domain for email links
DOMAIN: "https://vault.example.com"
# Optional: Limit org creation to admin only (requires paid plan or specific config)
# In Vaultwarden, org creation is tied to SIGNUPS_ALLOWED.
# If SIGNUPS_ALLOWED is false, only admins can create orgs.
volumes:
- vaultwarden_data:/data
- ./attachments:/data/attachments
- ./icons:/data/icons
ports:
- "127.0.0.1:8080:80"
networks:
- vault_net
volumes:
vaultwarden_data:
driver: local
networks:
vault_net:
driver: bridge
The ADMIN_TOKEN is essential for accessing the administrative dashboard at /admin. This token must be generated using a cryptographically secure random generator and stored in a secure password manager. The port mapping restricts access to localhost initially, assuming a reverse proxy (like Nginx or Caddy) handles TLS termination and external traffic. This separation of concerns ensures that Vaultwarden never directly handles HTTPS, reducing the attack surface.
ShVaSa Intuition
The fundamental vulnerability in default Vaultwarden configurations is the conflation of identity and infrastructure. By allowing public organization creation, the server implicitly trusts the network layer to authenticate intent. In a homelab, this trust is misplaced. The ShVaSa approach decouples these concerns by enforcing a "zero-trust" default for organizational boundaries.
When SIGNUPS_ALLOWED is set to false, the system shifts from an open registry to a closed directory. This is not merely a UI change; it alters the API response codes and internal logic for user creation. The intuition here is that in a sovereign self-hosted environment, the administrator is the sole source of truth for user identity. Any mechanism that allows external actors to define organizational structures introduces lateral movement risks. If an attacker gains access to one organization, they cannot automatically pivot to others unless explicitly invited. By disabling public org creation, we ensure that the "org" concept remains an administrative construct rather than a user-facing feature.
Furthermore, the use of SQLite WAL mode is not just a performance tweak; it is a data integrity safeguard. In the event of a power loss or container kill signal, WAL mode ensures that the database log is properly checkpointed, preventing corruption that could lock out the administrator. This aligns with the principle of operational resilience in resource-constrained environments.
sequenceDiagram
participant Client as User Client
participant Nginx as Reverse Proxy (TLS)
participant VW as Vaultwarden (App)
participant DB as SQLite (WAL)
Client->>Nginx: GET /health (Public)
Nginx->>VW: Forward Request
VW-->>Nginx: 200 OK
Nginx-->>Client: 200 OK
Client->>Nginx: POST /api/accounts/register
Note over Client, VW: SIGNUPS_ALLOWED=false
VW-->>Nginx: 400 Bad Request
Nginx-->>Client: 400 Bad Request
Admin->>Nginx: POST /api/admin/users (with Admin-Token)
Nginx->>VW: Forward Request
VW->>DB: INSERT User
DB-->>VW: Success
VW-->>Nginx: 201 Created
Nginx-->>Admin: 201 Created
Operational Pitfalls and Backup Strategies
A common pitfall is the neglect of attachment storage. Vaultwarden stores password attachments (files, images) in the /data/attachments directory. If this directory is not persisted in a volume, all attachments are lost on container restart. Similarly, the db.sqlite3 file must be backed up regularly.
For backups, we recommend a simple script that copies the database file and the attachments directory to a separate, encrypted storage location. This should be scheduled via cron or a systemd timer.
#!/bin/bash
# backup_vaultwarden.sh
BACKUP_DIR="/path/to/secure/backup"
DATE=$(date +%Y%m%d_%H%M%S)
DB_PATH="/path/to/docker/volumes/vaultwarden_data/_data/db.sqlite3"
ATTACH_PATH="/path/to/docker/volumes/vaultwarden_data/_data/attachments"
mkdir -p "$BACKUP_DIR/$DATE"
cp "$DB_PATH" "$BACKUP_DIR/$DATE/"
cp -r "$ATTACH_PATH" "$BACKUP_DIR/$DATE/"
# Encrypt the backup
gpg --symmetric --cipher-algo AES256 "$BACKUP_DIR/$DATE/db.sqlite3"
rm "$BACKUP_DIR/$DATE/db.sqlite3"
# Keep only last 7 backups
find "$BACKUP_DIR" -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
Security best practices also include rotating the ADMIN_TOKEN periodically and ensuring that the reverse proxy enforces HSTS and secure headers. The Vaultwarden server itself should never be exposed directly to the internet; it must always sit behind a reverse proxy that handles TLS termination, rate limiting, and IP whitelisting if necessary. This layered defense ensures that even if the application layer has vulnerabilities, the network layer provides additional protection.
Grounding & Source Attribution
- Original Topic: Self-Hosting Vaultwarden Without Trusting the Defaults
- Primary Author / Dispatcher: Traven via Dev.to
- Curated and Synthesized by: ShVaSa Lab (Sharath Japa)
- Preserved Canonical URL: https://shvasa.us/posts/self-hosting-vaultwarden-without-trusting-the-defaults