Skip to content

JWT: editing a SecurityPolicy returns 403 "Wrong requirement_name" on existing connections since v1.9.0 #10288

Closed

Description

@kkk777-7

Description:

Since v1.9.0 (#9430), the jwt_authn requirement name is built from a hash of the requirement content (<providers>-or-missing_<hash>). Editing a JWT SecurityPolicy changes the provider config. For example, it might add an audience, change the JWKS, or change claimToHeaders. The change renames the requirement in two places together:

  • the key in the listener's requirement_map (LDS)
  • the requirement_name in every route's per-route config (RDS)

Envoy applies the LDS and RDS updates separately. Downstream connections that are already open keep the old filter chain, with the old requirement_map, until the listener drains them. The new route config applies to them right away. The next request on each existing connection therefore asks for a requirement name that its filter chain does not hold, and Envoy rejects it:

403 jwt_authn_access_denied{Wrong_requirement_name:_example-or-missing_9e8a003bead59055._It_should_be_one_of_[example-or-missing_9824bfd54cd267ca]}

With optional: true, requests without a token are rejected too, so the impact is not limited to JWT clients.

This looks like #8313, but the cause differs. #8313 is about a requirement name being added: delivering LDS before RDS is a safe order, so it was closed as eventual consistency. Here the name is replaced, so no delivery order is safe:

  • new routes + old listener: the route asks for the new name, and the old map does not hold it
  • old routes + new listener: the route asks for the old name, and the new map no longer holds it

Both directions show up in the access log below.

Before v1.9.0, the requirement was named after the route, so a policy edit did not change it.

Expected: editing a SecurityPolicy does not reject requests. Connections still on the old filter chain should be evaluated with the old policy.

Repro steps:

  1. Install v1.9.2 and the quickstart on kind:

    helm install eg oci://docker.io/envoyproxy/gateway-helm --version v1.9.2 -n envoy-gateway-system --create-namespace --wait
    kubectl apply -f https://github.com/envoyproxy/gateway/releases/download/v1.9.2/quickstart.yaml
  2. Apply a JWT SecurityPolicy on the Gateway. optional: true and an inline JWKS are used here only so that the repro needs no token and no external fetch:

    apiVersion: gateway.envoyproxy.io/v1alpha1
    kind: SecurityPolicy
    metadata:
      name: jwt-gw
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: Gateway
        name: eg
      jwt:
        optional: true
        providers:
        - name: example
          audiences: [aud-a]
          localJWKS:
            type: Inline
            inline: |
              <contents of examples/kubernetes/jwt/jwks.json>
  3. From a pod inside the cluster, send steady traffic over N keep-alive connections to the Envoy service (Host www.example.com, path /). I used 8 HTTP/1.1 connections at 10 req/s each.

  4. While the traffic runs, edit the policy every 20 s:

    kubectl patch securitypolicy jwt-gw --type=json -p '[{"op":"add","path":"/spec/jwt/providers/0/audiences/-","value":"aud-b"}]'
    # 20 s later
    kubectl patch securitypolicy jwt-gw --type=json -p '[{"op":"remove","path":"/spec/jwt/providers/0/audiences/1"}]'

The rename shows without a cluster too. Run egctl x translate --from gateway-api --to xds -t all on the same input before and after adding one audience:

before after
provider (LDS) example_d021055cb0c610d0 example_86815370e6ee1cbc
requirement_map key (LDS) example-or-missing_9824bfd54cd267ca example-or-missing_9e8a003bead59055
route requirement_name (RDS) example-or-missing_9824bfd54cd267ca example-or-missing_9e8a003bead59055

Environment:

  • Envoy Gateway v1.9.2 (helm chart), default EnvoyProxy settings
  • The naming code is unchanged on main (1873acf): jwtRequirementName in internal/xds/translator/jwt.go
  • kind, single node

Logs:
Access log of one rejected request. 16 rejections had each direction of the mismatch:

{"response_code":403,"response_code_details":"jwt_authn_access_denied{Wrong_requirement_name:_example-or-missing_9e8a003bead59055._It_should_be_one_of_[example-or-missing_9824bfd54cd267ca]}","route_name":"httproute/default/foo/rule/0/match/0/www_example_com","protocol":"HTTP/1.1","start_time":"2026-10-15T08:44:44.602Z"}

Activity

  1. added
    kind/bug
    area/translator
    on Oct 15, 2026
  2. kkk777-7 commented on Oct 15, 2026

    @kkk777-7
    MemberAuthor

    Results:

    Each run lasted 100 s and included 4 policy edits.

    keep-alive connections requests 403 403 per edit
    on 8 7,816 32 8
    on 32 31,276 128 32
    off 8 7,648 0 0
    • Each edit rejects exactly one request per existing connection, about 90 ms after the edit. The number of rejections follows the number of connections, not a time window.
    • In every case, the rejected request was the last one on its connection. Envoy closes the connection as part of the listener drain, the client reconnects, and later requests succeed.
    • With keep-alive disabled, nothing is rejected.

    Possible fix:

    Make the requirement name independent of the provider content, but do not go back to per-route names. Per-route names would bring back the listener churn that #9103 fixed.

    One option is to name the requirement after the SecurityPolicy that owns the providers, as <namespace>/<name>[:missing|:missing-or-failed]. For a merged policy, the owner is whichever policy supplied the providers list. Provider names keep their content hash. Only the requirement's inner provider_name refers to them, and that reference lives inside the same LDS resource.

    With that naming:

    • A policy edit changes only the content of the requirement_map entry. The RDS requirement_name stays the same, so old and new filter chains both hold the name the route asks for.
    • Routes that share a policy still share one requirement, so adding or removing a route does not touch LDS.

    I tried this change as a patch on v1.9.2. With the same repro, it rejected 0 of 7,816 requests (8 connections) and 0 of 31,232 (32 connections). The listener still drains on each edit, as expected.

  3. FedeBev commented on Oct 25, 2026

    @FedeBev

    We hit this in production on v1.9.0; three data points that may help.

    1. HTTP/2 and HTTP/3 too. One apply added an issuer to providers on our gateway-, listener- and route-level JWT SecurityPolicies (they share one provider list). 16 connections opened before the apply sent a request after it. Within the log window we inspected, 15 of them logged exactly one 403 each, asking for the new requirement name against the old map (HTTP/1.1 7, HTTP/2 2, HTTP/3 6), and each 403 was the last request started on that connection. The 16th's only logged request after the apply, in that window, was a CORS preflight (answered before jwt_authn); it logged no 403. We only saw that direction (route config ahead of the connection's filter chain).

    2. A JWKS key change renames too. In a minimal fixture — a gateway-level JWT policy with localJWKS.type: ValueRef, plus a route policy (StrategicMerge) marking one route optional: true — adding one key to the ConfigMap renamed the provider and both requirements that reference it (egctl x translate, v1.9.0): provider example_5c58573eade5ec5b → example_1d4cc6f089987357; required example_9e29a489ca9f2446 → example_889ae4de86ea3745; optional example-or-missing_91088b04bef35f9d → example-or-missing_92bb7feabcdf058a. The hash covers the JWKS bytes: pretty-printing the same JWKS renamed them too (required → example_bbccbd5f83e3650a). In the same fixture a CORS-only change left every provider and requirement name unchanged.

    3. Impact. 9 of the 15 refusals hit devices that poll over mTLS (optional: true on their route) and keep the connection open between polls; off-peak scheduling does not prevent this on connections that stay open and keep sending requests. Two of our POS terminals locked on that single 403 (our client's bug, since fixed).

    +1 to naming the requirement after the policy that supplies providers. Two tests seem worth pinning: with the owning policy and its optional/failOpen mode unchanged, a provider or JWKS edit leaves every route's requirement_name unchanged; and two different requirements in one requirement_map never share a name (a duplicate key is overwritten silently on insert). One trade worth stating in the PR (reasoned from the drain settings, not measured): with stable names, a connection still draining after a provider change keeps validating against the old providers until it closes. A connection that remains idle serves no further requests; HTTP/1.1 may serve at most one more request; HTTP/2/3 may serve streams opened during the GOAWAY grace, while already-open streams may persist until force-close. With v1.9.0 defaults that is about 60 s from when the new listener config activates, not from the apply; a stalled or NACKed update has no bound.

    @kkk777-7 would you open the PR with your patch in time for v1.10.0-rc.1, and is a release-1.9 cherry-pick possible? We are glad to test it against our shapes (ValueRef JWKS, optional and failOpen route exemptions with StrategicMerge, several HTTPS listeners plus HTTP/3).

  4. kkk777-7 commented on Oct 26, 2026

    @kkk777-7
    MemberAuthor

    /assign

  5. added this to the v1.10.0-rc.1 Release milestone on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/translatorkind/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions