Skip to content

Commit 6510c27

Browse files
committed
allow s3 commands to work from non commercial environments
when running under something like us-gov-east-1, the latest-binaries.sh script fails b/c it tries to access the us-west-2 bucket from the wrong endpoints. this can be avoided by setting AWS_ENDPOINT_URL_S3 to point to us-west-2, but you still end up trying to use the gov-cloud creds in the request which would fail with: $ ./hack/latest-binaries.sh 1.29 An error occurred (InvalidToken) when calling the ListObjectsV2 operation: The provided token is malformed or otherwise invalid. so, specify to perform an unauthenticated s3 api request b/c the govcloud creds wouldn't work against the commercial cloud endpoints. in other places in the install-worker.sh script, there are 'aws s3' commands that would fail if running under something like the us-gov-east-1 environment. similar to the changes to the latest-binaries.sh script, update the 'aws' cli calls to ensure the requests are unsinged (to avoid trying to use us-gov creds against a non-gov endpoint). and plumb through using the user-specified AWS_ENDPOINT_URL_S3 env var into the install-worker.sh script so that the alternative endpoints can be used instead of the us-govcloud ones when running in a govcloud environment.
1 parent e493836 commit 6510c27

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

hack/latest-binaries.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MINOR_VERSION="${1}"
1313

1414
# retrieve the available "VERSION/BUILD_DATE" prefixes (e.g. "1.28.1/2023-09-14")
1515
# from the binary object keys, sorted in descending semver order, and pick the first one
16-
LATEST_BINARIES=$(aws s3api list-objects-v2 --bucket amazon-eks --prefix "${MINOR_VERSION}" --query 'Contents[*].[Key]' --output text | cut -d'/' -f-2 | sort -Vru | head -n1)
16+
LATEST_BINARIES=$(aws s3api list-objects-v2 --bucket amazon-eks --prefix "${MINOR_VERSION}" --query 'Contents[*].[Key]' --output text --no-sign-request | cut -d'/' -f-2 | sort -Vru | head -n1)
1717

1818
if [ "${LATEST_BINARIES}" == "None" ]; then
1919
echo >&2 "No binaries available for minor version: ${MINOR_VERSION}"

templates/al2/provisioners/install-worker.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ BINARIES=(
274274
for binary in ${BINARIES[*]}; do
275275
if [[ -n "$AWS_ACCESS_KEY_ID" ]]; then
276276
echo "AWS cli present - using it to copy binaries from s3."
277-
aws s3 cp --region $BINARY_BUCKET_REGION $S3_PATH/$binary .
278-
aws s3 cp --region $BINARY_BUCKET_REGION $S3_PATH/$binary.sha256 .
277+
aws s3 cp --no-sign-request --region $BINARY_BUCKET_REGION $S3_PATH/$binary .
278+
aws s3 cp --no-sign-request --region $BINARY_BUCKET_REGION $S3_PATH/$binary.sha256 .
279279
else
280280
echo "AWS cli missing - using wget to fetch binaries from s3. Note: This won't work for private bucket."
281281
sudo wget $S3_URL_BASE/$binary
@@ -308,8 +308,8 @@ if [ "$PULL_CNI_FROM_GITHUB" = "true" ]; then
308308
else
309309
if [[ -n "$AWS_ACCESS_KEY_ID" ]]; then
310310
echo "AWS cli present - using it to copy binaries from s3."
311-
aws s3 cp --region $BINARY_BUCKET_REGION $S3_PATH/${CNI_PLUGIN_FILENAME}.tgz .
312-
aws s3 cp --region $BINARY_BUCKET_REGION $S3_PATH/${CNI_PLUGIN_FILENAME}.tgz.sha256 .
311+
aws s3 cp --no-sign-request --region $BINARY_BUCKET_REGION $S3_PATH/${CNI_PLUGIN_FILENAME}.tgz .
312+
aws s3 cp --no-sign-request --region $BINARY_BUCKET_REGION $S3_PATH/${CNI_PLUGIN_FILENAME}.tgz.sha256 .
313313
else
314314
echo "AWS cli missing - using wget to fetch cni binaries from s3. Note: This won't work for private bucket."
315315
sudo wget "$S3_URL_BASE/${CNI_PLUGIN_FILENAME}.tgz"
@@ -369,7 +369,7 @@ sudo chmod +x /etc/eks/max-pods-calculator.sh
369369
ECR_CREDENTIAL_PROVIDER_BINARY="ecr-credential-provider"
370370
if [[ -n "$AWS_ACCESS_KEY_ID" ]]; then
371371
echo "AWS cli present - using it to copy ${ECR_CREDENTIAL_PROVIDER_BINARY} from s3."
372-
aws s3 cp --region $BINARY_BUCKET_REGION $S3_PATH/$ECR_CREDENTIAL_PROVIDER_BINARY .
372+
aws s3 cp --no-sign-request --region $BINARY_BUCKET_REGION $S3_PATH/$ECR_CREDENTIAL_PROVIDER_BINARY .
373373
else
374374
echo "AWS cli missing - using wget to fetch ${ECR_CREDENTIAL_PROVIDER_BINARY} from s3. Note: This won't work for private bucket."
375375
sudo wget "$S3_URL_BASE/$ECR_CREDENTIAL_PROVIDER_BINARY"

templates/al2/template.json

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"pull_cni_from_github": null,
3434
"remote_folder": null,
3535
"runc_version": null,
36+
"aws_endpoint_url_s3": null,
3637
"security_group_id": null,
3738
"source_ami_filter_name": null,
3839
"source_ami_id": null,
@@ -191,6 +192,7 @@
191192
"script": "{{template_dir}}/provisioners/install-worker.sh",
192193
"environment_vars": [
193194
"AWS_ACCESS_KEY_ID={{user `aws_access_key_id`}}",
195+
"AWS_ENDPOINT_URL_S3={{ user `aws_endpoint_url_s3`}}",
194196
"AWS_SECRET_ACCESS_KEY={{user `aws_secret_access_key`}}",
195197
"AWS_SESSION_TOKEN={{user `aws_session_token`}}",
196198
"BINARY_BUCKET_NAME={{user `binary_bucket_name`}}",

templates/al2/variables-default.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"pull_cni_from_github": "true",
2727
"remote_folder": "/tmp",
2828
"runc_version": "1.1.*",
29+
"aws_endpoint_url_s3": "{{env `AWS_ENDPOINT_URL_S3`}}",
2930
"security_group_id": "",
3031
"source_ami_filter_name": "amzn2-ami-minimal-hvm-*",
3132
"source_ami_id": "",

0 commit comments

Comments
 (0)