Skip to content

Commit

Permalink
Expose AWS env vars for web identity token file (#1774)
Browse files Browse the repository at this point in the history
Signed-off-by: Le Tran <le.tran@kasten.io>

Signed-off-by: Le Tran <le.tran@kasten.io>
Co-authored-by: Le Tran <le.tran@kasten.io>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 7, 2022
1 parent 65c7cea commit a41c00b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const (
Region = "AWS_REGION"

// From AWS SDK "aws/session/env_config.go"
webIdentityTokenFilePathEnvKey = "AWS_WEB_IDENTITY_TOKEN_FILE"
roleARNEnvKey = "AWS_ROLE_ARN"
WebIdentityTokenFilePathEnvKey = "AWS_WEB_IDENTITY_TOKEN_FILE"
RoleARNEnvKey = "AWS_ROLE_ARN"

// TODO: Make this configurable via `config`
AssumeRoleDurationDefault = 60 * time.Minute
Expand Down Expand Up @@ -108,7 +108,7 @@ func authenticateAWSCredentials(
return nil, "", err
}
if creds != nil {
return creds, os.Getenv(roleARNEnvKey), nil
return creds, os.Getenv(RoleARNEnvKey), nil
}

return nil, "", errors.New("Missing AWS credentials, please check that either AWS access keys or web identity token are provided")
Expand Down Expand Up @@ -140,13 +140,13 @@ func fetchWebIdentityTokenFromConfig(config map[string]string, assumeRoleDuratio
}

func fetchWebIdentityTokenFromFile(assumeRoleDuration time.Duration) (*credentials.Credentials, error) {
if os.Getenv(webIdentityTokenFilePathEnvKey) == "" || os.Getenv(roleARNEnvKey) == "" {
if os.Getenv(WebIdentityTokenFilePathEnvKey) == "" || os.Getenv(RoleARNEnvKey) == "" {
return nil, nil
}

creds, err := getCredentialsWithDuration(
os.Getenv(roleARNEnvKey),
stscreds.FetchTokenPath(os.Getenv(webIdentityTokenFilePathEnvKey)),
os.Getenv(RoleARNEnvKey),
stscreds.FetchTokenPath(os.Getenv(WebIdentityTokenFilePathEnvKey)),
assumeRoleDuration,
)
if err != nil {
Expand Down

0 comments on commit a41c00b

Please sign in to comment.