From aec222e0f14d50f8163ccc1f522a55d0bb18c044 Mon Sep 17 00:00:00 2001 From: Willy Go Date: Thu, 3 Feb 2022 14:31:06 +1100 Subject: [PATCH 1/2] Add AWS region with the auth tokens --- hooks/command | 6 ++++++ tests/command.bats | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hooks/command b/hooks/command index fd03d57..2e7b4ea 100755 --- a/hooks/command +++ b/hooks/command @@ -278,6 +278,12 @@ if [[ "${BUILDKITE_PLUGIN_DOCKER_PROPAGATE_AWS_AUTH_TOKENS:-false}" =~ ^(true|on if [[ -n "${AWS_SESSION_TOKEN:-}" ]] ; then args+=( --env "AWS_SESSION_TOKEN" ) fi + if [[ -n "${AWS_REGION:-}" ]] ; then + args+=( --env "AWS_REGION" ) + fi + if [[ -n "${AWS_DEFAULT_REGION:-}" ]] ; then + args+=( --env "AWS_DEFAULT_REGION" ) + fi fi if [[ "${BUILDKITE_PLUGIN_DOCKER_ALWAYS_PULL:-false}" =~ ^(true|on|1)$ ]] ; then diff --git a/tests/command.bats b/tests/command.bats index 323dbc1..cab6ac9 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -668,9 +668,11 @@ EOF export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE" export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" export AWS_SESSION_TOKEN="AQoEXAMPLEH4aoAH0gNCAPy...truncated...zrkuWJOgQs8IZZaIv2BXIa2R4Olgk" + export AWS_REGION="ap-southeast-2" + export AWS_DEFAULT_REGION="ap-southeast-2" stub docker \ - "run -it --rm --init --volume $PWD:/workdir --workdir /workdir --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_SESSION_TOKEN --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker" + "run -it --rm --init --volume $PWD:/workdir --workdir /workdir --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_SESSION_TOKEN --env AWS_REGION --env AWS_DEFAULT_REGION --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker" run $PWD/hooks/command @@ -760,4 +762,4 @@ EOF assert_output --partial "ran command in docker" unstub docker -} \ No newline at end of file +} From 3864fb7d222c7ce7deae8511c84bff2475a7cfdc Mon Sep 17 00:00:00 2001 From: Willy Go <73212684+iress-willygo@users.noreply.github.com> Date: Fri, 11 Mar 2022 23:43:09 +1100 Subject: [PATCH 2/2] Add env var to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e4d1d9..46c0f24 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ Note that only pipeline variables will automatically be propagated (what you see Whether or not to automatically propagate aws authentication environment variables into the docker container. Avoiding the need to be specified with `environment`. This is useful for example if you are using an assume role plugin. -Will propagate `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN`, only if they are set already. +Will propagate `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_REGION` and `AWS_DEFAULT_REGION`, only if they are set already. ### `propagate-uid-gid` (optional, boolean)