Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AWS SessionToken Support #189

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ commands:
- tf-install
- checkout

- when:
condition:
equal: [aws, << parameters.provider-test-infra-dir >>]
steps:
- run:
name: download and install AWS CLI
command: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
echo -e "${AWS_CLI_GPG_KEY}" | gpg --import
curl -o awscliv2.sig https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip.sig
gpg --verify awscliv2.sig awscliv2.zip
unzip awscliv2.zip
sudo ./aws/install
- run:
name: set assume-role creds
command: |
CREDENTIALS="$(aws sts assume-role --role-arn ${SERVICE_GO_DISCOVER_TESTS_ROLE_ARN} --role-session-name build-${CIRCLE_SHA1} | jq '.Credentials')"
echo "export AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | jq -r '.AccessKeyId')" >> $BASH_ENV
echo "export AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | jq -r '.SecretAccessKey')" >> $BASH_ENV
echo "export AWS_SESSION_TOKEN=$(echo $CREDENTIALS | jq -r '.SessionToken')" >> $BASH_ENV
# spin up infrastructure
- run:
working_directory: ./test/tf/<< parameters.provider-test-infra-dir >>
Expand Down
2 changes: 2 additions & 0 deletions provider/aws/aws_discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error
addrType := args["addr_type"]
accessKey := args["access_key_id"]
secretKey := args["secret_access_key"]
sessionToken := args["session_token"]

if addrType != "private_v4" && addrType != "public_v4" && addrType != "public_v6" {
l.Printf("[INFO] discover-aws: Address type %s is not supported. Valid values are {private_v4,public_v4,public_v6}. Falling back to 'private_v4'", addrType)
Expand Down Expand Up @@ -87,6 +88,7 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error
Value: credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
SessionToken: sessionToken,
},
},
&credentials.EnvProvider{},
Expand Down
1 change: 1 addition & 0 deletions provider/aws/aws_discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestAddrs(t *testing.T) {
"tag_value": "server",
"access_key_id": os.Getenv("AWS_ACCESS_KEY_ID"),
"secret_access_key": os.Getenv("AWS_SECRET_ACCESS_KEY"),
"session_token": os.Getenv("AWS_SESSION_TOKEN"),
}

if args["region"] == "" || args["access_key_id"] == "" || args["secret_access_key"] == "" {
Expand Down