Skip to content

Commit 8de045b

Browse files
authored
extend aws.kms.keys {tags} (#6052)
Signed-off-by: Manuel Weber <manuel@mondoo.com>
1 parent 2d7b4d6 commit 8de045b

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

providers/aws/resources/aws.lr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@ private aws.kms.key @defaults("id region metadata.Description") {
725725
keyRotationEnabled() bool
726726
// Metadata for the key
727727
metadata() dict
728+
// Tags for the KMS key
729+
tags() map[string]string
728730
}
729731

730732

providers/aws/resources/aws.lr.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

providers/aws/resources/aws.lr.manifest.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,8 @@ resources:
23962396
keyRotationEnabled: {}
23972397
metadata: {}
23982398
region: {}
2399+
tags:
2400+
min_mondoo_version: 9.0.0
23992401
is_private: true
24002402
min_mondoo_version: 5.15.0
24012403
platform:
@@ -3784,7 +3786,6 @@ resources:
37843786
name:
37853787
- aws
37863788
aws.waf.rule.statement.ratebasedstatement:
3787-
fields: {}
37883789
is_private: true
37893790
min_mondoo_version: 9.0.0
37903791
platform:

providers/aws/resources/aws_kms.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ func (a *mqlAwsKmsKey) keyRotationEnabled() (bool, error) {
119119
return key.KeyRotationEnabled, nil
120120
}
121121

122+
func (a *mqlAwsKmsKey) tags() (map[string]any, error) {
123+
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
124+
keyArn := a.Arn.Data
125+
126+
svc := conn.Kms(a.Region.Data)
127+
ctx := context.Background()
128+
129+
tags, err := svc.ListResourceTags(ctx, &kms.ListResourceTagsInput{KeyId: &keyArn})
130+
if err != nil {
131+
return nil, err
132+
}
133+
134+
res := map[string]any{}
135+
for i := range tags.Tags {
136+
tag := tags.Tags[i]
137+
res[convert.ToValue(tag.TagKey)] = convert.ToValue(tag.TagValue)
138+
}
139+
140+
return res, nil
141+
}
142+
122143
func (a *mqlAwsKmsKey) id() (string, error) {
123144
return a.Arn.Data, nil
124145
}

0 commit comments

Comments
 (0)