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:SourceIprestricts requests that arrive through a VPC endpoint: actually those requests are matched withaws:SourceVpcoraws:SourceVpce. - Believing the customer who opens the link needs S3 permissions: actually S3 evaluates the permissions of the principal that signed the URL.