Skip to content

Commit

Permalink
Merge pull request #103 from mattlandis/path-support
Browse files Browse the repository at this point in the history
Add support for ARNs with paths.
  • Loading branch information
nckturner committed Jun 22, 2018
2 parents d9bfef1 + b5938b9 commit 5232e35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/arn/arn.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ func Canonicalize(arn string) (string, error) {
case "federated-user":
return arn, nil
case "assumed-role":
if len(parts) < 2 {
if len(parts) < 3 {
return "", fmt.Errorf("assumed-role arn '%s' does not have a role", arn)
}
role := parts[1]
// IAM ARNs can contain paths, part[0] is resource, parts[len(parts)] is the SessionName.
role := strings.Join(parts[1:len(parts)-1], "/")
return fmt.Sprintf("arn:%s:iam::%s:role/%s", parsed.Partition, parsed.AccountID, role), nil
default:
return "", fmt.Errorf("unrecognized resource %s for service sts", parsed.Resource)
Expand Down
1 change: 1 addition & 0 deletions pkg/arn/arn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var arnTests = []struct {
{"arn:aws:sts::123456789012:assumed-role/Admin/Session", "arn:aws:iam::123456789012:role/Admin", nil},
{"arn:aws:sts::123456789012:federated-user/Bob", "arn:aws:sts::123456789012:federated-user/Bob", nil},
{"arn:aws:iam::123456789012:root", "arn:aws:iam::123456789012:root", nil},
{"arn:aws:sts::123456789012:assumed-role/Org/Team/Admin/Session", "arn:aws:iam::123456789012:role/Org/Team/Admin", nil},
}

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

0 comments on commit 5232e35

Please sign in to comment.