fix: gate Grafana ingress forward-auth annotation on site opt-in - #320
fix: gate Grafana ingress forward-auth annotation on site opt-in#320amdove wants to merge 3 commits into
Conversation
The Grafana Helm ingress unconditionally stamped the kube-system-traefik-forward-auth-main / -add-forwarded-headers middleware annotation. Those middlewares are only created by the clusters step when a site sets use_traefik_forward_auth: true, so on workloads that don't enable forward-auth the ingress referenced a non-existent middleware and Traefik invalidated the router (HTTP 404). Only add the annotation when the main site opts into forward-auth; otherwise Grafana routes straight through to its local-account login. Regression from the eks/cluster Python->Go migration (ae26379), which folded the previously-unconditional global traefik-forward-auth middleware into per-site, flag-gated logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…orward-auth-gate # Conflicts: # lib/steps/helm_aws_test.go
|
Claude finished @amdove's task in 1m 16s —— View job Code Review
The fix is correct and the extraction is clean. A few observations:
The The doc comment is multi-line and its first sentence ( // Adds the traefik-forward-auth middleware annotation only when the main site
// opts in — the middlewares are deployed by the clusters step only when
// use_traefik_forward_auth is set, so adding the annotation unconditionally
// causes a Traefik 404 on workloads without forward-auth.
func grafanaIngressValues(...) ...That said, this is a minor style point; the existing comment is still accurate and useful.
Test coverage is solid: flag-on, flag-off, no-main-site, nil-sites, and basic structural values. One gap worth noting: there's no test that verifies Correctness The known edge case (forward-auth annotation emitted when Overall this is a correct, well-scoped fix. The concerns above are minor. |
Description
Grafana's in-cluster ingress returned HTTP 404 on workloads that don't enable traefik-forward-auth. The Grafana Helm ingress always stamped a
traefik.ingress.kubernetes.io/router.middlewaresannotation referencing thekube-system-traefik-forward-auth-mainandkube-system-traefik-forward-auth-add-forwarded-headersmiddlewares. Those middlewares are only created by theclustersstep when a site setsuse_traefik_forward_auth: true, so on workloads without forward-auth the ingress referenced a non-existent middleware and Traefik invalidated the router.The annotation is now gated on the
mainsite's opt-in. When forward-auth is not enabled, Grafana routes straight through to its local-account login.Root cause
Regression from the eks/cluster Python→Go migration (commit
ae26379), which folded the previously-unconditional globaltraefik-forward-authmiddleware into per-site, flag-gated logic — but the Grafana ingress kept stamping the annotation unconditionally. It surfaced onacademy01-production(the only workload reaching Grafana via the publicgrafana.*ingress; others port-forward) after its cluster-version bump re-ran the Go steps.Code Flow
The ingress-map construction in
awsHelmGrafana(lib/steps/helm_aws.go) is extracted into a pure helpergrafanaIngressValues(domain, sites). It builds the base ingress (enabled,hosts,path) and only adds theannotationskey with the two-middleware string whensites["main"]is present andSpec.UseTraefikForwardAuthis true. Production behavior is byte-for-byte identical to the prior unconditional path when the flag is set.Known edge case
The annotation is gated only on
main'suse_traefik_forward_auth, but thetraefik-forward-auth-mainmiddleware it references also requires the cluster to settraefik_forward_auth_version(theclustersstep only deploys forward-auth when that version is present). Souse_traefik_forward_auth: trueonmainwithout atraefik_forward_auth_versionwould still emit the annotation with no middleware behind it — i.e. the same 404 this PR fixes. This isn't reachable in current config (the workloads that enable forward-auth also set the version) and isn't a regression (the old unconditional code 404'd in that case too), so it's left as-is rather than plumbing the cluster components into the helper.Test plan
TestGrafanaIngressValuesinlib/steps/helm_aws_test.gocovers: flag on → annotation present and equals the exact two-middleware string; flag off → no annotation; nomainsite → no annotation; nil sites → no annotation; and basichosts/path/enabledvalues.go test ./steps/...passes.Category of change
Checklist