Skip to content

basic_auth: add allow_missing field and emit dynamic metadata on success#43911

Open
QuentinBisson wants to merge 1 commit intoenvoyproxy:mainfrom
QuentinBisson:basic-auth-allow-missing-and-metadata
Open

basic_auth: add allow_missing field and emit dynamic metadata on success#43911
QuentinBisson wants to merge 1 commit intoenvoyproxy:mainfrom
QuentinBisson:basic-auth-allow-missing-and-metadata

Conversation

@QuentinBisson
Copy link

@QuentinBisson QuentinBisson commented Mar 11, 2026

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_missing field

When allow_missing: true is set, the filter passes through requests that have no Basic
credentials (missing Authorization header, or a non-Basic scheme such as Bearer).
Requests that do present Basic credentials are still fully validated — invalid credentials
are still rejected.

This mirrors the existing allow_missing / allow_missing_or_failed semantics in the
JWT authn filter.

2. Dynamic metadata on success

On successful authentication the filter now emits dynamic metadata under the
envoy.filters.http.basic_auth namespace with key username set to the authenticated
username. 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 SecurityPolicy
configures both jwt and basicAuth, each filter independently rejects requests that
don't carry its expected credential type.

With these two changes, OR semantics can be assembled entirely from existing filters:

# JWT filter
allow_missing: true   # pass through if no Bearer token; set metadata on success

# BasicAuth filter
allow_missing: true   # pass through if no Basic creds; set metadata on success

# RBAC filter — enforce "at least one auth succeeded"
rules:
  action: ALLOW
  policies:
    require-any-auth:
      permissions: [any: true]
      principals:
      - or_ids:
          ids:
          - metadata:
              filter: envoy.filters.http.jwt_authn
              path: [{key: sub}]
              value: {present_match: true}
          - metadata:
              filter: envoy.filters.http.basic_auth
              path: [{key: username}]
              value: {present_match: true}

With this setup:

  • Request with valid Bearer → JWT validates, BasicAuth passes through → RBAC sees JWT metadata → allowed
  • Request with valid Basic → JWT passes through, BasicAuth validates → RBAC sees basic_auth metadata → allowed
  • Request with no credentials → both pass through, no metadata set → RBAC rejects → 401
  • Request with invalid credentials → the relevant filter rejects → 401

Changes

  • api/envoy/extensions/filters/http/basic_auth/v3/basic_auth.proto: add bool allow_missing = 4
  • source/extensions/filters/http/basic_auth/basic_auth_filter.h: add allow_missing_ member, allowMissing() getter, setDynamicMetadata() method
  • source/extensions/filters/http/basic_auth/basic_auth_filter.cc: implement allow_missing pass-through and setDynamicMetadata() on success
  • source/extensions/filters/http/basic_auth/config.cc: wire proto_config.allow_missing() through to FilterConfig
  • test/extensions/filters/http/basic_auth/filter_test.cc: add tests for dynamic metadata emission and full AllowMissingFilterTest suite

Risk

Low. allow_missing defaults to false, preserving all existing behaviour. The dynamic
metadata emission on success is additive and has no effect on filters that don't consume it.

@repokitteh-read-only
Copy link

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.

🐱

Caused by: #43911 was opened by QuentinBisson.

see: more, trace.

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #43911 was opened by QuentinBisson.

see: more, trace.

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>
@QuentinBisson QuentinBisson force-pushed the basic-auth-allow-missing-and-metadata branch from cd350cc to 6972cbc Compare March 11, 2026 15:21
@QuentinBisson QuentinBisson requested a deployment to external-contributors March 11, 2026 15:21 — with GitHub Actions Waiting
headers.setCopy(Http::LowerCaseString(config_->forwardUsernameHeader()), username);
}

setDynamicMetadata(username);
Copy link
Contributor

Choose a reason for hiding this comment

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

my only problem with this PR is this line, which does a moderately expensive "copy and set metadata" regardless.

Copy link
Author

Choose a reason for hiding this comment

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

Do you have any idea on how to improve on this?

@paul-r-gall paul-r-gall assigned wbpcode and unassigned mattklein123 Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants