Sub topic 4
What a policy is and which policy types exist
This chapter assumes you know what a principal is and the difference between authentication and authorization. It also assumes you can read JSON and have an AWS account to try things in.
What a policy is
An IAM policy is a JSON document that states what is allowed or denied. A policy does nothing until it is attached to an identity or a resource, or applied to an account. When a request arrives, AWS gathers every policy that applies and decides whether to allow the request.
By default, all requests are denied. A request succeeds only when a policy allows it and no policy denies it. The next chapters cover the document format and the evaluation rules. Here the goal is to know which kinds of policy exist and what each one does.
The policy types
AWS groups policies into types by where they attach and what they do. Two types grant permissions. The others only limit them.
| Policy type | Attached to | What it does |
|---|---|---|
| Identity-based policy | A user, group, or role | Grants permissions to that identity |
| Resource-based policy | A resource, such as an S3 bucket | Grants permissions to a named principal on that resource |
| Permissions boundary | A user or role | Sets the maximum permissions the identity can have |
| Service control policy (SCP) | An AWS Organizations root, OU, or account | Sets the maximum permissions for accounts in that scope |
| Session policy | A temporary session | Limits the permissions of that session |
AWS also supports resource control policies and access control lists, but this tutorial focuses on the types above.
Grant versus limit
The most useful distinction is between policies that grant and policies that limit.
- Identity-based and resource-based policies grant permissions.
- Permissions boundaries, SCPs, and session policies grant nothing. They set a ceiling. An action must fit under every ceiling that applies, and it must also be granted by a grant policy.
An SCP that allows s3:* does not give anyone S3 access. It only says that accounts in that scope may be given S3 access by other policies.
A first example
This identity-based policy grants read access to one bucket's objects.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
}
]
}It has no Principal element, because the principal is whichever identity the policy is attached to. A resource-based policy must name a Principal, because it is attached to the resource and has to say who it applies to.
Common errors
- Assuming an SCP or boundary grants access. It never does.
- Forgetting that resource-based policies need a
Principal, while identity-based policies must not have one. - Expecting a policy to take effect without attaching it. An unattached policy affects nothing.
Exercise
An SCP on an account allows all S3 actions. A user in that account has no identity-based policy. Can the user list buckets? Why?
Show answer
No. An SCP only sets a maximum and grants nothing. The user has no policy granting s3:ListAllMyBuckets, so the request is denied by default.
Exercise
Which policy types grant permissions, and which only limit them?
Show answer
Identity-based and resource-based policies grant permissions. Permissions boundaries, SCPs, and session policies only limit them.