Bootstrap FreeKB - RabbitMQ - SSL/TLS
RabbitMQ - SSL/TLS

Updated:   |  RabbitMQ articles

Configuring RabbitMQ to use SSL will make it so that:

  • HTTPS can be used with the RabbitMQ web admin console
  • The AMQPS protocol can be used when making an AMQ connection to RabbitMQ
  • SSL is used when using the RabbitMQ CLI tools, such as the rabbitmqctl command

For example, after RabbitMQ has been configured to use SSL, you should be able to access the RabbitMQ web console over HTTPS.

 

The RabbitMQ configuration file, which by default is located at /etc/rabbitmq/rabbitmq.conf (Erlang format) or /etc/rabbitmq/rabbitmq.config (INI format), will list the SSL directives.

If the conf file in in the INI format, something like this should be displayed.

ssl_options.cacertfile = /var/lib/rabbitmq/config/certs/ca_certificate_bundle.pem
ssl_options.certfile   = /var/lib/rabbitmq/config/certs/server_certificate.pem
ssl_options.keyfile    = /var/lib/rabbitmq/config/certs/server_key.pem
ssl_options.password   = itsasecret
ssl_options.versions.1 = tlsv1.2
management.ssl.port    = 15671

 

If the rabbitmq.conf file is in Erlang format, and SSL is disabled, something like this should be defined.

{use_ssl, false}

 

On the other hand, if SSL is enabled, something like this should be defined.

[
  {rabbit, [{ssl_options, [{cacertfile,           "/var/lib/rabbitmq/config/certs/ca_certificate_bundle.pem"},
                           {certfile,             "/var/lib/rabbitmq/config/certs/server_certificate.pem"},
                           {keyfile,              "/var/lib/rabbitmq/config/certs/server_key.pem"},
                           {password,             "itsasecret"},
                           {verify,               verify_peer},
                           {fail_if_no_peer_cert, true}]}]}
].

 

If you have 2 or more nodes clustered, the /etc/rabbitmq/rabbitmq-env.conf file should contain something like this. Notice in this example a reference to a file named ssl_dist.config. This file name can be unique, and does not have to be ssl_dist.config. The file must be readable by the rabbitmq user.

SERVER_ADDITIONAL_ERL_ARGS="-pa $ERL_SSL_PATH
  -proto_dist inet_tls
  -ssl_dist_optfile /etc/rabbitmq/ssl_dist.config"

CTL_ERL_ARGS="-pa $ERL_SSL_PATH
  -proto_dist inet_tls
  -ssl_dist_optfile /etc/rabbitmq/ssl_dist.config"

 

The -ssl_dist_optfile, which is ssl_dist.config in this example, should contain something like this.

[
  {server, [
    {cacertfile, "/var/lib/rabbitmq/config/certs/ca_certificate_bundle.pem"},
    {certfile, "/var/lib/rabbitmq/config/certs/server_certificate.pem"},
    {keyfile,  "/var/lib/rabbitmq/config/certs/server_key.pem"},
    {password, "itsasecret"},
    {secure_renegotiate, true},
    {verify, verify_peer},
    {fail_if_no_peer_cert, true}
  ]},
  {client, [
    {cacertfile, "/var/lib/rabbitmq/config/certs/ca_certificate_bundle.pem"},
    {certfile, "/var/lib/rabbitmq/config/certs/server_certificate.pem"},
    {keyfile, "/var/lib/rabbitmq/config/certs/server_key.pem"},
    {password, "itsasecret"},
    {secure_renegotiate, true},
    {verify, verify_peer},
    {fail_if_no_peer_cert, true}
  ]}
].

 

The cat command (on Linux) can be used to view the content of each certificate file, which should return something like this.

]# cat certificate.pem
-----BEGIN CERTIFICATE-----
MIIG2zCCBcOgAwIBAgITFwAFD6 . . .
-----END CERTIFICATE-----

 

The openssl command with the X509, -text, and -noout options can be used to view the actual certificate data.

openssl x509 -text -noout -in certificate.pem

 

The rabbitmqctl encode command can be used to created an encoded version of the password. In this example, the string "itsasecret" is encoded, using 'foo' as the passphrase for the encoded string.

rabbitmqctl encode itsasecret foo

 

Something like this should be returned.

Encrypting value ...
{encrypted,<<"T/pCGSrOlDkpnBvUA6mOPe2aTj8UMDZKtB9FIgm0r6ql8QgroXQkaEnejuRNrKms">>}

 

The rabbitmq.conf file can then be updated to use the encoded string. Notice that this does not remove cleartext passwords, as this simply replaces "itsasecret" with "foo" in the configuration file.

[
  {rabbit, [{ssl_options, [{cacertfile,           "/var/lib/rabbitmq/config/certs/ca_certificate_bundle.pem"},
                           {certfile,             "/var/lib/rabbitmq/config/certs/server_certificate.pem"},
                           {keyfile,              "/var/lib/rabbitmq/config/certs/server_key.pem"},
                           {password,             "itsasecret"},
                             {encrypted, "T/pCGSrOlDkpnBvUA6mOPe2aTj8UMDZKtB9FIgm0r6ql8QgroXQkaEnejuRNrKms"}
                           {verify,               verify_peer},
                           {fail_if_no_peer_cert, true}]}]},
  {config_entry_decoder, [
    {passphrase, "foo"}
   ]
  }
].

 

When updating the certificate files (e.g. server_certificate.pem, ca_certificate_bundle.pem) with a new certificate, you will need to restart the RabbitMQ service for this change to take effect so that the RabbitMQ web browser console is using the new certificate.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


April 17 2024 by Peter Lux
Jeremy - I'm not sure if you're the person to ask but I'm brand new at a new job and I've literally have hit a brick wall with RabbitMQ. I managed to get tls-gen and generated to my laptop and have setup 5671. I've configured the user in Rabbit using port 5672 and I can send/receive messages till i'm blue-in-the-face. The problem is that NO MATTER WHAT, when it goes to CreateConnection, it bombs EVERYTIME with "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host." I've run it at least 300 times and it always bombs. I've configured the certificates but it will not LET ME PASS. I know the certs are good, I have the pass but I don't want to use user/password.. just the certs. I know that many people have this problem, so I now it's just me. I'm all Microsoft, as well. I have the certs .. do I have to add it in the CertMGR certificate manager?? Please let me know what I can do and I can buy you a coffee!!

Add a Comment


Please enter 8ec0e6 in the box below so that we can be sure you are a human.