Protecting S3 buckets and data
Bucket policy controls, VPC endpoints, TLS enforcement, MFA conditions, versioning, Object Lock, lifecycle retention and data event logging.
Exam tasks: 5.2.2 (integrity: Object Lock, Glacier Vault Lock, versioning), 5.2.3 (lifecycle and retention)
The decision: who can reach this bucket and from where, and what stops anyone, an administrator included, from changing or deleting objects before the retention period ends?
S3 sits outside your VPC, so security groups and network ACLs cannot control it. Access is shaped with bucket policies, VPC endpoints and conditions.
Controls and the condition that implements them
| Need | Control |
|---|---|
| Only from one VPC endpoint | Bucket policy aws:sourceVpce (or aws:SourceVpc) |
| Only from known addresses | aws:SourceIp |
| HTTPS only | Deny when aws:SecureTransport is false |
| MFA for sensitive actions | aws:MultiFactorAuthPresent, and aws:MultiFactorAuthAge to cap session age |
| Restrict what a VPC can reach | VPC endpoint policy |
| Stop public exposure | S3 Block Public Access, at account or bucket level |
| Audit object access | CloudTrail data events for GetObject, PutObject and similar. Off by default and billed |
| Find sensitive data | Amazon Macie scans buckets for PII and credentials |
| Transform on read | S3 Object Lambda, closed to new customers (see Sensitive data) |
- A gateway endpoint is Regional and works by adding a route table entry. Its default policy allows any principal in the VPC to reach any S3 resource. Tighten it with an endpoint policy.
- Bucket-level API calls are logged as management events. Object-level calls need data events.
Who can reach the bucket
- Block Public Access: four settings (block new public ACLs, ignore public ACLs, block new public policies,
restrict public buckets), at account and bucket level. On for new buckets by default. Protect the account-level
setting with an SCP that denies
s3:PutAccountPublicAccessBlock. - Object Ownership = bucket owner enforced disables ACLs, so the bucket owner owns every object and only policies grant access. This is the default for new buckets. Use it unless a legacy workload needs ACLs.
- VPC endpoint restriction in the bucket policy: deny unless
aws:SourceVpce(a specific gateway or interface endpoint) oraws:SourceVpcmatches. Remember this also blocks the console and any admin outside the VPC, so add an exception for an admin role if needed. - The gateway endpoint policy controls which buckets instances in the VPC can reach.
aws:ResourceOrgIDlimits them to buckets owned by your organization, a key data perimeter control. See Hybrid and private access. - IAM Access Analyzer flags buckets shared outside your zone of trust.
Exam trap
Security groups and NACLs cannot protect an S3 bucket. Use bucket policy conditions and VPC endpoint policies. Object Lock needs versioning, and it does not stop a new version from being written.
Integrity: versions, MFA delete and locks
| Control | Stops | Who can override |
|---|---|---|
| Versioning | Overwrites and deletes destroying data (old versions and delete markers stay) | Anyone with s3:DeleteObjectVersion |
| MFA delete | Permanent version deletion and turning off versioning without an MFA code | Only the root user can enable it, via CLI or API |
| Object Lock governance mode | Deletes and overwrites of a locked version until the retain-until date | Principals with s3:BypassGovernanceRetention who send the bypass header |
| Object Lock compliance mode | Same, and the retention can't be shortened | Nobody, including root |
| Legal hold | Deletion with no end date, until the hold is removed | Principals with s3:PutObjectLegalHold |
- Object Lock requires versioning and can be turned on for existing buckets. A default retention (mode and period) applies to every new version.
- Locks protect versions. A plain
DELETEstill adds a delete marker, but the locked version underneath survives. - A legal hold and a retention period are independent: a version is protected while either applies.
- Test with governance mode first. A compliance-mode mistake (retaining terabytes for 10 years) can only be undone by closing the account.
- Per-version retention overrides the bucket default. You can extend compliance retention but not shorten it. Variable retention (event hold plus duration) fits cases where the end date is unknown.
s3:object-lock-remaining-retention-dayslimits the retention a principal may set in a bucket policy.- Object Lock is assessed for SEC 17a-4, CFTC and FINRA.
- The same WORM idea exists for Backup recovery points and Glacier vaults. See Immutable storage and Vault Lock.
Exam signal
"Write once, read many", "SEC 17a-4", or "not even the root user can delete it" means Object Lock compliance mode. "Only a small group of approvers may shorten retention" means governance mode. "Keep it until litigation ends, with no known date" means legal hold.
Lifecycle and retention
- Transitions move versions to cheaper classes (Standard-IA, Glacier Instant Retrieval, Glacier Flexible Retrieval, Glacier Deep Archive). Expiration deletes current versions or, with noncurrent rules, old versions after a number of days.
- Retention usually needs both: Object Lock stops deletion before the period ends, and a lifecycle expiration removes the data after it ends. Lifecycle can't delete a version that is still locked.
- Add rules to abort incomplete multipart uploads and remove expired delete markers.
- For "delete personal data after 30 days", lifecycle expiration is evidence-friendly; a Lambda cleanup job isn't.
Scenarios
Compliance mode blocks deletion by everyone, root included, and lifecycle expiration removes versions once the retention ends. MFA delete can be disabled by the root user. SCPs don't apply to the management account's root user and can be changed, so governance mode stays bypassable. A legal hold has no end date and relies on custom code that someone could alter.
A deny on any endpoint other than the named one, with a principal exception, restricts reads while keeping admin access. Private IP addresses aren't visible through a gateway endpoint, so aws:SourceIp with a VPC CIDR doesn't work. A TLS deny doesn't restrict the network path. An Allow alone doesn't stop other principals who already have IAM permissions from reading from elsewhere.
Related
- S3 encryption options
- Immutable storage and Vault Lock
- Sensitive data and masking
- Hybrid and private access: VPN options