How the attack works
An inline policy is a policy document embedded in one IAM user, group or role. PutUserPolicy, PutGroupPolicy and PutRolePolicy add the document or replace an existing one with the same name. A principal allowed to call one of them on itself, on a group it belongs to, or on a role it can assume can write any statement into that identity, including every action on every resource.
The result is the same as attaching an administrator policy, but the trace is different. An inline policy has no ARN and is not listed among the managed policies attached to the identity, so monitoring that watches the attach calls or specific policy ARNs does not see it. CloudTrail records the call under iam.amazonaws.com with the caller in userIdentity, the target in requestParameters.userName, groupName or roleName, and the policy in requestParameters.policyName and policyDocument.
What an attacker needs
- Credentials for a principal allowed to call iam:PutUserPolicy, PutGroupPolicy or PutRolePolicy on a target it controls or can use.
- No permissions boundary or service control policy that caps the target's effective permissions.
Impact
The permissions written into the document, up to administrator access, on an identity the attacker controls. A policy placed on a quiet user or role also serves as persistence, because it stays in place after the attacker's original credentials are rotated.
Detection rules
Inline Policy Added to an IAM Role
Detects PutRolePolicy calls, which add an inline policy document to an IAM role or replace the document that exists under the same policy name. The inline policy becomes part of the role's permissions policy. The rule does not judge the document: read requestParameters.policyDocument, and check whether the caller (userIdentity.arn) can assume the role named in requestParameters.roleName. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Inline Policy Added to an IAM Role
id: 82db5e36-7bac-4246-bacb-e9ba566d3b4d
status: experimental
description: >-
Detects PutRolePolicy calls, which add an inline policy document to an IAM
role or replace the document that exists under the same policy name. The
inline policy becomes part of the role's permissions policy. The rule does
not judge the document: read requestParameters.policyDocument, and check
whether the caller (userIdentity.arn) can assume the role named in
requestParameters.roleName.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutRolePolicy.html
- https://docs.aws.amazon.com/securityhub/latest/userguide/cloudwatch-controls.html
author: Forestall
date: 2026-11-16
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1098.003
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: iam.amazonaws.com
eventName: PutRolePolicy
condition: selection
falsepositives:
- Infrastructure-as-code tools and deployment pipelines, which commonly write inline policies into the roles they create. The rule is useful only after those deployment roles are allow-listed, or after it is limited to roles with privileged access.
level: low
False positives
- Infrastructure-as-code tools and deployment pipelines, which commonly write inline policies into the roles they create. The rule is useful only after those deployment roles are allow-listed, or after it is limited to roles with privileged access.
Inline Policy Added to an IAM User or Group
Detects PutUserPolicy and PutGroupPolicy calls, which add an inline policy document to an IAM user or group or replace the document that exists under the same policy name. The rule does not judge the document: read requestParameters.policyDocument, and compare the caller (userIdentity.arn) with requestParameters.userName or groupName. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Inline Policy Added to an IAM User or Group
id: c5c6c27a-7776-4af4-977d-d958cb3f6422
status: experimental
description: >-
Detects PutUserPolicy and PutGroupPolicy calls, which add an inline policy
document to an IAM user or group or replace the document that exists under
the same policy name. The rule does not judge the document: read
requestParameters.policyDocument, and compare the caller (userIdentity.arn)
with requestParameters.userName or groupName.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutUserPolicy.html
- https://docs.aws.amazon.com/IAM/latest/APIReference/API_PutGroupPolicy.html
- https://docs.aws.amazon.com/securityhub/latest/userguide/cloudwatch-controls.html
author: Forestall
date: 2026-11-16
tags:
- attack.persistence
- attack.privilege-escalation
- attack.t1098.003
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: iam.amazonaws.com
eventName:
- PutUserPolicy
- PutGroupPolicy
condition: selection
falsepositives:
- Identity administrators and infrastructure-as-code pipelines that manage IAM users and groups with inline policies; allow-list those callers and review every other one.
level: medium
False positives
- Identity administrators and infrastructure-as-code pipelines that manage IAM users and groups with inline policies; allow-list those callers and review every other one.
Triage
- Compare the caller (userIdentity.arn) with the target named in requestParameters. An identity writing a policy into itself, its own group or a role it can assume is the strongest signal.
- Read requestParameters.policyDocument. Wildcard actions, IAM write actions, sts:AssumeRole and iam:PassRole on wildcard resources are the statements that matter.
- Check errorCode. A failed attempt shows that someone tested the permission.
- Check whether the caller is a deployment pipeline or an infrastructure-as-code role that normally creates this role and policy, and review what the target identity did after the change.
Response
Once the attack is confirmed:
- Delete the inline policy from the user, group or role named in the event. Permissions are evaluated on every request, so sessions of that identity that already exist lose the added rights as well.
- Contain the identity that received the policy and the principal that wrote it. Deactivate their access keys, and revoke the active sessions of roles, until you know who was using them.
- Find and remove what was created while the policy was in place, such as users, access keys, login profiles, roles, trust policy changes and identity providers. Deleting the policy does not undo any of these.
- Search CloudTrail for other inline policies the same caller wrote in the period, and for the same policy name on other identities.
- Take the permission to write inline policies away from the caller before its credentials go back into use, and confirm in CloudTrail that no further call follows.
Mitigation
- Restrict iam:PutUserPolicy, PutGroupPolicy and PutRolePolicy to IAM administrators, and deny them with a service control policy outside approved roles.
- Set permissions boundaries on the users and roles that delegated administrators manage, so that an inline policy cannot grant more than the boundary allows.
- Remove wildcard IAM actions (
iam:*) from customer managed policies so that ordinary principals cannot write policies. - Include inline policies in every permission review. They are part of the identity and do not show up in a list of attached managed policies.
Frequently asked questions
Do the rules tell me whether the inline policy grants administrator rights?
No. They match the three calls whatever the document contains, because the document is free text and its JSON can be written in many ways. Read requestParameters.policyDocument in the event to see what was granted. A document that allows every action on every resource is equal to the AdministratorAccess managed policy.
Why do inline policies need their own rules when managed policy attachments are already monitored?
They are written with different API calls. A managed policy is attached with AttachUserPolicy, AttachGroupPolicy or AttachRolePolicy and is identified by its ARN. An inline policy is embedded with PutUserPolicy, PutGroupPolicy or PutRolePolicy, has no ARN and is not among the attached managed policies of the identity. A rule on the attach calls or on a policy ARN therefore does not match it.
Why is the rule for roles separate and set to a lower level?
Infrastructure-as-code tools and deployment pipelines commonly write inline policies into the roles they create, so PutRolePolicy is frequent in accounts that are built this way. Keeping it in its own rule lets you allow-list the deployment roles there, while an inline policy written into a user or a group stays a rarer event with a higher level.
Does replacing an existing inline policy look different from adding a new one?
No. The same call adds a new document or updates the document that already exists under that policy name, and the event looks the same in both cases. An attacker can therefore widen a policy that has been in place for a long time without creating anything new, and only the document in the event shows the change.
References
- MITRE ATT&CK T1098.003: Additional Cloud Roles
- IAM API Reference: PutUserPolicy
- IAM API Reference: PutGroupPolicy
- IAM API Reference: PutRolePolicy
- Managed policies and inline policies
- Security Hub CSPM [CloudWatch.4]: metric filter for IAM policy changes
- Logging IAM and AWS STS API calls with AWS CloudTrail
- Revoke IAM role temporary security credentials