1.Identity-Based vs Resource-Based S3 Access
An identity-based policy is attached to an IAM user/role and says what that identity can do. A bucket policy is attached to the bucket itself (resource-based) and says who can do what to it — including granting access to a completely different AWS account. Both are evaluated together; access requires no explicit deny and at least one explicit allow.
Key features
- Identity-based policy: attached to an IAM user/role, portable across resources that policy references
- Bucket policy: resource-based, attached to the bucket itself, can grant access to principals in other AWS accounts directly
- Bucket policies are the standard way to grant cross-account access without creating a role in the granting account
- Access requires no explicit deny anywhere AND at least one explicit allow from either policy type
- Bucket policies are limited to 20 KB in size
Identity-based vs bucket (resource-based) policy
- Identity-based policy
- Attached to an IAM user/role
- Says what that identity can attempt
- Cannot alone grant cross-account access
- Bucket policy
- Attached to the bucket itself
- Can name a principal in another account directly
- The standard way to grant cross-account access
Command
{ "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::222233334444:root" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-bucket/*" }Identity-based policies are attached to IAM users/roles; bucket policies are attached to the bucket and are the standard way to grant cross-account access directly. Both are evaluated together — access needs no explicit deny and at least one explicit allow.