Create temporary credentials
Create S3 credentials with a session token that expire on their own, for a CI job or a script that should not hold a permanent key.
Temporary credentials act as the IAM user who creates them, with that user's IAM policies.
Prerequisites
- Permission for
s3:CreateTemporaryCredentials; without it the call answers 403.
Create the credentials
Not available in Console. Temporary credentials are made by the CLI and the API.
dcloud s3 temporary-credentials create --duration-seconds 3600 --description "nightly CI job"POST /s3/api/temporary-credentials
{ "durationSeconds": 3600 }With an access key: Authorization: EWS-ACCESS-KEY <id>:<secret>.
Not available in Terraform. Credentials that expire within hours are not configuration.
durationSeconds is 900 to 43200 (15 minutes to 12 hours) and defaults to 3600. A role session
may ask for at most 3600 seconds; more is refused with 400 "A role session may create temporary
credentials for at most 3600 seconds."
Use them
The answer has accessKeyId, secretAccessKey, sessionToken, expiresAt and endpoint. Set
all three in the client; the AWS CLI and SDKs read them from the environment:
export AWS_ACCESS_KEY_ID=<accessKeyId> AWS_SECRET_ACCESS_KEY=<secretAccessKey> AWS_SESSION_TOKEN=<sessionToken>
aws --endpoint-url https://s3.<domain> s3 lsEvery request must carry the session token as a signed x-amz-security-token header, or as
X-Amz-Security-Token in a presigned URL. AWS clients do this on their own when a session token is
set.
Result
- Temporary credentials are not listed with your access keys and cannot be revoked one by one;
they stop working at
expiresAt(ExpiredToken"The provided token has expired"). Credentials created by a role session are deleted when that role's sessions are revoked. - Without the token, S3 answers
InvalidToken"Temporary credentials require a session token". - A permanent key that sends a session token is refused with
InvalidToken"The provided token is malformed or invalid". - An unsigned token header is refused with
AccessDenied"x-amz-security-token must be a signed header".