Skip to content

Commit 4289dd1

Browse files
committed
Update managed identity doc for Kafka
1 parent eb26bfb commit 4289dd1

File tree

1 file changed

+106
-32
lines changed

1 file changed

+106
-32
lines changed

articles/event-hubs/event-hubs-quickstart-kafka-enabled-event-hubs.md

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,88 @@ When you create an Event Hubs namespace, the Kafka endpoint for the namespace is
3838

3939
3. Update the configuration details for the producer in `src/main/resources/producer.config` as follows:
4040

41-
**TLS/SSL:**
41+
42+
#### [Passwordless (Recommended)](#tab/passwordless)
43+
44+
**OAuth:**
45+
46+
Azure Event Hubs supports using Azure Active Directory (Azure AD) to authorize requests to Event Hubs resources. With Azure AD, you can use Azure role-based access control (Azure RBAC) to grant permissions to a security principal, which may be a user, or an application service principal.
47+
48+
If you want to run this sample locally with Azure AD authentication, be sure your user account has authenticated via Azure Toolkit for IntelliJ, Visual Studio Code Azure Account plugin, or Azure CLI. Also, be sure the account has been granted sufficient permissions.
49+
50+
> [!NOTE]
51+
> You need to set the following data plane access roles: `Azure Event Hubs Data Sender` and `Azure Event Hubs Data Receiver`.
52+
53+
To authenticate using the Azure CLI, use the following steps.
54+
55+
1. First, use the following command to get the resource ID for your Azure Event Hubs namespace:
56+
57+
```azurecli
58+
export AZURE_RESOURCE_ID=$(az resource show \
59+
--resource-group $AZ_RESOURCE_GROUP \
60+
--name $AZ_EVENTHUBS_NAMESPACE_NAME \
61+
--resource-type Microsoft.EventHub/Namespaces \
62+
--query "id" \
63+
--output tsv)
64+
```
65+
66+
1. Second, use the following command to get your user object ID of your Azure CLI user account:
67+
68+
```azurecli
69+
export AZURE_ACCOUNT_ID=$(az ad signed-in-user show \
70+
--query "id" --output tsv)
71+
```
72+
73+
1. Then, use the following commands to assign the `Azure Event Hubs Data Sender` and `Azure Event Hubs Data Receiver` roles to your account.
74+
75+
```azurecli
76+
az role assignment create \
77+
--assignee $AZURE_ACCOUNT_ID \
78+
--role "Azure Event Hubs Data Receiver" \
79+
--scope $AZURE_RESOURCE_ID
80+
81+
az role assignment create \
82+
--assignee $AZURE_ACCOUNT_ID \
83+
--role "Azure Event Hubs Data Sender" \
84+
--scope $AZURE_RESOURCE_ID
85+
```
86+
87+
For more information about granting access roles, see [Authorize access to Event Hubs resources using Azure Active Directory](/azure/event-hubs/authorize-access-azure-active-directory).
88+
89+
Once your user account is authenticated, you can update use following configuration in `src/main/resources/producer.config` as shown below.
90+
91+
```xml
92+
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
93+
security.protocol=SASL_SSL
94+
sasl.mechanism=OAUTHBEARER
95+
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
96+
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
97+
```
98+
99+
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/producer/src/main/java).
100+
101+
102+
---
103+
104+
#### [Connection string](#tab/connection-string)
105+
106+
**TLS/SSL:**
42107

43108
```xml
44109
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
45110
security.protocol=SASL_SSL
46111
sasl.mechanism=PLAIN
47112
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="{YOUR.EVENTHUBS.CONNECTION.STRING}";
48113
```
49-
50-
> [!IMPORTANT]
51-
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
52114

53-
**OAuth:**
115+
> [!IMPORTANT]
116+
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
117+
118+
---
119+
54120

55-
```xml
56-
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
57-
security.protocol=SASL_SSL
58-
sasl.mechanism=OAUTHBEARER
59-
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
60-
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
61-
```
62121

63-
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/producer/src/main/java).
122+
64123
4. Run the producer code and stream events into Event Hubs:
65124

66125
```shell
@@ -72,31 +131,46 @@ When you create an Event Hubs namespace, the Kafka endpoint for the namespace is
72131

73132
6. Update the configuration details for the consumer in `src/main/resources/consumer.config` as follows:
74133

75-
**TLS/SSL:**
76134

77-
```xml
78-
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
79-
security.protocol=SASL_SSL
80-
sasl.mechanism=PLAIN
81-
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="{YOUR.EVENTHUBS.CONNECTION.STRING}";
82-
```
135+
#### [Passwordless (Recommended)](#tab/passwordless)
83136

84-
> [!IMPORTANT]
85-
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
137+
Make sure you configure Azure AD authentication as mentioned in step 3 and use the followning consumer configuration.
138+
**OAuth:**
139+
140+
```xml
141+
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
142+
security.protocol=SASL_SSL
143+
sasl.mechanism=OAUTHBEARER
144+
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
145+
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
146+
```
147+
148+
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/consumer/src/main/java).
149+
150+
You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
151+
152+
153+
---
154+
155+
#### [Connection string](#tab/connection-string)
156+
157+
**TLS/SSL:**
158+
159+
```xml
160+
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
161+
security.protocol=SASL_SSL
162+
sasl.mechanism=PLAIN
163+
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="{YOUR.EVENTHUBS.CONNECTION.STRING}";
164+
```
165+
166+
> [!IMPORTANT]
167+
> Replace `{YOUR.EVENTHUBS.CONNECTION.STRING}` with the connection string for your Event Hubs namespace. For instructions on getting the connection string, see [Get an Event Hubs connection string](event-hubs-get-connection-string.md). Here's an example configuration: `sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXX";`
168+
169+
---
86170
87-
**OAuth:**
88171
89-
```xml
90-
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
91-
security.protocol=SASL_SSL
92-
sasl.mechanism=OAUTHBEARER
93-
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;
94-
sasl.login.callback.handler.class=CustomAuthenticateCallbackHandler;
95-
```
96172
97-
You can find the source code for the sample handler class CustomAuthenticateCallbackHandler on GitHub [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret/consumer/src/main/java).
98173
99-
You can find all the OAuth samples for Event Hubs for Kafka [here](https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth).
100174
7. Run the consumer code and process events from event hub using your Kafka clients:
101175
102176
```java

0 commit comments

Comments
 (0)