# Create an access key

Create an access key that S3 clients sign requests with; it acts as an IAM user and its secret is shown once.

An S3 client signs its requests with an access key ID and a secret access key. An IAM access key
does this: the same key also works for the Deutsche Cloud API, the CLI and Terraform. A key acts as
its IAM user: it can do exactly what that user's IAM policies allow, and no more than its scope
when it has one.

## Prerequisites

- Permission for `iam:CreateAccessKey`. Without it the page says "Creating a key needs
  iam:CreateAccessKey; ask an administrator." and has no **Create access key** button.
- The principal has fewer active keys than the `iam.access-keys` quota allows per user; otherwise
  the create is refused with `409` `Quota exceeded: Access keys per user (iam.access-keys) — …`.

## Create the key

**Console**
1. Open **Identity**, then choose **Access keys**.
2. Choose **Create access key**.
3. (Optional) For **Acts as**, choose another principal than yourself.
4. (Optional) For **Description**, enter what uses the key.
5. (Optional) Under **Limited to**, choose **One bucket** or **Custom policy** (see
   [Limit a key to one bucket](limit-a-key-to-one-bucket.md)); **No limit** is chosen.
6. (Optional) Under **Expiry**, for **Expires after (days)**, enter how long the key lives. It
   starts on your organization's default and cannot exceed its maximum.
7. Choose **Create access key**.
8. Copy the **Key ID** and the **Secret**. This is the only time the secret is shown.

The panel also shows the `aws configure set` lines for the key under **S3 clients (AWS CLI, rclone,
SDKs): access key ID and secret**.

**CLI**
```sh
dcloud iam access-keys create --description "uploads app"
```

**API**
```http
POST /iam/api/access-keys
{ "description": "uploads app" }
```

**Terraform**
```hcl
resource "dcloud_iam_access_key" "uploads" {
  description = "uploads app"
}
```

The secret is kept in the Terraform state; protect the state.

## Result

The response's `accessKeyId` (for example `EWS1EXAMPLEEXAMPLE00`) is the S3 access key ID and its
`secretKey` the secret access key. The secret is in this response and nowhere else. Every IAM key
expires: by default after your organization's default (90 days unless changed), and `expiresAt` is
in the response.

The key stops working:

- at once when it is deleted, deactivated or expired (S3 answers `InvalidAccessKeyId`, or
  `AccessDenied` "This key has expired");
- within 10 seconds when its IAM user is deactivated, the person is removed from the organization
  or deletes their account, or the organization is closed (`AccessDenied` "The key’s owner may no
  longer act in this organization").

**Last used** in the key list shows when it last signed a request.

## S3-only keys

`POST /s3/api/access-keys` (`dcloud s3 access-keys create`, Terraform `dcloud_s3_access_key`,
`s3:CreateAccessKey`) creates a key that works with S3 clients only; its id starts with `EWSS3`. Its
response contains `secretAccessKey` and the S3 endpoint; the secret is never shown again. These
keys count against the `s3.access-keys` quota; temporary credentials do not.

```sh
dcloud s3 access-keys create --description "nightly backup job"
```

## Related

- [Limit a key to one bucket](limit-a-key-to-one-bucket.md)
- [Create temporary credentials](create-temporary-credentials.md)
- [Use the AWS CLI](use-the-aws-cli.md)
- `s3.access-keys.create` · `dcloud iam access-keys create` · `dcloud_iam_access_key` · `dcloud_s3_access_key`
