Skip to content

Add support for different claims for authentication#5336

Merged
pranav shah (prashah-confluent) merged 21 commits intomasterfrom
dev_prashah_sasl_subclaim
Mar 16, 2026
Merged

Add support for different claims for authentication#5336
pranav shah (prashah-confluent) merged 21 commits intomasterfrom
dev_prashah_sasl_subclaim

Conversation

@prashah-confluent
Copy link
Copy Markdown
Member

@prashah-confluent pranav shah (prashah-confluent) commented Mar 2, 2026

PR description

Problem

For OIDC / SASL_OAUTHBEARER flows using librdkafka’s built‑in OIDC helper, we currently hard‑require that the JWT payload contain a sub claim. If the IdP omits sub or uses another claim (for example client_id) as the primary subject, librdkafka fails token acquisition with an error such as:

Failed to acquire SASL OAUTHBEARER token: Expected JSON JWT response with "sub" field

Fix

We have introduced a new config sub_claim_name using which customers can provide a different claim. The claim value will be honored and used for client side validation.

Note
Requires users to keep broker and client configs aligned for the subject claim name to avoid confusion and consistency.

Testing

Unit tests

To test the core JWT payload parsing and claim extraction logic inside rd_kafka_oidc_token_try_validate() in isolation (no broker, network, oidc server).

  1. Default Configuration & Backward Compatibility
    Implicit Default Behavior: Validate that when sub.claim.name is not provided, the system defaults to extracting the subject from the "sub" claim.
    Legacy Parity: Ensure that existing JWTs containing only the "sub" claim continue to be processed correctly, maintaining no regressions for standard OIDC flows.

  2. Explicit Claim Configuration (KIP-768 Parity)
    Custom Claim Extraction: Verify that setting sub.claim.name (e.g., to client_id) successfully extracts the value from the specified field instead of the hardcoded "sub" key.
    Configuration Precedence: Test that when both "sub" and a custom claim (e.g., "client_id") coexist in a JWT, the system honors the user-defined configuration over the OIDC default.

  3. Error Handling & Validation Logic
    Missing Claim Detection: Verify that providing a sub.claim.name that does not exist in the JWT triggers a specific "Claim not found" error, rather than failing on a hardcoded "sub".
    Empty Value Rejection: Ensure the system rejects empty string subjects with a "non-empty value required" error, addressing previous bugs where empty strings passed silently.
    Invalid Configuration Recovery: Validate that if sub.claim.name is set to an empty string, the system gracefully falls back to the OIDC default ("sub") to ensure continuous operation.

  4. librdkafka & Java Client Alignment
    Functional Parity: Ensure all scenarios are cross-validated against the Java KIP-768 implementation to guarantee identical extraction logic and exception triggers (e.g., ValidateException equivalents).

Integration tests

  • To validate end-to-end OIDC authentication against a real Kafka cluster (via trivup) with different sasl.oauthbearer.sub.claim.name configurations
  • The trivup setup requires changes for returning JWT response with multiple claims

Design Doc

@confluent-cla-assistant
Copy link
Copy Markdown

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@prashah-confluent pranav shah (prashah-confluent) marked this pull request as ready for review March 4, 2026 12:19
@prashah-confluent pranav shah (prashah-confluent) requested a review from a team as a code owner March 4, 2026 12:19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Pranav! This is my feedback:

Comment thread src/rdkafka_conf.c Outdated
Comment thread src/rdkafka_sasl_oauthbearer_oidc.c Outdated
Comment thread tests/0126-oauthbearer_oidc.c Outdated
Comment thread CHANGELOG.md Outdated
Comment thread src/rdkafka_sasl_oauthbearer_oidc.c Outdated
Comment thread tests/0126-oauthbearer_oidc.c
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@prashah-confluent pranav shah (prashah-confluent) merged commit f21766f into master Mar 16, 2026
4 checks passed
@prashah-confluent pranav shah (prashah-confluent) deleted the dev_prashah_sasl_subclaim branch March 16, 2026 15:10
airlock-confluentinc Bot pushed a commit that referenced this pull request Apr 6, 2026
* Add documentation for new sub claim config

* Add new config in rdkafka_conf

* Modify logic based on subclaim name value

* Add unit tests

* Fix style format errors for the modified files

* Add integration tests for sub claim name

* Fix style check for 0126-oauthbearer_oidc

* Add new trivup version 0.15.0 and update the dependency in requirements.txt

* Remove redundant comments

* Update Change log

* Remove the link for PR as GH adds it automatically

* Add validation for subclaim string configuration

* Remove tests as preconditions will already be validated before

* Function should fail agnostic of reason. Corrected the comment

* Modify integration test to fail at configuration finalization

* Fix comment for configuration.md consistency

* Add back the default value for sub_claim_name configuration

* Rebuilt CONFIGURATION.md and fix style check

* Fix style check

* Add unit tests for rd_kafka_conf_validate_str

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants