Repository navigation
Description
Problem description
I'm managing a multi-tenancy gateway with Azure JWT authentication. The goal is to have different routes with their dedicated set of allowed users. Here is my typical route config:
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: <ROUTE_NAME>
namespace: <NS_NAME>
spec:
parentRefs:
- name: <GW_NAME>
hostnames:
- '<DOMAIN_NAME>'
rules:
- backendRefs:
- group: gateway.envoyproxy.io
kind: Backend
name: <BACKEND_NAME>
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
name: <SP_NAME>
namespace: <NS_NAME>
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: <ROUTE_NAME>
jwt:
providers:
- name: azure-jwt
issuer: https://sts.windows.net/<ID>/
remoteJWKS:
uri: https://login.microsoftonline.com/common/discovery/keys
extractFrom:
headers:
- name: <JWT_HEADER>
claimToHeaders:
- claim: sub
header: <ID_HEADER>
authorization:
defaultAction: Deny
rules:
- name: "allow"
action: Allow
principal:
jwt:
provider: azure-jwt
claims:
- name: sub
values:
- "<ID>"
When you look at Envoy generated config, this actually translates in "type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication" filter config at listener level defining "providers" and "requirementMap" for every single route, exemple:
{
"name": "envoy.filters.http.jwt_authn",
"typedConfig": {
"@type": "type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication",
"providers": {
"httproute/<ns>/<route>/rule/0/match/0/<domain>/azure-jwt": {
"claimToHeaders": [
{
"claimName": "sub",
"headerName": "<ID_HEADER>"
}
],
"forward": true,
"fromHeaders": [
{
"name": "<JWT_HEADER>"
}
],
"issuer": "https://sts.windows.net/<id>/",
"normalizePayloadInMetadata": {
"spaceDelimitedClaims": [
"scope",
"scp"
]
},
"payloadInMetadata": "azure-jwt",
"remoteJwks": {
"asyncFetch": {},
"cacheDuration": "300s",
"httpUri": {
"cluster": "login_microsoftonline_com_443",
"timeout": "10s",
"uri": "https://login.microsoftonline.com/common/discovery/keys"
}
}
}
},
"requirementMap": {
"httproute/<ns>/<route>/rule/0/match/0/<domain>": {
"providerName": "httproute/<ns>/<route>/rule/0/match/0/<domain>/azure-jwt"
}
}
}
},
That "requirementMap" is then referenced in "dynamicRouteConfigs" for each routes through "type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.PerRouteConfig" and the actual autorization is configured through a RBAC filter also at route level.
That config is working but the issue is that every time a new HTTProute is added, the listener is modified (to add the new "envoy.filters.http.jwt_authn" filter block) so a drain of the listener is triggered.
My "envoy.filters.http.jwt_authn" filter is actually always the same, but it seems I cant mutualized its definition since, as the doc states "In order to use JWT claims for authorization, you must configure the JWT authentication with the same provider in the same SecurityPolicy".
That behaviour of the controller is not specific to HTTPRoute SecurityPolicies. While exploring workarounds to this I tried a different approach by defining a single SecurityPolicy with Gateway targetRef (instead of HTTPRoute) like this :
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
name: <SP_NAME>
namespace: <NS_NAME>
spec:
jwt:
providers:
- claimToHeaders:
- claim: sub
header: <ID_HEADER>
extractFrom:
headers:
- name: <HWT_HEADER>
issuer: https://sts.windows.net/<ID>/
name: azure-jwt
remoteJWKS:
uri: https://login.microsoftonline.com/common/discovery/keys
authorization:
defaultAction: Deny
rules:
- action: Allow
name: <RULE_NAME_1>
principal:
jwt:
claims:
- name: sub
valueType: String
values:
- <ID_1>
provider: azure-jwt
headers:
- name: Host
values:
- <DOMAIN_1>:443
- action: Allow
name: <RULE_NAME_2>
principal:
jwt:
claims:
- name: sub
valueType: String
values:
- <ID_2>
provider: azure-jwt
headers:
- name: Host
values:
- <DOMAIN_2>:443
targetRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: <GW_NAME>
When you do that you actually have the same issue, the "JwtAuthentication" filter config generates at listener level the exact same provider block (and associated "requirementMap") for every route you have attached to the gateway, which seems even less intuitive in that particular case. Since you have a single provider definition in your manifest, I guess you would expect to have a single provider also at listener level and all the dynamic routes referencing the same "requirementMap".
Possible solutions:
Different ways to approach this and avoid unnecessary listener drains have been discussed on slack with @zhaohuabing :
- EG could be able to deduplicate identical JWT providers/requirements and have routes reference a shared requirement, so adding a route with an already-known provider only updates RDS/RBAC rather than LDS.
- EG could allow users to split the SecurityPolicy definition. You'll have provider spec in a first SecurityPolicy with Gateway target (meaning you want a single "shared" definition of that provider) and a second SecurityPolicy with HTTPRoute target that references that "external" provider and defines the authorization spec.
Activity
github-actions commentedon Jun 27, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days.