Skip to content
Open
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
5 changes: 4 additions & 1 deletion kms/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func NewMasterKeyFromArn(arn string, context map[string]*string, awsProfile stri
key := &MasterKey{}
arn = strings.Replace(arn, " ", "", -1)
key.Arn = arn
roleIndex := strings.Index(arn, "+arn:aws:iam::")
// While ARN paths can contain '+', they cannot contain ':'.
// Thus '+arn:' must be separating two ARNs that have been concatenated with '+'.
// (While KMS ARN paths currently do not contain '+', I think it's better to be safe than sorry.)
roleIndex := strings.Index(arn, "+arn:")
if roleIndex > 0 {
// Overwrite ARN
key.Arn = arn[:roleIndex]
Expand Down
6 changes: 6 additions & 0 deletions kms/keysource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ func TestNewMasterKeyFromArn(t *testing.T) {
assert.Equal(t, "arn:aws:kms:us-west-2:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500", key.Arn)
assert.Equal(t, "arn:aws:iam::927034868273:role/sops-dev-xyz", key.Role)
})

t.Run("arn with role in another partition", func(t *testing.T) {
key := NewMasterKeyFromArn("arn:aws-foobar:kms:bazbam:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500+arn:aws-foobar:iam::927034868273:role/sops-dev-xyz", nil, "")
assert.Equal(t, "arn:aws-foobar:kms:bazbam:927034868273:key/fe86dd69-4132-404c-ab86-4269956b4500", key.Arn)
assert.Equal(t, "arn:aws-foobar:iam::927034868273:role/sops-dev-xyz", key.Role)
})
}

func TestMasterKeysFromArnString(t *testing.T) {
Expand Down
Loading