Bucket Policies and Public Access
Inkwell wants shoppers' browsers to load cover images straight from S3. The same bucket also holds a folder of order invoices with customer addresses. One careless setting could expose both. S3 gives you two tools that must be understood together: the bucket policy that grants access, and the Block Public Access switch that can veto it.
The rule
The bucket policy grants; Block Public Access vetoes anything public.
A bucket policy is a resource-based policy: it is attached to the bucket, not to a user, so it must name the Principal, meaning who it applies to. Everything else works like the IAM policies you already know: Effect, Action, Resource, deny wins.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::inkwell-covers/covers/*"
}
]
}"Principal": "*" means anyone, including anonymous visitors. The resource is only the covers/ prefix, so invoices remain private through the implicit deny.
Block Public Access is a set of four settings, available on each bucket and for the whole account, that stop public access through bucket policies and ACLs (older per-object permission lists). New buckets have it switched on, and new buckets also have ACLs disabled. While it is on, the policy above is refused. You must turn it off on purpose, which is exactly the point: public exposure should never happen by accident.
A bucket policy is also how you share with another AWS account: name that account or one of its roles as the Principal. Access within one account is allowed if either the identity policy or the bucket policy allows it; across accounts, both sides must allow it.