fix(aws): recognize service-specific condition keys as restrictive in is_policy_public#10600
Conversation
…n is_policy_public Add kms:CallerAccount, kms:ViaService, aws:CalledVia, aws:CalledViaFirst, and aws:CalledViaLast to valid_condition_options in is_condition_block_restrictive. These service-specific and global condition keys are functionally equivalent to existing restrictive keys (e.g. kms:CallerAccount acts like aws:SourceAccount) but were not recognized, causing false positives in checks like kms_key_policy_is_not_public for policies that use them to scope access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
✅ Conflict Markers Resolved All conflict markers have been successfully resolved in this pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #10600 +/- ##
===========================================
- Coverage 93.55% 18.93% -74.63%
===========================================
Files 225 841 +616
Lines 31652 23943 -7709
===========================================
- Hits 29613 4534 -25079
- Misses 2039 19409 +17370
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Re: codecov/project failure The The All other CI checks (sdk-tests across 3.10/3.11/3.12, code-quality, security-scans, etc.) pass. |
pedrooot
left a comment
There was a problem hiding this comment.
Just one small comment and it's ready to go! 🔝
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… is_policy_public (#10600) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Context
is_condition_block_restrictive()inprowler/providers/aws/services/iam/lib/policy.pymaintains a list of IAM condition keys it considers restrictive. Several service-specific and global condition keys that effectively scope access were missing from this list, causing false positives in checks likekms_key_policy_is_not_public.For example, a KMS key policy using
kms:CallerAccount+kms:ViaServiceto restrict access to a specific account via a specific AWS service was incorrectly flagged as public because these condition keys were not recognized as restrictive — even thoughkms:CallerAccountis functionally equivalent toaws:SourceAccount.Description
Add the following condition keys to
valid_condition_optionsinis_condition_block_restrictive()(bothStringEqualsandStringLikeoperators):kms:CallerAccount— functionally equivalent toaws:SourceAccount; restricts KMS key usage to a specific AWS accountkms:ViaService— restricts KMS key usage to calls made through a specific AWS service (e.g.,glue.eu-central-1.amazonaws.com)aws:CalledVia— global condition key that restricts to calls made through specific AWS services (confused deputy prevention)aws:CalledViaFirst/aws:CalledViaLast— variants that match the first/last service in the call chainThis fixes false positives for any check that relies on
is_policy_public()oris_condition_block_restrictive(), including but not limited tokms_key_policy_is_not_public.Steps to review
prowler/providers/aws/services/iam/lib/policy.py(lines ~604–647) — they follow the same pattern as existing entries likes3:resourceaccounttests/providers/aws/services/iam/lib/policy_test.py:aws:CalledVia/CalledViaFirst/CalledViaLastviais_condition_block_restrictivekms:CallerAccountandkms:ViaServiceviais_condition_block_restrictive(valid/invalid, str/list)is_policy_publicwith realistic KMS key policiesChecklist
SDK/CLI
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.