Skip to content

Commit 86cd6b8

Browse files
kpougetpraveenkumar
authored andcommitted
systemd/crc-pullsecret.sh: don't leak the pull secrets
1 parent 29a5268 commit 86cd6b8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

systemd/crc-pullsecret.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
#!/bin/bash
22

3+
set -o pipefail
4+
set -o errexit
5+
set -o nounset
6+
set -o errtrace
37
set -x
48

59
source /usr/local/bin/crc-systemd-common.sh
610
export KUBECONFIG="/opt/kubeconfig"
711

812
wait_for_resource secret
913

14+
set +x # disable the logging to avoid leaking the pull secrets
15+
1016
# check if existing pull-secret is valid if not add the one from /opt/crc/pull-secret
1117
existingPsB64=$(oc get secret pull-secret -n openshift-config -o jsonpath="{['data']['\.dockerconfigjson']}")
1218
existingPs=$(echo "${existingPsB64}" | base64 -d)
1319

14-
echo "${existingPs}" | jq -e '.auths'
15-
16-
if [[ $? != 0 ]]; then
17-
pullSecretB64=$(base64 -w0 < /opt/crc/pull-secret)
18-
oc patch secret pull-secret -n openshift-config --type merge -p "{\"data\":{\".dockerconfigjson\":\"${pullSecretB64}\"}}"
20+
# check if the .auths field is there
21+
if echo "${existingPs}" | jq -e 'has("auths")' >/dev/null 2>&1; then
22+
echo "Cluster already has the pull secrets, nothing to do"
23+
exit 0
1924
fi
2025

26+
echo "Cluster doesn't have the pull secrets. Setting them from /opt/crc/pull-secret ..."
27+
pullSecretB64=$(base64 -w0 < /opt/crc/pull-secret)
28+
# Create the JSON patch in memory and pipe it to the oc command
29+
printf '{"data":{".dockerconfigjson": "%s"}}' "${pullSecretB64}" | \
30+
oc patch secret pull-secret -n openshift-config --type merge --patch-file=/dev/stdin
31+
32+
exit 0

0 commit comments

Comments
 (0)