AWS IAM OAUTHBEARER support via optional oauthbearer-aws module#2267
Merged
Conversation
… subject extractor
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
oauthbearer-aws module
Emanuele Sabellico (emasab)
requested changes
Jun 23, 2026
Emanuele Sabellico (emasab)
left a comment
Contributor
There was a problem hiding this comment.
Thanks, a few comments:
Emanuele Sabellico (emasab)
requested changes
Jun 24, 2026
|
Emanuele Sabellico (emasab)
approved these changes
Jun 25, 2026
Emanuele Sabellico (emasab)
left a comment
Contributor
There was a problem hiding this comment.
Thanks pranav shah (@prashah-confluent) . Well done!
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.




What
Adds AWS IAM-based authentication to Kafka clients via the OAUTHBEARER SASL mechanism, delivered as a new optional install extra
confluent-kafka[oauthbearer-aws]. The extra mints short-lived JWTs through AWS STSGetWebIdentityToken(viaboto3) and hands them to librdkafka as the SASL bearer credential.Activation is config-only. Users install the extra and set three keys — no code changes at the integration site:
Users who don't install the extra see zero AWS dependencies (
boto3) in their dependency graph — theconfluent_kafka._oauthbearer.awsmodules ship in the wheel regardless, butimport boto3is the runtime gate, so nothing AWS loads unless the extra is present and the marker is set.Implementation highlights:
oauthbearer-aws(single wheel + PEP 621 extra — the Python idiom, vs .NET's separate NuGet package). Pulls inboto3(≥ the first release exposing STSget_web_identity_token).sasl.oauthbearer.metadata.authentication.type=aws_iam. Python config is string-keyed dicts.resolve_aws_oauthbearer_marker()incommon_conf_setup()(src/confluent_kafka/src/confluent_kafka.c) fires on everyProducer/Consumer/AdminClientconstruction (and transitivelyAIOProducer/AIOConsumer, which wrap the sync clients). On theaws_iammarker it lazy-imports the optionalconfluent_kafka._oauthbearer.aws.aws_autowire, callscreate_handler(...), and registers the returned callable as librdkafka's OIDCoauth_cb. Single chokepoint; no hard reference from core to boto3 (the import is lazy and gated on the marker).key=valueinsasl.oauthbearer.config; supportsregion,audience(both required),duration_seconds,signing_algorithm(ES384/RS256),sts_endpoint,aws_debug(Pythonicnone|consolesubset →boto3.set_stream_logger('botocore', DEBUG)), and repeatabletag_<name>JWT-claim entries (max 50). The principal is always derived from the JWTsub.sasl.oauthbearer.extensionsconfig key (comma-separatedkey=value), matching the convention used by the AzureIMDS path across the bindings.method=oidcenforced, friendly errors that name the missing key — and a friendlyImportErrornamingpip install 'confluent-kafka[oauthbearer-aws]'when the marker is set but the extra isn't installed. The underlying import failure is suppressed, so the third-party dependency never surfaces (no rawModuleNotFoundError: boto3, and no chained__cause__/__context__).librdkafka_string_parser(inconfluent_kafka._util) — a faithful Python port of librdkafka'srd_string_split+rd_kafka_conf_kv_split(backslash escaping, single,separator), sosasl.oauthbearer.config/extensionsstrings tokenize identically to the native client._oauthbearersubpackage (underscore-prefixed = private; users never import it directly):aws/aws_oauthbearer_config.py(parser),aws/aws_sts_token_provider.py(STS call → token mapping),aws/jwt_extractor.py,aws/sasl_extensions_parser.py,aws/aws_iam_marker.py(constants).aws/aws_autowire.create_handleris the internal entry point the C dispatcher resolves.examples/oauth_oidc_ccloud_aws_iam.py.docs/oauthbearer-aws.rst(generated todocs/oauthbearer-aws.mdvia therst2mdMakefile target), included fromdocs/index.rstand linked fromCHANGELOG.md.Companion librdkafka changes (already in v2.15.0-RC1 via librdkafka#5428):
aws_iamvalue tosasl.oauthbearer.metadata.authentication.type's enumtoken.endpoint.urlcheck foraws_iam(parallel toazure_imds)The dispatcher passes the
aws_iammarker straight through to librdkafka (which recognizes it natively, bypasses the OIDCtoken.endpoint.url/grant-type checks, and uses our registeredoauth_cb), so an AWS-IAM-aware librdkafka is required.LIBRDKAFKA_VERSIONis pinned to v2.15.0-RC1 (which contains #5428); bump to the final stable v2.15.0 as a follow-up once it releases.Checklist
New optional extra, new public config keys (
method/ marker /config/extensions), new example, new docs page. Not a breaking change — all additions are gated on theaws_iammarker (marker absent → the dispatcher is a no-op; opt-out installs pull zero AWS dependencies).206 tests under
tests/oauthbearer/aws/(9 files) plus 25 for the string parser undertests/_util/: config parser, STS token provider, JWT subject extractor, SASL-extensions parser, the C dispatcher (via Producer/Consumer/AdminClient construction), thecreate_handlerautowire entry point, a cross-language contract test, and a C↔Python marker-constant drift guard — of which 11 are real-STS integration tests (test_real_sts.py, skipped unless AWS credentials are present).References
JIRA: INIT-14269 (cross-language initiative; swap for the Python sub-task if one exists)
Companion librdkafka PR: confluentinc/librdkafka#5428
Test & Review
Automated:
Manual Testing:
Reviewer entry points:
examples/oauth_oidc_ccloud_aws_iam.py— the public-facing config surface and a worked example.docs/oauthbearer-aws.rst— the user-facing configuration guide (install, config grammar, keys, SASL extensions, common pitfalls).src/confluent_kafka/_oauthbearer/aws/aws_autowire.py— thecreate_handler()entry point + marker constants (aws_iam_marker.py).src/confluent_kafka/src/confluent_kafka.c→resolve_aws_oauthbearer_marker()— the C-extension dispatcher incommon_conf_setup()(the core's marker detection + lazy autowire).src/confluent_kafka/_oauthbearer/aws/aws_sts_token_provider.py— the STS call and response → token mapping.Open questions / Follow-ups