christensenjairus / Docker-Compose-Stack-for-Vaultwarden-Cloudflared

6 stars 0 forks source link

Docker-Compose Stack for Vaultwarden via a Cloudflare tunnel (On Linux or Mac)

image

Creates a Docker container stack of

  1. Vaultwarden Server
  2. Cloudflare tunnel

The Cloudflare tunnel allows for administration through Cloudflare to add a subdomain, HTTPS, access rules, and more, without the need for port forwarding, a firewall, or self-signed certs.

This is important because Vaultwarden won't let you log in without an encrypted connection (HTTPS), so a docker-compose stack with Cloudflare is one of the easiest methods for obtaining an HTTPS connection to an otherwise non-encrypted system.

Setup

Buy a Cloudflare domain

This is out of scope of this documentation, however obtaining a cloudflare domain is super simple. Create a cloudflare account and buy a domain here.

Following this README, you can run Vaultwarden on the root of this new domain or on a subdomain of your choice and have it be reachable to the outside world.

Clone this repository

The following command will create a folder in your home folder titled VaultWarden. This will contain the files from this repository and hopefully soon contain Vaultwarden's data. Note: Make sure to have git installed first.

git clone https://github.com/christensenjairus/Docker-Compose-Stack-for-Vaultwarden-Cloudflared.git ~/VaultWarden && cd ~/VaultWarden

Obtain a tunnel token

image

image

Add the token into docker-compose.yaml

In the docker-compose file, place the token on the following line.

    command: "tunnel --no-autoupdate run --token <token here!>"

Once done, it should look something like this

    command: "tunnel --no-autoupdate run --token eyJhIjoiYmNjMGFjZjYxZGM1Mzk2MzkxNjBhZjNhM2I4YTNjMTEiLCJ0IjoiYTg1YjczNWYtNTdjOC00ZGNmLTk2ZDgtMzkxNWEyNGI2OTAyIiwicyI6IllqRmxZV0ppTkRVdFlUazVNeTAwTlRjeExUZzNNekF0WWpZNFpqVm1NV1l5WldNNCJ9"

Edit where the VaultWarden data will be stored

By default, Vaultwarden will use the vw-data folder created when cloning this repo, as long as you run sudo docker-compose up -d while in the same folder as the docker-compose.yaml file.

If you’d like to store this data elsewhere, change the file path to the left of the colon (:) on the following line of docker-compose.yaml.

- ./vw-data:/data 

For example, this could be the following if I wanted it in Jacob’s Documents folder

- /home/jacob/Documents/VaultWarden_Data:/data

Run the Stack

cd into the same folder as the docker-compose.yaml file and run the following to create and run the docker stack. The -d flag means ‘run in the background’ and can be omitted for debugging so you can see the vaultwarden and cloudflare logs.

sudo docker-compose up -d

Verify the tunnel is working

image

image

image

image

image

Set up HTTPS redirects in Cloudflare

Visit the Cloudflare Dashboard, click on your website, then navigate with the left side panel to SSL/TLS > Overview. This page will look like this

image

image

Cronjob to Backup Vaultwarden's Data