feat(aws): add iam check for passrole without condition #9879
+154
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
This PR addresses a critical privilege escalation vector often referred to as Shadow Admin.
When an IAM policy allows
iam:PassRoleon all resources (*) without any Condition (such asiam:PassedToService), it allows a user to pass highly privileged roles to compute services (like EC2 or Lambda). An attacker can exploit this to launch an instance with an Administrator role, log into that instance, and effectively take over the AWS account.This check ensures strict validation of
iam:PassRolepermissions to align with the principle of least privilege and AWS security best practices.Description
I have added a new check
iam_policy_allows_passrole_without_conditionto the IAM service.Changes:
New Check Logic: This check evaluates customer-managed IAM policies only (excluding inline and AWS-managed policies) and flags any policy that allows
iam:PassRoleon*resources when theConditionblock is missing.Robustness: The logic explicitly checks for the condition key in a case-insensitive manner (
Conditionorcondition) to prevent false positives/negatives due to JSON formatting.Metadata: Assigned
Highseverity and mapped to NIST 800-53 (AC-6) standards.Unit Tests: Added comprehensive unit tests using
unittest.mockto verify detection of "Toxic" policies (FAIL) and "Safe" policies (PASS). Note: Used direct object injection in tests to ensure reliability independent ofmotolimitations regarding condition keys.Steps to review
Unit Testing: Run the included unit test to verify logic:
Manual Verification:
iam:PassRoleon*without any condition (e.g., missingiam:PassedToService).Example of a failing (toxic) policy:
{ "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*" }The check reports a FAIL, identifying the offending policy and confirming the absence of restrictive conditions on
iam:PassRole.Quick Security notes: I deleted the vulnerable policy immediately after confirming the tool worked.
iam:PassRoleon*BUT includes a valid condition.Example of a safe policy:
{ "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*", "Condition": { "StringEquals": { "iam:PassedToService": "ec2.amazonaws.com" } } }Expected result: The check should PASS, confirming that policies with proper conditions are not flagged. This safe policy restricts
iam:PassRoleto EC2 only.Checklist
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.