Skip to content

Commit f90726a

Browse files
committed
fix get-kube authorization headers
1 parent afa72e9 commit f90726a

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

cluster/get-kube-binaries.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,6 @@ function sha1sum_file() {
143143
fi
144144
}
145145

146-
# Get default service account credentials of the VM.
147-
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
148-
function get-credentials {
149-
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
150-
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
151-
}
152-
153-
function valid-storage-scope {
154-
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
155-
}
156-
157146
function download_tarball() {
158147
local -r download_path="$1"
159148
local -r file="$2"
@@ -168,8 +157,8 @@ function download_tarball() {
168157
# if the url belongs to GCS API we should use oauth2_token in the headers
169158
curl_headers=""
170159
if { [[ "${KUBERNETES_PROVIDER:-gce}" == "gce" ]] || [[ "${KUBERNETES_PROVIDER}" == "gke" ]] ; } &&
171-
[[ "$url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
172-
curl_headers="Authorization: Bearer $(get-credentials)"
160+
[[ "$url" =~ ^https://storage.googleapis.com.* ]]; then
161+
curl_headers="Authorization: Bearer $(gcloud auth print-access-token)"
173162
fi
174163
curl ${curl_headers:+-H "${curl_headers}"} -fL --retry 3 --keepalive-time 2 "${url}" -o "${download_path}/${file}"
175164
elif [[ $(which wget) ]]; then

cluster/get-kube.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ function create_cluster {
122122
)
123123
}
124124

125-
# Get default service account credentials of the VM.
126-
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
127-
function get-credentials {
128-
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
129-
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
130-
}
131-
132125
function valid-storage-scope {
133126
curl "${GCE_METADATA_INTERNAL}/service-accounts/default/scopes" -H "Metadata-Flavor: Google" -s | grep -E "auth/devstorage|auth/cloud-platform"
134127
}
@@ -242,8 +235,8 @@ if "${need_download}"; then
242235
# if the url belongs to GCS API we should use oauth2_token in the headers
243236
curl_headers=""
244237
if { [[ "${KUBERNETES_PROVIDER:-gce}" == "gce" ]] || [[ "${KUBERNETES_PROVIDER}" == "gke" ]] ; } &&
245-
[[ "$kubernetes_tar_url" =~ ^https://storage.googleapis.com.* ]] && valid-storage-scope ; then
246-
curl_headers="Authorization: Bearer $(get-credentials)"
238+
[[ "$kubernetes_tar_url" =~ ^https://storage.googleapis.com.* ]] ; then
239+
curl_headers="Authorization: Bearer $(gcloud auth print-access-token)"
247240
fi
248241
curl ${curl_headers:+-H "${curl_headers}"} -fL --retry 3 --keepalive-time 2 "${kubernetes_tar_url}" -o "${file}"
249242
elif [[ $(which wget) ]]; then

0 commit comments

Comments
 (0)