Identity at the Entrance: The Challenge of Authentication
In a cloud-native world, the cluster boundary is the first line of defense. Traditionally, developers handled authentication—checking who a user is—either deep within the application code or via complex Ingress controller annotations. While annotations worked, they often created a fragmented security posture, where different services used different auth logic, making audits and updates a nightmare.
The Kubernetes Gateway API aims to solve this by providing a cleaner, more extensible model. However, unlike traffic splitting or header manipulation, authentication is not yet a "core" standardized filter in the API spec. This is intentional: auth requirements vary wildly between organizations. Instead, the Gateway API uses ExtensionRefs and Policy Attachment to allow vendors to plug in their own robust authentication engines.
The Gateway API Auth Model
When you move away from Ingress, you stop using nginx.ingress.kubernetes.io/auth-url. Instead, you look for two primary patterns in the Gateway API:
- Custom Filters (ExtensionRefs): Referencing a vendor-specific resource (like a KongPlugin or a Traefik Middleware) directly within an
HTTPRoute. - Policy Attachment: Creating a separate
AuthenticationPolicyresource that "attaches" to aGatewayorHTTPRoute.
Scenario: Integrating OIDC with Kong
Let's say you want to protect your internal dashboard with Keycloak or Auth0 using the OIDC (OpenID Connect) protocol. If you are using Kong as your Gateway API controller, you would use a KongPlugin resource and reference it via an extensionRef.
1. Define the OIDC Plugin
First, we define the configuration for the authentication provider. This tells Kong where the discovery document is and what credentials to use.
apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: oidc-auth namespace: security config: issuer: "https://keycloak.neneos.com/realms/master" client_id: ["my-gateway-client"] client_secret: ["keep-this-secret"] auth_methods: ["authorization_code"] plugin: oidc
2. Attach the Filter to the HTTPRoute
Now, we reference this plugin in our HTTPRoute. This ensures that any traffic matching this route must pass the OIDC check before being forwarded to the service.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: internal-dashboard
spec:
parentRefs:
- name: public-gateway
rules:
- matches:
- path: { type: PathPrefix, value: /dashboard }
filters:
- type: ExtensionRef
extensionRef:
group: configuration.konghq.com
kind: KongPlugin
name: oidc-auth
backendRefs:
- name: dashboard-service
port: 80
The Traefik Approach: Middlewares
If you prefer Traefik, the pattern is remarkably similar but uses their Middleware resource. This highlights the "semi-portability" of the Gateway API: the structure of your route stays the same, even if the referenced auth engine changes.
# Traefik equivalent snippet
filters:
- type: ExtensionRef
extensionRef:
group: traefik.io
kind: Middleware
name: forward-auth-middleware
Why ExtensionRefs are a Step Forward
You might ask: "Isn't this just annotations in a different dress?" No, and here is why:
- Schema Validation: Unlike string-based annotations,
ExtensionRefspoint to CRDs with defined schemas. Your IDE and CI/CD tools can validate the configuration. - Auditability: Security teams can easily search for all
HTTPRoutesthat use (or don't use) a specificExtensionRef, making it clear which apps are properly protected. - Separation of Concerns: The security team can manage the
KongPluginorMiddleware(the "How"), while the app team just references it in their route (the "Where").
Moving Toward Standardization: GEP-1324
The Kubernetes community is actively working on GEP-1324 (Auth Policy), which aims to standardize how authentication policies are attached. In the future, you might see a native AuthPolicy resource that works across all controllers. For now, using vendor extensions is the most robust and production-ready path.
Best Practices for Edge Security
- Fail Closed: Ensure that if the authentication provider is unreachable, the Gateway denies access by default.
- Token Validation: If your Gateway handles OIDC, ensure it also validates the JWT signatures and expiry locally to reduce latency.
- Minimal Scopes: Only request the OIDC scopes (like
openid,profile,email) that your application actually needs. - HTTPS Everywhere: Auth filters should never be used over unencrypted HTTP. Ensure your Gateway is configured with valid TLS certificates (e.g., via cert-manager).
References & Further Reading
"By moving authentication to the Gateway level, you transform security from a checkbox in your code to a fundamental property of your infrastructure."