Skip to content

feat: support OIDC token cookie chunking - #10326

Closed
nobbs wants to merge 9 commits into
envoyproxy:mainfrom
nobbs:feat/oidc-token-cookie-chunking
Closed

nobbs wants to merge 9 commits into
envoyproxy:mainfrom
nobbs:feat/oidc-token-cookie-chunking

Conversation

@nobbs

@nobbs nobbs commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Adds spec.oidc.tokenCookieChunking to SecurityPolicy, which maps to the OAuth2 filter's token_cookie_chunking added 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-1 cookies plus a <name>_chunks count cookie, and rejoins them before the HMAC check. Both limits are optional and default to Envoy's values:

oidc:
  tokenCookieChunking:
    maxCookieSize: 4096   # 512..4096, cookie name and attributes included
    maxChunks: 8          # 2..16

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 ac1fe60cb09a to pick up the field. On its own it also lets an EnvoyPatchPolicy set token_cookie_chunking, which is rejected today with unknown field "token_cookie_chunking". The bump registers 9 new extension types and changes no golden output.

For reviewer attention:

  • The API was not discussed on OIDC: Redirect loop of OIDC Authentication due to the cookie length limit #7315 before this PR. It mirrors the Envoy field 1:1; I'm happy to split the api commit into its own PR if you'd rather agree on it first.
  • The OIDC e2e test client now ignores a cookie whose name and value exceed 4096 bytes and stops after 20 redirects, as a browser does. This applies to every OIDC e2e case, and the existing cases still pass.
  • Cookie names: besides the CEL rule at admission, buildOIDC now 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:

  • CEL tests cover both bounds of each limit. The out-of-range cases pass against the old CRD, so they fail without the change.
  • The securitypolicy-with-oidc and xds-ir oidc golden tests cover both an explicit limit set and {}. They fail without the translator change.
  • A new e2e case logs in through a Keycloak client whose access token carries a 6000-character claim (9302 characters in total). The route has refreshToken: false, so a lost access token cookie can't be recovered through a refresh.
  • A table test for validateOIDCCookieNames and the securitypolicy-with-oidc-cookie-name-collisions golden 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

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: If this PR contains API changes (changes under /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.)
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.) (coverage-test, gen-check and lint pass in CI.)
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: User-facing changes update the docs, either in this PR or a follow-up PR. N/A if this PR does not contain user-facing changes.
  • Release notes: For any non-trivial change, added a release-note fragment under release-notes/current/<section>/<pr-number>-<slug>.md (see release-notes/current/README.md for sections and naming). N/A if this PR does not contain non-trivial changes.
  • Generated files committed: Ran make gen-check and committed the result if API/helm charts/modules changed.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/.
  • Codex review: Requested a Codex review and addressed all of its comments. (Codex reviewed de07068 with no findings.)
  • Copilot review: Requested a Copilot review and addressed all of its comments.

nobbs added 5 commits October 19, 2026 09:19
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]>
@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 58eac39
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6ad8b2ba8b65c1823cfe6ddb
😎 Deploy Preview https://deploy-preview-10326--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.74%. Comparing base (eb17ff9) to head (58eac39).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nobbs
nobbs marked this pull request as ready for review October 19, 2026 10:51
@nobbs
nobbs requested a review from a team as a code owner October 19, 2026 10:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-21T12:40:35.099242Z 58eac39 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@zirain zirain added this to the v1.10.0-rc.1 Release milestone Oct 20, 2026
zirain
zirain previously approved these changes Oct 20, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread api/v1alpha1/oidc_types.go Resolved
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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread api/v1alpha1/oidc_types.go Resolved
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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +2326 to +2330
for _, token := range cookies {
if !token.token {
continue
}
for _, c := range cookies {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@nobbs

nobbs commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@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:

  • a cookie name that collides with a token's chunk cookies (<name>_0 to <name>_15, <name>_chunks). This copies Envoy's chunk naming and its limit of 16 into Envoy Gateway, and Envoy itself doesn't check for it.
  • duplicate cookie names on merged and file-provider policies. That gap predates this PR.

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]>
@zhaohuabing

zhaohuabing commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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 EnvoyGateway, like EndpointSliceIndex in v1.9, rather than a per-policy field, and drop the flag after a release or two. The maxCookieSize and maxChunks tuning could then stay optional or wait until someone needs it.

@zhaohuabing
zhaohuabing requested a review from a team October 26, 2026 06:07
@nobbs

nobbs commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

@zhaohuabing I've created a new PR for that approach in #10402

@zhaohuabing zhaohuabing removed this from the v1.10.0-rc.1 Release milestone Oct 27, 2026
@nobbs

nobbs commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Closing as #10402 enables cookie chunking by default.

@nobbs nobbs closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OIDC: Redirect loop of OIDC Authentication due to the cookie length limit

3 participants