Sub topic 2
The policy types at a glance: grant versus limit
This chapter assumes you know what IAM users, groups, and roles are, can read JSON, and know what an API action and an ARN look like. It does not cover evaluation order yet. It sorts the policy types into two groups so that later chapters have a frame to hang on.
Two jobs a policy can do
Every IAM policy type does one of two jobs:
- Grant: it can give permission. Without at least one grant, a request is denied.
- Limit: it can only restrict permission. It never gives access by itself, however broad its Allow statements look.
Mixing these up causes many surprises. A policy that limits is a filter, and a filter on its own lets nothing through.
The policy types
| Policy type | Attached to | Job |
|---|---|---|
| Identity-based policy | An IAM user, group, or role | Grants |
| Resource-based policy | A resource, such as an S3 bucket | Grants |
| Permission boundary | An IAM user or role | Limits |
| Session policy | A temporary session, passed when it is created | Limits |
| Service control policy (SCP) | An AWS Organizations root, OU, or account | Limits |
| Resource control policy (RCP) | An AWS Organizations root, OU, or account | Limits |
| VPC endpoint policy | A VPC endpoint | Limits |
Identity-based policies answer "what can this principal do?" Resource-based policies answer "who can use this resource?" The two grant types look at the same request from opposite sides. The limiting types never name a new permission. They set the outer edge of what the grants can deliver.
The diagram is a mental model, not the exact evaluation order. The step-by-step flow comes in a later chapter.
A grant policy
An identity-based policy has no Principal element, because the principal is whoever the policy is attached to.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteReports",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}Attach this to a role and the role can read and write objects in that bucket. A resource-based policy would carry a Principal instead, to say who gets the access.
A limit policy
A permission boundary uses the same JSON syntax, and that is the trap. Suppose the role from above also has a policy allowing s3:* and ec2:DescribeInstances. You then set this boundary on the role:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BoundaryCeiling",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}The Allow here does not grant anything. The role's effective permissions are only the overlap of the two policies: s3:GetObject and s3:PutObject on that bucket's objects. The ec2:DescribeInstances permission falls outside the boundary and is removed. If the role had no identity policy at all, the boundary alone would give it nothing.
Common errors
- Expecting an SCP to give access. An SCP that allows
s3:*does not let anyone use S3. An identity or resource policy must still grant it. - Forgetting the limits you cannot see. A role may be denied by an SCP or boundary that was set by another team. The role's own policies will look fine.
- Treating resource-based policies as optional. Some services require them, and in cross-account cases they matter greatly. That topic has its own chapter.
Exercise
A role has an identity policy allowing sqs:SendMessage and sqs:ReceiveMessage. Its permission boundary allows sqs:SendMessage and sns:Publish. Its account's SCP allows all actions. Which of these actions can the role use, and why?
Show answer
Only sqs:SendMessage. The identity policy grants SQS send and receive. The boundary limits the role to send and sns:Publish, so sqs:ReceiveMessage is removed. sns:Publish is allowed by the boundary but never granted by an identity or resource policy, and the SCP grants nothing. So only the overlap of grant and limit, sqs:SendMessage, remains.