Create an access key
Create a credential that acts as an IAM user outside the browser, for the API, the CLI, Terraform, the container registry, git over HTTPS and S3 clients.
An access key is a pair: a key ID of 20 characters that starts with EWS1, and a secret of 40
characters. The key acts as one IAM user or service account and can do what that account's
policies allow. For a script, create a service account with exactly the policies it needs and a
key for it. For a key that reaches one bucket, or a temporary key narrower than yourself, see
Give access to one bucket. Replace
ci-deploy with what the key is for.
Prerequisites
- Permission for
iam:CreateAccessKey. Without it the console says "Creating a key needs iam:CreateAccessKey; ask an administrator." and shows no Create access key button. - In the console, also
iam:ListAccessKeys: without it the Access keys page shows only "You do not have permission to list access keys." - The IAM user the key acts as is active, and has fewer active, unexpired keys than the
iam.access-keysquota allows per user (see Quotas).
Create the key
- Open Identity, then choose Access keys.
- Choose Create access key.
- (Optional) For Acts as, choose the IAM user the key acts as. It starts on you.
- (Optional) For Description, enter ci-deploy.
- (Optional) Open Expiry and, for Expires after (days), enter the key's lifetime. It starts on your organization's default and cannot exceed its maximum.
- Choose Create access key.
- Copy the Key ID and the Secret, then choose I've saved the secret, dismiss.
dcloud iam access-keys create --description ci-deploy --expires-in-days 30POST /iam/api/access-keys
{ "description": "ci-deploy", "expiresInDays": 30 }resource "dcloud_iam_access_key" "ci" {
iam_user_id = dcloud_iam_user.ci.id
description = "ci-deploy"
expires_in_days = 30
}Result
The secret is in the create response and on the console panel, and nowhere else: it cannot be read again. With Terraform it is kept in the state, so protect the state as you would the key.
Use the pair as:
Authorization: EWS-ACCESS-KEY EWS1EXAMPLEEXAMPLE00:<secret>The panel shows the same pair as a docker login line for the container registry (the same pair
works for git over HTTPS), as dcloud auth login --with-key for the CLI, and as
aws configure set lines for S3 clients.
- Expiry. Every new key expires. Without
expiresInDaysit gets the organization's default (90 days unless changed); a request may ask for 1 day up to the organization's maximum (365 days unless changed). - No limit on the key. What the key may do is its account's policies. The
scopePolicyfield (--scope-policy, Terraformscope_policy) is deprecated: it is still accepted and enforced, and the response then carries adeprecationnote. Give the account the policy it needs, or use a temporary key, instead. Keys made earlier with a limit keep it; Access keys lists them under Legacy limited keys, where Migrate replaces each (see Keys with a limit). - Acting as another person. A key for another person's own IAM user records everything done
with it as that person. The console asks you to select I create a key that acts as …; the
API needs
"actAsMember": true. The audit log names you as the creator.
If the key is refused
- 400
expiresInDays is 400; this organization allows at most 365 days. - 400
This key would act as …, a person in this organization: …whenactAsMemberis missing. - 400
scopePolicy: …when the deprecatedscopePolicyis not a valid policy document. - 404
IAM user not foundfor aniamUserIdoutside your organization. - 409
… is suspended (for example a former member) and cannot be given new access keys. - 409
Quota exceeded: Access keys per user (iam.access-keys) — …when the user has as many active keys as allowed. Deactivate or delete one first (see Manage access keys).
Related
- Manage access keys
- Sign in the CLI
- Web identity federation: credentials for CI jobs without a stored key.
POST /iam/api/access-keys·dcloud iam access-keys create·dcloud_iam_access_key
Related