- TLS termination: where to terminate TLS (Gateway vs upstream) and how to present a trusted certificate to clients.
- Redirects: configuring HTTP-to-HTTPS redirects to ensure traffic is encrypted.
- Reference grants: enabling cross-namespace references (for example, a Gateway referencing a Secret in another namespace) securely.
Tip: Use a consistent namespace strategy for Gateways, Secrets, and backend workloads. When components must be in different namespaces, use ReferenceGrant to give explicit access rather than granting broad cluster-wide permissions.
1 — TLS termination: Gateway vs upstream
Why it matters- Terminating TLS at the Gateway simplifies certificate management and allows features like routing, redirects, and Layer 7 filters to inspect traffic.
- Terminating TLS at the backend (upstream passthrough) preserves end-to-end encryption but reduces the Gateway’s ability to perform HTTP-level processing.
- Terminate at Gateway when you must inspect or route based on HTTP fields, offload certificate rotation, or integrate with policies (WAF, rate limiting).
- Use passthrough when backend services require end-to-end TLS (client certs) or when you must preserve the original TLS session.
- Use short-lived certificates and automate rotation with a tool like cert-manager.
- Prefer TLS termination at the Gateway for most web-facing services; use passthrough only where required.
- Restrict Secret access with least privilege and keep Secrets in the smallest set of namespaces needed.
- Gateway API TLS docs: https://gateway-api.sigs.k8s.io/
- cert-manager: https://cert-manager.io/
2 — Enforce HTTP-to-HTTPS redirects
Why redirect- Ensures all clients use encrypted connections.
- Prevents accidental exposure of sensitive data via HTTP.
- Use statusCode 301 (permanent) or 302/307 depending on requirements. For SEO and permanent change, 301 is typical.
- Combine redirects with HSTS to instruct browsers to always use HTTPS:
- Add a response header like
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadvia a ResponseHeaderModifier filter if supported by your controller.
- Add a response header like
Be careful when enabling global 301 redirects during testing. Browsers cache 301 redirects — an incorrect redirect can be cached and difficult to undo during development.
3 — ReferenceGrant: cross-namespace references (Secrets, Services)
Problem- Gateways often need to reference objects that live in a different namespace (for example, a TLS Secret in
appsreferenced by a Gateway ingateway-namespace). - Kubernetes restricts cross-namespace references by default; you must explicitly grant permission using a ReferenceGrant located in the namespace of the referenced object.
- A ReferenceGrant must be created in the namespace of the resource being referenced (e.g., where the Secret lives).
- It contains
fromentries (who is allowed to reference) andtoentries (which local resources are allowed to be referenced).
gateway-namespace to reference a Secret in apps
- Place this ReferenceGrant in the
appsnamespace (the namespace ofmy-tls-secret). - The Gateway in
gateway-namespacecan now referencemy-tls-secretinappsviacertificateRefsin its spec.
- Only grant the minimum set of
fromidentities required. - Scope the
toentries to the specific Secret names rather than allowing all Secrets. - Audit ReferenceGrant objects regularly.
Quick comparison table
Links and references
- Gateway API (official): https://gateway-api.sigs.k8s.io/
- Kubernetes Secrets: https://kubernetes.io/docs/concepts/configuration/secret/
- cert-manager (certificate automation): https://cert-manager.io/
That’s it for this lesson. Use the examples as templates and adapt them to your namespace layout, controller implementation, and security policy.