Azure AAD pod与Azure事件中心的标识



我需要使用托管身份机制从运行在kubernetes中的Spark流应用程序访问事件中心我正在通过azure AAD pod管理的身份连接到azure事件中心,没有找到任何关于事件中心的文档

  1. azure AAD pod标识是否支持使用azure active directory安全访问事件中心资源。

  2. 任何人都可以提供使用AAD吊舱的事件中心的步骤/代码吗

提前感谢

是的,Aad pod标识支持Azure Eventhub连接。以下是步骤:首先,配置集群以启用托管身份。此外,此场景与禁用RBAC的集群有关。

  • az aks update -g <rg-name> -n <cluster-name> --enable-managed-identity
  • az aks update -g <rg-name> -n <cluster-name> --enable-pod-identity --enable-pod-identity-with-kubenet

在这个conf.之后,您可以启用aad-pod标识:

  • kubectl apply -f https://raw.githubusercontent.com/Azure/aad-pod-identity/v1.8.13/deploy/infra/deployment.yaml
  • kubectl apply -f https://raw.githubusercontent.com/Azure/aad-pod-identity/v1.8.13/deploy/infra/mic-exception.yaml

检查默认名称空间中的3个pod是否为up&正在运行->kubectl get po

使用cli:创建aad-pod标识

az aks pod-identity add --resource-group <rg-name>
--cluster-name <cluster-name> --namespace <your-ns> --name <name> --identity-resource-id <resource-id>
--binding-selector <name_that_use_in_aks>

是否分配了已检查的身份?

az aks show -g <rg-name> -n <cluster-name> | grep -i
<user-assigned-managed-identiy-name>

如果您的配置有效,下面是java代码示例:

ManagedIdentityCredential managedIdentityCredential = new ManagedIdentityCredentialBuilder() //
.clientId("your_id") //
.maxRetry(1) //
.retryTimeout(duration -> Duration.ofMinutes(1)) //
.build();

EventHubProducerAsyncClient eventHubProducerAsyncClient = new EventHubClientBuilder() //
.credential("fullyQualifiedNamespace", "eventhub-name", managedIdentityCredential) //
.buildAsyncProducerClient();
EventData eventData = new EventData(message.getBytes(StandardCharsets.UTF_8));
eventData.setContentType("application/json");
CreateBatchOptions options = new CreateBatchOptions() //
.setPartitionKey("1");
eventHubProducerAsyncClient.createBatch(options) //
.flatMap(batch -> { //
batch.tryAdd(eventData);
return eventHubProducerAsyncClient.send(batch);
}) //
.subscribe(unused -> {
}, error -> {
LOGGER.error("Error occurred while sending message:" + error);
// Omit the exceptions in case sth went wrong while sending merge result
}, () -> { //
LOGGER.debug("Message send successfully.");
});

更多详细信息:

微软相关页面

aad吊舱身份相关页面

最新更新