Join our Newsletter — 33% off our NHI Course
Home› Guides› Kubernetes Gateway API Security Guide: Route Delegation, ReferenceGrant…
Guide Cloud Security

Kubernetes Gateway API Security Guide: Route Delegation, ReferenceGrant and TLS Done Safely

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 13 min read
On this page

The Kubernetes Gateway API splits ingress ownership across infrastructure providers, cluster operators and application teams, and every boundary between those roles is a place where a route, a certificate or a hostname can be claimed by the wrong namespace. This guide explains the security model behind GatewayClass, Gateway, routes and ReferenceGrant, and sets out the RBAC, delegation, admission and TLS settings that keep a shared Gateway from becoming a shared weakness.

Many teams are adopting the Gateway API as part of moving off Ingress NGINX. If you are planning that move, the Ingress NGINX Retirement guide covers timelines, inventory and migration options. This page assumes you have chosen the Gateway API and focuses on running it securely. General gateway controls such as token validation and rate limiting are covered in the API Gateway Security Guide and are not repeated here.

Key takeaways

  • The Gateway API is role oriented. The Gateway API security model assigns GatewayClass to infrastructure providers, Gateways to cluster operators and Routes to application developers, and recommends RBAC that follows those roles.
  • Every namespace crossing needs a two-sided handshake: allowedRoutes on the Gateway listener, and a ReferenceGrant in the namespace that owns the target Secret or Service.
  • Hostname conflicts between routes are usually resolved first come, first served, so an older route can hold a hostname another team expected to own. Delegate hostnames per listener or enforce them with admission policy.
  • Creating a Gateway is a privileged action because it can create load balancers and DNS records. Restrict it, and restrict who can write Gateway status.
  • TLS has three parts: listener certificates for clients, BackendTLSPolicy for re-encryption to backends, and optional client certificate validation at the Gateway. Each references Secrets or ConfigMaps that must be protected as credentials.

The resource model and its trust boundaries

The Gateway API replaces the single Ingress object with layered resources, each meant for a different owner.

  • GatewayClass is cluster scoped and names the controller that implements Gateways of that class. Different classes often mean different exposure, for example one class for internal load balancers and another for internet-facing ones.
  • Gateway is a namespaced request for traffic handling infrastructure. The Gateway API documentation states that a Gateway's lifecycle is tied to its infrastructure, and that depending on the class the controller may create a cloud load balancer, start a software proxy or program the network.
  • Listeners on a Gateway define hostnames, ports, protocols, TLS settings and which routes may attach.
  • Routes (HTTPRoute, GRPCRoute, TLSRoute and others) attach to a Gateway listener and send traffic to backends, usually Services.
  • ReferenceGrant lives in a target namespace and permits specific kinds of resources in another namespace to reference objects there.

The trust boundaries follow from this. The GatewayClass owner trusts the controller. The Gateway owner decides which namespaces can attach routes. The route owner decides where traffic goes, but cannot reach another namespace's Service or Secret without that namespace's consent. Security reviews should test each of those handoffs, because a weak one exposes every application behind the Gateway.

RBAC by role

The Gateway API security model focuses on write access because most roles can read all resources. In its simple three-tier model, infrastructure providers write GatewayClass, Gateway and Route; cluster operators write Gateway and Route; application developers write Route only. An advanced four-tier model adds an application admin who can write Gateways and Routes in specified namespaces only.

Turn that into concrete rules:

  • GatewayClass: create, update and delete for the platform team only, through a ClusterRole bound to a group, not to individuals.
  • Gateway: create and update for cluster operators, or for named application admins in their own namespaces. Never include Gateway write rights in the default edit style roles you hand to application teams.
  • Gateway status: the security model tells administrators to prevent regular users from modifying Gateway status. The gateways/status subresource should be writable only by the controller's service account.
  • Routes: application teams write routes in their own namespaces. Avoid ClusterRoles that grant route write rights across all namespaces.
  • ReferenceGrant: treat creation as a security decision. The security model suggests a ValidatingAdmissionPolicy to control who can create grants.

Review the controller's own identity too. The Gateway controller runs with a service account that can read Secrets referenced by listeners, update status and, for some classes, create cloud resources through a cloud identity. It is one of the most powerful non-human identities in the cluster. Check its bindings with kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa>, and see the Kubernetes RBAC Guide for scoping patterns.

Route delegation with allowedRoutes

Route attachment is the first handshake. A route names a parent Gateway, and optionally a listener section, but it only attaches if the listener's allowedRoutes accepts it. The namespaces.from field takes Same, All, Selector or None, and defaults to Same, which limits attachment to the Gateway's own namespace. Listeners can also restrict the route kinds they accept.

Practical rules:

  • Avoid from: All on shared Gateways. It lets any namespace, including ones created tomorrow, attach routes to your public entry point.
  • Select namespaces by name label. The security model notes that only kubernetes.io/metadata.name is reliably set on every namespace. Custom labels such as env: prod are riskier, because anyone who can label namespaces can change which namespaces the Gateway accepts.
  • Restrict namespace labelling. If you must use custom labels, make sure only the platform team can patch namespaces.
  • Limit route kinds per listener. An HTTPS listener should accept HTTPRoute, not TCPRoute, so a team cannot bypass HTTP layer policy by attaching a lower level route.
  • Use one listener per delegated hostname where practical, so each application team's attachment rights are scoped to the hostname it owns.

Cross-namespace references with ReferenceGrant

ReferenceGrant is the second handshake. The ReferenceGrant documentation states that without a ReferenceGrant a cross-namespace reference is invalid. Typical uses are a Gateway in an infrastructure namespace reading a certificate Secret held by an application team, and a route forwarding to a Service in another namespace.

How it works, and where it goes wrong:

  • Placement: the grant must be created in the namespace that holds the referenced resource. The owner of the target consents; the referencing side cannot grant itself access.
  • The from section lists the group, kind and namespace allowed to make the reference. Names cannot be set in from, and namespace selectors are not allowed, so every route of that kind in that namespace gains the access.
  • The to section lists the group and kind that may be referenced, and optionally a name. The security model tells grant owners to specify group, kind and name, and not to leave the name unset. A grant without a name exposes every Secret or Service of that kind in the namespace.
  • Revocation: grants are additive. Implementations must recalculate validity when a grant changes or is deleted, so deleting a grant is the way to withdraw access.
  • Information leakage: implementations must not reveal whether a resource exists in another namespace unless a grant allows it. Test your controller's status messages to confirm.
  • Confused deputy risk: the documentation cites CVE-2021-25740 as the class of problem ReferenceGrant exists to prevent, where a controller with broad rights is tricked into reaching resources the requester could not reach directly.

Audit grants regularly. List every grant, its from namespaces and whether to names a specific object:

kubectl get referencegrants -A -o json | jq -r '.items[] | .metadata.namespace as $ns | .spec.from[] as $f | .spec.to[] | [$ns, $f.namespace, $f.kind, .kind, (.name // "ANY")] | @tsv'

Any row ending in ANY against Secrets deserves an immediate review.

Hostname ownership and conflicts

The security model warns that multiple routes or ListenerSets can claim the same hostname, and that conflicts are usually resolved first come, first served. An older route can therefore keep a hostname that a newer team was told it owned, or a team can pre-claim a hostname before the real owner deploys. That is hostname hijacking inside your own cluster.

The documented mitigations are to delegate each hostname to specific namespaces using listeners, and to use a ValidatingAdmissionPolicy to restrict which hostnames each namespace may use. The documentation's example policy is labelled as illustrative and must be adapted before use. Apply the same thinking to automated DNS: if a controller creates DNS records from route hostnames, the right to set a hostname is the right to publish a DNS name.

The model also notes that a Gateway allows at most 64 listeners. Large multi-tenant Gateways therefore often let teams set hostnames on routes rather than listeners, which makes admission policy the main control for hostname ownership. If you take that approach, write and test the policy before you open the Gateway to tenants, and see the Kubernetes Admission Control Guide for the policy mechanics.

Controlling Gateway creation and GatewayClass use

The security model calls Gateway creation a privileged action because it can trigger costs and infrastructure changes such as load balancers and DNS records. A developer who can create a Gateway with an internet-facing class can publish a new public endpoint without any network review.

  • Limit Gateway creation with Roles and RoleBindings, as the documentation recommends.
  • Use admission policy to stop unauthorised namespaces attaching Gateways to restricted classes, for example only the edge namespace may use the internet-facing class.
  • Keep an inventory of Gateways and their addresses from status.addresses, and reconcile it with your external attack surface monitoring.
  • Alert on new Gateways and on changes to listeners, especially new hostnames, new ports and changes to allowedRoutes.

TLS at the Gateway: termination, passthrough and client certificates

The Gateway API TLS guide describes two listener modes. In Terminate mode, the default, the Gateway decrypts traffic using certificates referenced from tls.certificateRefs. In Passthrough mode, used with TLS listeners and TLSRoute, the session is not terminated at the Gateway and TLS settings do not take effect; the backend presents its own certificate.

Security points for listener TLS:

  • Certificate Secrets are credentials. Whoever can read them can impersonate the hostname. Keep them in a namespace with tight read access, and if they live in an application namespace, use a ReferenceGrant that names the specific Secret.
  • Wildcard and specific hostnames. A specific listener hostname takes priority over a wildcard, so foo.example.com can have its own certificate while *.example.com covers the rest. Avoid broad wildcard certificates on shared Gateways where a narrower certificate will do.
  • Protocol versions and ciphers are implementation specific and set through the listener TLS options map. Check your controller's documentation and set a minimum version explicitly.
  • Automate renewal. Most teams issue listener certificates with a certificate controller; the cert-manager security guide covers protecting the issuer credentials behind that automation.

Client certificate validation (mutual TLS from clients) is configured at the Gateway level under spec.tls.frontend, which the TLS guide describes as an Extended feature in the Standard Channel since v1.5.0. It is set per Gateway rather than per listener to reduce HTTP/2 connection coalescing risks, references CA bundles through caCertificateRefs, and can be overridden per port. The default mode, AllowValidOnly, rejects clients without a valid certificate. The alternative, AllowInsecureFallback, accepts missing or failed certificates. Treat that mode as a migration aid only, and alert if it appears in production.

Backend TLS and the Gateway's own identity

Terminating TLS at the Gateway leaves the hop to the backend in plaintext unless you re-encrypt. BackendTLSPolicy, which the TLS guide lists as generally available in the Standard Channel since v1.4.0, attaches to Services through targetRefs and tells the Gateway how to validate the backend's certificate.

  • hostname is required and sets the SNI value, which must match the backend certificate.
  • Either caCertificateRefs (specific CA certificates) or wellKnownCACertificates: System (the implementation's trusted CAs) is required. Prefer a private CA reference for internal services; the system trust store accepts any public CA.
  • Cross-namespace CA references and wildcard hostnames are not allowed in BackendTLSPolicy, which keeps validation scoped to the backend's own namespace.

The Gateway can also present a client certificate to backends through tls.backend.clientCertificateRef on the Gateway resource, listed as Standard Channel since v1.5.0. That certificate is a machine identity shared by every upstream connection the Gateway makes, so backends that trust it trust the whole Gateway, not a single route. Rotate it on a schedule, store it like any other private key, and if backends need to distinguish callers, use separate Gateways or application-layer authentication rather than one shared client certificate.

Detection and measurement

  • Watch Kubernetes audit logs for create, update and delete on GatewayClass, Gateway, ReferenceGrant and BackendTLSPolicy, and for writes to gateways/status by anything other than the controller. The Kubernetes Audit Log Detection Guide covers the pipeline.
  • Alert on routes whose hostnames fall outside the owning namespace's allowed set, and on routes reporting attachment conflicts in status.
  • Track the count of ReferenceGrants with no target name, listeners with from: All, and Gateways using AllowInsecureFallback. Each should trend to zero.
  • Monitor certificate expiry for every listener and backend client certificate.
  • Map findings to MITRE ATT&CK T1190 Exploit Public-Facing Application for exposure issues and T1557 Adversary-in-the-Middle for missing backend TLS.

Common failure patterns

  • Shared Gateway with from: All. Any namespace can attach a route to the public entry point.
  • Selecting namespaces by a label anyone can set. Tenants add the label and join the Gateway.
  • ReferenceGrant to all Secrets. A grant without a name exposes every certificate and key in the namespace to the referencing namespace's routes or Gateways.
  • No hostname policy. First come, first served attachment lets one team hold another team's hostname.
  • Gateway write rights in default developer roles. Developers create internet-facing load balancers without review.
  • Termination without re-encryption. Traffic is decrypted at the edge and travels to backends in plaintext.
  • Insecure client certificate fallback left on. Mutual TLS appears to be configured but unauthenticated clients are accepted.
  • Over-privileged controller identity. The controller can read every Secret in the cluster, so a controller flaw becomes a cluster-wide credential leak.

Practitioner checklist

  • Map each Gateway API resource kind to an owning role and write RBAC to match, with Gateway status writable only by the controller.
  • Remove from: All from shared listeners and select namespaces by kubernetes.io/metadata.name.
  • Restrict route kinds per listener.
  • Require a target name in every ReferenceGrant to Secrets, and control grant creation with admission policy.
  • Enforce hostname ownership per namespace with listeners or a tested ValidatingAdmissionPolicy.
  • Limit Gateway creation and restrict which namespaces can use internet-facing GatewayClasses.
  • Protect listener certificate Secrets, set a minimum TLS version and automate renewal.
  • Use BackendTLSPolicy with a private CA reference for internal backends.
  • Keep client certificate validation in AllowValidOnly mode in production.
  • Scope and review the controller's service account and cloud identity, and rotate the backend client certificate.
  • Alert on changes to Gateways, listeners, grants and policies.

Standards and references

Related NHI Mgmt Group resources: Ingress NGINX Retirement · API Gateway Security Guide · Kubernetes Ingress Controller vs Service Mesh · cert-manager security guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.