Files
scrabble-game/deploy/caddy/Caddyfile
T
Ilia Denisov cf9fa75d62
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 14s
CI / ui (pull_request) Successful in 53s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m3s
fix(deploy): honeypot tag dropped — Caddy applies header_up delete after set
The @honeypot block both deleted and set X-Scrabble-Honeypot in one reverse_proxy.
Caddy applies header_up deletions *after* sets, so the tag we set was immediately
stripped: the gateway never saw it, and a decoy hit (e.g. GET /.env) fell through
to the gateway's /app redirect (308) instead of tripping the honeypot. Drop the
delete — the bare set already replaces any client-supplied value. The real
endpoints keep stripping the header in the @gateway block (delete-only, no
conflicting set). Caught on the live test contour (no caddy locally).
2026-06-21 09:02:23 +02:00

70 lines
2.8 KiB
Caddyfile

# Edge reverse proxy for the Scrabble contour. A single Basic-Auth gate covers
# every operator surface under /_gm (the backend-rendered admin console and the
# Grafana subpath); the game SPA (/app/, /telegram/) and the Connect edge go to
# the gateway; the catch-all — notably the public landing at / — goes to the
# static landing container, so stray traffic never reaches the Go edge.
# Mirrors ../galaxy-game's /_gm model.
#
# CADDY_SITE_ADDRESS is ":80" in the test contour (the host caddy terminates TLS
# and forwards); set it to a domain in prod so this caddy does its own
# ACME and the contour is self-contained.
{
admin off
# Trust X-Forwarded-For from private-range upstreams so the real client IP survives
# (chat moderation + per-IP rate limiting in the gateway). Test contour: the host caddy
# (a private IP) is trusted, so its forwarded client IP is preserved. Prod (no host caddy):
# clients connect from public IPs, which are NOT trusted, so Caddy uses the real peer —
# the same config is correct (and spoof-safe) in both contours.
servers {
trusted_proxies static private_ranges
}
}
{$CADDY_SITE_ADDRESS::80} {
# Operator surfaces under /_gm: a single shared Basic-Auth, then route.
@gm path /_gm /_gm/*
handle @gm {
basic_auth {
{$GM_BASICAUTH_USER:gm} {$GM_BASICAUTH_HASH}
}
# Grafana serves from this sub-path (GF_SERVER_SERVE_FROM_SUB_PATH=true), so
# the prefix is forwarded intact, not stripped.
handle /_gm/grafana* {
reverse_proxy grafana:3000
}
# Everything else under /_gm is the backend-rendered admin console.
handle {
reverse_proxy backend:8080
}
}
# The game SPA and the Connect edge are served by the gateway. Strip any
# client-supplied X-Scrabble-Honeypot here so the gateway only ever honours the
# tag the honeypot block sets below (a client cannot self-tag a real request).
@gateway path /app /app/* /telegram /telegram/* /scrabble.edge.v1.Gateway/*
handle @gateway {
reverse_proxy gateway:8081 {
header_up -X-Scrabble-Honeypot
}
}
# Honeypot decoy paths: classic vulnerability-scanner bait no real client ever
# requests. Route them to the gateway tagged with X-Scrabble-Honeypot — the set
# replaces any client-supplied value — so it logs the scanner hit and (in prod)
# bans the source IP. (A delete + set in one block would not work: Caddy applies
# header_up deletions after sets, which would strip the tag we just set; the real
# endpoints instead strip the header in the @gateway block above.) Keep this list
# disjoint from every legitimate landing/app path.
@honeypot path /.env /.git /.git/* /.aws/* /wp-login.php /wp-admin /wp-admin/* /phpmyadmin /phpmyadmin/*
handle @honeypot {
reverse_proxy gateway:8081 {
header_up X-Scrabble-Honeypot 1
}
}
# Everything else — the public landing at / and any stray path — is static.
handle {
reverse_proxy landing:80
}
}