basic_auth: add allow_missing field and emit dynamic metadata on success#43911
Open
QuentinBisson wants to merge 1 commit intoenvoyproxy:mainfrom
Open
basic_auth: add allow_missing field and emit dynamic metadata on success#43911QuentinBisson wants to merge 1 commit intoenvoyproxy:mainfrom
QuentinBisson wants to merge 1 commit intoenvoyproxy:mainfrom
Conversation
|
Hi @QuentinBisson, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
d43a9c0 to
cd350cc
Compare
When allow_missing is true the filter passes through requests that carry no Basic credentials (absent Authorization header, or a non-Basic scheme such as Bearer). Requests that do present Basic credentials are still fully validated and invalid credentials are still rejected. On every successful authentication the filter now emits dynamic metadata under the envoy.filters.http.basic_auth namespace with key 'username'. This allows downstream RBAC filters to detect that BasicAuth succeeded, which is the missing piece needed to implement OR semantics when combining BasicAuth with other auth methods (e.g. JWT). See envoyproxy/gateway#8491 for the motivating use case. Signed-off-by: QuentinBisson <quentin@giantswarm.io>
cd350cc to
6972cbc
Compare
paul-r-gall
reviewed
Mar 16, 2026
| headers.setCopy(Http::LowerCaseString(config_->forwardUsernameHeader()), username); | ||
| } | ||
|
|
||
| setDynamicMetadata(username); |
Contributor
There was a problem hiding this comment.
my only problem with this PR is this line, which does a moderately expensive "copy and set metadata" regardless.
Author
There was a problem hiding this comment.
Do you have any idea on how to improve on this?
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
This PR adds two related features to the BasicAuth HTTP filter that enable OR-semantics
when combining it with other auth filters (e.g. JWT):
1.
allow_missingfieldWhen
allow_missing: trueis set, the filter passes through requests that have no Basiccredentials (missing
Authorizationheader, or a non-Basicscheme such asBearer).Requests that do present Basic credentials are still fully validated — invalid credentials
are still rejected.
This mirrors the existing
allow_missing/allow_missing_or_failedsemantics in theJWT authn filter.
2. Dynamic metadata on success
On successful authentication the filter now emits dynamic metadata under the
envoy.filters.http.basic_authnamespace with keyusernameset to the authenticatedusername. This allows downstream filters (e.g. RBAC) to detect that BasicAuth succeeded.
Motivation
Addresses the AND-semantics problem described in envoyproxy/gateway#8491: when a
SecurityPolicyconfigures both
jwtandbasicAuth, each filter independently rejects requests thatdon't carry its expected credential type.
With these two changes, OR semantics can be assembled entirely from existing filters:
With this setup:
Changes
api/envoy/extensions/filters/http/basic_auth/v3/basic_auth.proto: addbool allow_missing = 4source/extensions/filters/http/basic_auth/basic_auth_filter.h: addallow_missing_member,allowMissing()getter,setDynamicMetadata()methodsource/extensions/filters/http/basic_auth/basic_auth_filter.cc: implementallow_missingpass-through andsetDynamicMetadata()on successsource/extensions/filters/http/basic_auth/config.cc: wireproto_config.allow_missing()through toFilterConfigtest/extensions/filters/http/basic_auth/filter_test.cc: add tests for dynamic metadata emission and fullAllowMissingFilterTestsuiteRisk
Low.
allow_missingdefaults tofalse, preserving all existing behaviour. The dynamicmetadata emission on success is additive and has no effect on filters that don't consume it.