Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .kokoro/populate-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ mkdir -p ${SECRET_LOCATION}
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
do
msg "Retrieving secret ${key}"
docker run --entrypoint=gcloud \
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
VERSION=$(docker run --rm --entrypoint=gcloud \
--volume="${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR}" \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access latest \
secrets versions list "${key}" \
--project cloud-devrel-kokoro-resources \
--secret ${key} > \
--filter="state=enabled" \
--sort-by="~createTime" \
--limit=1 \
--format="value(name.basename())") || VERSION=""
Comment thread
sakthivelmanii marked this conversation as resolved.

if [ -z "${VERSION}" ]; then
msg "Error retrieving enabled version for secret ${key}"
exit 1
fi

docker run --rm --entrypoint=gcloud \
--volume="${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR}" \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access "${VERSION}" \
--project cloud-devrel-kokoro-resources \
--secret "${key}" > \
"${SECRET_LOCATION}/${key}"
Comment thread
sakthivelmanii marked this conversation as resolved.
Comment on lines +46 to 52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the docker run command to access the secret payload fails, the script currently does not exit explicitly (unless set -e is active). To prevent silent failures or continuing with empty/corrupted secret files, we should explicitly handle the failure of this command and exit with an error.

Suggested change
docker run --rm --entrypoint=gcloud \
--volume="${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR}" \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access "${VERSION}" \
--project cloud-devrel-kokoro-resources \
--secret "${key}" > \
"${SECRET_LOCATION}/${key}"
docker run --rm --entrypoint=gcloud \
--volume="${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR}" \
gcr.io/google.com/cloudsdktool/cloud-sdk \
secrets versions access "${VERSION}" \
--project cloud-devrel-kokoro-resources \
--secret "${key}" > \
"${SECRET_LOCATION}/${key}" || { msg "Error retrieving secret payload for ${key}"; exit 1; }

if [[ $? == 0 ]]; then
msg "Secret written to ${SECRET_LOCATION}/${key}"
Expand Down
Loading