-
Notifications
You must be signed in to change notification settings - Fork 28
/
start_rabbitmq.sh
executable file
·56 lines (48 loc) · 1.79 KB
/
start_rabbitmq.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
COMMON_NAME=AMQPRS_TEST
USERNAME=user
# Create directories for rabbitmq server and client and alter permissions
#------------------------
mkdir -p rabbitmq_conf/server
mkdir -p rabbitmq_conf/client
sudo chown -R 1001:root rabbitmq_conf/server
sudo chmod 755 rabbitmq_conf/server
sudo chmod 400 rabbitmq_conf/server/*
sudo chmod 444 rabbitmq_conf/client/*
# generate tls cert/key
#------------------------
git clone https://github.com/rabbitmq/tls-gen tls-gen
cd tls-gen/basic
make CN=$COMMON_NAME CLIENT_ALT_NAME=$USERNAME
make verify CN=$COMMON_NAME
make info CN=$COMMON_NAME
ls -lha ./result
cd -
# copy client files
sudo cp tls-gen/basic/result/ca_* rabbitmq_conf/client
sudo cp tls-gen/basic/result/client_* rabbitmq_conf/client
# copy server files
sudo cp tls-gen/basic/result/ca_* rabbitmq_conf/server
sudo cp tls-gen/basic/result/server_* rabbitmq_conf/server
# clean up
rm -rf tls-gen
# to make sure the cert/key files have correct permissions
# and owners within container after bind mount
#------------------------
# copy server files to temparory folder for test
# `1001` is the default user of `bitnami/rabbitmq` container
sudo chown -R 1001:root rabbitmq_conf/server
# strict permissions is mandatory for TLS cert/key files
sudo chmod 755 rabbitmq_conf/server
sudo chmod 400 rabbitmq_conf/server/*
sudo chmod 444 rabbitmq_conf/client/*
# start rabbitmq server
docker compose down
docker compose up -d
# # verify tls connection
# echo "---------- Start rabbitmq now, then come back ... ---------------"
# read -p "After rabbitmq started, press 'y' to verify TLS connection: " ans
# if [ "$ans" = "y" ]; then
# cd rabbitmq_conf/client
# openssl s_client -connect localhost:5671 -cert client_${COMMON_NAME}_certificate.pem -key client_${COMMON_NAME}_key.pem -CAfile ca_certificate.pem
# fi