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

aws/credential: Add credential_process provider #2217

Merged
merged 5 commits into from Dec 4, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
425 changes: 425 additions & 0 deletions aws/credentials/processcreds/provider.go

Large diffs are not rendered by default.

561 changes: 561 additions & 0 deletions aws/credentials/processcreds/provider_test.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions aws/credentials/processcreds/testdata/expired.json
@@ -0,0 +1,7 @@
{
"Version": 1,
"AccessKeyId": "accessKey",
"SecretAccessKey": "secret",
"SessionToken": "tokenDefault",
"Expiration": "2000-01-01T00:00:00-00:00"
}
2 changes: 2 additions & 0 deletions aws/credentials/processcreds/testdata/malformed.json
@@ -0,0 +1,2 @@
{
"Version": 1
4 changes: 4 additions & 0 deletions aws/credentials/processcreds/testdata/missingkey.json
@@ -0,0 +1,4 @@
{
"Version": 1,
"AccessKeyId": "accesskey"
}
4 changes: 4 additions & 0 deletions aws/credentials/processcreds/testdata/missingsecret.json
@@ -0,0 +1,4 @@
{
"Version": 1,
"SecretAccessKey": "secretkey"
}
6 changes: 6 additions & 0 deletions aws/credentials/processcreds/testdata/nonexpire.json
@@ -0,0 +1,6 @@
{
"Version": 1,
"AccessKeyId": "accessKey",
"SecretAccessKey": "secret",
"SessionToken": "nonDefaultToken"
}
10 changes: 10 additions & 0 deletions aws/credentials/processcreds/testdata/shconfig.ini
@@ -0,0 +1,10 @@
[default]
credential_process = cat ./testdata/expired.json

[profile non_expire]
credential_process = cat ./testdata/nonexpire.json

[profile not_alone]
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = cat ./testdata/verybad.json
10 changes: 10 additions & 0 deletions aws/credentials/processcreds/testdata/shconfig_win.ini
@@ -0,0 +1,10 @@
[default]
credential_process = type .\testdata\expired.json

[profile non_expire]
credential_process = type .\testdata\nonexpire.json

[profile not_alone]
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = type .\testdata\verybad.json
10 changes: 10 additions & 0 deletions aws/credentials/processcreds/testdata/shcred.ini
@@ -0,0 +1,10 @@
[default]
credential_process = cat ./testdata/expired.json

[non_expire]
credential_process = cat ./testdata/nonexpire.json

[not_alone]
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = cat ./testdata/verybad.json
10 changes: 10 additions & 0 deletions aws/credentials/processcreds/testdata/shcred_win.ini
@@ -0,0 +1,10 @@
[default]
credential_process = type .\testdata\expired.json

[non_expire]
credential_process = type .\testdata\nonexpire.json

[not_alone]
aws_access_key_id = notFromCredProcAccess
aws_secret_access_key = notFromCredProcSecret
credential_process = type .\testdata\verybad.json
5 changes: 5 additions & 0 deletions aws/credentials/processcreds/testdata/static.json
@@ -0,0 +1,5 @@
{
"Version":1,
"AccessKeyId":"accesskey",
"SecretAccessKey":"secretkey"
}
5 changes: 5 additions & 0 deletions aws/credentials/processcreds/testdata/verybad.json
@@ -0,0 +1,5 @@
{
"Version":1,
"AccessKeyId":"veryBadAccessKeyID",
"SecretAccessKey":"veryBadSecretAccessKey"
}
3 changes: 3 additions & 0 deletions aws/credentials/processcreds/testdata/wrongversion.json
@@ -0,0 +1,3 @@
{
"Version": 2
}
5 changes: 5 additions & 0 deletions aws/session/session.go
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/corehandlers"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/processcreds"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/csm"
"github.com/aws/aws-sdk-go/aws/defaults"
Expand Down Expand Up @@ -534,6 +535,10 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config, envCfg envConfig, sharedCfg share
cfg.Credentials = credentials.NewStaticCredentialsFromCreds(
sharedCfg.Creds,
)
} else if len(sharedCfg.CredentialProcess) > 0 {
cfg.Credentials = processcreds.NewCredentials(
sharedCfg.CredentialProcess,
)
} else {
// Fallback to default credentials provider, include mock errors
// for the credential chain so user can identify why credentials
Expand Down
10 changes: 10 additions & 0 deletions aws/session/shared_config.go
Expand Up @@ -28,6 +28,8 @@ const (

// endpoint discovery group
enableEndpointDiscoveryKey = `endpoint_discovery_enabled` // optional
// External Credential Process
credentialProcessKey = `credential_process`

// DefaultSharedConfigProfile is the default profile to be used when
// loading configuration from the config files if another profile name
Expand Down Expand Up @@ -60,6 +62,9 @@ type sharedConfig struct {
AssumeRole assumeRoleConfig
AssumeRoleSource *sharedConfig

// An external process to request credentials
CredentialProcess string

// Region is the region the SDK should use for looking up AWS service endpoints
// and signing requests.
//
Expand Down Expand Up @@ -223,6 +228,11 @@ func (cfg *sharedConfig) setFromIniFile(profile string, file sharedConfigFile) e
}
}

// `credential_process`
if credProc := section.String(credentialProcessKey); len(credProc) > 0 {
cfg.CredentialProcess = credProc
}

// Region
if v := section.String(regionKey); len(v) > 0 {
cfg.Region = v
Expand Down