-
Notifications
You must be signed in to change notification settings - Fork 1
/
psmdb-custom-tls-secret.sh
executable file
·86 lines (78 loc) · 2.2 KB
/
psmdb-custom-tls-secret.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
# This script is used to generate custom tls certificates
# (you can update hosts directly in the script)
# https://docs.percona.com/percona-operator-for-mongodb/TLS.html#generate-certificates-manually
CLUSTER_NAME=${1:-my-cluster-name}
NAMESPACE=${2:-default}
cat <<EOF | cfssl gencert -initca - | cfssljson -bare ca
{
"CN": "Root CA",
"names": [
{
"O": "PSMDB"
}
],
"key": {
"algo": "rsa",
"size": 2048
}
}
EOF
cat <<EOF > ca-config.json
{
"signing": {
"default": {
"expiry": "87600h",
"usages": ["signing", "key encipherment", "server auth", "client auth"]
}
}
}
EOF
cat <<EOF | cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=./ca-config.json - | cfssljson -bare server
{
"hosts": [
"localhost",
"${CLUSTER_NAME}-rs0",
"${CLUSTER_NAME}-rs0.${NAMESPACE}",
"${CLUSTER_NAME}-rs0.${NAMESPACE}.svc.cluster.local",
"*.${CLUSTER_NAME}-rs0",
"*.${CLUSTER_NAME}-rs0.${NAMESPACE}",
"*.${CLUSTER_NAME}-rs0.${NAMESPACE}.svc.cluster.local"
],
"names": [
{
"O": "PSMDB"
}
],
"CN": "${CLUSTER_NAME/-rs0}",
"key": {
"algo": "rsa",
"size": 2048
}
}
EOF
cfssl bundle -ca-bundle=ca.pem -cert=server.pem | cfssljson -bare server
kubectl create secret generic ${CLUSTER_NAME}-ssl-internal --from-file=tls.crt=server.pem --from-file=tls.key=server-key.pem --from-file=ca.crt=ca.pem --type=kubernetes.io/tls
cat <<EOF | cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=./ca-config.json - | cfssljson -bare client
{
"hosts": [
"${CLUSTER_NAME}-rs0",
"${CLUSTER_NAME}-rs0.${NAMESPACE}",
"${CLUSTER_NAME}-rs0.${NAMESPACE}.svc.cluster.local",
"*.${CLUSTER_NAME}-rs0",
"*.${CLUSTER_NAME}-rs0.${NAMESPACE}",
"*.${CLUSTER_NAME}-rs0.${NAMESPACE}.svc.cluster.local"
],
"names": [
{
"O": "PSMDB"
}
],
"CN": "${CLUSTER_NAME/-rs0}",
"key": {
"algo": "rsa",
"size": 2048
}
}
EOF
kubectl create secret generic ${CLUSTER_NAME}-ssl --from-file=tls.crt=client.pem --from-file=tls.key=client-key.pem --from-file=ca.crt=ca.pem --type=kubernetes.io/tls