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 web identity provider #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions plugins/aws/aws_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
ec2 "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/sts"
tbnflag "github.com/turbinelabs/nonstdlib/flag"
"os"
)

// client represents the command-line flags specifying configuration of
Expand Down Expand Up @@ -98,20 +100,29 @@ func (ff *clientImpl) awsCredentials() *credentials.Credentials {
// awsSession on the call to `session.New()
defaultConfig := defaults.Config()
defaultHandlers := defaults.Handlers()

customProvider := &credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: ff.awsAccessKeyID,
SecretAccessKey: ff.awsSecretAccessKey,
},
}

webIdentityProvider := stscreds.NewWebIdentityRoleProvider(
sts.New(&session.Session{
Config: defaultConfig,
Handlers: defaultHandlers,
}),
os.Getenv("AWS_ROLE_ARN"),
"rotor-sess-dev",
os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE"),
)

// Unfortunately AWS doesn't have a variable for its default providers.
// So this mimics the latest provider chain in the defaults package
// located at
// https://github.com/aws/aws-sdk-go/blob/d856824058f17a35c61cabdfb1c40559ce070cd9/aws/defaults/defaults.go#L95-L99
// This takes the default chain, and adds the `legacy` cli way to highest
// hierachy. Currently have an issue to address this in aws-sdk-go
// hierarchy. Currently have an issue to address this in aws-sdk-go
// https://github.com/aws/aws-sdk-go/issues/2051
return credentials.NewCredentials(
&credentials.ChainProvider{
Expand All @@ -120,6 +131,7 @@ func (ff *clientImpl) awsCredentials() *credentials.Credentials {
customProvider,
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{Filename: "", Profile: ""},
webIdentityProvider,
defaults.RemoteCredProvider(*defaultConfig, defaultHandlers),
},
},
Expand Down