| 1 | # UI Requests: Internet -> Caddy 8080 -> Frontend |
| 2 | # Backend Requests: Internet -> Caddy 8080 -> Auth Proxy -> Caddy 8081 -> Backend |
| 3 | |
| 4 | :8080 { |
| 5 | map {path} {target_host} {target_port} { |
| 6 | ~^/api/.* {$AUTH_PROXY_UPSTREAM_HOST} 8080 |
| 7 | ~^/oauth2/.* {$AUTH_PROXY_UPSTREAM_HOST} 8080 |
| 8 | default {$FRONTEND_UPSTREAM_HOST} 8080 |
| 9 | } |
| 10 | |
| 11 | reverse_proxy {target_host}:{target_port} { |
| 12 | header_down -Gap-Auth |
| 13 | } |
| 14 | |
| 15 | # Set security headers for UI responses |
| 16 | header { |
| 17 | X-Frame-Options "DENY" |
| 18 | +Content-Security-Policy "frame-ancestors 'none'" |
| 19 | } |
| 20 | |
| 21 | # Set security headers for API responses |
| 22 | header /api/* { |
| 23 | X-Content-Type-Options nosniff |
| 24 | +Content-Security-Policy "script-src 'none'" |
| 25 | +Cache-Control "no-store" |
| 26 | } |
| 27 | |
| 28 | # Set Cache-Control for UI assets |
| 29 | header /assets/* { |
| 30 | +Cache-Control "public, max-age=2592000, immutable" |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | # Caddy 8081 -> Backend |
| 35 | # We need this second block because the auth proxy |
| 36 | # does not pass the token on the right header due to |
| 37 | # kubernetes conventions. |
| 38 | :8081 { |
| 39 | reverse_proxy {$BACKEND_UPSTREAM_HOST}:8080 { |
| 40 | header_up Authorization "Bearer {header.X-Forwarded-Access-Token}" |
| 41 | } |
| 42 | } |