Sub topic 5
Identity-based policies
This chapter assumes you know what IAM users, groups, and roles are, can read JSON, and recognize an ARN and an API action such as s3:GetObject. It covers identity-based policies: what they attach to, how they grant permissions, and the errors people hit most often. Earlier chapters introduced the default-deny rule and the policy document structure. Later chapters cover resource-based policies and boundaries in detail.
What an identity-based policy is
An identity-based policy is a JSON permissions document that you attach to an IAM identity. The identity can be a user, a group, or a role. The policy says what that identity may do, on which resources, and under which conditions.
Identity-based policies are one of the two kinds of policy that can grant permissions. The other kind is the resource-based policy. Boundaries, SCPs, and session policies only limit what other policies grant. They never grant anything on their own.
Because the policy is attached to the principal, the principal is implied. It is whoever the policy is attached to. For that reason an identity-based policy has no Principal element. If you add one, IAM rejects the policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteReports",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}Read this policy as a sentence: the identity it is attached to may call GetObject and PutObject on any object in example-reports-bucket. Two details matter here:
- The
ResourceARN ends in/*, which matches objects. It does not match the bucket itself. - The policy does not allow
s3:ListBucket. That action applies to the bucket ARN (arn:aws:s3:::example-reports-bucket), so a user with only this policy can read a known key but cannot list the bucket.
Kinds of identity-based policies
You can create identity-based policies in three forms.
| Form | Who manages it | Reusable | Typical use |
|---|---|---|---|
| AWS managed policy | AWS | Yes, attach to many identities | Broad job functions such as `ReadOnlyAccess` |
| Customer managed policy | You | Yes, attach to many identities | Least-privilege policies you version and review |
| Inline policy | You | No, embedded in one identity | A strict one-to-one link between policy and identity |
Customer managed policies keep up to five versions, and you can roll back to an earlier one. Inline policies are deleted when the identity is deleted. In most cases a customer managed policy is the better choice, because you can see where it is used and change it in one place.
What the policy attaches to
Where you attach a policy decides who receives the permissions.
- User: the policy applies to that one user.
- Group: the policy applies to every user in the group. A group is not a principal. You cannot name a group in a
Principalelement or sign in as a group. It only collects users so that you can attach policies once. - Role: the policy applies to anyone who assumes the role, for the duration of the session.
A user's effective identity-based permissions are the union of the policies attached to the user and the policies on every group the user belongs to. Each policy is evaluated for the request, and an explicit Deny in any of them wins.
The diagram below shows how policies from different attachment points combine for one user.
How a request is matched against the policy
For each statement, IAM checks four things, and all must match for the statement to apply to the request.
- The
Action(orNotAction) matches the API action being called. - The
Resource(orNotResource) matches the ARN the action targets. - Every
Conditionblock evaluates to true for the request context. - The statement's
Effectthen decides whether it contributes an allow or a deny.
A statement that does not match contributes nothing. It is not a deny. This is why a missing permission shows up as an implicit deny and not as an error in the policy.
Wildcards
* matches any run of characters and ? matches one character, in both Action and Resource. "s3:Get*" covers s3:GetObject, s3:GetBucketPolicy, and every other action that starts with s3:Get. Wildcards are convenient but widen access when the service adds new actions, so prefer explicit action lists for sensitive services.
Actions and resource types must line up
Each action works on specific resource types, and the Resource element must name an ARN of that type. Some actions do not support resource-level permissions and require "Resource": "*". An example is ec2:DescribeInstances. The Service Authorization Reference lists, for each action, which resource types and condition keys it supports. If a policy with a specific ARN does not work, check that the action supports that ARN type.
Explicit deny inside identity policies
You can write Deny statements in identity policies too. An explicit deny always beats an allow, no matter which policy contains the allow. A common pattern is to attach a guard statement to a group.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInsecureTransport",
"Effect": "Deny",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::example-reports-bucket",
"arn:aws:s3:::example-reports-bucket/*"
],
"Condition": { "Bool": { "aws:SecureTransport": "false" } }
}
]
}Any request to that bucket made without TLS is denied, even if another policy on the same user allows s3:*. The same statement also works in a bucket policy, where it applies to all principals.
Identity policies and the same-account rule
For a request within one account, an allow in the identity policy is enough, as long as nothing denies it and no limiting policy blocks it. The resource's own policy does not have to mention the principal.
For a cross-account request the identity policy is only half of the answer. The principal's account must allow the action in an identity policy, and the account that owns the resource must also allow it, usually in a resource-based policy. If either side is missing, the result is an implicit deny. The resource-based policy chapter covers this in detail.
Common errors
- Adding a
Principalelement. An identity policy does not take one. IAM returns a validation error when you save it. - Wrong ARN for the action.
s3:ListBucketneeds the bucket ARN, whiles3:GetObjectneeds the object ARN with/*. Using onlybucket/*for both leaves list calls denied. - Relying on a group as a principal. Groups cannot be named in resource policies. Name the users or roles instead.
- Expecting the policy to override a boundary or SCP. An identity policy allow does nothing if a permission boundary, SCP, or session policy does not also allow the action.
- Forgetting an explicit deny elsewhere. A
Denyin another attached policy, such as a group policy, cancels your allow. List every attached policy when you debug. - Using
NotActionwithAllowby accident."Effect": "Allow"withNotActionallows everything except the listed actions, which is often far wider than intended. - Editing a shared managed policy. A change to a customer managed policy takes effect for every identity it is attached to.
Checking what an identity policy allows
You can test the policies on an identity without making real calls. The IAM policy simulator evaluates the identity policies, and a permission boundary if one is set, against actions and resources you choose.
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/ReportWriter \
--action-names s3:GetObject s3:PutObject \
--resource-arns arn:aws:s3:::example-reports-bucket/2026/summary.csvFor each action the output gives an EvalDecision of allowed, explicitDeny, or implicitDeny. It also lists MatchedStatements, which tells you which policy produced the decision. An implicitDeny with no matched statements means no policy allowed the action. An explicitDeny with a matched statement points to the exact policy to change. The simulator does not model every case. For example, it does not evaluate resource-based policies unless you supply them, so treat it as a check on the identity side.
Exercise
A user belongs to a group whose policy allows s3:GetObject and s3:PutObject on arn:aws:s3:::example-reports-bucket/*. The user's own inline policy contains only a statement that denies s3:PutObject on the same resource. The user then calls s3:GetObject and s3:PutObject on example-reports-bucket/2026/summary.csv, in the same account, with no boundary or SCP. What is the result of each call, and why?
Show answer
s3:GetObject is allowed. The group policy allows it and nothing denies it. s3:PutObject is denied. The inline policy contains an explicit deny that matches the action and resource, and an explicit deny overrides the allow in the group policy. The user's effective identity permissions are the union of both policies, but a matching deny always wins.
Exercise
A role has an identity policy that allows only s3:GetObject on arn:aws:s3:::example-reports-bucket/*. A developer runs aws s3 ls s3://example-reports-bucket with that role and gets AccessDenied. Why does it fail, and what is the smallest change that fixes it?
Show answer
Listing a bucket calls s3:ListBucket, which is not in the policy, so it is an implicit deny. Also, s3:ListBucket applies to the bucket ARN, not to object ARNs. The fix is to add a statement that allows s3:ListBucket on arn:aws:s3:::example-reports-bucket, without the /*.