From ec27701d2b4bac1820dbb6d50deb18e9cdb8ffe0 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Wed, 14 Dec 2022 16:15:12 -0700 Subject: [PATCH] manifest: toolbox and jobs mount secret volume The toolbox, toolbox job, and osd prepare jobs need to mount the ceph admin keyring as a file instead of using an env var. The toolbox script will still allow setting of the env var for backward compatibility, though all the examples are now updated to use the keyring as a file. Signed-off-by: Travis Nielsen (cherry picked from commit 4f7766486201a8d2a5ba02e53110d3cc2ce1a6a7) --- .../templates/deployment.yaml | 14 +++++++---- deploy/examples/direct-mount.yaml | 14 +++++++---- deploy/examples/osd-purge.yaml | 14 +++++++---- deploy/examples/toolbox-job.yaml | 14 +++++++---- deploy/examples/toolbox.yaml | 23 ++++++++++++++----- images/ceph/toolbox.sh | 16 +++++++++---- 6 files changed, 64 insertions(+), 31 deletions(-) diff --git a/deploy/charts/rook-ceph-cluster/templates/deployment.yaml b/deploy/charts/rook-ceph-cluster/templates/deployment.yaml index c5b939d9a..7ec53919e 100644 --- a/deploy/charts/rook-ceph-cluster/templates/deployment.yaml +++ b/deploy/charts/rook-ceph-cluster/templates/deployment.yaml @@ -37,11 +37,6 @@ spec: secretKeyRef: name: rook-ceph-mon key: ceph-username - - name: ROOK_CEPH_SECRET - valueFrom: - secretKeyRef: - name: rook-ceph-mon - key: ceph-secret {{- if .Values.toolbox.resources }} resources: {{- toYaml .Values.toolbox.resources | nindent 12 }} @@ -51,7 +46,16 @@ spec: name: ceph-config - name: mon-endpoint-volume mountPath: /etc/rook + - name: ceph-admin-secret + mountPath: /var/lib/rook-ceph-mon volumes: + - name: ceph-admin-secret + secret: + secretName: rook-ceph-mon + optional: false + items: + - key: ceph-secret + path: secret.keyring - name: mon-endpoint-volume configMap: name: rook-ceph-mon-endpoints diff --git a/deploy/examples/direct-mount.yaml b/deploy/examples/direct-mount.yaml index b378b6220..2f7e60b38 100644 --- a/deploy/examples/direct-mount.yaml +++ b/deploy/examples/direct-mount.yaml @@ -29,11 +29,6 @@ spec: secretKeyRef: name: rook-ceph-mon key: ceph-username - - name: ROOK_CEPH_SECRET - valueFrom: - secretKeyRef: - name: rook-ceph-mon - key: ceph-secret securityContext: privileged: true runAsUser: 0 @@ -46,9 +41,18 @@ spec: name: libmodules - name: mon-endpoint-volume mountPath: /etc/rook + - name: ceph-admin-secret + mountPath: /var/lib/rook-ceph-mon # if hostNetwork: false, the "rbd map" command hangs, see https://github.com/rook/rook/issues/2021 hostNetwork: true volumes: + - name: ceph-admin-secret + secret: + secretName: rook-ceph-mon + optional: false + items: + - key: ceph-secret + path: secret.keyring - name: dev hostPath: path: /dev diff --git a/deploy/examples/osd-purge.yaml b/deploy/examples/osd-purge.yaml index a544ea1ba..b70c9d1ee 100644 --- a/deploy/examples/osd-purge.yaml +++ b/deploy/examples/osd-purge.yaml @@ -60,11 +60,6 @@ spec: secretKeyRef: key: ceph-username name: rook-ceph-mon - - name: ROOK_CEPH_SECRET - valueFrom: - secretKeyRef: - key: ceph-secret - name: rook-ceph-mon - name: ROOK_CONFIG_DIR value: /var/lib/rook - name: ROOK_CEPH_CONFIG_OVERRIDE @@ -81,7 +76,16 @@ spec: name: ceph-conf-emptydir - mountPath: /var/lib/rook name: rook-config + - name: ceph-admin-secret + mountPath: /var/lib/rook-ceph-mon volumes: + - name: ceph-admin-secret + secret: + secretName: rook-ceph-mon + optional: false + items: + - key: ceph-secret + path: secret.keyring - emptyDir: {} name: ceph-conf-emptydir - emptyDir: {} diff --git a/deploy/examples/toolbox-job.yaml b/deploy/examples/toolbox-job.yaml index e4a8770e1..4565c9e7e 100644 --- a/deploy/examples/toolbox-job.yaml +++ b/deploy/examples/toolbox-job.yaml @@ -20,16 +20,13 @@ spec: secretKeyRef: name: rook-ceph-mon key: ceph-username - - name: ROOK_CEPH_SECRET - valueFrom: - secretKeyRef: - name: rook-ceph-mon - key: ceph-secret volumeMounts: - mountPath: /etc/ceph name: ceph-config - name: mon-endpoint-volume mountPath: /etc/rook + - name: ceph-admin-secret + mountPath: /var/lib/rook-ceph-mon containers: - name: script image: rook/ceph:v1.10.7 @@ -47,6 +44,13 @@ spec: # example: print the ceph status ceph status volumes: + - name: ceph-admin-secret + secret: + secretName: rook-ceph-mon + optional: false + items: + - key: ceph-secret + path: secret.keyring - name: mon-endpoint-volume configMap: name: rook-ceph-mon-endpoints diff --git a/deploy/examples/toolbox.yaml b/deploy/examples/toolbox.yaml index bb1563390..ddad50e7b 100644 --- a/deploy/examples/toolbox.yaml +++ b/deploy/examples/toolbox.yaml @@ -68,10 +68,16 @@ spec: done } + # read the secret from an env var (for backward compatibility), or from the secret file + ceph_secret=${ROOK_CEPH_SECRET} + if [[ "$ceph_secret" == "" ]]; then + ceph_secret=$(cat /var/lib/rook-ceph-mon/secret.keyring) + fi + # create the keyring file cat < ${KEYRING_FILE} [${ROOK_CEPH_USERNAME}] - key = ${ROOK_CEPH_SECRET} + key = ${ceph_secret} EOF # write the initial config file @@ -91,17 +97,22 @@ spec: secretKeyRef: name: rook-ceph-mon key: ceph-username - - name: ROOK_CEPH_SECRET - valueFrom: - secretKeyRef: - name: rook-ceph-mon - key: ceph-secret volumeMounts: - mountPath: /etc/ceph name: ceph-config - name: mon-endpoint-volume mountPath: /etc/rook + - name: ceph-admin-secret + mountPath: /var/lib/rook-ceph-mon + readOnly: true volumes: + - name: ceph-admin-secret + secret: + secretName: rook-ceph-mon + optional: false + items: + - key: ceph-secret + path: secret.keyring - name: mon-endpoint-volume configMap: name: rook-ceph-mon-endpoints diff --git a/images/ceph/toolbox.sh b/images/ceph/toolbox.sh index 78f631b3a..f03f48318 100755 --- a/images/ceph/toolbox.sh +++ b/images/ceph/toolbox.sh @@ -22,12 +22,12 @@ KEYRING_FILE="/etc/ceph/keyring" # without specifying any arguments write_endpoints() { endpoints=$(cat ${MON_CONFIG}) - + # filter out the mon names # external cluster can have numbers or hyphens in mon names, handling them in regex # shellcheck disable=SC2001 mon_endpoints=$(echo "${endpoints}"| sed 's/[a-z0-9_-]\+=//g') - + DATE=$(date) echo "$DATE writing mon endpoints to ${CEPH_CONFIG}: ${endpoints}" cat < ${CEPH_CONFIG} @@ -47,20 +47,26 @@ watch_endpoints() { while true; do real_path=$(realpath ${MON_CONFIG}) latest_time=$(stat -c %Z "${real_path}") - + if [[ "${latest_time}" != "${initial_time}" ]]; then write_endpoints initial_time=${latest_time} fi - + sleep 10 done } +# read the secret from an env var (for backward compatibility), or from the secret file +ceph_secret=${ROOK_CEPH_SECRET} +if [[ "$ceph_secret" == "" ]]; then + ceph_secret=$(cat /var/lib/rook-ceph-mon/secret.keyring) +fi + # create the keyring file cat < ${KEYRING_FILE} [${ROOK_CEPH_USERNAME}] -key = ${ROOK_CEPH_SECRET} +key = ${ceph_secret} EOF # write the initial config file