Repository navigation
Conversation
Picks up the mirror of envoyproxy/envoy@45f1e100, which includes envoyproxy/envoy#48086: token_cookie_chunking on the OAuth2 filter splits an access, ID or refresh token that is too large for one browser cookie across several cookies. Without it the translator cannot set the field, and an EnvoyPatchPolicy that adds it fails to unmarshal with "unknown field". Signed-off-by: Alexej Disterhoft <[email protected]>
Adds spec.oidc.tokenCookieChunking, which maps to the OAuth2 filter's token_cookie_chunking. When set, Envoy splits an access, ID or refresh token that does not fit in one browser cookie across several cookies, so an IdP that issues large tokens no longer causes a login loop. maxCookieSize (512..4096) and maxChunks (2..16) bound the split and default to Envoy's 4096 and 8. Chunking is opt-in, as it is in Envoy: a proxy still on an Envoy older than v1.40 cannot read chunked cookies, so enabling it is left to the operator once every proxy runs a version that can. Refs: envoyproxy#7315 Signed-off-by: Alexej Disterhoft <[email protected]>
Carries spec.oidc.tokenCookieChunking through the IR into the per-route OAuth2 config. An empty object turns chunking on with Envoy's defaults; maxCookieSize and maxChunks are set only when the policy sets them. 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 causes, tokenCookieChunking and its limits, why it is opt-in, and the request header limit to watch. 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 tokenCookieChunking set and 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 tokenCookieChunking 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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10326 +/- ##
==========================================
+ Coverage 81.71% 81.74% +0.02%
==========================================
Files 268 268
Lines 42310 42354 +44
==========================================
+ Hits 34574 34621 +47
+ Misses 7735 7732 -3
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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: facc392f59
ℹ️ 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".
Envoy names the chunks of a token cookie "<name>_0" to "<name>_15" plus "<name>_chunks", and reads and erases those names on every request, whether or not tokenCookieChunking is set. A cookieNames override such as accessToken "session" with oauthHmac "session_0" therefore passed admission, but the HMAC cookie and the first access token chunk would share a name and the login would fail or loop. A second CEL rule on OIDCCookieNames now rejects any effective cookie name, explicit or derived from the suffix, that matches a chunk name of the access, ID or refresh token cookie. Indexes from 16 up and other suffixes stay allowed. Refs: envoyproxy#7315 Signed-off-by: Alexej Disterhoft <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a114b7e19a
ℹ️ 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".
The CEL rule that keeps OIDC cookie names unique only runs at admission, so it never sees the names a policy ends up with when a route policy is merged into its parent with mergeType, or when the policy comes from the file provider. It also cannot see the generated cookie suffix. A parent with accessToken "same" and a merging child with oauthHmac "same" were both accepted, and the two cookies then overwrite each other. buildOIDC now checks the effective cookie names once the suffix is resolved, for Gateway and route policies alike, and marks the policy invalid when two cookies share a name or when a cookie is named like a chunk of a token cookie. Envoy splits a large token cookie into "<name>_0".."<name>_15" plus "<name>_chunks" and reads those names on every request, whether or not chunking is configured. Signed-off-by: Alexej Disterhoft <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32bfe1760a
ℹ️ 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".
| for _, token := range cookies { | ||
| if !token.token { | ||
| continue | ||
| } | ||
| for _, c := range cookies { |
There was a problem hiding this comment.
Reject cross-policy chunk-name collisions
When separate OIDC policies protect paths on the same hostname and use the same cookie scope, these loops compare names only within the current policy. For example, policy A with accessToken: session and chunking enabled and policy B with oauthHmac: session_0 both pass CEL and this Go validation because each policy's own names are distinct, but a large token on A writes its first chunk over B's HMAC cookie; subsequent requests to B then fail authentication. Account for derived chunk names across effective OIDC configurations that share a cookie scope, or otherwise prevent such cross-policy overrides.
Useful? React with 👍 / 👎.
|
@zirain you approved this at facc392. After that I added a114b7e and 32bfe17 for the Codex findings. Before you review again: would you rather that validation went into a separate PR? The two commits add a CEL rule and a Go check on top of the feature. Together they reject:
Codex has since flagged a third case: collisions between separate policies on the same host. Envoy Gateway doesn't check that even for plain duplicate names. Each fix pulls in more of Envoy's naming, so I'd prefer to revert both commits here, which takes the PR back to what you approved, and leave the validation to a possible follow-up PR. Does that work for you? |
Merge upstream main while retaining the go-control-plane versions required for OIDC token cookie chunking. Signed-off-by: Alexej Disterhoft <[email protected]>
|
I'd lean toward chunking by default rather than opt-in. For a browser nothing changes: a token that fits is still one cookie, and a token that doesn't is already looping today. Envoy went opt-in because a mixed fleet can't be upgraded safely, but each EG release pins one Envoy minor, so this lands with the move to 1.40 either way, and the compatibility matrix already rules out mixing minors. What pinning doesn't cover is the proxy rollout itself, where a non-browser client that accepts cookies over 4KB could bounce between old and new pods and get re-authed. That's an operator concern, so I'd guard it with an enabled-by-default runtime flag on |
|
@zhaohuabing I've created a new PR for that approach in #10402 |
|
Closing as #10402 enables cookie chunking by default. |
What this PR does / why we need it:
Adds
spec.oidc.tokenCookieChunkingto SecurityPolicy, which maps to the OAuth2 filter'stoken_cookie_chunkingadded in envoyproxy/envoy#48086 (Envoy v1.40).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 the field set, Envoy splits such a token into
<name>_0..<name>_N-1cookies plus a<name>_chunkscount cookie, and rejoins them before the HMAC check. Both limits are optional and default to Envoy's values:Chunking is opt-in, as it is in Envoy: with the field unset the generated xDS is unchanged, and a proxy still running an Envoy older than v1.40 can't read chunked cookies during a rollout. Envoy reads chunked cookies whether or not the field is set, so removing it later keeps existing sessions.
The first commit bumps go-control-plane to
ac1fe60cb09ato pick up the field. On its own it also lets an EnvoyPatchPolicy settoken_cookie_chunking, which is rejected today withunknown field "token_cookie_chunking". The bump registers 9 new extension types and changes no golden output.For reviewer attention:
apicommit into its own PR if you'd rather agree on it first.buildOIDCnow checks the effective cookie names once the suffix is resolved, so merged, Gateway-targeted and file-provider policies are covered too, including the generated suffix. The check also enforces the existing uniqueness rule, which had the same gap.Tests:
securitypolicy-with-oidcand xds-iroidcgolden tests cover both an explicit limit set and{}. They fail without the translator change.refreshToken: false, so a lost access token cookie can't be recovered through a refresh._chunks=4, the session works without a second login, and logout deletes every chunk.stopped after 20 redirects, which is the loop reported in OIDC: Redirect loop of OIDC Authentication due to the cookie length limit #7315.validateOIDCCookieNamesand thesecuritypolicy-with-oidc-cookie-name-collisionsgolden cover the effective-name check: a merged policy, duplicate names, and a collision with the generated suffix are rejected, a valid set is accepted. The golden fails without the check.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. (Not discussed beforehand, see above.)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.) (coverage-test,gen-checkandlintpass in CI.)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/.de07068with no findings.)