# Make Traefik trust the X-Forwarded-* headers that the host nginx sets. # # Without this, Traefik rewrites every forwarded header from its own connection, # which is plain HTTP on port 80. The application then sees scheme=http even # though the browser connected over TLS. See docs/two-hop-proxy-header-contract.md. # # k3s installs Traefik through its bundled HelmChart, so values are overridden # with a HelmChartConfig rather than by editing the deployment. k3s reconciles # the chart and recreates the Traefik pod. # # kubectl apply -f deploy/lab/k8s/traefik-forwarded-headers.yaml # kubectl -n kube-system rollout status deploy/traefik --timeout=180s apiVersion: helm.cattle.io/v1 kind: HelmChartConfig metadata: name: traefik namespace: kube-system spec: valuesContent: |- ports: web: forwardedHeaders: # Requests arriving from these sources keep their existing # X-Forwarded-* values instead of having them rewritten. # # 10.42.0.0/16 is the pod CIDR. It is required because the traefik # Service uses externalTrafficPolicy: Cluster, so svclb SNATs the # traffic and Traefik sees a pod-network address rather than the # host nginx address. # # The node/host range is deliberately absent. Because svclb SNATs, # the host nginx address never reaches Traefik — measured, not assumed. # Trusting a range that cannot appear only widens the surface. # # Trusting the whole pod CIDR still means any pod in the cluster could # forge these headers, which is why echo-network-policy.yaml restricts # who may reach the application at all. trustedIPs: - 10.42.0.0/16 websecure: forwardedHeaders: trustedIPs: - 10.42.0.0/16