Self-hosting Vaultwarden, an open-source Bitwarden-compatible server, provides complete control over your password data. Combining Vaultwarden with Cloudflare Tunnel creates a highly secure, private, and accessible password management solution without exposing any ports directly to the internet. This setup leverages Cloudflare's global network and Zero Trust capabilities to protect your instance from direct attacks and provide encrypted access from any location, as of 2026-04.
Cloudflare Tunnel establishes an outbound-only connection from your server to Cloudflare's edge, effectively bypassing traditional firewall configurations and port forwarding. This guide walks through deploying Vaultwarden using Docker Compose and securing its access via a Cloudflare Tunnel, ensuring your digital vault remains protected.
Why Self-Host Vaultwarden with Cloudflare Tunnel?
Self-hosting your password manager offers unparalleled control over your sensitive data, removing reliance on third-party cloud providers. Vaultwarden, a lightweight Rust implementation of the Bitwarden server API, uses minimal resources, making it ideal for deployment on a small Virtual Private Server (VPS).
Integrating Cloudflare Tunnel enhances this self-hosted setup significantly. It eliminates the need to open firewall ports, a common security vulnerability, by proxying all traffic through Cloudflare's infrastructure. This architecture inherently protects your server from direct IP-based attacks and scans. Cloudflare also handles TLS encryption, ensuring all data transmitted between your clients and Vaultwarden is secured with modern cryptography, typically TLS 1.3 as of 2026-04.
Using Cloudflare Tunnel for Vaultwarden means your server never directly faces the internet, significantly reducing its attack surface. This zero-trust approach isolates your self-hosted application from public internet threats.
Furthermore, Cloudflare's Zero Trust platform allows you to implement granular access policies for your Vaultwarden instance. You can restrict access based on user identity, device posture, or geographic location, adding an extra layer of authentication before traffic even reaches your server. This contrasts sharply with traditional VPNs, which provide network-level access rather than application-specific protection.
Prerequisites for Your Secure Vaultwarden Deployment
Before beginning the installation, ensure you have the following prerequisites in place. These foundational elements are crucial for a smooth and secure deployment of Vaultwarden via Cloudflare Tunnel.
- A Virtual Private Server (VPS): A Linux-based VPS with at least 1GB RAM and 20GB SSD storage is generally sufficient for Vaultwarden. Ubuntu 24.04 LTS is a recommended operating system for its stability and extensive package support. Providers such as Valebyte offer robust VPS options suitable for self-hosting. For initial server hardening, refer to the Ubuntu 24.04 VPS Hardening Checklist.
- A Domain Name: You need a domain name (e.g.,
passwords.yourdomain.com) that is managed by Cloudflare. This is essential for Cloudflare Tunnel to route traffic correctly. - Docker and Docker Compose: These tools simplify the deployment and management of containerized applications like Vaultwarden. Docker Engine 25.0.x and Docker Compose v2.24.x are stable versions as of 2026-04.
- SSH Access: You need SSH access to your VPS with a user account that has
sudoprivileges.
Confirming these prerequisites before starting saves troubleshooting time later. For a comparison of popular Linux distributions for VPS hosting, you might consider reading Debian vs Ubuntu for VPS Hosting.
Step-by-Step: Installing Docker and Docker Compose
Docker provides an efficient way to deploy Vaultwarden in an isolated environment. Docker Compose orchestrates multi-container Docker applications. Here's how to install them on an Ubuntu 24.04 LTS VPS.
- Update System Packages: Always start by updating your package lists and upgrading any installed packages to their latest versions. This ensures you have access to the most current software and security patches.
sudo apt update && sudo apt upgrade -y - Install Necessary Dependencies: Install packages that allow
aptto use repositories over HTTPS.sudo apt install -y ca-certificates curl gnupg lsb-release - Add Docker's Official GPG Key: Docker packages are signed with a GPG key. Add this key to your system to verify the authenticity of Docker packages.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg - Add Docker Repository: Configure your
aptsource to include the Docker repository.echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - Install Docker Engine: Now, install Docker Engine, Containerd, and Docker Compose (CLI plugin). The command installs the latest stable versions available from the repository.
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - Verify Docker Installation: Run a simple test to ensure Docker is installed correctly and the Docker service is running.
sudo docker run hello-worldYou should see a message indicating that your Docker installation is working. For more details on Docker installation, consult the official Docker documentation for Ubuntu.
- Add Your User to the Docker Group (Optional but Recommended): To run Docker commands without
sudo, add your user to thedockergroup. Remember to log out and log back in for this change to take effect.sudo usermod -aG docker $USER
Setting Up Cloudflare Tunnel for Secure Access
Cloudflare Tunnel allows you to connect your Vaultwarden instance to Cloudflare's network without opening any inbound ports. This ensures all traffic is routed securely through Cloudflare's infrastructure.
- Install the
cloudflaredClient: Download and install the Cloudflare Tunnel daemon on your VPS. As of 2026-04, the client version 2026.4.x is recommended.curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb
sudo cloudflared -v - Authenticate
cloudflared: Authenticate thecloudflaredclient with your Cloudflare account. This command will provide a URL to open in your browser, where you select your domain.cloudflared tunnel loginUpon successful authentication,
cloudflaredsaves a certificate file (cert.pem) to your~/.cloudflared/directory. - Create a Cloudflare Tunnel: Name your tunnel and create it. Replace
vaultwarden-tunnelwith a descriptive name.cloudflared tunnel create vaultwarden-tunnelThis command generates a Tunnel ID and a credentials file (e.g.,
~/.cloudflared/<TUNNEL-ID>.json). Note the Tunnel ID for later use. - Configure the Tunnel: Create a configuration file (e.g.,
~/.cloudflared/config.yml) for your tunnel. This file defines how the tunnel routes traffic to your Vaultwarden instance. Replace<TUNNEL-ID>with your actual Tunnel ID andpasswords.yourdomain.comwith your chosen domain.tunnel: <TUNNEL-ID>
credentials-file: /home/<YOUR-USER>/.cloudflared/<TUNNEL-ID>.json
ingress:
- hostname: passwords.yourdomain.com
service: http://localhost:8080
originRequest:
noTLSVerify: true
- service: http_status:404The
service: http://localhost:8080directs Cloudflare Tunnel to forward requests forpasswords.yourdomain.comto port 8080 on your local server, where Vaultwarden will be listening.noTLSVerify: trueis typically used here because Cloudflare Tunnel is handling the public-facing TLS, and the connection to localhost is often plain HTTP or a self-signed certificate, which the tunnel can bypass for simplicity and performance. - Create DNS Record for the Tunnel: Point your chosen subdomain to your tunnel. This command automatically creates a CNAME record in your Cloudflare DNS settings. Replace
passwords.yourdomain.comandvaultwarden-tunnel.cloudflared tunnel route dns vaultwarden-tunnel passwords.yourdomain.com - Run the Tunnel as a Service: Deploy the tunnel as a systemd service to ensure it starts automatically on boot and runs persistently. This command installs a systemd unit file.
sudo cloudflared tunnel run vaultwarden-tunnelThis command also starts the tunnel. You can check its status using
sudo systemctl status cloudflared@vaultwarden-tunnel. For comprehensive details on setting up Cloudflare Tunnel, refer to the Cloudflare Tunnel documentation.
Deploying Vaultwarden with Docker Compose
With Docker and Cloudflare Tunnel configured, the next step is to deploy Vaultwarden itself. Using Docker Compose simplifies the setup of Vaultwarden, its database, and persistent storage.
- Create a Project Directory: Create a directory for your Vaultwarden project and navigate into it.
mkdir ~/vaultwarden
cd ~/vaultwarden - Create
docker-compose.yml: Create a file nameddocker-compose.ymlwithin this directory. This file defines your Vaultwarden service.version: '3.8'
services:
vaultwarden:
image: vaultwarden/server:latest
container_name: vaultwarden
restart: always
ports:
- "8080:80"
volumes:
- ./vw-data:/data
environment:
# Set the URL where Vaultwarden will be accessible
- WEBSOCKET_ENABLED=true
- ROCKET_TLS=false # Cloudflare Tunnel handles TLS
- DOMAIN=https://passwords.yourdomain.com
# Optional: Admin token for management interface (highly recommended)
- ADMIN_TOKEN=your_strong_admin_token_hereReplace
passwords.yourdomain.comwith your actual domain and set a strongADMIN_TOKEN. TheROCKET_TLS=falsesetting is crucial because Cloudflare Tunnel handles SSL termination at the edge, forwarding plain HTTP to your local Vaultwarden container on port 80 (which is mapped to 8080 on the host). The./vw-data:/datavolume ensures your Vaultwarden data (database, attachments, etc.) persists outside the container, making upgrades and backups straightforward. - Deploy Vaultwarden: Start your Vaultwarden container using Docker Compose.
docker compose up -dThe
-dflag runs the container in detached mode, allowing it to run in the background. Docker will pull thevaultwarden/server:latestimage if it's not already present and then start the container. - Verify Vaultwarden Status: Check that your Vaultwarden container is running successfully.
docker compose ps
docker compose logs vaultwardenYou should see the Vaultwarden container listed as
Up, and the logs should indicate it's listening on port 80. For more configuration options, the Vaultwarden Wiki on GitHub provides extensive details.
Configuring Cloudflare Zero Trust Policies (Optional but Recommended)
Cloudflare Zero Trust Access adds an additional layer of security, requiring users to authenticate before they can even reach your Vaultwarden instance. This is a robust way to protect sensitive applications.
- Navigate to Cloudflare Zero Trust Dashboard: Log in to your Cloudflare account and go to the Zero Trust dashboard.
- Create an Application: Under the 'Access' section, select 'Applications' and then 'Add an application'. Choose 'Self-hosted' and provide your Vaultwarden domain (e.g.,
passwords.yourdomain.com). - Define Access Policies: Create policies to control who can access your Vaultwarden application. For example, you can:
- Require specific email addresses or domains: Only allow users with an
@yourdomain.comemail. - Require MFA: Enforce multi-factor authentication for access.
- Filter by IP address: Restrict access to specific IP ranges (e.g., your home or office network).
A common policy is to allow access only to specific email addresses or groups, requiring users to authenticate via an identity provider (IdP) like Google, Microsoft, or a one-time PIN sent to their email. For detailed guidance on setting up these policies, refer to the Cloudflare Zero Trust documentation.
- Require specific email addresses or domains: Only allow users with an
- Test Access: After setting up policies, try accessing your Vaultwarden URL (e.g.,
https://passwords.yourdomain.com) in a browser. You should be redirected to a Cloudflare Access login page before being granted access to Vaultwarden. This ensures your policies are correctly enforced.
Maintaining and Updating Your Vaultwarden Instance
Regular maintenance and updates are essential for the security and performance of your self-hosted Vaultwarden instance. This includes updating the Docker image and performing routine backups of your data.
Updating Vaultwarden
To update Vaultwarden to the latest version, you simply need to pull the new Docker image and recreate the container. Your persistent data volume (./vw-data) ensures that your passwords and settings remain intact.
- Navigate to Your Vaultwarden Directory:
cd ~/vaultwarden - Pull the Latest Image: This command fetches the newest version of the Vaultwarden Docker image.
docker compose pull - Recreate and Restart the Container: This command stops the old container, removes it, and starts a new one using the updated image, all while preserving your data volume.
docker compose up -d - Clean Up Old Images (Optional): To free up disk space, you can remove old, unused Docker images.
docker image prune
Backup Strategy
Your Vaultwarden data is stored in the ~/vaultwarden/vw-data directory on your VPS. Regularly backing up this directory is critical for disaster recovery. A simple backup strategy involves compressing this directory and transferring it to a secure offsite location.
cd ~/vaultwarden
sudo tar -czvf vaultwarden_backup_$(date +%Y%m%d).tar.gz vw-data/
# Transfer vaultwarden_backup_YYYYMMDD.tar.gz to a secure offsite storage
# Example: scp vaultwarden_backup_$(date +%Y%m%d).tar.gz user@remotehost:/backups/Consider automating this backup process using a cron job. For general best practices in self-hosting maintenance and updates, exploring resources like the Self-Host Ghost CMS on Ubuntu 24.04: A Detailed Tutorial can provide broader context on managing self-hosted applications.
Conclusion
Deploying a self-hosted Vaultwarden instance with Cloudflare Tunnel provides a robust, secure, and private password management solution. By leveraging Docker for easy deployment and Cloudflare's zero-trust network for secure access, you maintain full control over your sensitive data without compromising on accessibility or security. This setup eliminates the need for complex firewall rules and offers advanced protection against direct internet threats, as demonstrated in this 2026 guide.





