Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.
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
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"Version": 1
4 changes: 4 additions & 0 deletions aws/credentials/processcreds/testdata/missingkey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Version": 1,
"AccessKeyId": "accesskey"
}
4 changes: 4 additions & 0 deletions aws/credentials/processcreds/testdata/missingsecret.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Version": 1,
"SecretAccessKey": "secretkey"
}
6 changes: 6 additions & 0 deletions aws/credentials/processcreds/testdata/nonexpire.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Version": 1,
"AccessKeyId": "accessKey",
"SecretAccessKey": "secret",
"SessionToken": "nonDefaultToken"
}
10 changes: 10 additions & 0 deletions aws/credentials/processcreds/testdata/shconfig.ini
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Version":1,
"AccessKeyId":"accesskey",
"SecretAccessKey":"secretkey"
}
5 changes: 5 additions & 0 deletions aws/credentials/processcreds/testdata/verybad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Version":1,
"AccessKeyId":"veryBadAccessKeyID",
"SecretAccessKey":"veryBadSecretAccessKey"
}
3 changes: 3 additions & 0 deletions aws/credentials/processcreds/testdata/wrongversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Version": 2
}
5 changes: 5 additions & 0 deletions aws/session/session.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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