KAFKA-18608: feat: implement private_key_jwt client authentication for OAuth 2.0 #21156
+765
−0
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.
KAFKA-18608: feat: implement private_key_jwt client authentication for OAuth 2.0
Add support for RFC 7523 "private_key_jwt" client authentication method in OAuth Bearer token retrieval, providing an alternative to client_secret authentication using JWT assertions signed with private keys.
New Components
Core Implementation:
PrivateKeyJwtRetriever: Main JWT retriever implementing private_key_jwt client authentication using client_credentials grant type with JWT assertionsPrivateKeyRequestFormatter: HTTP request formatter for OAuth requests with client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearerKidAssertionJwtTemplate: JWT template supporting 'kid' (Key ID) header for key identification in multi-key scenariosKey Features:
Configuration
New SASL configuration options:
sasl.oauthbearer.client.credentials.client.id: Client identifiersasl.oauthbearer.assertion.algorithm: JWT signing algorithmsasl.oauthbearer.assertion.private.key.file: Private key file pathsasl.oauthbearer.assertion.private.key.passphrase: Optional passphraseOAuth 2.0 Compliance
Implements RFC 7523 specification:
grant_type=client_credentialsclient_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearerDifferentiation from Existing Implementation
JwtBearerJwtRetriever: Usesgrant_type=urn:ietf:params:oauth:grant-type:jwt-bearerfor service account authorization flowsPrivateKeyJwtRetriever: Usesgrant_type=client_credentialswith JWT assertions for client authentication (replaces client_secret with JWT)Testing
Comprehensive test coverage:
PrivateKeyJwtRetrieverTest: 6 test cases covering configuration, error handling, and private key authentication flowsPrivateKeyRequestFormatterTest: 17 test cases including parameterized tests for URL encoding, optional parameters, and OAuth request formattingTest scenarios include:
Example Configuration