Skip to content

🐛 aws-secret-manager-edgecases-enhancement#6534

Open
LittleSalkin1806 wants to merge 8 commits intomondoohq:mainfrom
LittleSalkin1806:edgecase-enhancement-aws-secrets-manager
Open

🐛 aws-secret-manager-edgecases-enhancement#6534
LittleSalkin1806 wants to merge 8 commits intomondoohq:mainfrom
LittleSalkin1806:edgecase-enhancement-aws-secrets-manager

Conversation

@LittleSalkin1806
Copy link
Copy Markdown
Contributor

@LittleSalkin1806 LittleSalkin1806 commented Feb 2, 2026

KMS Keys API calls use KeyID = support multiple formats aliases, UUID(ID) or arn format.

I tried to stick as much as possible to the current code structure with out refactoring but let KMS Key handle normalization.

When we look at types
KmsKeyId is already an ARN from the AWS API for secetmanager and probably most of the others.

But as you can see from the screenshot eventbridge connection and potentially others have edge cases.
types.secretsmanager states that only arn should be rerturned but UUId was returned.

image

I could replicate this by creating event bridge connection using the basic auth and then selecting a key
IMPORTANT! kms key arn is returned if i select an alias or kmskeyarn but if i just search and select kmskey id then only the UUID is returned by go sdsk

image

I did some normalization on kms side to handle such cases as we dont always know if this case will happen or not for the responding service where the key is linked.

Todos:

  • []: I also found some policy limiations. Either for the same account or cross acccount
    I would still need this information and distungish on mql level.
    Therefore i added some todo with the idear accessible: bool
    Every Key which exist and we dont have access return accessible: false

This should probably be an another issue.

@LittleSalkin1806 LittleSalkin1806 changed the title aws-secret-manager-edgecases-enhancement 🐛 aws-secret-manager-edgecases-enhancement Feb 2, 2026
@LittleSalkin1806
Copy link
Copy Markdown
Contributor Author

@tas50 would be great if this can be reviewed. As this has an impact on every kms key.
I am not 100% sure if this is correctly handeled but i choosed to do it on KMS level for potential other edge cases and not on secretsmanager where i found the problem.
I CANT test every IAC tool etc. This was reproducible via UI as we had this case already in our dev account.

@tas50 tas50 requested review from chris-rock and vjeffrey February 5, 2026 05:14
@tas50
Copy link
Copy Markdown
Member

tas50 commented Feb 5, 2026

I'll see if we can get some subject matter experts on this one for you @LittleSalkin1806

@LittleSalkin1806
Copy link
Copy Markdown
Contributor Author

I am just curious if you would handle this for an edge case of secretmanager normalization for example eventbridge special cases or if you would handle it in theory as it could happen in other services as well.

What would be your approach here ?

@tas50
Copy link
Copy Markdown
Member

tas50 commented Mar 3, 2026

/review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

KMS key lookups from services like EventBridge that return UUIDs instead of ARNs will now resolve correctly, but the normalization has edge-case gaps.

@vjeffrey
Copy link
Copy Markdown
Contributor

sorry for the delay. i have the pr checked out locally, addressing review comments and looking at the code

thank you for the contribution!

@mondoo-code-review mondoo-code-review bot dismissed their stale review March 13, 2026 17:24

Superseded by new review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Both previous findings are addressed: empty-region guard added with error return, and table-driven unit tests now cover key scenarios.

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Cross-account KMS keys now return their ARN instead of null, improving visibility for security tools.

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Cross-account KMS keys now skip API calls, preventing access-denied errors during AWS scans.

LittleSalkin1806 and others added 7 commits March 13, 2026 12:26
- Add early guard for empty region when normalizing bare UUID keys
- Remove dead extractKmsKeyId function (the "key/" prefix branch was unreachable)
- Downgrade cross-account log from Error to Warn (expected operational condition)
- Add table-driven unit tests for NormalizeKmsKeyRef

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a KMS key belongs to a different AWS account, we can't fetch its
details, but we should still return the resource with the ARN populated
so security tools can see which KMS key is referenced.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When a KMS key belongs to a different AWS account, the lazy-loaded
fields (metadata, tags, aliases, keyRotationEnabled, keyState) would
fail with AccessDeniedException or ValidationException. Now these
methods detect cross-account keys and return empty values instead of
making API calls that will always fail.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Log warning when ARN parse fails in isCrossAccountKey
- Remove duplicate arn/region assignments in cross-account block
  (already set before the check)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add isCrossAccountKey() checks to createdAt, deletedAt, enabled,
description, and grants methods that were added during rebase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vjeffrey vjeffrey force-pushed the edgecase-enhancement-aws-secrets-manager branch from f56f504 to 5151f51 Compare March 13, 2026 18:31
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Cross-account KMS keys are silently returned with false/empty defaults instead of signaling missing data, and the metadata method loses its caching.

Additional findings (file/line not in diff):

  • 🟡 providers/aws/resources/aws_kms.go:170keyRotationEnabled() returns false, nil for cross-account keys. Returning a zero-value boolean with no error is indistinguishable from "rotation is genuinely disabled". Security policies querying aws.kms.key.keyRotationEnabled == false will flag cross-account keys as non-compliant even though the real state is unknown.

Consider setting the field to null state (plugin.StateIsNull | plugin.StateIsSet) or returning an explicit error so downstream consumers can differentiate "unknown" from "disabled". The same concern applies to enabled() (line 300).

- Replace hand-rolled UUID heuristic with google/uuid.Parse for proper
  validation of KMS key ID format
- Rewrite metadata() to use getKeyMetadata() so it shares the cached
  DescribeKey result with keyState, createdAt, deletedAt, etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mondoo-code-review mondoo-code-review bot dismissed their stale review March 13, 2026 18:46

Superseded by new review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

Fix correctly reuses cached DescribeKey call and improves UUID validation.

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.

3 participants