c++使用librdkafka kerberos认证

1 增加配置:

# Use SASL plaintext
security.protocol=SASL_PLAINTEXT

# Broker service name
sasl.kerberos.service.name=$SERVICENAME

# Client keytab location
sasl.kerberos.keytab=/etc/security/keytabs/${CLIENT_NAME}.keytab

# sasl.kerberos.principal
sasl.kerberos.principal=${CLIENT_NAME}/${CLIENT_HOST}

sasl.kerberos.kinit.cmd命令不用加,文档上面写的是默认执行:kinit -R -t "%{sasl.kerberos.keytab}" -k %{sasl.kerberos.principal} || kinit -t "%{sasl.kerberos.keytab}" -k %{sasl.kerberos.principal}

2 ubuntu客户端安装软件:

apt-get libsasle-modules-gssapi-mit

apt-get libsasle-dev 

apt-get krb5-user
apt-get krb5-config


设置环境变量 KRB5_CONFIG=/***/krb5.conf

把krb5.conf拷贝到/etc/目录替换到原来的krb5.conf文件

3 我这边连接kafka后报错:Failed to initialize SASL authentication: SASL handshake failed (start (-1)): SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure.  Minor code may provide more information (Included profile directory could not be read) (after 0ms in state AUTH_REQ)

其中最主要的报错信息是Included profile directory could not be read,查找之后是krb5.conf文件开头多了一行includedir /etc/krb5.conf.d/,把这行删除,因为不确定默认读的是哪个krb5.conf文件,我把krb5.conf的includedir都删了

4 打包镜像,运行成功。

参考文档:librdkafka: Configuration properties

Kerberos - Community Help Wiki

kinit: Included profile directory could not be read while initializing Kerberos 5 library - 爱码网Using SASL with librdkafka · edenhill/librdkafka Wiki · GitHub

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Python 中实现 Kerberos 认证并避免使用 Kerberos 客户端,需要使用 Python 的 `gssapi` 库。这个库提供了一个 Python 接口,可以使用 GSSAPI 协议进行 Kerberos 认证。 以下是一个简单的 Python 程序,演示如何使用 `gssapi` 库进行 Kerberos 认证: ```python import gssapi # 定义 Kerberos 服务的主机名和服务名 host = "hostname" service = "HTTP" # 创建 GSSAPI 上下文 ctx = gssapi.SecurityContext(usage="initiate") # 初始化上下文并获得初始身份验证令牌 initiate_token = ctx.step() # 向 Kerberos 服务发送身份验证令牌并获得响应 response_token = kerberos_authenticate(host, service, initiate_token) # 处理响应令牌并完成 Kerberos 认证过程 while not ctx.complete: ctx.step(response_token) response_token = kerberos_authenticate(host, service, ctx.step()) # 认证成功,打印客户端身份信息 print("Authenticated as", ctx.initiator_name) ``` 在上面的代码中,`kerberos_authenticate` 函数是用于向 Kerberos 服务发送身份验证令牌并获得响应的自定义函数。这个函数应该调用与 Kerberos 服务器通信的代码,以完成身份验证过程。在函数中,应该使用 `gssapi` 库提供的 `wrap` 和 `unwrap` 方法来对身份验证令牌进行加密和解密。 请注意,这只是一个简单的示例程序,实际的 Kerberos 认证过程可能更加复杂。在实际使用中,您需要根据您的具体需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值