From 34c4cb32a0b744b41586f758e4b7ef5b4a726485 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 2 Dec 2026 12:51:06 +0900 Subject: [PATCH 1/4] in_http: leave OAuth option strings owned by the config map Signed-off-by: Hiroshi Hatake --- plugins/in_http/http_config.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/plugins/in_http/http_config.c b/plugins/in_http/http_config.c index b698fa3e894..87bfd4eb8ea 100644 --- a/plugins/in_http/http_config.c +++ b/plugins/in_http/http_config.c @@ -99,25 +99,7 @@ int http_config_destroy(struct flb_http *ctx) if (ctx->oauth2_ctx) { flb_oauth2_jwt_context_destroy(ctx->oauth2_ctx); - ctx->oauth2_ctx = NULL; - ctx->oauth2_cfg.issuer = NULL; - ctx->oauth2_cfg.jwks_url = NULL; - ctx->oauth2_cfg.allowed_audience = NULL; } - else { - if (ctx->oauth2_cfg.issuer) { - flb_sds_destroy(ctx->oauth2_cfg.issuer); - } - - if (ctx->oauth2_cfg.jwks_url) { - flb_sds_destroy(ctx->oauth2_cfg.jwks_url); - } - - if (ctx->oauth2_cfg.allowed_audience) { - flb_sds_destroy(ctx->oauth2_cfg.allowed_audience); - } - } - flb_free(ctx->listen); flb_free(ctx->tcp_port); From cebba8a98ccca4046365b85749f0539d5d27b611 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 2 Dec 2026 12:51:09 +0900 Subject: [PATCH 2/4] oauth2_jwt: require an explicit audience policy for validation Signed-off-by: Hiroshi Hatake --- include/fluent-bit/flb_oauth2_jwt.h | 1 + src/flb_oauth2_jwt.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/fluent-bit/flb_oauth2_jwt.h b/include/fluent-bit/flb_oauth2_jwt.h index e78ac9c0921..62f9f9e7be2 100644 --- a/include/fluent-bit/flb_oauth2_jwt.h +++ b/include/fluent-bit/flb_oauth2_jwt.h @@ -71,6 +71,7 @@ struct flb_oauth2_jwt_cfg { flb_sds_t issuer; /* expected issuer */ flb_sds_t jwks_url; /* JWKS endpoint */ flb_sds_t allowed_audience; /* audience claim to enforce */ + int allow_any_audience; /* explicitly skip audience matching */ struct mk_list *allowed_clients; /* list of authorized azp/client_id/appid */ int jwks_refresh_interval; /* refresh cadence in seconds */ size_t jwks_buffer_max_size; /* maximum JWKS HTTP response size */ diff --git a/src/flb_oauth2_jwt.c b/src/flb_oauth2_jwt.c index 00e83b3f6aa..77138ae732d 100644 --- a/src/flb_oauth2_jwt.c +++ b/src/flb_oauth2_jwt.c @@ -1319,6 +1319,25 @@ struct flb_oauth2_jwt_ctx *flb_oauth2_jwt_context_create(struct flb_config *conf ctx->cfg.jwks_response_timeout = OAUTH2_JWKS_TIMEOUT_DEFAULT; } + if (ctx->cfg.validate) { + if (ctx->cfg.allow_any_audience && ctx->cfg.allowed_audience) { + flb_error("[oauth2_jwt] configure only one of oauth2.allowed_audience " + "and oauth2.allow_any_audience"); + flb_free(ctx); + return NULL; + } + + if (ctx->cfg.allow_any_audience) { + flb_warn("[oauth2_jwt] oauth2.allow_any_audience is enabled; " + "tokens for other audiences may be accepted"); + } + else if (!ctx->cfg.allowed_audience || ctx->cfg.allowed_audience[0] == '\0') { + flb_error("[oauth2_jwt] oauth2.validate requires a non-empty oauth2.allowed_audience"); + flb_free(ctx); + return NULL; + } + } + if (ctx->cfg.jwks_buffer_max_size < FLB_HTTP_DATA_SIZE_MAX || ctx->cfg.jwks_buffer_max_size > OAUTH2_JWKS_BUFFER_LIMIT_SIZE) { flb_error("[oauth2_jwt] oauth2.jwks_buffer_max_size must be between " @@ -1507,7 +1526,7 @@ int flb_oauth2_jwt_validate(struct flb_oauth2_jwt_ctx *ctx, } /* Check audience */ - if (ctx->cfg.allowed_audience) { + if (!ctx->cfg.allow_any_audience) { /* Check audience by re-parsing the payload to handle both string and array formats. * Per JWT spec (RFC 7519), when aud is an array, the token is valid if ANY element * in the array matches the expected audience. */ @@ -1582,7 +1601,12 @@ static struct flb_config_map oauth2_jwt_config_map[] = { { FLB_CONFIG_MAP_STR, "oauth2.allowed_audience", NULL, 0, FLB_TRUE, offsetof(struct flb_oauth2_jwt_cfg, allowed_audience), - "Audience claim to enforce for OAuth2 JWT validation" + "Expected JWT audience, required when validation is enabled unless allow_any_audience is set" + }, + { + FLB_CONFIG_MAP_BOOL, "oauth2.allow_any_audience", "false", + 0, FLB_TRUE, offsetof(struct flb_oauth2_jwt_cfg, allow_any_audience), + "Accept any JWT audience instead of requiring a match with oauth2.allowed_audience" }, { FLB_CONFIG_MAP_SLIST_1, "oauth2.allowed_clients", NULL, From f2220e044da01cead65cc888b6732685024b40c6 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 2 Dec 2026 12:51:12 +0900 Subject: [PATCH 3/4] tests: integration: cover OAuth audience policies on HTTP inputs Signed-off-by: Hiroshi Hatake --- .../in_http/tests/test_in_http_001.py | 52 +++++++++++++++++++ .../in_http/tests/test_jwks_timeout.py | 1 + 2 files changed, 53 insertions(+) diff --git a/tests/integration/scenarios/in_http/tests/test_in_http_001.py b/tests/integration/scenarios/in_http/tests/test_in_http_001.py index c278bbc5222..a51c7e7bc05 100644 --- a/tests/integration/scenarios/in_http/tests/test_in_http_001.py +++ b/tests/integration/scenarios/in_http/tests/test_in_http_001.py @@ -9,9 +9,11 @@ import pytest import requests +import yaml from flask import Response from server.http_server import MOCK_JWKS_BODY, app, data_storage, http_server_run +from utils.fluent_bit_manager import FluentBitStartupError from utils.http_matrix import PROTOCOL_CASES, run_curl_request from utils.oauth2 import duplicate_header_token, duplicate_jwks_body, track_jwks_requests from utils.input_pause_resume import ( @@ -696,6 +698,56 @@ def test_in_http_health_endpoint(case): assert payload["timestamp"].endswith("Z") +@pytest.mark.parametrize("plugin", ["http", "opentelemetry"]) +@pytest.mark.parametrize("policy,error", [ + ({}, "requires a non-empty oauth2.allowed_audience"), + ({"oauth2.allowed_audience": ""}, "oauth2.allowed_audience"), + ({"oauth2.allowed_audience": "audience", "oauth2.allow_any_audience": True}, + "configure only one of oauth2.allowed_audience and oauth2.allow_any_audience"), +]) +def test_oauth2_audience_startup(tmp_path, plugin, policy, error): + config = { + "pipeline": { + "inputs": [{ + "name": plugin, "oauth2.validate": True, "oauth2.issuer": "issuer", + "oauth2.jwks_url": "http://127.0.0.1/keys", **policy, + }], + "outputs": [{"name": "null", "match": "*"}], + }, + } + path = tmp_path / "oauth.yaml" + path.write_text(yaml.safe_dump(config)) + service = FluentBitTestService(str(path)) + with pytest.raises(FluentBitStartupError, match=r"exited early with code [1-9][0-9]*\."): + service.start() + assert error in Path(service.flb.log_file).read_text() + + +@pytest.mark.parametrize("policy,expected_status", [ + ({"oauth2.allowed_audience": "different-service"}, 401), + ({"oauth2.allow_any_audience": True}, 201), +]) +def test_in_http_oauth2_audience_policy(tmp_path, policy, expected_status): + source = Path(__file__).resolve().parents[1] / "config" / "in_http_oauth2.yaml" + config = yaml.safe_load(source.read_text()) + input_config = config["pipeline"]["inputs"][0] + del input_config["oauth2.allowed_audience"] + input_config.update(policy) + path = tmp_path / "oauth.yaml" + path.write_text(yaml.safe_dump(config)) + service = Service(str(path)) + service.start() + try: + response = requests.post(f"http://127.0.0.1:{service.flb_listener_port}/", + json={"message": "audience test"}, + headers={"Authorization": f"Bearer {MOCK_VALID_JWT}"}, timeout=10) + assert response.status_code == expected_status + finally: + service.stop() + if policy.get("oauth2.allow_any_audience"): + assert "tokens for other audiences may be accepted" in Path(service.flb.log_file).read_text() + + def test_in_http_oauth2_requires_bearer_token(): service = Service("in_http_oauth2.yaml") service.start() diff --git a/tests/integration/scenarios/in_http/tests/test_jwks_timeout.py b/tests/integration/scenarios/in_http/tests/test_jwks_timeout.py index 478e915a383..08f64d9293c 100644 --- a/tests/integration/scenarios/in_http/tests/test_jwks_timeout.py +++ b/tests/integration/scenarios/in_http/tests/test_jwks_timeout.py @@ -149,6 +149,7 @@ def serve(): "inputs": [{ "name": plugin, "port": "${FLUENT_BIT_TEST_LISTENER_PORT}", "oauth2.validate": True, "oauth2.issuer": "issuer", + "oauth2.allowed_audience": "audience", "oauth2.jwks_url": ( f"{'https' if https else 'http'}://127.0.0.1:{listener.getsockname()[1]}/keys" ), From 831f45fbad0943c942f559dcb90a063cbf2b3e2f Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 2 Dec 2026 12:51:16 +0900 Subject: [PATCH 4/4] oauth2_jwt: document audience configuration for upgrades Signed-off-by: Hiroshi Hatake --- docs/configuration/oauth2-audience.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/configuration/oauth2-audience.md diff --git a/docs/configuration/oauth2-audience.md b/docs/configuration/oauth2-audience.md new file mode 100644 index 00000000000..6449fcfe93a --- /dev/null +++ b/docs/configuration/oauth2-audience.md @@ -0,0 +1,23 @@ +# Upgrading OAuth2 JWT validation on HTTP and OpenTelemetry inputs + +Before this change, an input could start with the following OAuth2 settings +and accept a token issued for another service. + +```yaml +oauth2.validate: true +oauth2.issuer: https://issuer.example +oauth2.jwks_url: https://issuer.example/keys +``` + +After upgrading, that configuration fails at startup. Add the audience your +issuer assigns to this input. For example, if the identifier is +`telemetry-ingest`, add this setting to the same input. + +```yaml +oauth2.allowed_audience: telemetry-ingest +``` + +The token's `aud` string or one of its array entries must match this value. +To explicitly retain the previous behavior, set `oauth2.allow_any_audience: true` +and omit `oauth2.allowed_audience`. This logs a startup warning and permits +tokens intended for other services if they pass the remaining JWT checks.