Skip to content

Commit a14e482

Browse files
anandsyncslsierant
authored andcommitted
add enterprise snippets for search tls updates
1 parent 22c818a commit a14e482

File tree

10 files changed

+172
-4
lines changed

10 files changed

+172
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
required=(
2+
K8S_CTX
3+
MDB_NS
4+
MDB_RESOURCE_NAME
5+
MDB_VERSION
6+
MDB_MEMBERS
7+
CERT_MANAGER_NAMESPACE
8+
MDB_TLS_CA_SECRET_NAME
9+
MDB_TLS_SERVER_CERT_SECRET_NAME
10+
MDB_SEARCH_TLS_SECRET_NAME
11+
MDB_ADMIN_USER_PASSWORD
12+
MDB_SEARCH_SYNC_USER_PASSWORD
13+
MDB_USER_PASSWORD
14+
OPERATOR_HELM_CHART
15+
OPS_MANAGER_PROJECT_NAME
16+
OPS_MANAGER_API_URL
17+
OPS_MANAGER_API_USER
18+
OPS_MANAGER_API_KEY
19+
)
20+
21+
missing_req=()
22+
for v in "${required[@]}"; do [[ -n "${!v:-}" ]] || missing_req+=("$v"); done
23+
if (( ${#missing_req[@]} )); then
24+
echo "ERROR: Missing required environment variables:" >&2
25+
for m in "${missing_req[@]}"; do echo " - $m" >&2; done
26+
else
27+
echo "All required environment variables present."
28+
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
helm upgrade --install \
2+
cert-manager \
3+
oci://quay.io/jetstack/charts/cert-manager \
4+
--kube-context "${K8S_CTX}" \
5+
--namespace "${CERT_MANAGER_NAMESPACE}" \
6+
--create-namespace \
7+
--set crds.enabled=true
8+
9+
for deployment in cert-manager cert-manager-cainjector cert-manager-webhook; do
10+
kubectl --context "${K8S_CTX}" \
11+
-n "${CERT_MANAGER_NAMESPACE}" \
12+
wait --for=condition=Available "deployment/${deployment}" --timeout=300s
13+
done
14+
15+
echo "cert-manager is ready in namespace ${CERT_MANAGER_NAMESPACE}."
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Bootstrap a self-signed ClusterIssuer to mint the CA secret consumed by application workloads.
2+
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
3+
apiVersion: cert-manager.io/v1
4+
kind: ClusterIssuer
5+
metadata:
6+
name: ${MDB_TLS_SELF_SIGNED_ISSUER}
7+
spec:
8+
selfSigned: {}
9+
EOF_MANIFEST
10+
11+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_SELF_SIGNED_ISSUER}"
12+
13+
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
14+
apiVersion: cert-manager.io/v1
15+
kind: Certificate
16+
metadata:
17+
name: ${MDB_TLS_CA_CERT_NAME}
18+
namespace: ${CERT_MANAGER_NAMESPACE}
19+
spec:
20+
isCA: true
21+
commonName: ${MDB_TLS_CA_CERT_NAME}
22+
secretName: ${MDB_TLS_CA_SECRET_NAME}
23+
privateKey:
24+
algorithm: ECDSA
25+
size: 256
26+
issuerRef:
27+
name: ${MDB_TLS_SELF_SIGNED_ISSUER}
28+
kind: ClusterIssuer
29+
EOF_MANIFEST
30+
31+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${CERT_MANAGER_NAMESPACE}" certificate "${MDB_TLS_CA_CERT_NAME}"
32+
33+
kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST
34+
apiVersion: cert-manager.io/v1
35+
kind: ClusterIssuer
36+
metadata:
37+
name: ${MDB_TLS_CA_ISSUER}
38+
spec:
39+
ca:
40+
secretName: ${MDB_TLS_CA_SECRET_NAME}
41+
EOF_MANIFEST
42+
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 -
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF_MANIFEST
2+
apiVersion: cert-manager.io/v1
3+
kind: Certificate
4+
metadata:
5+
name: ${MDB_RESOURCE_NAME}-server-tls
6+
spec:
7+
secretName: ${MDB_TLS_SERVER_CERT_SECRET_NAME}
8+
issuerRef:
9+
name: ${MDB_TLS_CA_ISSUER}
10+
kind: ClusterIssuer
11+
duration: 240h0m0s
12+
renewBefore: 120h0m0s
13+
usages:
14+
- digital signature
15+
- key encipherment
16+
- server auth
17+
- client auth
18+
dnsNames:
19+
- "${MDB_RESOURCE_NAME}-0"
20+
- "${MDB_RESOURCE_NAME}-1"
21+
- "${MDB_RESOURCE_NAME}-2"
22+
- "${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local"
23+
- "${MDB_RESOURCE_NAME}-1.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local"
24+
- "${MDB_RESOURCE_NAME}-2.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local"
25+
---
26+
apiVersion: cert-manager.io/v1
27+
kind: Certificate
28+
metadata:
29+
name: ${MDB_RESOURCE_NAME}-search-tls
30+
spec:
31+
secretName: ${MDB_SEARCH_TLS_SECRET_NAME}
32+
issuerRef:
33+
name: ${MDB_TLS_CA_ISSUER}
34+
kind: ClusterIssuer
35+
duration: 240h0m0s
36+
renewBefore: 120h0m0s
37+
usages:
38+
- digital signature
39+
- key encipherment
40+
- server auth
41+
- client auth
42+
dnsNames:
43+
- "${MDB_RESOURCE_NAME}-search-svc.${MDB_NS}.svc.cluster.local"
44+
EOF_MANIFEST
45+
46+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${MDB_NS}" certificate "${MDB_RESOURCE_NAME}-server-tls"
47+
kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${MDB_NS}" certificate "${MDB_RESOURCE_NAME}-search-tls"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ spec:
1717
ignoreUnknownUsers: true
1818
modes:
1919
- SCRAM
20+
certsSecretPrefix: ${MDB_TLS_CERT_SECRET_PREFIX}
21+
tls:
22+
enabled: true
23+
ca: ${MDB_TLS_CA_CONFIGMAP}
2024
agent:
2125
logLevel: INFO
2226
podSpec:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ metadata:
66
spec:
77
# no need to specify source.mongodbResourceRef if MongoDBSearch CR has the same name as MongoDB CR
88
# the operator infer it automatically
9+
security:
10+
tls:
11+
certificateKeySecretRef:
12+
name: ${MDB_SEARCH_TLS_SECRET_NAME}
913
resourceRequirements:
1014
limits:
1115
cpu: "3"

docs/search/02-search-enterprise-deploy/env_variables.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,15 @@ export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes"
3333
# comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operator
3434
export OPERATOR_ADDITIONAL_HELM_VALUES=""
3535

36-
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}"
37-
36+
export MDB_TLS_CERT_SECRET_PREFIX="certs"
37+
export MDB_TLS_CA_CONFIGMAP="${MDB_RESOURCE_NAME}-ca-configmap"
38+
39+
export CERT_MANAGER_NAMESPACE="cert-manager"
40+
export MDB_TLS_SELF_SIGNED_ISSUER="selfsigned-bootstrap-issuer"
41+
export MDB_TLS_CA_CERT_NAME="my-selfsigned-ca"
42+
export MDB_TLS_CA_SECRET_NAME="root-secret"
43+
export MDB_TLS_CA_ISSUER="my-ca-issuer"
44+
export MDB_TLS_SERVER_CERT_SECRET_NAME="${MDB_TLS_CERT_SECRET_PREFIX}-${MDB_RESOURCE_NAME}-cert"
45+
export MDB_SEARCH_TLS_SECRET_NAME="${MDB_RESOURCE_NAME}-search-tls"
46+
47+
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true"

docs/search/02-search-enterprise-deploy/test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ cd "${script_dir}"
1111

1212
prepare_snippets
1313

14+
run 02_0040_validate_env.sh
1415
run 02_0045_create_namespaces.sh
1516
run 02_0046_create_image_pull_secrets.sh
1617
run 02_0048_configure_prerelease_image_pullsecret.sh
1718

1819
run_for_output 02_0090_helm_add_mogodb_repo.sh
1920
run_for_output 02_0100_install_operator.sh
2021
run 02_0300_create_ops_manager_resources.sh
22+
23+
#TLS related steps
24+
run 02_0301_install_cert_manager.sh
25+
run 02_0302_configure_tls_prerequisites.sh
26+
run 02_0304_generate_tls_certificates.sh
27+
2128
run 02_0305_create_mongodb_database_resource.sh
2229
run_for_output 02_0310_wait_for_database_resource.sh
2330
run 02_0315_create_mongodb_users.sh

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
volumes:
2020
- name: mongo-ca
2121
configMap:
22-
name: ${MDB_TLS_CA_CONFIGMAP}
22+
name: ${MDB_TLS_CA_CONFIGMAP:-"${MDB_RESOURCE_NAME}-ca-configmap"}
2323
optional: true
2424
items:
2525
- key: ca.crt

scripts/code_snippets/tests/test_kind_search_enterprise_snippets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ echo "Sourcing env variables for ${CODE_SNIPPETS_FLAVOR} flavor"
3030
# shellcheck disable=SC1090
3131
test -f "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh" && source "${test_dir}/env_variables_${CODE_SNIPPETS_FLAVOR}.sh"
3232

33-
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}"
33+
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=/tls/ca.crt"
3434

3535
${test_dir}/test.sh

0 commit comments

Comments
 (0)