【问题标题】:Exception (403) Reason: "username or password not allowed"异常 (403) 原因:“用户名或密码不允许”
【发布时间】:2021-06-19 19:56:30
【问题描述】:

我正在尝试访问启用了 TLS 的 rabbitmq 集群。我编写了示例 go 应用程序,它尝试使用一组客户端证书和客户端密钥连接到 rabbitmq 服务器。

我遇到了错误 -

Error is - Exception (403) Reason: "username or password not allowed"
panic: Exception (403) Reason: "username or password not allowed"

我的代码sn-p

package main

import (
    "crypto/tls"
    "crypto/x509"
    "fmt"
    "io/ioutil"
    "log"

    "github.com/streadway/amqp"
)

func main() {
    fmt.Println("Go RabbitMQ Consumer Tutorial")
    fmt.Println("Testing ClusterIP service connection over TLS")

    cert, err := tls.LoadX509KeyPair("client.crt", "client.key")
    if err != nil {
        panic(err)
    }
    //Load CA cert.
    caCert, err := ioutil.ReadFile("ca.crt") // The same you configured in your MQ server
    if err != nil {
        log.Fatal(err)
    }
    caCertPool := x509.NewCertPool()
    caCertPool.AppendCertsFromPEM(caCert)

    TlsConfig1 := &tls.Config{
        Certificates:       []tls.Certificate{cert}, // from tls.LoadX509KeyPair
        RootCAs:            caCertPool,
        InsecureSkipVerify: true,
        // ...other options are just the same as yours
    }
    
    conn, err := amqp.DialTLS("amqps://<username>:<password>@<rabbitmq-service-name>.<namespace>.svc.cluster.local:5671/", TlsConfig1)
    if err != nil {
        fmt.Println("Error is -", err)
        panic(err)
    }

    fmt.Println("Connected to consumer successfully")
    defer conn.Close()

    ch, err := conn.Channel()
    if err != nil {
        fmt.Println(err)
    }
    defer ch.Close()

    if err != nil {
        fmt.Println(err)
    }

    msgs, err := ch.Consume(
        "TestQueue",
        "",
        true,
        false,
        false,
        false,
        nil,
    )

    forever := make(chan bool)
    go func() {
        for d := range msgs {
            fmt.Printf("Recieved Message: %s\n", d.Body)
        }
    }()

    fmt.Println("Successfully Connected to our RabbitMQ Instance")
    fmt.Println(" [*] - Waiting for messages")
    <-forever

}

代码 sn-p 在我的 rabbitmq 集群运行的 EKS 集群中作为 pod 运行。

【问题讨论】:

    标签: docker go ssl kubernetes rabbitmq


    【解决方案1】:

    通过rabbitmq TLS调试文档-https://www.rabbitmq.com/access-control.html我发现我输入了错误的用户名和密码。

    注意:如果有人也遇到同样的错误 - 请确认您使用的用户名和密码正确。

    您可以通过登录rabbitmq集群pod查看集群的用户名和密码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 2013-09-13
      • 1970-01-01
      相关资源
      最近更新 更多