Skip to content

Commit 9179763

Browse files
authored
Merge pull request #8 from ssijbabu/workloadidentity
Added azure workload identity
2 parents 20c4493 + 3f44509 commit 9179763

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ The rest of the parameters are read from the environment variables.
7575
- `AZURE_CLIENT_ID` / `AZURE_USERNAME` / `AZURE_PASSWORD` / `AZURE_TENANT_ID` : for username password authentication
7676

7777

78+
```properties
79+
sasl.login.callback.handler.class=io.conduktor.kafka.security.oauthbearer.azure.AzureManagedIdentityCallbackHandler
80+
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required scope="https://<resource>/.default";
81+
```
82+
83+
### Workload Identity Authentication
84+
85+
Use Azure workload identity environment variables to configure token auth bearer retriever.
86+
More details on Azure identity [WorkloadIdentityCredential documentation](https://learn.microsoft.com/en-us/java/api/com.azure.identity.workloadidentitycredential?view=azure-java-stable)
87+
88+
Use `io.conduktor.kafka.security.oauthbearer.azure.AzureManagedIdentityCallbackHandler` as the callback handler class and provide
89+
the following required parameters in the `sasl.jaas.config` property :
90+
- `scope` : The [scope](https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc#the-default-scope) of the token
91+
92+
The rest of the parameters are read from the environment variables.
93+
- `AZURE_CLIENT_ID` / `AZURE_TENANT_ID` / `AZURE_FEDERATED_TOKEN_FILE` : for workload identity authentication
94+
95+
7896
```properties
7997
sasl.login.callback.handler.class=io.conduktor.kafka.security.oauthbearer.azure.AzureManagedIdentityCallbackHandler
8098
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required scope="https://<resource>/.default";

src/main/java/io/conduktor/kafka/security/oauthbearer/azure/AzureIdentityAccessTokenRetriever.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.azure.identity.ClientCertificateCredential;
66
import com.azure.identity.ClientCertificateCredentialBuilder;
77
import com.azure.identity.EnvironmentCredentialBuilder;
8+
import com.azure.identity.WorkloadIdentityCredentialBuilder;
89
import org.apache.kafka.common.config.ConfigException;
910
import org.apache.kafka.common.errors.AuthenticationException;
1011
import org.apache.kafka.common.security.oauthbearer.internals.secured.AccessTokenRetriever;
@@ -57,9 +58,10 @@ public String retrieve() {
5758
try {
5859
// See https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow#second-case-access-token-request-with-a-certificate
5960
// See https://learn.microsoft.com/en-us/java/api/overview/azure/identity-readme?view=azure-java-stable#credential-classes
60-
var chainedTokenCredentialBuilder = new ChainedTokenCredentialBuilder();
61-
clientCertificateCredentials.ifPresent(chainedTokenCredentialBuilder::addFirst);
61+
var chainedTokenCredentialBuilder = new ChainedTokenCredentialBuilder();
6262
chainedTokenCredentialBuilder.addLast(new EnvironmentCredentialBuilder().build());
63+
chainedTokenCredentialBuilder.addLast(new WorkloadIdentityCredentialBuilder().build());
64+
clientCertificateCredentials.ifPresent(chainedTokenCredentialBuilder::addLast);
6365

6466
var clientCredentials = chainedTokenCredentialBuilder.build();
6567
return clientCredentials.getTokenSync(new TokenRequestContext().setScopes(scopes)).getToken();

0 commit comments

Comments
 (0)