Skip to content

Commit aa5fda2

Browse files
authored
Merge pull request kubernetes#75269 from javier-b-perez/gce-configure
gce: configure: validate SA has storage scope
2 parents 164fad5 + e783f0b commit aa5fda2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cluster/gce/gci/configure.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,16 @@ function validate-hash {
124124
}
125125

126126
# Get default service account credentials of the VM.
127+
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
127128
function get-credentials {
128-
curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
129+
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
129130
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
130131
}
131132

133+
function valid-storage-scope {
134+
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -q "auth/devstorage"
135+
}
136+
132137
# Retry a download until we get it. Takes a hash and a set of URLs.
133138
#
134139
# $1 is the sha1 of the URL. Can be "" if the sha1 is unknown.
@@ -144,7 +149,7 @@ function download-or-bust {
144149
rm -f "${file}"
145150
# if the url belongs to GCS API we should use oauth2_token in the headers
146151
local curl_headers=""
147-
if [[ "$url" =~ ^https://storage.googleapis.com.* ]]; then
152+
if [[ "$url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
148153
curl_headers="Authorization: Bearer $(get-credentials)"
149154
fi
150155
if ! curl ${curl_headers:+-H "${curl_headers}"} -f --ipv4 -Lo "${file}" --connect-timeout 20 --max-time 300 --retry 6 --retry-delay 10 ${CURL_RETRY_CONNREFUSED} "${url}"; then

0 commit comments

Comments
 (0)