ghp: serve plain HTTP behind the gateway (fix redirect loop) #361
Reference in New Issue
Block a user
Delete Branch "benvin/ghp-reverse-proxy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
https://ghp.unkin.net/ 308-loops onto itself. The traefik gateway terminates TLS and forwards cleartext to the ghp Service port 80 -> container :8080, but :8080 was
GHP_SERVER_HTTP_LISTEN— ghp's http->https 308 redirect listener. So ghp bounced every request back to https, the gateway re-forwarded it to :8080, and it looped forever.Root cause (confirmed against ghp source)
internal/server/server.goRun()picks the serving mode:It is strictly either/or.
serveTLSserves the app onHTTPSListenand givesHTTPListenonlyhttpsRedirectHandler()(redirect.go:http.StatusPermanentRedirect= 308).servePlainserves the same full handler onListenin cleartext (createListener()usescfg.Server.Listen). The mgmt UI is the samehandlerin both modes, so it IS served on the plainListenport.Behind a TLS-terminating gateway that forwards cleartext to :8080, ghp therefore has to run in plain mode. Keeping
GHP_SERVER_HTTPS_LISTENwould keephasTLStrue, leaveGHP_SERVER_LISTENignored, and nothing would serve cleartext on :8080.Change
GHP_SERVER_HTTPS_LISTENandGHP_SERVER_HTTP_LISTEN; setGHP_SERVER_LISTEN: ":8080"so :8080 SERVES the app; addGHP_SERVER_TRUST_PROXY_HEADERS: "true"so ghp trusts the gateway'sX-Forwarded-*/Forwardedfor scheme/host (GHP_SERVER_BASE_URLalready set).hasTLSis true (Run()gatesloadTLSConfigonhasTLS); in plain mode it is cleartext, so the/metricsliveness/readiness probes and the VMServiceScrape switch from HTTPS/https to HTTP/http.Service, HTTPRoute and Gateway are unchanged. configmap+deployment carry the stakater reloader annotation, so pods roll on the change.
Deviation from the brief
The brief said to keep
GHP_SERVER_HTTPS_LISTEN: ":8443". Source shows that is incompatible with serving cleartext on :8080 (the two modes are mutually exclusive), so this drops it. The unusedGHP_TLS_CERT_FILE/KEY_FILE, thetlsvolume, and containerPort 8443 are left in place (harmless) for an easy revert to TLS mode. The alternative — gateway -> Service 443 -> :8443 with a BackendTLSPolicy — is the bigger change flagged in the brief and is NOT taken here.Validated:
kustomize build apps/overlays/au-syd1/ghpclean, kubeconform 0 invalid/0 errors, pre-commit clean. Not applied.