如何将 librdkafka 与 OIDC 和 Azure AD 结合使用作为 OAUTHBEARER 的令牌提供程序?

问题描述 投票:0回答:2

问题

我想将 Kafka OIDC 与 Azure AD 结合使用作为令牌提供程序,但我遇到了一些奇怪的错误。

我已经阅读了许多 azure 文档页面,并尝试了来自 https://github.com/Azure/azure-event-hubs-for-kafka 的示例 - 当我使用 python 和 C++ 进行测试时,所有这些都对我有用。 包括https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/python

中列出的oauth(使用Azure AD)示例

错误

当我尝试按照 https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc 使用注册应用程序网页中的凭据并使用 v2 端点时,我最终得到了

ERROR|rdkafka#producer-1| [thrd:app]: rdkafka#producer-1: sasl_ssl://myhub.servicebus.windows.net:9093/bootstrap: SASL authentication error: Invalid URI: The format of the URI could not be determined. (after 272ms in state AUTH_REQ)
。 对于没有范围的 v1,错误是类似的 -
FAIL|rdkafka#producer-1| [thrd:sasl_ssl://myhub.servicebus.windows.net:9093/bootstrap]: sasl_ssl://myhub.servicebus.windows.net:9093/bootstrap: SASL authentication error: Invalid URI: The format of the URI could not be determined. (after 259ms in state AUTH_REQ).

设置

同样,我测试的所有现有示例都适合我,但没有一个使用 OIDC。 我正在使用的配置如下 - 我应该在

sasl.oauthbearer.token.endpoint.url
sasl.oauthbearer.config
中使用什么来完成这项工作?

    conf->set("bootstrap.servers", "myhub.servicebus.windows.net:9093", errstr);
    conf->set("security.protocol", "SASL_SSL", errstr);
    conf->set("sasl.mechanism", "OAUTHBEARER", errstr);
    conf->set("sasl.oauthbearer.method", "oidc", errstr);
    conf->set("sasl.oauthbearer.client.id", "***", errstr);
    conf->set("sasl.oauthbearer.client.secret", "***", errstr);
    conf->set("sasl.oauthbearer.token.endpoint.url", "https://login.microsoftonline.com/***/oauth2/v2.0/token", errstr);
    conf->set("sasl.oauthbearer.scope", "api://***/.default", errstr);

链接

Confluence Kafka OIDC - https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=186877575

C++ librdkafka OIDC - https://github.com/edenhill/librdkafka/blob/b871fdabab84b2ea1be3866a2ded4def7e31b006/src/rdkafka_sasl_oauthbearer_oidc.c#L242

Github 问题 - https://github.com/Azure/azure-event-hubs-for-kafka/issues/223

编辑:

使用 debug=all 进行进一步调试显示,当应用程序在 SASL 身份验证序列上失败时,会收到 OAUTHBEARER 令牌。

SASL OAUTHBEARER client in state client-first-message
Send SASL Kafka frame to broker
Sent SaslAuthenticateRequest

Received SaslAuthenticateResponse
Invalid URI: The format of the URI could not be determined.
c++ azure oauth-2.0 openid-connect librdkafka
2个回答
0
投票

好的,Azure 回应说 Kafka OIDC 没有在他们这边进行测试,可能不受代理支持。

但我测试了它可以与 Kafka OIDC 配合使用 - 我很快就会向他们的存储库贡献示例。

问题是使用注册应用程序的范围(

api://{app-id}/.default
)与命名空间的范围(
https://myhub.servicebus.windows.net/.default
) - 后一个是正确的。

这反过来又导致接收到错误的令牌类型和无效的 URI 格式 - 这里真正有帮助的是来自 confluence-kafka 的示例,不涉及任何 azure 依赖项

https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/oauth_producer.py


0
投票

我注意到有一个名为 sasl.login.callback.handler.class 的配置,应该在 kafka 生产者客户端中配置。但我找不到合适的地方来配置它。您能分享一下如何配置吗?非常感谢!

© www.soinside.com 2019 - 2024. All rights reserved.