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

Fix ToString for AWS KMS to include role, context, and profile #1733

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

felixfontein
Copy link
Contributor

@felixfontein felixfontein commented Jan 17, 2025

Follow-up for #1493, in particular #1493 (comment). Turns out the other fields were important as well.

This not only applies to #1493, but also other operations where kms.ToString is used, for example the rotate subcommand, the updatekeys subcommand, and the publish subcommand (the two latter use DiffKeyGroups, which relies on ToString to identify a full key).

Fixes #1580.

Copy link
Contributor

@jonasbadstuebner jonasbadstuebner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Felix,
first of all, thank you for creating this fix. Sorry that I broke stuff for others with my change.

The PR looks good to me.
I still am no AWS guy, so my comments on it can not cover the behavior of the code after your changes. I cannot judge if it is working correctly afterwards, but I understood the #1580 (comment) to match what you implemented now.

🚀

@@ -538,9 +553,10 @@ func TestKeyGroupsForFileWithGroups(t *testing.T) {
conf, err := parseCreationRuleForFile(parseConfigFile(sampleConfigWithGroups, t), "/conf/path", "whatever", nil)
assert.Nil(t, err)
assert.Equal(t, "bar", conf.KeyGroups[0][0].ToString())
assert.Equal(t, "foo", conf.KeyGroups[0][1].ToString())
assert.Equal(t, "foo||bar", conf.KeyGroups[0][1].ToString())
assert.Equal(t, "foo|baz:bam", conf.KeyGroups[0][2].ToString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a test-case where both context and profile are set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some more tests.

kms/keysource.go Outdated
if key.AwsProfile != "" {
return fmt.Sprintf("%s|%s|%s", arnRole, context, key.AwsProfile)
}
if len(key.EncryptionContext) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(key.EncryptionContext) > 0 {
if context != "" {

Just a thought, that the kmsContextToString could return something even if the length of the EncryptionContext is zero. It doesn’t right now, but maybe in the future?
Checking if the string is empty is also more consistent with the other if statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think kmsContextToString() should ever return anything than the empty string for an empty EncryptionContext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add second kms list entry when SOPS file created
2 participants