Skip to content

Commit

Permalink
config: respect aws_profile from group config
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Ludewig <benjamin.ludewig@neuland-bfi.de>
  • Loading branch information
Kouzukii authored and hiddeco committed Oct 13, 2023
1 parent b6d3c97 commit 7ee554c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func getKeyGroupsFromCreationRule(cRule *creationRule, kmsEncryptionContext map[
keyGroup = append(keyGroup, pgp.NewMasterKeyFromFingerprint(k))
}
for _, k := range group.KMS {
keyGroup = append(keyGroup, kms.NewMasterKey(k.Arn, k.Role, k.Context))
keyGroup = append(keyGroup, kms.NewMasterKeyWithProfile(k.Arn, k.Role, k.Context, k.AwsProfile))
}
for _, k := range group.GCPKMS {
keyGroup = append(keyGroup, gcpkms.NewMasterKeyFromResourceID(k.ResourceID))
Expand Down
6 changes: 4 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ creation_rules:
key_groups:
- kms:
- arn: foo
aws_profile: bar
pgp:
- bar
gcp_kms:
Expand All @@ -105,6 +106,7 @@ creation_rules:
- 'https://foo.vault:8200/v1/foo/keys/foo-key'
- kms:
- arn: baz
aws_profile: foo
pgp:
- qux
gcp_kms:
Expand Down Expand Up @@ -287,14 +289,14 @@ func TestLoadConfigFileWithGroups(t *testing.T) {
PathRegex: "",
KeyGroups: []keyGroup{
{
KMS: []kmsKey{{Arn: "foo"}},
KMS: []kmsKey{{Arn: "foo", AwsProfile: "bar"}},
PGP: []string{"bar"},
GCPKMS: []gcpKmsKey{{ResourceID: "foo"}},
AzureKV: []azureKVKey{{VaultURL: "https://foo.vault.azure.net", Key: "foo-key", Version: "fooversion"}},
Vault: []string{"https://foo.vault:8200/v1/foo/keys/foo-key"},
},
{
KMS: []kmsKey{{Arn: "baz"}},
KMS: []kmsKey{{Arn: "baz", AwsProfile: "foo"}},
PGP: []string{"qux"},
GCPKMS: []gcpKmsKey{
{ResourceID: "bar"},
Expand Down
8 changes: 8 additions & 0 deletions kms/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func NewMasterKey(arn string, role string, context map[string]*string) *MasterKe
}
}

// NewMasterKeyWithProfile creates a new MasterKey from an ARN, role, context
// and awsProfile, setting the creation date to the current date.
func NewMasterKeyWithProfile(arn string, role string, context map[string]*string, awsProfile string) *MasterKey {
k := NewMasterKey(arn, role, context)
k.AwsProfile = awsProfile
return k
}

// NewMasterKeyFromArn takes an ARN string and returns a new MasterKey for that
// ARN.
func NewMasterKeyFromArn(arn string, context map[string]*string, awsProfile string) *MasterKey {
Expand Down

0 comments on commit 7ee554c

Please sign in to comment.