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

auth/aws: Fix panics when malformed ARNs are passed in #3280

Merged
merged 1 commit into from
Sep 4, 2017
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
6 changes: 6 additions & 0 deletions builtin/credential/aws/path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ func parseIamArn(iamArn string) (*iamEntity, error) {
// most people would expect, which is arn:aws:iam::<account_id>:role/<RoleName>
var entity iamEntity
fullParts := strings.Split(iamArn, ":")
if len(fullParts) != 6 {
return nil, fmt.Errorf("unrecognized arn: contains %d colon-separated parts, expected 6", len(fullParts))
}
if fullParts[0] != "arn" {
return nil, fmt.Errorf("unrecognized arn: does not begin with arn:")
}
Expand All @@ -1330,6 +1333,9 @@ func parseIamArn(iamArn string) (*iamEntity, error) {
entity.AccountNumber = fullParts[4]
// fullParts[5] would now be something like user/<UserName> or assumed-role/<RoleName>/<RoleSessionName>
parts := strings.Split(fullParts[5], "/")
if len(parts) < 2 {
return nil, fmt.Errorf("unrecognized arn: %q contains fewer than 2 slash-separated parts", fullParts[5])
}
entity.Type = parts[0]
entity.Path = strings.Join(parts[1:len(parts)-1], "/")
entity.FriendlyName = parts[len(parts)-1]
Expand Down
21 changes: 21 additions & 0 deletions builtin/credential/aws/path_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ func TestBackend_pathLogin_parseIamArn(t *testing.T) {
"",
iamEntity{Partition: "aws", AccountNumber: "123456789012", Type: "instance-profile", Path: "profilePath", FriendlyName: "InstanceProfileName"},
)

// Test that it properly handles pathological inputs...
_, err := parseIamArn("")
if err == nil {
t.Error("expected error from empty input string")
}

_, err = parseIamArn("arn:aws:iam::123456789012:role")
if err == nil {
t.Error("expected error from malformed ARN without a role name")
}

_, err = parseIamArn("arn:aws:iam")
if err == nil {
t.Error("expected error from incomplete ARN (arn:aws:iam)")
}

_, err = parseIamArn("arn:aws:iam::1234556789012:/")
if err == nil {
t.Error("expected error from empty principal type and no principal name (arn:aws:iam::1234556789012:/)")
}
}

func TestBackend_validateVaultHeaderValue(t *testing.T) {
Expand Down