Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below is a practical, console-focused process to find and fix IAM role permissions that allow privilege escalation in AWS.
Avoid letting low-privilege roles, wildcards, or external accounts assume highly privileged roles.
If you share a specific risky role/policy JSON, I can give exact edits line-by-line for remediation.
1. Understand What You’re Looking For
Privilege escalation usually happens when a principal (user/role) can:- Attach/Update IAM policies to themselves or to roles they can assume:
iam:AttachUserPolicy,iam:AttachRolePolicy,iam:PutUserPolicy,iam:PutRolePolicy,iam:CreatePolicyVersion,iam:SetDefaultPolicyVersion, etc.
- Assume or pass roles with more privileges:
sts:AssumeRoleiam:PassRole(combined with other actions)
- Create or modify access keys / login profiles:
iam:CreateAccessKey,iam:UpdateAccessKey,iam:CreateLoginProfile,iam:UpdateLoginProfile
- Create/Update Lambda, EC2, or other services with privileged roles:
lambda:UpdateFunctionCode,lambda:CreateFunction,ec2:RunInstanceswith a powerful instance profile, etc.
2. Inventory IAM Roles and Attached Policies
- Sign in to the AWS Management Console with an admin account.
- Go to IAM:
- Top right search bar → type “IAM” → IAM.
- In the left navigation, check:
- Roles
- Users
- Policies
- Managed policies (AWS-managed & Customer-managed).
- Inline policies on users/roles/groups.
3. Identify High-Risk Policies Using IAM Access Analyzer
- In IAM console, left menu → Access Analyzer → Policy analyzer.
- Use Policy analyzer to search for policies containing sensitive actions:
- In Actions filter, enter:
iam:*,sts:*,lambda:*,ec2:RunInstances, etc.
- In Actions filter, enter:
- For each policy result, open it in a new tab and inspect:
- Look for statements with
Effect: Allowand:Action: "iam:*"or broad wildcards like"*"on Action.Resource: "*".
- Look for statements with
- Prioritize:
- Policies with
Action="*"andResource="*". - Policies that allow specific escalation actions (list in section 1).
- Policies with
4. Analyze a Specific Role for Escalation Path
To deep dive into one role:- IAM console → Roles.
- Click a role name to inspect it.
- Tabs to check:
- Permissions:
- Look at each Attached policy and any Inline policies.
- Click policy name → JSON tab.
- Trust relationships:
- Check which principals can assume this role (
sts:AssumeRole).
- Check which principals can assume this role (
- Permissions:
-
Problematic Actions:
Common privilege-escalation enablers:
iam:AttachUserPolicyiam:AttachGroupPolicyiam:AttachRolePolicyiam:PutUserPolicyiam:PutGroupPolicyiam:PutRolePolicyiam:CreatePolicyVersioniam:SetDefaultPolicyVersioniam:PassRolests:AssumeRoleiam:CreateAccessKeyiam:UpdateAccessKeyiam:CreateLoginProfileiam:UpdateLoginProfile
-
Broad Resources:
Resource: "*"on the above actions.- Or resources that cover admin roles/policies.
sts:AssumeRole), that is a privilege escalation path.5. Remediate Policies (Least-Privilege Hardening)
5.1 Remove or Restrict Dangerous IAM Actions
For each risky policy:- IAM → Policies → search for the policy name.
- Open policy → Permissions tab → Edit.
-
In JSON or Visual editor, do the following:
a) Remove unneeded IAM-write actions completely
For example, remove:iam:Attach*iam:Put*iam:CreatePolicyVersioniam:SetDefaultPolicyVersioniam:CreateAccessKeyiam:UpdateAccessKeyiam:CreateLoginProfileiam:UpdateLoginProfile
iam:PassRoleis required:- Restrict Resource to specific safe roles, not
"*". - Add conditions like:
sts:AssumeRoleis required:- Restrict to only the specific role ARNs needed.
- Do not allow
"*"for resources.
- Click Next, review, then Save changes.
- Detach it from users/roles and replace with a custom, scoped-down customer-managed policy:
- Policies → Create policy.
- Define least-privilege permissions.
- Create policy, then Attach it to the target role/user.
- Detach the AWS-managed policy from the entity.
5.2 Tighten Trust Policies (Who Can Assume the Role)
- IAM → Roles → choose role → Trust relationships tab.
- Click Edit trust policy.
-
Check for:
"Principal": "*"or overly broad accounts.- Conditions missing on
sts:AssumeRole.
- Adjust to only allow required principals and, ideally, require conditions. Example (only one account and specific role):
6. Use the IAM Policy Simulator to Validate
- Go to IAM → Policy Simulator.
- Choose User or Role you want to test.
- Select services like IAM, STS, Lambda, EC2.
- Test specific actions:
iam:PassRole,iam:AttachRolePolicy,sts:AssumeRole,iam:CreateAccessKey, etc.
- Confirm:
- Only the minimal, intended actions are allowed.
- Escalation-enabling combinations are not possible.
7. Add Guardrails: SCPs and Permissions Boundaries (If Using Organizations)
If you use AWS Organizations:-
Service Control Policies (SCPs):
- AWS Organizations console → Policies → Service control policies.
- Create SCPs that deny dangerous actions for all non-admin accounts, e.g.:
- Attach SCP to appropriate OUs/accounts.
- Exclude a tightly-controlled admin account if necessary.
-
Permissions boundaries (optional, more advanced):
- Create a boundary policy that excludes privilege-escalation actions.
- Attach as permission boundary to roles developers can create.
8. Continuous Monitoring
- IAM console → Access Analyzer → Analyzer:
- Enable analyzers to detect broad or external access.
- IAM → Credential report:
- Periodically review user access keys, console access.
- Enable CloudTrail and (optionally) CloudTrail Lake / GuardDuty:
- Monitor for suspicious IAM activity (e.g., new
CreatePolicyVersion,SetDefaultPolicyVersion,AttachRolePolicy).
- Monitor for suspicious IAM activity (e.g., new
If you share a specific risky role/policy JSON, I can give exact edits line-by-line for remediation.
Using CLI
Using CLI
Below is a practical, CLI‑focused process to identify and fix IAM role permissions that allow privilege escalation in AWS.
For each role (or for ones you suspect):Look in the policy JSON for
Edit Re‑apply the edited inline policy:
Create a least‑privilege customer‑managed policy:
Example safer trust policy (from a specific account/role only):Apply:
Verify that high‑risk actions are
Apply with:
If you want, you can paste one specific role’s current policy JSON, and I can show you exactly how to rewrite it to remove the privilege‑escalation paths and give you the exact
1. Know the risky IAM permissions
These actions are commonly used for privilege escalation when overly broad:iam:PassRoleiam:PutRolePolicyiam:AttachRolePolicyiam:PutUserPolicyiam:CreatePolicyVersioniam:SetDefaultPolicyVersioniam:UpdateAssumeRolePolicyiam:AddUserToGroup,iam:AttachGroupPolicysts:AssumeRolests:AssumeRoleWithWebIdentity
2. Enumerate IAM roles and their policies
Action containing the risky IAM actions above.3. Identify privilege‑escalation patterns
Flags to look for in the policy JSON:- Wildcard actions:
"Action": "iam:*"or"*"on IAM / STS
- Unrestricted
PassRole:"Action": "iam:PassRole"with"Resource": "*"
- Policy modification on high‑privilege policies:
iam:AttachRolePolicy,iam:PutRolePolicy,iam:CreatePolicyVersion,iam:SetDefaultPolicyVersionwith"Resource": "*"
- Trust policies that are too broad:
sts:AssumeRoleallowed fromPrincipal: "*", or from untrusted accounts/services.
4. Remove or scope dangerous permissions (inline policies)
4.1. Download and edit the inline policy locally
policy.json:- Remove unneeded risky actions (e.g.,
iam:*,iam:PassRole, etc.). - Or narrow them:
- Restrict
Resourceto only specific ARNs (e.g., just one role that truly needs to be passed). - Add
Condition(e.g., limitiam:PassRoleto certain services).
- Restrict
iam:PassRole to a single role:5. Replace or detach risky managed policies
If a role has broad AWS‑managed or customer‑managed policies (e.g.,AdministratorAccess, custom *:* policies):6. Lock down trust policies (AssumeRole)
For any role that can lead to higher privilege (e.g., admin roles):- Restrict who can assume it.
- Avoid
Principal: "*". - Limit to specific AWS accounts, roles, or services.
7. Fix dangerous policy versioning rights
If a role can calliam:CreatePolicyVersion or iam:SetDefaultPolicyVersion on sensitive policies, an attacker can swap in an admin version.For customer‑managed policies:- List who can modify them.
- Remove those actions, or scope them with conditions (e.g., only to non‑privileged policies, or only a CI/CD role).
iam:CreatePolicyVersioniam:SetDefaultPolicyVersioniam:DeletePolicyVersion
put-role-policy.8. Validate with the Policy Simulator
Before and after changes, you can check what a role can do:explicitDeny or not allowed.9. Optional: enforce org‑wide via SCPs (if using AWS Organizations)
At the org/root or OU level, create SCPs that deny dangerous privilege‑escalation patterns except for tightly controlled admin roles:Example SCP snippet:If you want, you can paste one specific role’s current policy JSON, and I can show you exactly how to rewrite it to remove the privilege‑escalation paths and give you the exact
aws cli commands to apply the fix.Using Python
Using Python
Below is a practical, step‑by‑step remediation approach for AWS IAM privilege‑escalation risks, with Python (boto3) examples.
Usage: loop through roles and attached policies:This identifies where privilege‑escalation‑prone actions exist.
5. Remediate Excessive
Typical flow:
6. Remove or Restrict Delegated Policy Management (
If a role has permissions like After (if minimal is needed):If the role only needs to attach a pre‑approved policy to a specific role:Apply via same
7. Constrain
Even if role A doesn’t have broad After (restricted):Or with conditions:
Attach via Python:
If you want, I can:
1. Understand the Common IAM Privilege Escalation Paths
Typical dangerous permissions (especially if a user/principal can call them on themselves or roles they assume):iam:CreatePolicyVersion(withSetAsDefault=true)iam:PutRolePolicy,iam:PutUserPolicy,iam:AttachRolePolicy,iam:AttachUserPolicy,iam:AttachGroupPolicyiam:PassRole(especially combined with EC2, Lambda, Step Functions, etc.)sts:AssumeRole- Permissions on Lambda, EC2, Glue, Step Functions, etc., that allow attaching or modifying roles/policies:
lambda:UpdateFunctionConfiguration(to change execution role)ec2:RunInstanceswith instance profile you can controlglue:CreateDevEndpointwith role you can pass
- Wildcards like
"Action": "*","Resource": "*"(especially in combination).
2. Enumerate IAM Roles and Policies (Python/boto3)
3. Identify High‑Risk Permissions in Policies
Define a set of “risky” actions and scan all attached + inline policies.4. Decide on Remediation Strategy (Per Finding)
Per role/policy combination, you should:- Confirm business need for each risky action.
- If not needed:
- Remove or narrow the statement.
- If needed:
- Restrict resources.
- Add IAM conditions.
- Use permission boundaries and/or SCPs.
- Separate “break‑glass” roles from normal operators.
5. Remediate Excessive iam:PassRole
5.1 Policy Before (too broad)
5.2 Policy After (restricted roles + conditions)
5.3 Update Policy Version via Python
For managed policies:- Get existing document.
- Manually or programmatically modify statements (e.g., change
Resource: "*"to specific ARNs; addCondition). - Call
create_policy_versionwithSetAsDefault=True. - Optionally delete old versions later (max 5).
6. Remove or Restrict Delegated Policy Management (iam:*Policy*)
If a role has permissions like iam:CreatePolicyVersion, iam:PutRolePolicy, etc., and it’s not a dedicated IAM admin role:- Create a new, least‑privilege IAM admin role for identity team only.
- Remove those actions from operational roles.
create_policy_version mechanism.For inline policies, update with put_role_policy:7. Constrain sts:AssumeRole and Trust Policies
Even if role A doesn’t have broad iam:*, it can escalate by assuming a more‑privileged role B.7.1 Inspect trust policies
7.2 Restrict trust policies
- Use specific principals, not
*. - Add conditions like
aws:PrincipalTag,aws:SourceAccount,aws:SourceArn.
8. Guardrails: Permission Boundaries and SCPs (Org‑Level)
8.1 Permission Boundaries (per principal)
Create a boundary policy that forbids escalation actions (or limits them tightly), then attach it as a permission boundary to roles/users that you do not want to be able to escalate.Example permission boundary:8.2 Service Control Policies (SCPs) (Org‑wide)
In AWS Organizations, SCPs can deny dangerous actions account‑wide except for a specific IAM admin role.Example (pseudo; must be applied via Organizations API/console):9. Special Case: Service‑Based Escalation (Lambda, EC2, etc.)
Even ifiam:PassRole is restricted, some combos can still escalate; for each:- Lambda:
lambda:UpdateFunctionConfigurationto changeRole. - EC2:
ec2:RunInstanceswith a modifiable instance profile. - Step Functions:
states:CreateStateMachinewith high‑priv role.
- Constrain
Resourceto specific functions, instances, state machines. - Combine with tight
iam:PassRole(only low‑priv roles). - Use conditions like
iam:PassedToService,ec2:InstanceProfile, or tags.
10. Verification / Regression Checks
After changes:- Use IAM Access Analyzer (console or API) to detect potential privilege escalation.
- Re‑run your Python audit script to ensure:
- No unexpected
iam:*Policy*/iam:PassRole/sts:AssumeRolewildcards. - No
Action: "*"+Resource: "*"for non‑admin roles.
- No unexpected
- Test critical workflows to confirm business operations continue to function.
If you want, I can:
- Help you adapt the audit script to automatically suggest a “patched” policy document, or
- Focus on a specific privileged role’s policies and walk through concrete JSON diffs.
Using Terraform
Using Terraform
aws_iam_policy in Terraform (rather than editing inline JSON only) forces replacement of the policy resource; any existing attachments will be recreated by Terraform, which may briefly remove and reattach the policy during apply.For verification, terraform plan should show: removal of the old IAM policy resource (with privilege‑escalation actions), creation of the new restricted aws_iam_policy, and updates to aws_iam_role_policy_attachment resources so that the role is attached only to the remediated policy.
