Skip to content

perf: cache required keys in secrets and configmaps#8045

Merged
arkodg merged 1 commit intoenvoyproxy:mainfrom
rudrakhp:perf_cm_secret_cache
Jan 28, 2026
Merged

perf: cache required keys in secrets and configmaps#8045
arkodg merged 1 commit intoenvoyproxy:mainfrom
rudrakhp:perf_cm_secret_cache

Conversation

@rudrakhp
Copy link
Copy Markdown
Member

What type of PR is this?
perf: cache required keys in secrets and configmaps

What this PR does / why we need it:
Including only needed keys in Secret and ConfigMap data to reduce memory usage.

Release Notes: Yes

@rudrakhp rudrakhp requested a review from a team as a code owner January 25, 2026 19:59
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 25, 2026

Deploy Preview for cerulean-figolla-1f9435 canceled.

Name Link
🔨 Latest commit 97cbc2b
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/697762af9468f400084e89a5

@rudrakhp rudrakhp force-pushed the perf_cm_secret_cache branch from 0a572e5 to 641eb3d Compare January 25, 2026 19:59
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 87.23404% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.78%. Comparing base (fa32a93) to head (97cbc2b).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
internal/provider/kubernetes/helpers.go 87.50% 2 Missing and 2 partials ⚠️
internal/gatewayapi/securitypolicy.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8045      +/-   ##
==========================================
+ Coverage   73.70%   73.78%   +0.08%     
==========================================
  Files         237      237              
  Lines       35703    35744      +41     
==========================================
+ Hits        26314    26374      +60     
+ Misses       7529     7513      -16     
+ Partials     1860     1857       -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.

)

var (
// cachedConfigMapKeys defines the keys to keep in ConfigMap data cache
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for some of these cases we pick the first key if we cant find the desired key, we'll need to make sure we dont include those
cc @zirain

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

expectedAndFirstFallbackFilter is supposed to handle this (moved it to helpers just now)

@rudrakhp rudrakhp force-pushed the perf_cm_secret_cache branch 4 times, most recently from 7606860 to d36bcdb Compare January 26, 2026 08:58
@zirain
Copy link
Copy Markdown
Member

zirain commented Jan 26, 2026

it would be good to have a test case for fallback to first key of the configmap, maybe change an existing one.

@rudrakhp rudrakhp force-pushed the perf_cm_secret_cache branch from d36bcdb to 0e2495e Compare January 26, 2026 10:21
@rudrakhp
Copy link
Copy Markdown
Member Author

rudrakhp commented Jan 26, 2026

Added unit tests for the transform functions, also changed the key in Lua configmap in E2E so it picks first key.

@rudrakhp rudrakhp force-pushed the perf_cm_secret_cache branch 2 times, most recently from 1ffdf7e to a1b45b0 Compare January 26, 2026 11:08
@rudrakhp rudrakhp requested review from arkodg and zirain January 26, 2026 11:31
zirain
zirain previously approved these changes Jan 26, 2026
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Comment on lines +29 to +55
var (
// cachedConfigMapKeys defines the keys to keep in ConfigMap data cache
cachedConfigMapKeys = map[string]bool{
gatewayapi.JWKSConfigMapKey: true,
gatewayapi.LuaConfigMapKey: true,
gatewayapi.ResponseBodyConfigMapKey: true,
gatewayapi.CACertKey: true,
gatewayapi.CRLKey: true,
}

// cachedSecretKeys defines the keys to keep in Secret data cache
cachedSecretKeys = map[string]bool{
corev1.TLSCertKey: true,
corev1.TLSPrivateKeyKey: true,
egv1a1.TLSOCSPKey: true,
egv1a1.OIDCClientIDKey: true,
egv1a1.OIDCClientSecretKey: true,
egv1a1.BasicAuthUsersSecretKey: true,
egv1a1.InjectedCredentialKey: true,
egv1a1.APIKeysSecretKey: true,
corev1.DockerConfigJsonKey: true,
gatewayapi.CACertKey: true,
gatewayapi.CRLKey: true,
hmacSecretKey: true,
}
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do we need to define an unified list instead of different ones for configmap vs secret? I have seen cases where we use secrets and configmaps interchangeably using SecretObjectReference.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is fine, we can add comments to remind devs to add to both places

@cnvergence cnvergence added this to the v1.7.0-rc.1 Release milestone Jan 27, 2026
@zhaohuabing
Copy link
Copy Markdown
Member

zhaohuabing commented Jan 28, 2026

This looks good - just curious, are people putting other keys in the Secret/ConfigMaps that aren't required?

Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@arkodg arkodg merged commit 3e91fdf into envoyproxy:main Jan 28, 2026
36 checks passed
@rudrakhp
Copy link
Copy Markdown
Member Author

rudrakhp commented Jan 28, 2026

This looks good - just curious, are people putting other keys in the Secret/ConfigMaps that aren't required?

Might be sharing configmap for multiple purposes @zhaohuabing

SadmiB pushed a commit to SadmiB/gateway that referenced this pull request Jan 30, 2026
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: Sadmi Bouhafs <sadmibouhafs@gmail.com>
@nobbs
Copy link
Copy Markdown

nobbs commented Feb 9, 2026

This PR introduced a regression for API key authentication when secrets contain multiple client IDs.

Issue: The expectedAndFirstFallbackFilter logic keeps only predefined keys plus the first key alphabetically. For API key secrets, client IDs are arbitrary keys (e.g., client1, client2, client3), not the predefined credentials key (that's at least the documentation and implementation). This results in all clients except the lexicographically first one being dropped from the cache.

Example:

apiVersion: v1
kind: Secret
metadata:
  name: apikey-secret
data:
  client1: a2V5MQ==  # cached ✓
  client2: a2V5Mg==  # dropped ✗
  client3: a2V5Mw==  # dropped ✗

Impact: Authentication fails for all API keys except the first client ID alphabetically.

Affected: v1.7.0 and main branch

Tracking issue: #8227

nobbs added a commit to nobbs/gateway that referenced this pull request Feb 9, 2026
Fixes API key authentication bug where secrets with multiple client IDs
were incorrectly filtered, keeping only the first client ID alphabetically.

The filter now detects when NO predefined keys exist in the data and
preserves all keys in that case. This handles API key secrets where each
key represents a client ID, as well as any other similar use cases.

Changes:
- Modified expectedAndFirstFallbackFilter to check if any predefined
  keys exist before filtering
- If no predefined keys found, all keys are preserved
- Updated tests to reflect new expected behavior

Fixes envoyproxy#8227
Related to envoyproxy#8045
nobbs added a commit to nobbs/gateway that referenced this pull request Feb 9, 2026
Fixes API key authentication bug where secrets with multiple client IDs
were incorrectly filtered, keeping only the first client ID alphabetically.

The filter now detects when NO predefined keys exist in the data and
preserves all keys in that case. This handles API key secrets where each
key represents a client ID, as well as any other similar use cases.

Changes:
- Modified expectedAndFirstFallbackFilter to check if any predefined
  keys exist before filtering
- If no predefined keys found, all keys are preserved
- Updated tests to reflect new expected behavior

Fixes envoyproxy#8227
Related to envoyproxy#8045
nobbs added a commit to nobbs/gateway that referenced this pull request Feb 9, 2026
Fixes API key authentication bug where secrets with multiple client IDs
were incorrectly filtered, keeping only the first client ID alphabetically.

The filter now detects when NO predefined keys exist in the data and
preserves all keys in that case. This handles API key secrets where each
key represents a client ID, as well as any other similar use cases.

Changes:
- Modified expectedAndFirstFallbackFilter to check if any predefined
  keys exist before filtering
- If no predefined keys found, all keys are preserved
- Updated tests to reflect new expected behavior

Fixes envoyproxy#8227
Related to envoyproxy#8045

Signed-off-by: Alexej Disterhoft <alexej@disterhoft.de>
@zhaohuabing zhaohuabing mentioned this pull request Feb 13, 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.

6 participants