diff --git a/.env.example b/.env.example index ecbbb27..c8fd6aa 100644 --- a/.env.example +++ b/.env.example @@ -28,6 +28,14 @@ OPER_MASK=* # --- internal ports (rarely need to change) --- SSL_PORT=6697 WS_PORT=8080 +# Caddy reaches obbyircd's websocket port from WS_PROXY_IP on its own +# network, and obbyircd takes each web client's IP from the +# X-Forwarded-For header Caddy sends from that address only. Change both +# if the subnet collides with a network on the host, and keep WS_PROXY_IP +# at the top of the subnet because Docker hands obbyircd the lowest free +# address when it starts first. +# WS_PROXY_SUBNET=10.213.71.0/29 +# WS_PROXY_IP=10.213.71.6 # --- optional features --- # Filehost is configured at runtime in obbyircd.conf via: diff --git a/compose.yaml b/compose.yaml index 5e76bfc..60efc48 100644 --- a/compose.yaml +++ b/compose.yaml @@ -28,6 +28,7 @@ services: - ${VOICE_BRIDGE_BIND:-/data/obby/voice-bridge}:/run/obbyirc environment: WS_PORT: "${WS_PORT:-8080}" + WS_TRUSTED_PROXIES: ${WS_PROXY_IP:-10.213.71.6} SSL_PORT: "${SSL_PORT:-6697}" VOICE_BRIDGE_SOCKET: /run/obbyirc/voice.sock VOICE_TURN_EXTERNAL_URLS: ${VOICE_TURN_EXTERNAL_URLS:-} @@ -47,6 +48,11 @@ services: timeout: 5s retries: 6 start_period: 30s + networks: + default: + websocket: + aliases: + - obbyircd-websocket labels: - traefik.enable=true - traefik.http.routers.obbyircd-invite.rule=Host(`${INVITE_FQDN}`) @@ -65,6 +71,10 @@ services: configs: - source: caddyfile target: /etc/caddy/Caddyfile + networks: + default: + websocket: + ipv4_address: ${WS_PROXY_IP:-10.213.71.6} labels: - traefik.enable=true - traefik.http.routers.obby-edge.rule=Host(`${API_FQDN}`) @@ -162,18 +172,34 @@ services: - traefik.http.routers.panel.tls.certresolver=letsencrypt - traefik.http.services.panel.loadbalancer.server.port=8080 +# Caddy reaches obbyircd's websocket port over this network from one fixed +# address, so obbyircd can trust the client IP Caddy forwards from that +# address alone. +networks: + websocket: + internal: true + ipam: + config: + - subnet: ${WS_PROXY_SUBNET:-10.213.71.0/29} + configs: caddyfile: content: | { auto_https off admin off + servers { + trusted_proxies static private_ranges + trusted_proxies_strict + } } :80 { @websocket { header Connection *Upgrade* header Upgrade websocket } - reverse_proxy @websocket obbyircd:${WS_PORT:-8080} + reverse_proxy @websocket obbyircd-websocket:${WS_PORT:-8080} { + header_up X-Forwarded-For {client_ip} + } reverse_proxy obby-api:8080 }