Skip to content

Commit 18bccd5

Browse files
Add demo script for enabling TLS on mdbm resource (#246)
1 parent 0b2d87a commit 18bccd5

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

tools/multicluster/.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project_name: kubectl-mongodb-multicluster
1+
project_name: kubectl-mongodb_multicluster
22

33
before:
44
hooks:
@@ -17,7 +17,7 @@ builds:
1717

1818
archives:
1919
- format: tar.gz
20-
name_template: "kubectl-mongodb-multicluster_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
20+
name_template: "kubectl-mongodb_multicluster_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
2121
checksum:
2222
name_template: 'checksums.txt'
2323
snapshot:

tools/multicluster/setup_tls.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
5+
# This script is intended for demoing and not for general customer usage. This script has no official MongoDB support and is not guaranteed to be maintained.
6+
#
7+
# This script requires having `mkcert` installed for creating a local CA
8+
# Sample usage:
9+
# ./setup_tls.sh mongodb multi-cluster-replica-set
10+
11+
namespace="${1:-mongodb}"
12+
resource="${2:-multi-replica-set}"
13+
14+
# Install cert-manager
15+
helm upgrade --install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
16+
17+
# Setup local CA
18+
mkcert -install
19+
20+
# Create CA secret in kubernetes
21+
kubectl create secret tls ca-key-pair --cert="$(mkcert --CAROOT)/rootCA.pem" --key="$(mkcert --CAROOT)/rootCA-key.pem" -n "${namespace}"
22+
23+
# Download mongodb certs and append them to the local CA cert
24+
openssl s_client -showcerts -verify 2 -connect downloads.mongodb.com:443 -servername downloads.mongodb.com </dev/null | awk '/BEGIN/,/END/{ if(/BEGIN/){a++}; out="cert"a".crt"; print >out}' || true
25+
cat "$(mkcert --CAROOT)/rootCA.pem" cert1.crt cert2.crt cert3.crt cert4.crt >>ca-chain.crt
26+
27+
# Create CA certificates config map from certificate chain
28+
kubectl create configmap issuer-ca --from-file=mms-ca.crt=ca-chain.crt --from-file=ca-pem=ca-chain.crt -n "${namespace}"
29+
30+
# Crete Issuer for certs
31+
cat <<EOF | kubectl -n "${namespace}" apply -f -
32+
apiVersion: cert-manager.io/v1
33+
kind: Issuer
34+
metadata:
35+
name: mongodb-ca-issuer
36+
spec:
37+
ca:
38+
secretName: ca-key-pair
39+
EOF
40+
41+
# Create server certificates on central cluster
42+
cat <<EOF | kubectl -n "${namespace}" apply -f -
43+
apiVersion: cert-manager.io/v1
44+
kind: Certificate
45+
metadata:
46+
name: clustercert-${resource}-cert
47+
spec:
48+
dnsNames:
49+
- ${resource}-svc.mongodb.svc.cluster.local
50+
- ${resource}-0-0-svc.mongodb.svc.cluster.local
51+
- ${resource}-0-1-svc.mongodb.svc.cluster.local
52+
- ${resource}-0-2-svc.mongodb.svc.cluster.local
53+
- ${resource}-1-0-svc.mongodb.svc.cluster.local
54+
- ${resource}-1-1-svc.mongodb.svc.cluster.local
55+
- ${resource}-2-0-svc.mongodb.svc.cluster.local
56+
- ${resource}-2-1-svc.mongodb.svc.cluster.local
57+
- ${resource}-2-2-svc.mongodb.svc.cluster.local
58+
duration: 240h0m0s
59+
issuerRef:
60+
kind: Issuer
61+
name: mongodb-ca-issuer
62+
renewBefore: 120h0m0s
63+
secretName: clustercert-${resource}-cert
64+
subject:
65+
countries:
66+
- US
67+
localities:
68+
- NY
69+
organizationalUnits:
70+
- mongodb
71+
organizations:
72+
- cluster.local-server
73+
provinces:
74+
- NY
75+
usages:
76+
- digital signature
77+
- key encipherment
78+
- client auth
79+
- server auth
80+
EOF
81+
82+
# Enable TLS for custom resource
83+
kubectl -n "${namespace}" patch mdbm "${resource}" --type=json -p='[{"op": "add", "path": "/spec/security", "value": {"certsSecretPrefix": "clustercert", "tls": {"ca": "issuer-ca"}}}]'

0 commit comments

Comments
 (0)