Skip to main content

02. Amazon S3 Security

Amazon S3 (Simple Storage Service) provides multiple layers of security and access control to protect your data.
Security in S3 can be broadly classified into:

  1. User-Based Security (IAM Policies)
  2. Resource-Based Security (Bucket Policies, ACLs)
  3. Encryption
  4. Public Access Settings

๐Ÿ‘ค 01. User-Based Securityโ€‹

ComponentDescription
IAM PoliciesDefine which API calls are allowed for specific IAM users, groups, or roles.
Attached ToIAM users, groups, or roles.
Use CaseAllow/deny users within the same AWS account to access S3.

Example:

  • Grant an IAM user permission to s3:ListBucket and s3:GetObject.

๐Ÿงฑ 02. Resource-Based Securityโ€‹

๐Ÿ”น a. Bucket Policiesโ€‹

  • JSON-based policies applied directly to S3 buckets.
  • Allow cross-account access.
  • Define permissions at the bucket or object level.
ElementDescription
EffectAllow / Deny
PrincipalThe AWS account, user, or role the policy applies to
ActionAPI actions (s3:GetObject, s3:PutObject, etc.)
ResourceARN of bucket or objects

๐Ÿงพ Example: Public Read Bucket Policyโ€‹

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::examplebucket/*"]
}
]
}

โœ… Use Cases:

  • Grant public access to bucket.
  • Force encryption on uploaded objects.
  • Allow cross-account access.

๐Ÿ”น b. Access Control Lists (ACLs)โ€‹

TypePurposeNotes
Object ACLFine-grained access to individual objectsCan be disabled
Bucket ACLAccess control at the bucket levelLess common and can be disabled

๐Ÿ” Access Evaluation Logicโ€‹

An IAM principal can access an S3 object if:

(IAM permissions allow it) OR (Resource policy allows it)
AND
(No explicit DENY exists)

๐Ÿ—๏ธ Encryptionโ€‹

Encrypt data stored in S3 using encryption keys.

TypeDescription
SSE-S3Server-side encryption with S3-managed keys
SSE-KMSServer-side encryption with AWS KMS-managed keys
SSE-CServer-side encryption with customer-provided keys
Client-Side EncryptionData encrypted by client before upload

๐Ÿšซ Block Public Access Settingsโ€‹

AWS provides Block Public Access at:

  • Bucket level
  • Account level

โœ… Purpose:

  • Prevent accidental data exposure.
  • Overrides public Bucket Policies or ACLs.

Even if a bucket policy allows public access,
if Block Public Access is enabled โ€” bucket stays private.


๐Ÿ”„ Access Scenariosโ€‹

ScenarioMechanism UsedDescription
IAM user in same accountIAM PolicyUser granted permissions via IAM console
EC2 instance accessIAM RoleRole with S3 permissions attached to instance
Public websiteBucket PolicyAllow Principal: * with s3:GetObject
Cross-account userBucket PolicyAllow another AWS accountโ€™s IAM principal

๐Ÿง  Summaryโ€‹

Security TypeControl LocationCommon Use Case
IAM PolicyUser / RoleInternal account access
Bucket PolicyS3 BucketCross-account or public access
ACLObject / BucketLegacy, fine-grained control
EncryptionS3 or ClientData protection at rest
Block Public AccessAccount / BucketPrevent data leaks

๐Ÿ“Key Takeaways:

  • Prefer Bucket Policies over ACLs.
  • Use Block Public Access for safety.
  • Combine IAM policies + resource policies for flexible access control.
  • Enable encryption for sensitive data.