Skip to content

Commit 86d13a7

Browse files
committed
use cluster issuer
1 parent 1b80dd1 commit 86d13a7

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
# Bootstrap a self-signed Issuer scoped to the cert-manager namespace. This is
2-
# only used to mint the CA secret and is not referenced by application
3-
# workloads.
4-
kubectl apply --context "${K8S_CTX}" -n "${CERT_MANAGER_NAMESPACE}" -f - <<EOF_MANIFEST
1+
# Bootstrap a self-signed ClusterIssuer to mint the CA secret consumed by application workloads.
2+
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
53
apiVersion: cert-manager.io/v1
6-
kind: Issuer
4+
kind: ClusterIssuer
75
metadata:
86
name: ${MDB_TLS_SELF_SIGNED_ISSUER}
97
spec:
108
selfSigned: {}
119
EOF_MANIFEST
1210

13-
kubectl --context "${K8S_CTX}" wait --namespace "${CERT_MANAGER_NAMESPACE}" --for=condition=Ready issuer "${MDB_TLS_SELF_SIGNED_ISSUER}"
11+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_SELF_SIGNED_ISSUER}"
1412

1513
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
1614
apiVersion: cert-manager.io/v1
@@ -27,37 +25,29 @@ spec:
2725
size: 256
2826
issuerRef:
2927
name: ${MDB_TLS_SELF_SIGNED_ISSUER}
30-
kind: Issuer
28+
kind: ClusterIssuer
3129
EOF_MANIFEST
3230

3331
kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${CERT_MANAGER_NAMESPACE}" certificate "${MDB_TLS_CA_CERT_NAME}"
3432

35-
TMP_DIR="$(mktemp -d)"
36-
trap 'rm -rf "${TMP_DIR}"' EXIT
37-
38-
kubectl --context "${K8S_CTX}" get secret "${MDB_TLS_CA_SECRET_NAME}" -n "${CERT_MANAGER_NAMESPACE}" -o jsonpath="{.data['ca\\.crt']}" | base64 --decode > "${TMP_DIR}/ca.crt"
39-
40-
cat "${TMP_DIR}/ca.crt" > "${TMP_DIR}/mms-ca.crt"
41-
42-
kubectl --context "${K8S_CTX}" create configmap "${MDB_TLS_CA_CONFIGMAP}" -n "${MDB_NS}" \
43-
--from-file=ca-pem="${TMP_DIR}/mms-ca.crt" --from-file=mms-ca.crt="${TMP_DIR}/mms-ca.crt" \
44-
--dry-run=client -o yaml | kubectl --context "${K8S_CTX}" apply -f -
45-
46-
# Ensure CA secret also exists in application namespace for mounts expecting a Secret (root-secret)
47-
if ! kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get secret "${MDB_TLS_CA_SECRET_NAME}" >/dev/null 2>&1; then
48-
kubectl --context "${K8S_CTX}" -n "${CERT_MANAGER_NAMESPACE}" get secret "${MDB_TLS_CA_SECRET_NAME}" -o yaml \
49-
| sed 's/namespace: .*/namespace: '"${MDB_NS}"'/' \
50-
| kubectl --context "${K8S_CTX}" apply -n "${MDB_NS}" -f - || echo "Warning: failed to copy ${MDB_TLS_CA_SECRET_NAME} to ${MDB_NS}" >&2
51-
fi
52-
53-
kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF_MANIFEST
33+
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
5434
apiVersion: cert-manager.io/v1
55-
kind: Issuer
35+
kind: ClusterIssuer
5636
metadata:
5737
name: ${MDB_TLS_CA_ISSUER}
5838
spec:
5939
ca:
6040
secretName: ${MDB_TLS_CA_SECRET_NAME}
6141
EOF_MANIFEST
6242

63-
kubectl --context "${K8S_CTX}" wait --namespace "${MDB_NS}" --for=condition=Ready issuer "${MDB_TLS_CA_ISSUER}"
43+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_CA_ISSUER}"
44+
45+
TMP_CA_CERT="$(mktemp)"
46+
trap 'rm -f "${TMP_CA_CERT}"' EXIT
47+
48+
kubectl --context "${K8S_CTX}" get secret "${MDB_TLS_CA_SECRET_NAME}" -n "${CERT_MANAGER_NAMESPACE}" -o jsonpath="{.data['ca\\.crt']}" | base64 --decode > "${TMP_CA_CERT}"
49+
50+
kubectl --context "${K8S_CTX}" create configmap "${MDB_TLS_CA_CONFIGMAP}" -n "${MDB_NS}" \
51+
--from-file=ca-pem="${TMP_CA_CERT}" --from-file=mms-ca.crt="${TMP_CA_CERT}" \
52+
--from-file=ca.crt="${TMP_CA_CERT}" \
53+
--dry-run=client -o yaml | kubectl --context "${K8S_CTX}" apply -f -

docs/search/02-search-enterprise-deploy/code_snippets/02_0304_generate_tls_certificates.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
secretName: ${MDB_TLS_SERVER_CERT_SECRET_NAME}
88
issuerRef:
99
name: ${MDB_TLS_CA_ISSUER}
10-
kind: Issuer
10+
kind: ClusterIssuer
1111
duration: 240h0m0s
1212
renewBefore: 120h0m0s
1313
usages:
@@ -31,7 +31,7 @@ spec:
3131
secretName: ${MDB_SEARCH_TLS_SECRET_NAME}
3232
issuerRef:
3333
name: ${MDB_TLS_CA_ISSUER}
34-
kind: Issuer
34+
kind: ClusterIssuer
3535
duration: 240h0m0s
3636
renewBefore: 120h0m0s
3737
usages:

docs/search/03-search-query-usage/code_snippets/03_0410_run_mongodb_tools_pod.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ spec:
1818
restartPolicy: Never
1919
volumes:
2020
- name: mongo-ca
21-
secret:
22-
secretName: ${MDB_TLS_CA_SECRET_NAME}
21+
configMap:
22+
name: ${MDB_TLS_CA_CONFIGMAP}
23+
items:
24+
- key: ca.crt
25+
path: ca.crt
2326
EOF
2427

2528
echo "Waiting for the mongodb-tools to be ready..."

0 commit comments

Comments
 (0)