AWS IAM OAUTHBEARER support via optional oauthbearer-aws module#2267
Draft
pranav shah (prashah-confluent) wants to merge 15 commits into
Draft
AWS IAM OAUTHBEARER support via optional oauthbearer-aws module#2267pranav shah (prashah-confluent) wants to merge 15 commits into
oauthbearer-aws module#2267pranav shah (prashah-confluent) wants to merge 15 commits into
Conversation
… subject extractor
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
oauthbearer-aws module
|
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(required),duration_seconds,signing_algorithm(ES384/RS256),sts_endpoint,principal_name,aws_debug(Pythonicnone|consolesubset →boto3.set_stream_logger('botocore', DEBUG)), and repeatabletag_<name>JWT-claim entries (max 50). Full parity with the .NET grammar.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 anImportErrornamingpip install 'confluent-kafka[oauthbearer-aws]'when the marker is set but the extra isn't installed (never a rawModuleNotFoundError: boto3)._kv_string_parserfor the whitespace/equals grammar, placed inconfluent_kafkacore (mirrors .NET'sKvStringParserplacement)._aws_oauthbearer_config.py(parser),_aws_sts_token_provider.py(STS call → token mapping),_aws_jwt_subject_extractor.py,_aws_sasl_extensions_parser.py,_aws_iam_marker.py(constants). Onlyaws_autowire.create_handleris public.examples/oauth_oidc_ccloud_aws_iam.py.Companion librdkafka changes are required for this PR to function end-to-end:
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. When the changes ship to a stablelibrdkafkarelease, bumpLIBRDKAFKA_VERSIONto it as a follow-up.Checklist
New optional extra, new public config keys (
method/ marker /config/extensions), new example. 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).209 tests under
tests/oauthbearer/aws/(9 files): 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 12 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.src/confluent_kafka/oauthbearer/aws/aws_autowire.py— the staticcreate_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