Hi there,
I am trying to enable TLS authentication for RabbitMQ clients and despite all the useful information
I've found on this mailing list I am still not capable to solve my problem(s).
First of all, I should clarify that I don't have any previous experience with RabbitMQ nor SSL/TLS,
hence I'll appreciate any suggestion/correction about what I've done since now.
Before proceeding into the description of the steps I made, some information:
[server]
Ubuntu 18.04.2 LTS
Linux 4.15.0-50-generic x86_64
[RabbitMQ]
[RabbitMQ - enabled plugins]
[E*] rabbitmq_auth_backend_http 3.7.15
[E*] rabbitmq_auth_mechanism_ssl 3.7.15
[E*] rabbitmq_management 3.7.15
[e*] rabbitmq_management_agent 3.7.15
[E*] rabbitmq_mqtt 3.7.15
[E*] rabbitmq_shovel 3.7.15
[E*] rabbitmq_shovel_management 3.7.15
[E*] rabbitmq_top 3.7.15
[e*] rabbitmq_web_dispatch 3.7.15
[E*] rabbitmq_web_mqtt 3.7.15
[Erlang]
[Erlang - VM TLS support]
tlsv1.3
tlsv1.2
tlsv1.1
tlsv1
sslv3
Following
the RabbitMQ ssl guide I created CA and certificate/key pairs using tls-gen (basic profile), ending up with the following files:
ca_certificate.pem
ca_key.pem
client_certificate.pem
client_key.p12
client_key.pem
server_certificate.pem
server_key.p12
server_key.pem
I moved all of them to /etc/rabbitmq/certs and checked that both directories and files have the correct owner (which I found using ps aux | grep rabbitmq):
ls -l /etc/rabbitmq/
drwxr-sr-x 2 rabbitmq rabbitmq 4096 Jun 12 00:58 certs/
-rw-r--r-- 1 root rabbitmq 166 Jun 12 01:23 enabled_plugins
-rw-r--r-- 1 rabbitmq rabbitmq 570 Jun 12 02:19 rabbitmq.conf
and
ls -l /etc/rabbitmq/certs
-rw-r--r-- 1 rabbitmq rabbitmq 1196 Jun 12 00:58 ca_certificate.pem
-rw------- 1 rabbitmq rabbitmq 1704 Jun 12 00:58 ca_key.pem
-rw-r--r-- 1 rabbitmq rabbitmq 1147 Jun 12 00:58 client_certificate.pem
-rw------- 1 rabbitmq rabbitmq 2405 Jun 12 00:58 client_key.p12
-rw------- 1 rabbitmq rabbitmq 1675 Jun 12 00:58 client_key.pem
-rw-r--r-- 1 rabbitmq rabbitmq 1237 Jun 12 00:58 server_certificate.pem
-rw------- 1 rabbitmq rabbitmq 2477 Jun 12 00:58 server_key.p12
-rw------- 1 rabbitmq rabbitmq 1679 Jun 12 00:58 server_key.pem
Once I recognised that my client (which is paho-mqtt) had some issues during TLS authentication,
NOTE:
server -> Ubuntu VM (VirtualBox) with bridge network (IP: 192.168.0.26)
client -> Ubuntu Host, same version of the server (also same openssl version: 1.1.1)
Protocol listeners are:
Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Interface: [::], port: 5671, protocol: amqp/ssl, purpose: AMQP 0-9-1 and AMQP 1.0 over TLS
Interface: [::], port: 1883, protocol: mqtt, purpose: MQTT
Interface: [::], port: 15675, protocol: http/web-mqtt, purpose: MQTT over WebSockets
Interface: [::], port: 15672, protocol: http, purpose: HTTP API
double checking with netstat confirm the previous results:
netstat -tulnp | grep beam
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 7232/beam.smp
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 7232/beam.smp
tcp 0 0 0.0.0.0:15675 0.0.0.0:* LISTEN 7232/beam.smp
tcp6 0 0 :::5671 :::* LISTEN 7232/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 7232/beam.smp
tcp6 0 0 :::1883 :::* LISTEN 7232/beam.smp
Openssl tools to test TLS connections confirm that certificates and keys are OK, running:
openssl s_server -accept 8443 -cert server_certificate.pem -key server_key.pem -CAfile ca_certificate.pem
on the server and:
openssl s_client -connect 192.168.0.26:8443 -cert client_certificate.pem -key client_key.pem -CAfile ca_certificate.pem -verify 8 -verify_hostname caldev
the trust chain is established and the client shows:
Verify return code: 0 (ok)
But when I run the same test against the RabbitMQ broker using:
openssl s_client -connect 192.168.0.26:5671 -cert client_certificate.pem -key client_key.pem -CAfile ca_certificate.pem
on server side I can see (tail -f /var/log/rabbitmq/rab...@caldev.log):
2019-06-12 04:14:23.287 [info] <0.2844.0> accepting AMQP connection <0.2844.0> (192.168.0.25:51481 -> 192.168.0.26:5671)
2019-06-12 04:14:23.288 [error] <0.2844.0> closing AMQP connection <0.2844.0> (192.168.0.25:51481 -> 192.168.0.26:5671): {handshake_timeout,handshake}
which cause the client to log:
or, when I run openssl s_client in -debug mode:
read from 0x7fffbfde0990 [0x7fffbfde92a3] (5 bytes => 5 (0x5))
0000 - 15 03 03 00 1a .....
read from 0x7fffbfde0990 [0x7fffbfde92a8] (26 bytes => 26 (0x1A))
0000 - 04 ff 3a 82 48 b8 1c 57-79 91 ab 03 25 71 e3 e5 ..:.H..Wy...%q..
0010 - 94 e0 6b 4c e4 5a 84 bd-33 78 ..kL.Z..3x
closed
write to 0x7fffbfde0990 [0x7fffbfded3f3] (31 bytes => 0 (0x0))
read from 0x7fffbfde0990 [0x7fffbfdd4e50] (8192 bytes => 0 (0x0))
Since the RabbitMQ and openssl documentation are both well written, I think that due to my lack of experience of the whole thing I am missing something important, could someone of you point me in the right direction?
Also, please find attached my:
- rabbitmq.conf
- rabbitmq.logs
Thank you for your time,
Lorenzo