Finding Over-Broad Policies and IAM Privilege Escalation
An access key with "only a few IAM permissions" can be worth as much as an administrator key. If a principal may create a new version of a policy attached to itself, attach a managed policy to itself, or pass a powerful role to a service it controls, it can grant itself more: that is IAM privilege escalation, and it is one of the most common findings in cloud assessments. The other common finding is plainer: policies that are simply too broad, with * actions or * resources on sensitive services. This lesson builds a finder for both over the lab account's policies, then covers how escalation shows up in CloudTrail and how to prevent it.
The escalation methods below are documented, well-known classes of misconfiguration (public research has catalogued over twenty for AWS). They are described as what a permission allows, so you can find and remove it; no step-by-step attack is given or needed.
What makes a permission dangerous
| Class | Permissions (AWS names) | Why it matters |
|---|---|---|
| Edit your own policies | iam:CreatePolicyVersion, iam:SetDefaultPolicyVersion, iam:PutUserPolicy, iam:PutRolePolicy, iam:AttachUserPolicy, iam:AttachRolePolicy, iam:AttachGroupPolicy |
rewrite or add a policy on a principal you control → any permission |
| Take over other identities | iam:CreateAccessKey, iam:CreateLoginProfile, iam:UpdateLoginProfile on other users; iam:UpdateAssumeRolePolicy |
get credentials for, or the right to assume, someone more powerful |
| Pass a role to compute | iam:PassRole together with ec2:RunInstances, lambda:CreateFunction (+ invoke), ecs:RunTask, glue:CreateDevEndpoint, cloudformation:CreateStack… |
run code under a role you couldn't assume yourself |
| Assume anything | sts:AssumeRole on * |
every role whose trust policy accepts the account |
| Read all data | s3:GetObject, kms:Decrypt, secretsmanager:GetSecretValue, ssm:GetParameter* on * |
no escalation needed: the data is the goal |
| Everything | *, service:* on *, or Allow + NotAction |
administrator in all but name |
A finder
The program expands each Allow statement's action patterns against a catalogue of sensitive actions (IAM wildcards, case-insensitive), notes when the resource is * or a wildcard, and checks the PassRole combinations per principal. It deliberately reports potential paths: a human still decides whether a condition or an SCP makes a path impossible.
from fnmatch import fnmatchcase
def L(x):
return x if isinstance(x, list) else [x]
SELF_EDIT = ["iam:CreatePolicyVersion", "iam:SetDefaultPolicyVersion", "iam:PutUserPolicy", "iam:PutRolePolicy",
"iam:AttachUserPolicy", "iam:AttachRolePolicy", "iam:AttachGroupPolicy"]
TAKEOVER = ["iam:CreateAccessKey", "iam:CreateLoginProfile", "iam:UpdateLoginProfile", "iam:UpdateAssumeRolePolicy"]
PASS_TARGETS = {"ec2:RunInstances": "EC2", "lambda:CreateFunction": "Lambda", "ecs:RunTask": "ECS",
"cloudformation:CreateStack": "CloudFormation"}
DATA = ["s3:GetObject", "kms:Decrypt", "secretsmanager:GetSecretValue", "ssm:GetParameter"]
def grants(statements, action):
"""Resources on which the principal's Allow statements grant this action."""
res = []
for st in statements:
if st["Effect"] != "Allow":
continue
if "Action" in st:
hit = any(fnmatchcase(action.lower(), p.lower()) for p in L(st["Action"]))
else:
hit = not any(fnmatchcase(action.lower(), p.lower()) for p in L(st["NotAction"]))
if hit:
res += L(st.get("Resource", "*"))
return res
def wide(resources):
return any(r == "*" or r.endswith("/*") or r.endswith(":*") for r in resources)
def review(name, statements):
out = []
for st in statements:
if st["Effect"] == "Allow" and "NotAction" in st:
out.append(("HIGH", f"Allow + NotAction {L(st['NotAction'])}: everything else is allowed"))
if st["Effect"] == "Allow" and any(a == "*" or a.endswith(":*") for a in L(st.get("Action", []))) and "*" in L(st["Resource"]):
out.append(("HIGH", f"{L(st['Action'])} on *"))
for a in SELF_EDIT + TAKEOVER:
r = grants(statements, a)
if r:
sev = "CRITICAL" if wide(r) or any(name in x for x in r) else "HIGH"
out.append((sev, f"escalation: {a} on {', '.join(r)}"))
passrole = grants(statements, "iam:PassRole")
if passrole:
for act, svc in PASS_TARGETS.items():
if grants(statements, act):
out.append(("CRITICAL" if wide(passrole) else "HIGH",
f"escalation: iam:PassRole on {', '.join(passrole)} + {act} (run code as any passable role via {svc})"))
for a in DATA:
r = grants(statements, a)
if "*" in r:
out.append(("MEDIUM", f"data-wide: {a} on *"))
rank = {"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2}
print(f"{name}: {len(out)} finding(s)")
for sev, text in sorted(set(out), key=lambda f: (rank[f[0]], f[1])):
print(f" {sev:8} {text}")
A = "arn:aws:iam::123456789012"
principals = {
"alice": [{"Effect": "Allow", "Action": ["s3:Get*", "s3:List*"], "Resource": "arn:aws:s3:::lab-app-uploads*"},
{"Effect": "Allow", "Action": ["iam:CreatePolicyVersion", "iam:GetPolicy*"], "Resource": f"{A}:policy/alice-dev"}],
"bob": [{"Effect": "Allow", "NotAction": "iam:*", "Resource": "*"}],
"ci-deploy": [{"Effect": "Allow", "Action": ["lambda:CreateFunction", "lambda:InvokeFunction", "lambda:UpdateFunctionCode"], "Resource": "*"},
{"Effect": "Allow", "Action": "iam:PassRole", "Resource": "*"},
{"Effect": "Allow", "Action": "s3:*", "Resource": ["arn:aws:s3:::lab-*", "arn:aws:s3:::lab-*/*"]}],
"helpdesk": [{"Effect": "Allow", "Action": ["iam:UpdateLoginProfile", "iam:CreateAccessKey", "iam:ListUsers"], "Resource": f"{A}:user/*"}],
"svc-backup": [{"Effect": "Allow", "Action": ["s3:GetObject", "s3:ListBucket", "kms:Decrypt"], "Resource": "*"}],
"app-role": [{"Effect": "Allow", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::lab-app-uploads/incoming/*"},
{"Effect": "Allow", "Action": "iam:PassRole", "Resource": f"{A}:role/app-worker"}],
"auditor": [{"Effect": "Allow", "Action": ["iam:Get*", "iam:List*", "cloudtrail:LookupEvents"], "Resource": "*"}],
}
for name, statements in principals.items():
review(name, statements)alice: 1 finding(s)
CRITICAL escalation: iam:CreatePolicyVersion on arn:aws:iam::123456789012:policy/alice-dev
bob: 5 finding(s)
HIGH Allow + NotAction ['iam:*']: everything else is allowed
MEDIUM data-wide: kms:Decrypt on *
MEDIUM data-wide: s3:GetObject on *
MEDIUM data-wide: secretsmanager:GetSecretValue on *
MEDIUM data-wide: ssm:GetParameter on *
ci-deploy: 1 finding(s)
CRITICAL escalation: iam:PassRole on * + lambda:CreateFunction (run code as any passable role via Lambda)
helpdesk: 2 finding(s)
CRITICAL escalation: iam:CreateAccessKey on arn:aws:iam::123456789012:user/*
CRITICAL escalation: iam:UpdateLoginProfile on arn:aws:iam::123456789012:user/*
svc-backup: 2 finding(s)
MEDIUM data-wide: kms:Decrypt on *
MEDIUM data-wide: s3:GetObject on *
app-role: 0 finding(s)
auditor: 0 finding(s)
What the findings say:
- alice may create a new version of
alice-dev, the policy attached to her. A new default version can contain anything, so her two harmless-looking permissions are a path to administrator. - bob has the
NotActionnear-admin grant from the evaluator lesson; the finder also lists everything that grant implies, including reading every secret and decrypting with every key. - ci-deploy can pass any role to a Lambda function it creates and then invoke it. Every role whose trust policy accepts
lambda.amazonaws.com(PassRole only works for roles that trust the receiving service) is now a role CI can run code as, and accounts usually have powerful ones. - helpdesk can reset the console password or create keys for every user, administrators included.
- svc-backup escalates nothing but reads every object and decrypts with every key the key policies allow it.
- app-role passes only one named role and has no compute action, so the finder is silent, and auditor is read-only. (
iam:Get*does includeiam:GetCredentialReportand policy contents: fine for an auditor, but still sensitive.)
How escalation is detected
The permissions above are the possibility; CloudTrail shows the use. Events worth an alert, especially from principals that never call them:
Event (eventName, source iam.amazonaws.com) |
What to check in requestParameters |
|---|---|
CreatePolicyVersion |
setAsDefault: true, a document containing "Action": "*" |
AttachUserPolicy, AttachRolePolicy |
policyArn ending in AdministratorAccess or IAMFullAccess |
PutUserPolicy, PutRolePolicy |
inline documents with wildcards |
CreateAccessKey, CreateLoginProfile, UpdateLoginProfile |
userName different from the caller's own name |
UpdateAssumeRolePolicy |
a new principal, especially from another account |
CreateFunction / RunInstances with a role |
the passed role (role, iamInstanceProfile) more powerful than the caller |
The rules themselves are written in Cloud Detections.
How it is fixed
- Remove self-edit: no principal should hold
iam:*Policy*write actions on policies attached to itself; give policy management to a pipeline role that is itself reviewed. - Scope
iam:PassRoleto exact role ARNs and add theiam:PassedToServicecondition (lambda.amazonaws.com), so a role can only be passed to the intended service. - Scope takeover actions to
${aws:username}for self-service ("Resource": "arn:aws:iam::123456789012:user/${aws:username}"), and handle resets for others through an identity provider, not IAM users. - Cap with boundaries and SCPs (the previous lesson), so a missed path still can't reach organisation-level damage.
- Re-run the finder (or a maintained tool: PMapper, Cloudsplaining, Prowler's IAM checks, the providers' own analysers) on every policy change in CI.
Pitfalls
- Looking only for
"Action": "*". The worst paths are made of narrow, legitimate-sounding permissions. - Reviewing principals one by one: escalation is often a chain (A can pass role B, B can assume C). Treat it as a graph, as attack-path analysis does for Active Directory.
- Ignoring conditions and SCPs in the other direction: a path blocked by an SCP is still worth fixing at the source, but rank it lower.
Practice
1. Scope ci-deploy's iam:PassRole to arn:aws:iam::123456789012:role/app-*. What does the finder report now, and is it enough?
The PassRole finding drops from CRITICAL to HIGH: the finder keeps CRITICAL for * and …/* resources, but app-* is still a wildcard that covers every future app- role. Better: list the exact function roles and add "Condition": {"StringEquals": {"iam:PassedToService": "lambda.amazonaws.com"}}, and make sure no app-* role is powerful.
2. Add {"Effect": "Allow", "Action": "iam:AttachRolePolicy", "Resource": "*"} to app-role. What does the finder say, and why does it matter for an application?
CRITICAL escalation: iam:AttachRolePolicy on *. If the application is compromised (for example through SSRF to the metadata service), the attacker can attach AdministratorAccess to app-role itself.
3. Which CloudTrail event would show helpdesk abusing its permission against an administrator?
UpdateLoginProfile or CreateAccessKey with requestParameters.userName of an administrator, where userIdentity is the helpdesk principal. The new key would then appear as a new accessKeyId in later events.
Test yourself
Why is iam:CreatePolicyVersion on a policy attached to yourself critical?
- It is read-only
- A new default version can contain any permission, so it is a path to administrator
- It deletes the policy
- It only works with MFA
ci-deploy has iam:PassRole on * plus lambda:CreateFunction and lambda:InvokeFunction. What can it effectively do?
- Only deploy code
- Run code with the permissions of any role it can pass, including the most powerful one
- Nothing without MFA
- Read Lambda logs
Which is the best fix for a broad iam:PassRole?
- Remove CloudTrail
- Exact role ARNs plus the iam:PassedToService condition
- Add MFA to the role
- Rename the roles
In the program, why does app-role produce no finding despite having iam:PassRole?
- It is a role, not a user
- It passes one named role and has no compute action to pass it to
- PassRole is not sensitive
- The finder skips roles