Skip to content

Commit a7670ca

Browse files
tas50claude
andcommitted
🐛 Reject non-KMS ARNs in initAwsKmsKey to prevent misleading warnings
When scanning individual assets (S3 buckets, CloudTrail trails, etc.) and a policy includes a bare `aws.kms.key` query, initAwsKmsKey falls back to getAssetIdentifier and receives the asset's own ARN—which is not a KMS ARN. Those ARNs then hit the cross-account code path (S3 ARNs have no account ID; org trail ARNs belong to a different account) producing misleading "cross-account KMS keys are not supported yet" warnings. This adds a service check after ARN parsing to reject non-KMS ARNs early with a clear error message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b0bccb5 commit a7670ca

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

providers/aws/resources/aws_kms.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ func initAwsKmsKey(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[s
331331
if err != nil {
332332
return nil, nil, fmt.Errorf("invalid ARN %q: %w", a, err)
333333
}
334+
// Guard against non-KMS ARNs being passed in. This happens when scanning
335+
// individual assets (e.g., S3 buckets or CloudTrail trails) and a policy
336+
// includes a bare `aws.kms.key { ... }` query: initAwsKmsKey is called with
337+
// no args, falls back to getAssetIdentifier, and the asset's own ARN (which
338+
// is not a KMS ARN) ends up here. Without this check those ARNs hit the
339+
// cross-account code path below (S3 ARNs have no account ID, trail ARNs
340+
// belong to the org account) and produce misleading "cross-account KMS keys
341+
// are not supported yet" warnings.
342+
if arnVal.Service != "kms" {
343+
return nil, nil, fmt.Errorf("expected a KMS key ARN but got %q (service=%q)", a, arnVal.Service)
344+
}
334345
if arnVal.AccountID != runtime.Connection.(*connection.AwsConnection).AccountId() {
335346
// Cross-account key: we can't fetch details, but we should still return the ARN
336347
// so security tools can see which KMS key is referenced

0 commit comments

Comments
 (0)