Skip to content

oauth2_jwt: require an explicit audience policy for JWT validation - #12897

Open
cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-validation-acceptance-tokens-for-unrelated-audiences
Open

cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-validation-acceptance-tokens-for-unrelated-audiences

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Require an explicit audience policy when OAuth2 JWT validation is enabled on the HTTP or OpenTelemetry input. Previously, omitting oauth2.allowed_audience allowed a correctly signed token issued for another service to pass validation if it satisfied the remaining checks. This matters when multiple services trust the same issuer.

Both inputs now reject that configuration at startup. With oauth2.allowed_audience set, the token’s aud string or one of its array entries must match the configured value. The change also fixes cleanup of configuration-owned strings when HTTP input initialization fails.

Upgrade impact

This is a breaking configuration change for inputs that enable JWT validation and omit oauth2.allowed_audience. Before upgrading, add the audience identifier your issuer assigns to the input. For example, if that identifier is telemetry-ingest, update the input as follows.

 oauth2.validate: true
 oauth2.issuer: https://issuer.example
 oauth2.jwks_url: https://issuer.example/keys
+oauth2.allowed_audience: telemetry-ingest

Inputs that already specify a non-empty audience need no configuration change. To deliberately retain the previous behavior, set oauth2.allow_any_audience: true and omit oauth2.allowed_audience. This logs a startup warning. Configuring both options fails startup.

Test results

Coverage Result
Internal JWT tests (flb-it-oauth2_jwt) Passed
HTTP runtime tests (oauth2_requires_token, oauth2_accepts_valid_token) Both passed
Focused HTTP and OpenTelemetry integration tests 20/20 passed
Same integration tests under strict Linux Valgrind 20/20 passed

The rebuilt HTTP input returned 401 for a correctly signed token whose audience differed from the configured value. The same token returned 201 with the explicit opt-out. Both inputs rejected missing, empty, and conflicting audience settings at startup.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • OAuth2 JWT validation now checks that a token’s audience matches the configured audience.
    • An opt-out allows tokens with any audience, provided they pass the other JWT checks; startup displays a warning when this option is enabled.
  • Bug Fixes

    • OAuth2 validation now fails at startup if no audience policy is configured or if conflicting audience options are set.

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
@cosmo0920
cosmo0920 requested a review from edsiper as a code owner December 2, 2026 04:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T04:30:46.158236Z 831f45f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cosmo0920 cosmo0920 added this to the Fluent Bit v6.0 milestone Dec 2, 2026
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OAuth2 JWT validation now requires a configured audience unless oauth2.allow_any_audience is enabled. The change adds startup checks, conditional audience matching, integration tests, and upgrade documentation.

Changes: OAuth2 audience policy

Layer / File(s) Summary
Audience configuration and startup validation
include/fluent-bit/flb_oauth2_jwt.h, src/flb_oauth2_jwt.c, docs/configuration/oauth2-audience.md, tests/integration/scenarios/in_http/tests/test_in_http_001.py
The JWT configuration adds oauth2.allow_any_audience. Context creation rejects missing or conflicting audience settings and warns when any audience is allowed. Documentation and tests cover these startup rules.
Audience enforcement and HTTP input coverage
src/flb_oauth2_jwt.c, plugins/in_http/http_config.c, tests/integration/scenarios/in_http/tests/test_in_http_001.py, tests/integration/scenarios/in_http/tests/test_jwks_timeout.py
JWT validation skips audience matching when oauth2.allow_any_audience is enabled. Tests cover mismatched and unrestricted audiences, and the JWKS timeout configuration sets an allowed audience. The HTTP config destroy path no longer clears OAuth2 pointers or destroys the configured strings when no context exists.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant HTTPClient
  participant HTTPInput
  participant OAuth2JWTValidation
  HTTPClient->>HTTPInput: Submit request with JWT
  HTTPInput->>OAuth2JWTValidation: Validate JWT audience policy
  OAuth2JWTValidation-->>HTTPInput: Return validation result
  HTTPInput-->>HTTPClient: Return HTTP response
Loading

Suggested labels: docs-required

Merge Risk: Minimal · up to 831f4

This change makes an audience policy mandatory for JWT validation on the HTTP and OpenTelemetry inputs. Configurations that enable validation without an audience will now fail at startup, which is documented as an upgrade step. No concrete merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: JWT validation in the oauth2_jwt component now requires an explicit audience policy. The summary confirms this. Startup fails without oauth2.allowed_audience or allow_…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: JWT validation in the oauth2_jwt component now requires an explicit audience policy. The summary confirms this. Startup fails without oauth2.allowed_audience or allow_any_audience, and the audience check is enforced when the option is set. The title is specific and matches the changeset and PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: afaf977b-8ea7-4a21-ae56-9e74c77f310f
Commits

Reviewing files that changed from the base of the PR and between 984519c and 831f45f.

Files selected for processing: 6

  • docs/configuration/oauth2-audience.md
  • include/fluent-bit/flb_oauth2_jwt.h
  • plugins/in_http/http_config.c
  • src/flb_oauth2_jwt.c
  • tests/integration/scenarios/in_http/tests/test_in_http_001.py
  • tests/integration/scenarios/in_http/tests/test_jwks_timeout.py
Files with no reviewable changes: 1

  • plugins/in_http/http_config.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant