-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
provider/aws: Add support for AssumeRole prior to operations #8638
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ func TestAWSGetAccountId_shouldBeValid_EC2RoleHasPriority(t *testing.T) { | |
defer awsTs() | ||
|
||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{200, iamResponse_GetUser_valid, "text/xml"}, | ||
}, | ||
|
@@ -72,7 +72,7 @@ func TestAWSGetAccountId_shouldBeValid_EC2RoleHasPriority(t *testing.T) { | |
|
||
func TestAWSGetAccountId_shouldBeValid_fromIamUser(t *testing.T) { | ||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{200, iamResponse_GetUser_valid, "text/xml"}, | ||
}, | ||
|
@@ -94,11 +94,11 @@ func TestAWSGetAccountId_shouldBeValid_fromIamUser(t *testing.T) { | |
|
||
func TestAWSGetAccountId_shouldBeValid_fromGetCallerIdentity(t *testing.T) { | ||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{403, iamResponse_GetUser_unauthorized, "text/xml"}, | ||
}, | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetCallerIdentity&Version=2011-06-15"}, | ||
Response: &iamResponse{200, stsResponse_GetCallerIdentity_valid, "text/xml"}, | ||
}, | ||
|
@@ -119,15 +119,15 @@ func TestAWSGetAccountId_shouldBeValid_fromGetCallerIdentity(t *testing.T) { | |
|
||
func TestAWSGetAccountId_shouldBeValid_fromIamListRoles(t *testing.T) { | ||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{403, iamResponse_GetUser_unauthorized, "text/xml"}, | ||
}, | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetCallerIdentity&Version=2011-06-15"}, | ||
Response: &iamResponse{403, stsResponse_GetCallerIdentity_unauthorized, "text/xml"}, | ||
}, | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=ListRoles&MaxItems=1&Version=2010-05-08"}, | ||
Response: &iamResponse{200, iamResponse_ListRoles_valid, "text/xml"}, | ||
}, | ||
|
@@ -148,11 +148,11 @@ func TestAWSGetAccountId_shouldBeValid_fromIamListRoles(t *testing.T) { | |
|
||
func TestAWSGetAccountId_shouldBeValid_federatedRole(t *testing.T) { | ||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{400, iamResponse_GetUser_federatedFailure, "text/xml"}, | ||
}, | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=ListRoles&MaxItems=1&Version=2010-05-08"}, | ||
Response: &iamResponse{200, iamResponse_ListRoles_valid, "text/xml"}, | ||
}, | ||
|
@@ -173,11 +173,11 @@ func TestAWSGetAccountId_shouldBeValid_federatedRole(t *testing.T) { | |
|
||
func TestAWSGetAccountId_shouldError_unauthorizedFromIam(t *testing.T) { | ||
iamEndpoints := []*iamEndpoint{ | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=GetUser&Version=2010-05-08"}, | ||
Response: &iamResponse{403, iamResponse_GetUser_unauthorized, "text/xml"}, | ||
}, | ||
&iamEndpoint{ | ||
{ | ||
Request: &iamRequest{"POST", "/", "Action=ListRoles&MaxItems=1&Version=2010-05-08"}, | ||
Response: &iamResponse{403, iamResponse_ListRoles_unauthorized, "text/xml"}, | ||
}, | ||
|
@@ -218,15 +218,20 @@ func TestAWSGetCredentials_shouldError(t *testing.T) { | |
defer resetEnv() | ||
cfg := Config{} | ||
|
||
c := GetCredentials(&cfg) | ||
_, err := c.Get() | ||
c, err := GetCredentials(&cfg) | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if awsErr.Code() != "NoCredentialProviders" { | ||
t.Fatal("Expected NoCredentialProviders error") | ||
} | ||
} | ||
_, err = c.Get() | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if awsErr.Code() != "NoCredentialProviders" { | ||
t.Fatalf("Expected NoCredentialProviders error") | ||
t.Fatal("Expected NoCredentialProviders error") | ||
} | ||
} | ||
if err == nil { | ||
t.Fatalf("Expected an error with empty env, keys, and IAM in AWS Config") | ||
t.Fatal("Expected an error with empty env, keys, and IAM in AWS Config") | ||
} | ||
} | ||
|
||
|
@@ -251,14 +256,19 @@ func TestAWSGetCredentials_shouldBeStatic(t *testing.T) { | |
Token: c.Token, | ||
} | ||
|
||
creds := GetCredentials(&cfg) | ||
creds, err := GetCredentials(&cfg) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should check the err before we check if the creds are nil |
||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected a static creds provider to be returned") | ||
t.Fatal("Expected a static creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
|
||
if v.AccessKeyID != c.Key { | ||
t.Fatalf("AccessKeyID mismatch, expected: (%s), got (%s)", c.Key, v.AccessKeyID) | ||
} | ||
|
@@ -286,9 +296,12 @@ func TestAWSGetCredentials_shouldIAM(t *testing.T) { | |
// An empty config, no key supplied | ||
cfg := Config{} | ||
|
||
creds := GetCredentials(&cfg) | ||
creds, err := GetCredentials(&cfg) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same - err check first before creds? |
||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected a static creds provider to be returned") | ||
t.Fatal("Expected a static creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
|
@@ -335,10 +348,14 @@ func TestAWSGetCredentials_shouldIgnoreIAM(t *testing.T) { | |
Token: c.Token, | ||
} | ||
|
||
creds := GetCredentials(&cfg) | ||
creds, err := GetCredentials(&cfg) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Err before creds? :) |
||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected a static creds provider to be returned") | ||
t.Fatal("Expected a static creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
|
@@ -362,7 +379,14 @@ func TestAWSGetCredentials_shouldErrorWithInvalidEndpoint(t *testing.T) { | |
ts := invalidAwsEnv(t) | ||
defer ts() | ||
|
||
creds := GetCredentials(&Config{}) | ||
creds, err := GetCredentials(&Config{}) | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatal("Expected a static creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to check the creds are not nil as elsewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if err == nil { | ||
t.Fatal("Expected error returned when getting creds w/ invalid EC2 endpoint") | ||
|
@@ -380,11 +404,17 @@ func TestAWSGetCredentials_shouldIgnoreInvalidEndpoint(t *testing.T) { | |
ts := invalidAwsEnv(t) | ||
defer ts() | ||
|
||
creds := GetCredentials(&Config{AccessKey: "accessKey", SecretKey: "secretKey"}) | ||
creds, err := GetCredentials(&Config{AccessKey: "accessKey", SecretKey: "secretKey"}) | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
v, err := creds.Get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check that creds are not nil ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, added this now. |
||
if err != nil { | ||
t.Fatalf("Getting static credentials w/ invalid EC2 endpoint failed: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatal("Expected a static creds provider to be returned") | ||
} | ||
|
||
if v.ProviderName != "StaticProvider" { | ||
t.Fatalf("Expected provider name to be %q, %q given", "StaticProvider", v.ProviderName) | ||
|
@@ -406,10 +436,14 @@ func TestAWSGetCredentials_shouldCatchEC2RoleProvider(t *testing.T) { | |
ts := awsEnv(t) | ||
defer ts() | ||
|
||
creds := GetCredentials(&Config{}) | ||
creds, err := GetCredentials(&Config{}) | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected an EC2Role creds provider to be returned") | ||
t.Fatal("Expected an EC2Role creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("Expected no error when getting creds: %s", err) | ||
|
@@ -452,10 +486,14 @@ func TestAWSGetCredentials_shouldBeShared(t *testing.T) { | |
t.Fatalf("Error resetting env var AWS_SHARED_CREDENTIALS_FILE: %s", err) | ||
} | ||
|
||
creds := GetCredentials(&Config{Profile: "myprofile", CredsFilename: file.Name()}) | ||
creds, err := GetCredentials(&Config{Profile: "myprofile", CredsFilename: file.Name()}) | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected a provider chain to be returned") | ||
t.Fatal("Expected a provider chain to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
|
@@ -479,10 +517,14 @@ func TestAWSGetCredentials_shouldBeENV(t *testing.T) { | |
defer resetEnv() | ||
|
||
cfg := Config{} | ||
creds := GetCredentials(&cfg) | ||
creds, err := GetCredentials(&cfg) | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
} | ||
if creds == nil { | ||
t.Fatalf("Expected a static creds provider to be returned") | ||
} | ||
|
||
v, err := creds.Get() | ||
if err != nil { | ||
t.Fatalf("Error gettings creds: %s", err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why errors.New and not errWrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are generating a new error rather than wrapping one produced by an upstream API?