Repository navigation
feat: chunk large OIDC token cookies by default - #10402
Conversation
Sets token_cookie_chunking with Envoy's default limits on every OIDC filter, so Envoy splits an access, ID or refresh token too large for one browser cookie across several cookies, instead of the browser dropping it and the login looping back to the OIDC provider. A token that fits is still written as one cookie, byte for byte as before. The OIDCTokenCookieChunking runtime flag, enabled by default, turns it off. Envoy older than v1.40 can't read the split cookies, so operators disable the flag while proxies of an earlier release serve the same hostnames, for example during an upgrade. Refs: envoyproxy#7315 Signed-off-by: Alexej Disterhoft <[email protected]>
Adds a "Large Tokens" section to the OIDC task: the login loop a token over 4096 bytes caused, how Envoy now splits it and within which limits, the request header limit to watch, and when to disable the OIDCTokenCookieChunking runtime flag. Adds the release note. Refs: envoyproxy#7315 Signed-off-by: Alexej Disterhoft <[email protected]>
Adds a Keycloak client whose access token carries a 6000-character claim, and an OIDC route for it with refresh tokens off, so a dropped access token cookie cannot be papered over by a refresh. The test checks the token arrives as "<name>_N" chunks plus a "<name>_chunks" count cookie and that the session works from them. The OIDC test client now behaves like a browser in the two ways this depends on: it ignores a cookie whose name and value exceed 4096 bytes, and it gives up after 20 redirects instead of following a login loop until the test times out. Without chunking the new case fails with "stopped after 20 redirects", the loop reported in envoyproxy#7315. Refs: envoyproxy#7315 Signed-off-by: Alexej Disterhoft <[email protected]>
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5105c3b67c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if oidc.TokenCookieChunking { | ||
| oauth2.Config.TokenCookieChunking = &oauth2v3.TokenCookieChunking{} |
There was a problem hiding this comment.
Validate generated chunk cookie names before enabling chunking
When a valid SecurityPolicy names the access-token cookie session and another OIDC cookie session_0 or session_chunks, the existing OIDCCookieNames uniqueness rule accepts the distinct base names. Once the access token is large enough to be chunked, this setting makes Envoy generate those same names for the first chunk or chunk count, so one cookie value overwrites the other and the OIDC session cannot be validated. Reserve the generated _<index>/_chunks names during admission or translation before enabling this config.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10402 +/- ##
==========================================
- Coverage 82.12% 82.12% -0.01%
==========================================
Files 272 272
Lines 43156 43160 +4
==========================================
Hits 35443 35443
- Misses 7712 7716 +4
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What this PR does / why we need it:
Supersedes #10326, following @zhaohuabing's suggestion there. Instead of a per-policy
tokenCookieChunkingfield, Envoy Gateway sets the OAuth2 filter'stoken_cookie_chunking(envoyproxy/envoy#48086, in Envoy v1.40.0) on every OIDC filter, with Envoy's default limits. A new runtime flag,OIDCTokenCookieChunking, enabled by default, turns it off.Browsers silently drop a cookie larger than 4096 bytes. When the OIDC provider issues a larger access, ID or refresh token, for example one carrying many group claims, the session cookie never comes back and the user is redirected to the provider again and again. With chunking, Envoy splits such a token into
<name>_0..<name>_N-1cookies plus a<name>_chunkscount cookie, and rejoins them before the HMAC check.gatewayapi runner Translator{OIDCTokenCookieChunkingDisabled: !runtimeFlags.IsEnabled(OIDCTokenCookieChunking)} buildOIDC + ir.OIDC.TokenCookieChunking = !OIDCTokenCookieChunkingDisabled xds translator oauth2Config + token_cookie_chunking: {} # Envoy defaults: 4096 bytes per cookie, at most 8 chunksWhy on by default:
What the flag is for: Envoy older than v1.40 can't read split cookies. While an older proxy serves the same hostname, during the rollout or while the clusters of a multi-cluster setup are upgraded one by one, a client that holds such a token in one cookie today is sent back to the provider when it reaches the older proxy. That client is a non-browser client, or a browser whose token is just under the limit, since Envoy counts the cookie attributes and browsers don't. The docs and the release note say to disable the flag until every proxy is upgraded.
Differences from #10326:
maxCookieSizeandmaxChunkscan wait until someone needs them; an EnvoyPatchPolicy can set them meanwhile.v1.40.0since build(deps): bump github.com/envoyproxy/go-control-plane/envoy from 1.39.1-0.20260927022543-fc8912c55e30 to 1.40.0 #10344, which already carries the field.Tests:
TestTranslate: every OIDC golden now carriestokenCookieChunking: truein the IR. All 11 fail with the translator change reverted. The newsecuritypolicy-with-oidc-token-cookie-chunking-disabledgolden covers the flag turned off and fails if the translator ignores the flag.TestTranslateXds/oidc:token_cookie_chunking: {}on the first route, absent on the second. Fails without the xDS change.TestOIDCTokenCookieChunkingRuntimeFlag: enabled by default, off throughruntimeFlags.disabled.refreshToken: false, so a lost access token cookie can't be recovered through a refresh. The test client now ignores a cookie whose name and value exceed 4096 bytes and stops after 20 redirects, as a browser does. The test checks the token arrives asAccessToken-…_Nchunks plusAccessToken-…_chunks, and that the session works without a second login. On feat: support OIDC token cookie chunking #10326, the same case without chunking failed withstopped after 20 redirects, the loop reported in OIDC: Redirect loop of OIDC Authentication due to the cookie length limit #7315.Merge danger: a two-way door. The flag turns the behavior off without a release, and Envoy keeps reading split cookies with the field unset, so neither turning it off nor reverting this PR ends existing sessions. The blast radius is every OIDC route, limited to tokens larger than one cookie.
Which issue(s) this PR fixes:
Fixes #7315
PR Checklist
git commit -s). See DCO: Sign your work./api), the API was discussed and agreed before the implementation. The API change can be in a separate PR, or in the same PR, but the API must be agreed before implementation. N/A if this PR does not contain API changes. (The only API change is theOIDCTokenCookieChunkingruntime flag @zhaohuabing proposed on feat: support OIDC token cookie chunking #10326.)make generate gen-check,make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, butgen-check,lint, and coverage MUST pass.) (gen-check,lintand the coverage tests pass locally.)release-notes/current/<section>/<pr-number>-<slug>.md(seerelease-notes/current/README.mdfor sections and naming). N/A if this PR does not contain non-trivial changes.make gen-checkand committed the result if API/helm charts/modules changed.release-notes/current/breaking_changes/. (Chunking is on by default; the upgrade window is called out above, in the docs and in the release note.)