Certopolis

AWS Certified Solutions Architect – Associate

S3 access control: bucket policies, Block Public Access, ACLs

New S3 buckets have ACLs disabled and no public access, so access is decided by policies: IAM policies and bucket policies. Block Public Access overrides any policy or ACL that would make a bucket or object public. A presigned URL gives time-limited access using the permissions of whoever created it.

Block Public Access

There are four settings. BlockPublicAcls rejects requests that set a public ACL, including PutObject with a public ACL. IgnorePublicAcls makes S3 ignore public ACLs on the bucket and its objects. BlockPublicPolicy rejects PutBucketPolicy when the new policy allows public access. RestrictPublicBuckets limits a bucket with a public policy to AWS service principals and users in the bucket owner's account, which also blocks cross-account access.

The settings can be applied at the organization, account, bucket and access point level, and S3 applies the most restrictive combination. AWS recommends BlockPublicPolicy at the account level, because a user who can edit a bucket policy could otherwise turn the bucket's own setting off.

None of the settings change existing policies or ACLs. Turning a setting off makes a bucket with a public policy or ACL public again.

An ACL is public if it grants anything to the AllUsers or AuthenticatedUsers groups. A bucket policy is non-public only if it grants access to fixed values, such as specific principals or accounts, aws:SourceVpce, or a fixed aws:SourceIp range. A policy that names a partner account is not public.

Object Ownership and ACLs

Object Ownership has three settings. Bucket owner enforced is the default for new buckets: ACLs are disabled, the bucket owner owns every object, and only policies decide access. Bucket owner preferred keeps ACLs, and the bucket owner owns new objects uploaded with the bucket-owner-full-control canned ACL. Object writer keeps ACLs, and the uploading account owns the object.

With ACLs disabled, the bucket accepts only PUT requests that set no ACL or set bucket-owner-full-control. Any other ACL fails with HTTP 400 and the error code AccessControlListNotSupported. Other accounts get access through the bucket policy. AWS recommends keeping ACLs disabled unless you must control access per object.

Presigned URLs

A presigned URL lets someone without AWS credentials download or upload a specific object until it expires. It uses the credentials of the IAM principal that created it. Anyone with credentials can create one, but it only works if the creator has permission for the operation, such as s3:PutObject for an upload.

Expiry is capped. The S3 console allows 1 minute to 12 hours. The CLI and SDKs allow up to 7 days, which requires IAM user credentials and Signature Version 4. A URL made with temporary credentials expires when those credentials expire. For an EC2 instance role that is typically about 6 hours, whatever expiry you asked for.

S3 checks the expiry when the request starts, and the URL can be used more than once until then. A bucket policy can use s3:signatureAge to reject URLs whose signature is older than a limit you set.

Where the exam catches people

  • Believing Block Public Access removes public grants that already exist: it overrides them without changing them, so turning it off makes them public again.
  • Believing BlockPublicAcls rejects every upload that carries an ACL: it rejects public ACLs, and it is Bucket owner enforced that rejects other ACLs.
  • Believing a presigned URL lasts as long as you ask: it cannot outlive the credentials that signed it.
  • Believing a read-only user can create a working upload URL: the creator needs permission for the operation the URL performs.
  • Believing a bucket policy that grants a named partner account is public: grants to fixed principals are non-public.

Written from Amazon Web Services's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A company lets each team edit the bucket policies of its own Amazon S3 buckets in one AWS account, and some policies grant access to partner accounts, which must keep working. The security team must make sure that no one who can edit a bucket policy can make a bucket public, even with full permissions on that bucket. Two buckets already have public statements that must stop granting public access. Which combination of steps should a solutions architect take to meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: D,E is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    BlockPublicPolicy causes Amazon S3 "to reject calls to PutBucketPolicy if the specified bucket policy allows public access", and the page is specific about where it must be set: "To use this setting effectively, we recommend that you apply it at the account level." "If this setting is enabled for the entire account, rather than for a specific bucket, Amazon S3 blocks public policies even if a user alters the bucket policy to disable this setting." Existing policies are untouched - "Enabling this setting doesn't affect existing access point or bucket policies" - so the public statements have to be removed, which also keeps partner access, since a policy granting fixed accounts is not public.

    Written from docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html

  2. A partner account uploads to a bucket whose Object Ownership is Bucket owner enforced, with all four account-level Block Public Access settings on and a bucket policy granting the partner s3:PutObject. The partner's tool sends a canned ACL of bucket-owner-read with every PutObject, and every upload fails. Uploads must succeed and the bucket must not become public. Which approach will meet these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: B is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    And public means an ACL that "grants any permissions to members of the predefined AllUsers or AuthenticatedUsers groups". bucket-owner-read grants nothing to either. Object Ownership is what is failing the call: with Bucket owner enforced, "your bucket accepts only PUT requests that do not specify an ACL or PUT requests with bucket owner full control ACLs... PUT requests that contain other ACLs (for example, custom grants to certain AWS accounts) fail and return a 400 error with the error code AccessControlListNotSupported." Held alone, the ownership fact suggests re-enabling ACLs; held alone, the Block Public Access fact suggests weakening the account. The upload itself is the thing to change, and both settings stay.

    Written from docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html

  3. A partner must be able to upload one file to an S3 bucket at any point over the next five days, without an AWS account of their own. A service running on an EC2 instance generates a presigned URL with an expiration of five days and emails it to them, and the partner reports that the link stops working after a few hours. Which solution meets these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: A is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    And "in general, a presigned URL expires when the credential you used to create it is revoked, deleted, or deactivated. This is true even if the URL was created with a later expiration time." Only one credential type reaches five days: "IAM user - Valid up to 7 days when you're using AWS Signature Version 4. To create a presigned URL that's valid for up to 7 days, first delegate IAM user credentials (the access key and secret key) to the method you're using to create the presigned URL."

    Written from docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html