S3 is one of the most widely used AWS services, and also one of those that show up most often in data leaks. The problem is almost always the configuration rather than the service: a bucket marked as public, an overly permissive policy, or inherited ACLs that nobody reviewed. And since S3 stores data, the impact of a mistake here tends to be high.
Configuring buckets defensively starts from a simple principle: data only becomes accessible when someone has decided so, explicitly and deliberately. To get there, public access is blocked by default, policies are written narrowly, encryption and secure transport become mandatory, and every access remains traceable.
Block Public Access and policies
Keep Block Public Access turned on at the account and bucket level, except for justified exceptions. It works as a master lock: even if a policy or ACL tries to make something public, the block wins. For content that really has to be public, such as the assets of a website, the current standard is to serve it through CloudFront with a restricted origin, without opening the bucket.
Prefer bucket policies over ACLs. ACLs are an old, confusing model, and the ideal is to disable them by setting Object Ownership to Bucket owner enforced. From then on, access is managed only through policies and IAM. Write specific policies that restrict principal, action, and resource, and avoid broad wildcards. In the example, the condition requires an encrypted connection:
"Condition": { "Bool": { "aws:SecureTransport": "false" }}Cross-account access, VPC endpoints, and presigned URLs
Even with public access blocked, not every bucket needs to be reachable from the internet. If the data should only be read by workloads inside your network, restrict the policy to a specific VPC endpoint, and any request coming from outside that path will be denied. This adds a network control on top of the identity control, and a credential that leaks outside the environment loses much of its value. The condition looks like this:
"Condition": { "StringEquals": { "aws:SourceVpce": "vpce-0abc123example" }}When access has to cross accounts, grant the minimum. Instead of opening the bucket to an entire account, use a specific role with permission only on the prefixes it needs. In environments with AWS Organizations, the aws:PrincipalOrgID condition refuses any principal from outside the organization, which catches the kind of policy mistake that would open overly broad access by accident.
Presigned URLs give temporary access to an object without making the bucket public, which works well for one-off downloads. The catch is the validity period. A link with a long expiration becomes a de facto credential: it keeps working long after it is no longer needed and can be passed on to anyone. Generate the URLs with the shortest lifetime the use case allows, and avoid putting them on pages or in logs with long retention.
Encryption, versioning, and SecureTransport
Enable encryption at rest. Default encryption already covers all new objects, and for sensitive data you should use a dedicated KMS key, which lets you control who can decrypt. In parallel, a policy with the SecureTransport condition denies any access that does not use HTTPS.
Versioning and lifecycle
Versioning keeps previous versions recoverable, which protects against accidental or malicious deletion and overwrites. The cost comes along with it: without lifecycle rules, versioning keeps accumulating versions and spending grows indefinitely. With the rules in place, you move old versions to cheaper storage, expire what is no longer needed, and set how long the history is retained before it is discarded.
Resilience: Object Lock, MFA delete, and replication
On its own, versioning is a partial protection, because anyone with permission to delete versions can erase the history. Object Lock closes that gap: in compliance mode, not even the root account can remove an object before the retention period ends. It is the foundation for backups and records that must withstand malicious deletion, including when someone uses a compromised credential to try to erase the data. You can set the default retention through the CLI, as in:
aws s3api put-object-lock-configuration \ --bucket my-bucket \ --object-lock-configuration \ '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"COMPLIANCE","Days":30}}}'For critical data, consider replicating to a bucket in another account. That leaves a copy out of reach of whoever administers the production environment. MFA delete adds a barrier to deleting versions and to disabling versioning. None of these controls replaces a tested backup routine, but together they lower the chance of losing data irreversibly in an incident.
Logging and detection
Enable server access logging to know who read or wrote objects, and consider CloudTrail data events on sensitive buckets. Without that record, unauthorized access to the data can go by without anyone noticing. Also use Access Analyzer for S3, which flags buckets with unintended external access.
Practical checklist
- Keep Block Public Access on at the account and bucket level
- Disable ACLs with Bucket owner enforced
- Write specific bucket policies without broad wildcards
- Serve public content through CloudFront with a restricted origin
- Require HTTPS with the SecureTransport condition
- Enable encryption at rest, and KMS for sensitive data
- Turn on versioning and lifecycle rules
- Enable access logging and data events on critical buckets
- Run Access Analyzer for S3 and review what it flags
- Review buckets with external access from time to time
- Restrict access to the organization with aws:PrincipalOrgID where applicable
- Limit internal buckets to VPC endpoint traffic with aws:SourceVpce
- Set short expiration times for presigned URLs
- Evaluate Object Lock for data that requires immutability
- Keep a replicated copy in a separate account for critical data
Best practices
- Treat public access as an explicit exception, never as the default
- Prefer policies and IAM over ACLs for access control
- Use a dedicated KMS key for sensitive data and control who can use it
- Combine versioning with lifecycle rules to get protection without letting costs grow without limit
- Keep reads and writes on sensitive buckets traceable
- Centralize exposure reviews with Access Analyzer
- Restrict internal buckets to specific networks and accounts
- Combine Object Lock and replication to withstand malicious deletion
Common mistakes
- Public bucket to serve a website
- It can expose all the content and makes control harder. The right pattern is CloudFront with a restricted origin.
- Inherited, forgotten ACLs
- They grant access without anyone noticing, outside of policy control.
- Policy with a broad wildcard in the principal
- It grants access far beyond what is needed and creates a risk of unintended exposure.
- No SecureTransport condition
- Data can travel without HTTPS and is open to interception.
- No access logging
- Unauthorized data access goes unnoticed and the investigation is left without evidence.
- Presigned URLs that stay valid for too long
- The link stays valid far longer than needed and can be passed around or leak.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.