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
- Public Traffic: Can reach
/api/*,/identity/*, and the web vault for ordinary password synchronization. - Admin Portal (
/admin): Fully locked down and invisible (returning404 Not Found) unless the connection originates from a trusted internal VPN subnet (e.g., Tailscale100.64.0.0/10or WireGuard).
Configuration (Traefik, Caddy & NGINX)
# 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-serviceAdvanced 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:
- Zero-Trust Allowlist (
allow_patterns/allowPatterns): Permit strictly public Send viewing (/api/sends/*), the token unlock API (/identity/connect/token), and frontend static assets. - 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. - Payload Inspection (
check_body&check_body_patterns): Guard/identity/connect/tokenby blocking(?i)grant_type=passwordwhile permittinggrant_type=send_access. - 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)
# 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-serviceTesting with Routewarden CLI (rwarden)
Validate rules offline before deploying:
# 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.20Verification Matrix
| Action | Path & Method | Payload | Public Client | VPN Client (allowed_ips) |
|---|---|---|---|---|
| Public Send Access | GET /api/sends/{id} | N/A | ✅ Allowed | ✅ Allowed |
| Password Send Unlock | POST /identity/connect/token | grant_type=send_access | ✅ Allowed | ✅ Allowed |
| Root Web Vault Access | GET / | N/A | ❌ Blocked (404) | ✅ Allowed |
| User Vault Login Attempt | POST /identity/connect/token | grant_type=password | ❌ Blocked (404) | ✅ Allowed |
| Vault Sync / Cipher Theft | GET /api/sync | N/A | ❌ Blocked (404) | ✅ Allowed |
| Admin Panel Access | GET /admin | N/A | ❌ Blocked (404) | ✅ Allowed |