Skip to content

fix(gatewayapi): sort api key auth credentials#9042

Open
nobbs wants to merge 4 commits into
envoyproxy:mainfrom
nobbs:fix-apikey-auth-credential-order
Open

fix(gatewayapi): sort api key auth credentials#9042
nobbs wants to merge 4 commits into
envoyproxy:mainfrom
nobbs:fix-apikey-auth-credential-order

Conversation

@nobbs
Copy link
Copy Markdown

@nobbs nobbs commented May 20, 2026

What type of PR is this?

fix

What this PR does / why we need it:

API key auth credentials are currently built by iterating over Secret.Data directly. Since Secret.Data is a Go map, the credential order can vary between otherwise equivalent translations.

That nondeterministic order is preserved into the generated API key auth filter and per-route xDS config. In clusters with frequent Gateway API/xDS rebuilds, Envoy can receive byte-different listener or route resources even when the effective API key auth configuration did not change. For long-lived connections such as WebSockets, this can cause Envoy to replace the active filter chain and close existing connections with:

downstream_local_disconnect(filter_chain_is_being_removed)

This PR makes API key auth credential generation deterministic by sorting the secret data keys before appending credentials to the IR. It also adds a unit test that verifies credentials are emitted in stable client ID order.

With this change applied in a reproducing environment, the internal HTTPS listener stopped flipping due to API key credential reordering and the WebSocket connection stayed alive.

Validation:

  • make generate gen-check
  • go test ./internal/gatewayapi

Which issue(s) this PR fixes:

Fixes #8889

Release Notes: Yes

@nobbs nobbs requested a review from a team as a code owner May 20, 2026 09:06
@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 6b7a522
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a157549fe8d610008c58c5a
😎 Deploy Preview https://deploy-preview-9042--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.

@nobbs nobbs force-pushed the fix-apikey-auth-credential-order branch from a9bfe1d to 46f9774 Compare May 20, 2026 09:07
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.81%. Comparing base (34b343b) to head (ecfb79d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9042      +/-   ##
==========================================
+ Coverage   74.76%   74.81%   +0.05%     
==========================================
  Files         252      252              
  Lines       40571    40576       +5     
==========================================
+ Hits        30331    30356      +25     
+ Misses       8166     8149      -17     
+ Partials     2074     2071       -3     

☔ View full report in Codecov by Sentry.
📢 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.

@zirain zirain force-pushed the fix-apikey-auth-credential-order branch from 46f9774 to 6825ffc Compare May 20, 2026 22:02
@nobbs nobbs force-pushed the fix-apikey-auth-credential-order branch 2 times, most recently from 7cd801c to e7efd21 Compare May 21, 2026 10:43
zirain
zirain previously approved these changes May 22, 2026
nobbs added 2 commits May 22, 2026 20:24
Signed-off-by: Alexej Disterhoft <alexej.disterhoft@redcare-pharmacy.com>
Signed-off-by: Alexej Disterhoft <alexej.disterhoft@redcare-pharmacy.com>
@nobbs nobbs force-pushed the fix-apikey-auth-credential-order branch from e7efd21 to ffc44f2 Compare May 22, 2026 18:24
Signed-off-by: Alexej Disterhoft <alexej@disterhoft.de>
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.

bug: periodic equivalent xDS updates drain active websocket connections

2 participants