Skip to content

Commit d271bf7

Browse files
authored
add tls script back (#88)
# Summary found this there; https://github.com/mongodb/mongodb-enterprise-kubernetes/blob/master/tools/multicluster/setup_tls.sh its linked in docs and we don't have it here ## Proof of Work <!-- Enter your proof that it works here.--> ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent a0b99f1 commit d271bf7

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
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)