Skip to Content
Asterrr's Handbook
5 · Data protection

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.

VPCroute tableHTTPSobject API callsApp instanceS3 gatewayendpointBucket + policyCloudTrail dataevents
A gateway endpoint keeps S3 traffic off the internet. The bucket policy then pins access to that endpoint with aws:sourceVpce and can force TLS.
24 hours
Glacier Vault Lock in-progress window before CompleteVaultLock.
Root only
Who can enable MFA delete.

Controls and the condition that implements them

RequestBlock Public Access(account and bucket)Bucket policy TLS, VPCendpoint, org, requiredkeyKMS key policy(SSE-KMS only)Object versionsversioning, Object LockLifecycle transition,expire
Diagram of layers on a bucket
NeedControl
Only from one VPC endpointBucket policy aws:sourceVpce (or aws:SourceVpc)
Only from known addressesaws:SourceIp
HTTPS onlyDeny when aws:SecureTransport is false
MFA for sensitive actionsaws:MultiFactorAuthPresent, and aws:MultiFactorAuthAge to cap session age
Restrict what a VPC can reachVPC endpoint policy
Stop public exposureS3 Block Public Access, at account or bucket level
Audit object accessCloudTrail data events for GetObject, PutObject and similar. Off by default and billed
Find sensitive dataAmazon Macie scans buckets for PII and credentials
Transform on readS3 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) or aws:SourceVpc matches. 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:ResourceOrgID limits 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

ControlStopsWho can override
VersioningOverwrites and deletes destroying data (old versions and delete markers stay)Anyone with s3:DeleteObjectVersion
MFA deletePermanent version deletion and turning off versioning without an MFA codeOnly the root user can enable it, via CLI or API
Object Lock governance modeDeletes and overwrites of a locked version until the retain-until datePrincipals with s3:BypassGovernanceRetention who send the bypass header
Object Lock compliance modeSame, and the retention can't be shortenedNobody, including root
Legal holdDeletion with no end date, until the hold is removedPrincipals 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 DELETE still 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-days limits 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.
99%
Maximum reduction in KMS requests with S3 Bucket Keys.
24 hours
Glacier Vault Lock in-progress window before CompleteVaultLock.
Root only
Who can enable MFA delete.
April 2026
SSE-C blocked by default on new buckets.

Scenarios

Scenario
A broker-dealer must keep trade confirmations in Amazon S3 for 6 years in a form that no user, including the AWS account root user, can delete or overwrite. After 6 years, the objects must be removed automatically. Which combination meets these requirements?
Scenario
A research institute wants objects in a bucket to be readable only from its analysis VPC, through a specific S3 gateway endpoint, while its cloud platform team keeps console access for administration. What should the bucket policy contain?

Further reading

On this page