Skip to content

Case Study: Self-Hosted Cloud & Vault Protection (Vaultwarden & Nextcloud) ​

This case study demonstrates how to secure critical self-hosted services like Vaultwarden (Bitwarden-compatible password manager) and Nextcloud without interfering with day-to-day mobile synchronization or public file sharing.


The Threat Model: Vaultwarden ​

Vaultwarden is one of the most popular self-hosted password managers. To allow mobile apps and browser extensions to sync passwords, the /api/* and /identity/* endpoints must be reachable over the internet.

However, the /admin portal (which allows creating/deleting accounts, viewing server logs, and changing master secrets) represents an existential security risk if probed by external attackers.

The Objective ​

  1. Public Traffic: Can reach /api/*, /identity/*, and the web vault for ordinary password synchronization.
  2. Admin Portal (/admin): Fully locked down and invisible (returning 404 Not Found) unless the connection originates from a trusted internal VPN subnet (e.g., Tailscale 100.64.0.0/10 or WireGuard).

Configuration (Traefik, Caddy & NGINX) ​

File:
# dynamic_conf.ymlhttp:  middlewares:    vaultwarden-shield:      plugin:        routewarden:          enabled: true          methods:            - GET            - POST            - PUT            - DELETE            - PATCH            - HEAD          enableDefaultPatterns: true          # Intercept the administrative console          blockPatterns:            - '(?i)^/admin(/.*)?$'          # Allow ONLY internal WireGuard & Tailscale VPN addresses          allowedIps:            - "100.64.0.0/10"   # Tailscale CGNAT range            - "10.8.0.0/24"     # WireGuard VPN subnet            - "127.0.0.1"       # Localhost          response:            mode: json            statusCode: 404            body: '{"error":"Not Found","message":"The requested resource was not found"}'  routers:    vault-router:      rule: "Host(`vault.example.com`)"      entryPoints:        - websecure      middlewares:        - vaultwarden-shield      service: vault-service

Advanced Architecture: Public Vaultwarden with "Send Only" Allowed ​

A common security requirement is exposing only the Bitwarden Send feature to public recipients while keeping the rest of the vault (user login, vault sync, ciphers, and admin console) strictly private to your VPN.

The Challenge with Password-Protected Sends ​

When a recipient unlocks a password-protected Send, the client sends a POST request to /identity/connect/token with grant_type=send_access. A full vault login also targets /identity/connect/token with grant_type=password.

Solution with Zero-Trust Allowlisting and check_body ​

Using Routewarden's allowlisting and request body inspection across Caddy, Traefik, and NGINX:

  1. Zero-Trust Allowlist (allow_patterns / allowPatterns): Permit strictly public Send viewing (/api/sends/*), the token unlock API (/identity/connect/token), and frontend static assets.
  2. Default-Deny Catch-All (block_patterns / blockPatterns): Catch-all regex (?i)^/.*$ blocks all unlisted routes—including the root path /, vault sync, ciphers, and admin panel.
  3. Payload Inspection (check_body & check_body_patterns): Guard /identity/connect/token by blocking (?i)grant_type=password while permitting grant_type=send_access.
  4. VPN Subnets (allowed_ips / allowedIps): Trusted Tailscale / WireGuard subnets bypass the catch-all block, retaining full vault access for authorized users.

Gateway Configuration (Traefik, Caddy & NGINX) ​

File:
# dynamic.ymlhttp:  middlewares:    vaultwarden-send-only:      plugin:        routewarden:          enabled: true          enableDefaultPatterns: true          methods:            - GET            - POST          # 1. Zero-Trust Allowlist: permit strictly public Send viewing and unlock APIs          allowPatterns:            - '(?i)^/api/sends(/.*)?$'            - '(?i)^/identity/connect/token$'            - '(?i)^/(app|images|fonts|locales|scripts)(/.*)?$'            - '(?i)^/(favicon\.ico|manifest\.json)$'          # 2. Catch-all: default-deny all other routes (blocks root web vault, sync, ciphers, admin)          blockPatterns:            - '(?i)^/.*$'          # 3. Inspect POST body payloads on /identity/connect/token to block password logins          checkBody: true          checkBodyPatterns:            - '(?i)grant_type=password'          # 4. Trusted VPN subnets bypass all restrictions          allowedIps:            - "100.64.0.0/10"            - "10.8.0.0/24"            - "127.0.0.1"          response:            mode: json            statusCode: 404            body: '{"error":"Not Found","message":"The requested resource was not found"}'  routers:    vault-router:      rule: "Host(`vault.example.com`)"      entryPoints:        - websecure      middlewares:        - vaultwarden-send-only      service: vaultwarden-service

Testing with Routewarden CLI (rwarden) ​

Validate rules offline before deploying:

test-commands.shbash
# 1. Test public password-protected Send unlock (Allowed)rwarden test -c routewarden.json -X POST /identity/connect/token -b "grant_type=send_access"# 2. Test root web vault access (Blocked by Default-Deny)rwarden test -c routewarden.json -X GET /# 3. Test public vault login attempt (Blocked by checkBody)rwarden test -c routewarden.json -X POST /identity/connect/token -b "grant_type=password&username=admin"# 4. Test VPN client bypassing restriction (Allowed)rwarden test -c routewarden.json -X POST /identity/connect/token -b "grant_type=password&username=admin" --ip 100.64.1.20

Verification Matrix ​

ActionPath & MethodPayloadPublic ClientVPN Client (allowed_ips)
Public Send AccessGET /api/sends/{id}N/A✅ Allowed✅ Allowed
Password Send UnlockPOST /identity/connect/tokengrant_type=send_access✅ Allowed✅ Allowed
Root Web Vault AccessGET /N/A❌ Blocked (404)✅ Allowed
User Vault Login AttemptPOST /identity/connect/tokengrant_type=password❌ Blocked (404)✅ Allowed
Vault Sync / Cipher TheftGET /api/syncN/A❌ Blocked (404)✅ Allowed
Admin Panel AccessGET /adminN/A❌ Blocked (404)✅ Allowed

Released under the MIT License.