diff --git a/hermes_squid/brencher-state-proxy.conf b/hermes_squid/brencher-state-proxy.conf new file mode 100644 index 0000000..eae3142 --- /dev/null +++ b/hermes_squid/brencher-state-proxy.conf @@ -0,0 +1,74 @@ +# nginx config for the brencher-state-proxy sidecar. +# +# Path-locked reverse proxy for the brencher /state endpoint: +# - /state -> proxied to https://brencher.rudolf.keenetic.link/state +# - everything else -> 403 Forbidden +# +# This lets hermes-agent reach /state without going through squid's +# host-level allowlist (which can't see inside TLS) and without exposing +# the rest of brencher's surface area. +# +# Listen on 8443 with a self-signed cert (mounted via docker secrets +# 'brencher_state_tls_cert' / 'brencher_state_tls_key'). Clients connect +# with `curl -k` or accept the cert via a trusted CA bundle. +# +# Upstream is the public URL on purpose -- the sidecar reaches the public +# brencher.rudolf.keenetic.link through the nginx-ingress overlay the same +# way any external client would, which means it doesn't need to be on the +# brencher container's private networks. + +server { + listen 8443 ssl; + server_name _; + + ssl_certificate /run/secrets/brencher_state_tls_cert; + ssl_certificate_key /run/secrets/brencher_state_tls_key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + # Tiny access log; default nginx format + access_log /var/log/nginx/brencher-state-access.log; + error_log /var/log/nginx/brencher-state-error.log warn; + + # Healthcheck for swarm -- not /state, deliberately, so a 200 here + # doesn't accidentally imply /state is reachable from outside the + # allowlist. + location = /healthz { + access_log off; + return 200 "ok\n"; + add_header Content-Type text/plain; + } + + # The only allowed path. Exact match: query strings or trailing + # anything else fall through to the default 403. + location = /state { + proxy_pass https://brencher.rudolf.keenetic.link/state; + proxy_http_version 1.1; + + # The upstream is HTTPS; the sidecar trusts the LE-issued cert + # via the system CA bundle. + proxy_ssl_server_name on; + proxy_ssl_name brencher.rudolf.keenetic.link; + + proxy_set_header Host brencher.rudolf.keenetic.link; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + + proxy_connect_timeout 5s; + proxy_read_timeout 30s; + proxy_send_timeout 10s; + + # Don't cache -- state should be live. + proxy_buffering off; + add_header Cache-Control "no-store" always; + } + + # Catch-all: deny everything else, including /state/ (with trailing + # slash), /state?foo=bar (with query), and any other path. + location / { + access_log off; + return 403 "forbidden: only /state is allowed through this proxy\n"; + add_header Content-Type text/plain; + } +} diff --git a/hermes_squid/squid.conf b/hermes_squid/squid.conf index 4ef06a8..9ef2de6 100644 --- a/hermes_squid/squid.conf +++ b/hermes_squid/squid.conf @@ -1,7 +1,7 @@ acl hermes_network src 10.0.0.0/8 acl hermes_network src 172.16.0.0/12 acl hermes_network src 192.168.0.0/16 -acl allowed_domains dstdomain .minimax.io .minimax.chat .minimax.com .githubusercontent.com deb.debian.org gitea.rudolf.keenetic.link +acl allowed_domains dstdomain .minimax.io .minimax.chat .minimax.com .githubusercontent.com deb.debian.org gitea.rudolf.keenetic.link brencher.rudolf.keenetic.link acl CONNECT method CONNECT acl SSL_ports port 443 acl Safe_ports port 80 443 diff --git a/hermes_squid/stack-compose.yml b/hermes_squid/stack-compose.yml index a5e54ec..01209d9 100644 --- a/hermes_squid/stack-compose.yml +++ b/hermes_squid/stack-compose.yml @@ -155,6 +155,40 @@ services: delay: 5s max_attempts: 3 + + brencher-state-proxy: + # Path-locked reverse proxy for brencher.rudolf.keenetic.link/state. + # Lets hermes-agent reach /state without going through squid (which + # can't see inside TLS) and without exposing the rest of brencher. + # See hermes_squid/brencher-state-proxy.conf for the path rules. + image: nginx:alpine + hostname: brencher-state-proxy + networks: + - admin # so hermes_infra services can reach it + - nginx_ingress # so it can reach brencher.rudolf.keenetic.link via the LE front-proxy + configs: + - source: brencher_state_proxy_conf + target: /etc/nginx/conf.d/brencher-state-proxy.conf + secrets: + - source: brencher_state_tls_cert + target: brencher_state_tls_cert + - source: brencher_state_tls_key + target: brencher_state_tls_key + ports: + - target: 8443 + published: 8443 + protocol: tcp + deploy: + mode: replicated + replicas: 1 + placement: + constraints: + - node.hostname == odroid # must run where the secret is mounted (and where the public ingress routes back to) + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + networks: hermes_proxy: driver: overlay @@ -165,12 +199,16 @@ networks: admin: driver: overlay attachable: true + nginx_ingress: + external: true configs: squid_conf: file: ./squid.conf nginx_hermes_conf: file: ./nginx-hermes.conf + brencher_state_proxy_conf: + file: ./brencher-state-proxy.conf volumes: squid_etc: @@ -178,3 +216,9 @@ volumes: squid_reports: hermes_gateway_data: hermes_agent_data: + +secrets: + brencher_state_tls_cert: + external: true + brencher_state_tls_key: + external: true