feat: per-request backend credentials from request headers and dynamic metadata#2253
Open
kanurag94 wants to merge 2 commits into
Open
feat: per-request backend credentials from request headers and dynamic metadata#2253kanurag94 wants to merge 2 commits into
kanurag94 wants to merge 2 commits into
Conversation
…c metadata Adds credentialOverride to BackendSecurityPolicy. When set, the gateway reads the upstream credential from a request header injected by a trusted filter, or from Envoy dynamic metadata, instead of using the static credential in the policy. Supported for APIKey, AnthropicAPIKey, AzureAPIKey, AzureCredentials, and GCPCredentials. AWSCredentials is out of scope (needs SigV4 + three values, separate follow-up). Two sources: - fromRequestHeaders: reads a single header (default x-aigw-* per type). The header is stripped before the request reaches the upstream. - fromDynamicMetadata: reads from filter metadata set by ext_authz. Preferred since the client cannot forge it. fallbackToConfigured controls behavior when the source is absent: true falls back to the static credential, false returns 401. Closes envoyproxy#2216 Signed-off-by: Anurag Aggarwal <kanurag94@gmail.com>
31756ac to
2710bf1
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2253 +/- ##
========================================
Coverage 84.70% 84.70%
========================================
Files 144 145 +1
Lines 21204 21337 +133
========================================
+ Hits 17960 18073 +113
- Misses 2162 2177 +15
- Partials 1082 1087 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
/retest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BackendSecurityPolicy today uses one static credential for every request. This adds an optional credentialOverride field so a trusted upstream filter can supply the credential per-request instead.
Two sources: fromRequestHeaders reads from a request header the filter injects (stripped before forwarding upstream), fromDynamicMetadata reads from Envoy filter metadata which the client cannot forge. fallbackToConfigured decides whether a missing source falls back to the static credential or returns 401.
Default header names use the x-aigw- prefix (e.g. x-aigw-api-key) so they don't collide with real provider headers and are redacted from logs automatically. AWSCredentials is not supported here — it needs three values plus SigV4 signing, that's a separate follow-up.
Example with header source, falls back to the secret when header is absent:
Example with dynamic metadata, 401 when key is missing:
Related Issues/PRs (if applicable)
Closes #2216
Related: #2076
Special notes for reviewers (if applicable)
The fromRequestHeaders source strips the input header from the request before it reaches the upstream backend. This is done by adding it to the backend's HeaderMutation.Remove list, which tells Envoy to drop it while keeping it visible in the local header map so the handler can still read it.