fix(kms): detect public access for any KMS action, not just kms:*#3
Conversation
Co-authored-by: jfagoagas <16007882+jfagoagas@users.noreply.github.com>
|
✅ Conflict Markers Resolved All conflict markers have been successfully resolved in this pull request. |
|
Please add an entry to the corresponding |
There was a problem hiding this comment.
Pull request overview
This PR fixes a false negative in the kms_key_not_publicly_accessible security check where KMS keys with specific actions (e.g., kms:DescribeKey) granted to wildcard principals were incorrectly reported as not publicly accessible, despite AWS SecurityHub correctly flagging them as public.
Changes:
- Removed the
not_allowed_actions=["kms:*"]parameter from theis_policy_public()call, allowing detection of ANY KMS action with public principals - Added comprehensive test coverage for the reported bug scenario with both single and multiple specific actions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| prowler/providers/aws/services/kms/kms_key_not_publicly_accessible/kms_key_not_publicly_accessible.py | Removed not_allowed_actions parameter and added clarifying comment to detect public access for any KMS action, not just wildcard |
| tests/providers/aws/services/kms/kms_key_not_publicly_accessible/kms_key_not_publicly_accessible_test.py | Added two new test cases covering single action (kms:DescribeKey) and multiple actions scenarios with public principals |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Context
The
kms_key_not_publicly_accessiblecheck failed to detect public access when KMS policies granted specific actions (e.g.,kms:DescribeKey) to wildcard principals, despite AWS SecurityHub correctly flagging these as publicly accessible.Description
Root Cause: The check filtered public access detection to only
kms:*wildcard actions vianot_allowed_actions=["kms:*"]. Theis_policy_public()function performs exact string matching, not pattern matching, so"kms:DescribeKey"≠"kms:*".Fix: Removed
not_allowed_actionsparameter. Any action with public principal ("Principal": "*"or"Principal": {"AWS": "*"}) is now correctly flagged, aligning with AWS SecurityHub behavior.Test Coverage: Added tests for
kms:DescribeKeywith public principal and multiple specific actions scenarios.Steps to review
kms_key_not_publicly_accessible.pyChecklist
Community Checklist
SDK/CLI
UI
API
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.