IAM Policies
Inkwell's developers need to upload book covers to the inkwell-covers bucket and read them back. Last month someone deleted two hundred covers by mistake, so this time deleting must be impossible. Groups say who; policies say what exactly they may do.
The rule
Deny wins; then allow; otherwise, no.
A policy is a JSON document of statements:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::inkwell-covers/*"
},
{
"Effect": "Deny",
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::inkwell-covers/*"
}
]
}- Effect:
AlloworDeny. - Action: API operations, written
service:Operation. Wildcards work:s3:*means every S3 action. - Resource: which things, named by ARN (Amazon Resource Name).
arn:aws:s3:::inkwell-coversis the bucket;arn:aws:s3:::inkwell-covers/*is every object inside it. - Condition (optional): extra tests, such as requiring MFA or a source IP range.
- Version is always
"2012-10-17", the current policy language, not today's date.
When a request arrives, AWS gathers every policy that applies and decides in a fixed order:
- Any explicit Deny that matches → denied, no matter what else says.
- Otherwise, any Allow that matches → allowed.
- Otherwise → denied. This default is called the implicit deny.
Policies attached to users, groups and roles are identity-based. Policies attached to a resource, such as an S3 bucket policy, are resource-based and name a Principal, the who. You will write one of those in the S3 section.
Policies also come in two packagings. Managed policies stand alone and can be attached to many identities: AWS publishes ready-made ones such as ReadOnlyAccess, and you can write your own. Inline policies are embedded in a single identity and are deleted with it. Prefer your own managed policies that grant only the actions the job needs: the principle of least privilege.