Certopolis

AWS Certified Developer – Associate

S3 presigned URLs: expiry, revoking and limits for DVA-C03

The Amazon S3 User Guide says a presigned URL acts with the credentials of the IAM principal that signed it and can be reused until it expires. An IAM user's access key can sign for up to 7 days with Signature Version 4. A URL signed with temporary credentials stops working when those credentials expire.

Who signs a presigned URL and what it can do

Anyone with valid security credentials can create a presigned URL. The signer supplies a bucket, an object key, an HTTP method such as GET or PUT, and an expiration interval. The URL only works if the signer has permission for that operation, because Amazon S3 treats the request as coming from the signer.

The person who uses the URL needs no AWS credentials. The URL is a bearer token: whoever holds it can use it, as many times as they like, until it expires. A forwarded download link works for the next person too.

A presigned PUT URL lets someone upload one object. If an object with the same key already exists, S3 replaces it, and the bucket owner owns the uploaded object. Signing happens locally, so S3 records no event when a URL is issued. CloudTrail data events and server access logs record the later requests and identify the signer, not the person who used the URL.

How long does a presigned URL last?

The S3 console lets you set between 1 minute and 12 hours. The AWS CLI and SDKs allow up to 7 days. With the CLI the value is in seconds: aws s3 presign with --expires-in 604800 is 7 days.

The credential type sets a second limit. A URL ends at its configured expiration or when its credentials expire, whichever comes first. An AssumeRole session lasts 1 hour by default. Amazon EC2 instance profile credentials are valid for about 6 hours at most. Amazon ECS task role credentials typically rotate every 1 to 6 hours. Only an IAM user's access key can back a full 7-day URL.

S3 checks the expiration when the HTTP request arrives. A download that started before the expiration time continues. If the connection drops and the client restarts after that time, the request fails.

Revoking and restricting presigned URLs

There is no call that cancels one URL. A presigned URL stops working when the credential that signed it is revoked, deleted or deactivated, even if its own expiration is later. An explicit deny in the bucket policy against the signer has the same effect: requests return 403 Forbidden when the signer lacks permission or the bucket policy denies access.

For URLs signed with Signature Version 4, a bucket policy can use the s3:signatureAge condition key to deny requests whose signature is older than a limit you choose. The User Guide example denies anything signed more than 10 minutes ago, whatever expiration the signer set.

A network-path condition on the bucket applies to every request, presigned or not. Use aws:SourceIp when clients use the public S3 endpoint. Use aws:SourceVpc or aws:SourceVpce when requests arrive through a VPC endpoint.

Where the exam catches people

  • Believing a presigned URL is single-use: actually it can be used any number of times by anyone who holds it until it expires.
  • Believing a URL signed with role credentials can last 7 days: actually it stops when the role session ends, which is 1 hour by default for AssumeRole.
  • Believing an issued URL cannot be stopped before it expires: actually deactivating or deleting the signing credential, or explicitly denying the signer in the bucket policy, ends it.
  • Believing aws:SourceIp restricts requests that arrive through a VPC endpoint: actually those requests are matched with aws:SourceVpc or aws:SourceVpce.
  • Believing the customer who opens the link needs S3 permissions: actually S3 evaluates the permissions of the principal that signed the URL.

Written from these sources

Try 3 questions on this

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

  1. A company sells ebooks and stores each file in a private Amazon S3 bucket. After a purchase, the application generates a presigned GET URL with a 24-hour expiration and emails it to the customer. The company finds that some customers forward the link, and other people download the same ebook with it on the same day. What could be causing this?

    Right. In the game that’s Renown for your Security building.

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

    Show the full explanation and doc quotes

    Forwarding the link hands the same download right to someone else for the rest of the 24 hours. Presigned URLs therefore need to be protected, and their lifetime kept as short as the use allows.

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

  2. A support portal signs Amazon S3 presigned GET URLs with an IAM user's access key so that customers can download diagnostic log bundles. Each URL expires 7 days after it is signed. Several of these download links were posted on a public forum, and every download link that the portal has already issued must stop working now. Which solutions will meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Security building.

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

    Show the full explanation and doc quotes

    Deactivating the signing access key therefore ends every outstanding URL at once. Independently, a bucket policy statement that explicitly denies s3:GetObject to the signing IAM user makes Amazon S3 refuse every download made with that user's URLs. Either change alone meets the requirement.

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

  3. Several teams' applications in one AWS account generate Amazon S3 presigned URLs for a shared bucket, and each team's IAM role allows s3:GetObject on it. A new standard says that Amazon S3 must refuse a presigned request made more than 10 minutes after its URL was signed, even when the URL's own expiration is later. Every request must also arrive through the company's gateway VPC endpoint. Which combination of actions should the developer perform to meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Security building.

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

    Show the full explanation and doc quotes

    For requests that arrive through a VPC endpoint, the network-path condition keys are aws:SourceVpc and aws:SourceVpce, so a Deny when aws:SourceVpce is not the endpoint's ID refuses every request from any other path. Both statements are needed, one per requirement.

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

Ask for something