首页 > 解决方案 > 使用 Python 3 和 pika 进行 X.509 身份验证中的 RabbitMQ EXTERNAL 身份验证错误

问题描述

到目前为止,我已经能够使用 pika 在我的 RabbitMQ 后端 (mTLS) 上启用 verify_peer 与 pika 连接到 rabbitmq。所以理论上,当我尝试连接 ssl_auth 插件时,所有事情都应该很棒,对吧?

当我尝试使用 CN 连接 rabbit_auth_mechanism_ssl 时,它失败了。我得到的鼠兔例外我似乎无法在任何地方找到信息。

我已在 RabbitMQ 中将 CN 设置为无密码用户

下面是我的配置和 pika 代码


这些是我启用的插件:

rabbitmq_auth_backend_ldap
rabbitmq_auth_mechanism_ssl
rabbitmq_management

这是我对 rabbitmq conf 的配置:

auth_backends.1=external
auth_backends.2=ldap
auth_backends.3=internal

ssl_cert_login_from = common_name

listeners.tcp = none
listeners.ssl.default = 5671

log.file.level = debug
log.file = rabbit.log

ssl_options.cacertfile = /etc/rabbitmq/certs/cacert.pem
ssl_options.certfile = /etc/rabbitmq/certs/cert.crt
ssl_options.keyfile = /etc/rabbitmq/certs/key.key
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = true

##Some management plugin config##

##Some cluster config## 

我在 advanced.conf 中设置了 ldap,但我不会发送它。


这是python3中的鼠兔代码。我使用的证书同时包含服务器和客户端扩展,所以我在这里使用相同的证书进行身份验证:

import logging
import pika
import ssl
from pika.credentials import ExternalCredentials

if __name__ == '__main__':
  logging.basicConfig(level=logging.INFO)
  context = ssl.create_default_context(cafile="cacert")
  context.load_cert_chain("cert.crt", "key.key")
  context.verify_mode = ssl.CERT_REQUIRED
  ssl_options = pika.SSLOptions(context, "host_that_is_allowed_on_cert.com")
  conn_params = pika.ConnectionParameters(host="rabbit_mq_host_load_balancer_dns", credentials=ExternalCredentials(), port=5671, ssl_options=ssl_options)
  connection = pika.BlockingConnection(conn_params)
  channel = connection.channel()

我需要帮助的 Pika 异常。我不知道从哪里开始

ERROR:pika.adapters.blocking_connection:Connection workflow failed: AMQPConnectionWorkflowFailed: 3 exceptions in all; last exception - 
AMQPConnectorAMQPHandshakeError: AuthenticationError: Server and client could not negotiate use of the EXTERNAL authentication mechanism; first exception
 - AMQPConnectorAMQPHandshakeError: AuthenticationError: Server and client could not negotiate use of the EXTERNAL authentication mechanism

我在兔子服务器日志中看到的只是“客户端意外关闭了连接”,看起来不像“登录”尝试开始了。

<Date Time> [warning] <> closing AMQP connection <> (client_ip:port -> rabbit_node_ip:5671):client unexpectedly closed TCP connection

有没有人以前见过这种事情并且可以指出我正确的调试方向?任何帮助,将不胜感激。

标签: sslrabbitmqpika

解决方案


推荐阅读