Skip to content

Commit 8494a31

Browse files
committed
Add script to generate client certs
1 parent 920322b commit 8494a31

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

ansible/roles/docker_client/scripts/genClientCert.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
#!/bin/bash
2-
CERT_PATH=/Users/anandkumarpatel/run/devops-scripts/ansible/certs
32
if [[ $1 = '' ]]; then
43
echo 'script requires a client name'
54
exit 1
65
fi
7-
CLIENT=./files/certs/$1
86

97
echo 'WARN: hard coded alpha-api-old gamma-services and beta-services for SWARM'
10-
# if [[ $2 = '' ]]; then
11-
# echo 'script requires a client ip address'
12-
# exit 1
13-
# fi
8+
if [[ $2 = '' ]]; then
9+
echo 'script requires a client ip address'
10+
exit 1
11+
fi
12+
13+
if [[ $3 = '' ]]; then
14+
echo 'script requires a path for secrets'
15+
exit 1
16+
fi
17+
18+
CERT_PATH=$3
19+
if [ ! -d "$CERT_PATH" ]; then
20+
echo 'The specified directory for certs does not exist'
21+
fi
1422

23+
CLIENT=./$CERT_PATH/$1
1524
mkdir $CLIENT
1625

1726
# generate key for client
@@ -28,16 +37,17 @@ openssl req \
2837
chmod 400 "$CLIENT/client.csr"
2938

3039
echo extendedKeyUsage=clientAuth,serverAuth > "$CLIENT/extfile.cnf"
31-
echo subjectAltName=IP:127.0.0.1,DNS:localhost,DNS:swarm >> "$CLIENT/extfile.cnf"
40+
echo subjectAltName=IP:$2 >> "$CLIENT/extfile.cnf"
3241

3342
# generate cert for client
3443
openssl x509 \
3544
-req \
36-
-days 3650 \
45+
-days 365 \
3746
-sha256 \
3847
-in "$CLIENT/client.csr" \
3948
-CA $CERT_PATH/ca.pem \
4049
-CAkey $CERT_PATH/ca-key.pem \
50+
-passin file:$CERT_PATH/pass \
4151
-CAcreateserial \
4252
-out "$CLIENT/cert.pem" \
4353
-extfile "$CLIENT/extfile.cnf"
@@ -48,4 +58,4 @@ chmod 644 "$CLIENT/key.pem"
4858

4959
# cleanup files we do not need
5060
rm $CLIENT/extfile.cnf
51-
rm $CLIENT/client.csr
61+
rm -f $CLIENT/client.csr

generate-all-client-certs.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- hosts: user-local
3+
connection: local
4+
tasks:
5+
- name: generate client certs
6+
shell:
7+
cmd: ./roles/docker_client/scripts/genClientCert.sh "{{ item }}" "{{ groups['main'][0] }}"
8+
chdir: ./
9+
with_items:
10+
- "api"
11+
- "api-core"
12+
- "socket-server"
13+
- "api-socket-server"
14+
- "workers"
15+
- "api-worker"
16+
- "khronos"
17+
- "palantiri"
18+
- "docker-listener"
19+
- "shiva"
20+
- "sauron"
21+
- "swarm-manager"

0 commit comments

Comments
 (0)