

# Encryption at rest

Claude Managed Agents for Amazon Bedrock encrypts the content it stores at rest, with no configuration on your part. By default, it uses an AWS owned key. You can choose to encrypt a project's content with a customer managed AWS Key Management Service (AWS KMS) key instead. Encryption is server side: the service encrypts content before it stores it and decrypts it when an authorized caller reads it.

## How the service uses your key
<a name="claude-managed-agents-bedrock-encryption-how-the-service-uses-your-key"></a>

You set a key on an Amazon Bedrock project. The key then protects this content in the project:


| Resource | What the key encrypts | 
| --- | --- | 
| Agents | Each version's configuration, including the system prompt, tools, MCP servers, and skills | 
| Sessions | The conversation and its events, including messages, tool inputs, and tool results, and the session's `resources` entries, such as S3 folder paths | 
| Memory stores | The memories and their versions | 

These are not under your key. They include, but are not limited to:
+ What the service needs to find, route, and authorize requests: resource IDs and ARNs, the account and project, versions, status, timestamps, the IAM roles that agents and sessions run as, and the IAM principal that created a session. The service encrypts these at rest under a KMS key that it owns. Don't put sensitive data in them.
+ Resource tags, which AWS stores as it does for other AWS resources.
+ Telemetry. Where you turn on trace delivery, text that you choose, such as an agent's name or a session's title, can appear on trace spans delivered to Amazon CloudWatch and AWS X-Ray, which are not under your key.

Large values, such as long events, are encrypted the same way.

Files that tools write are not stored by the service. They stay where the tool runner wrote them, such as your runtime's storage or your S3 folders, under that storage's own encryption.

The service uses envelope encryption. Your KMS key encrypts the project's data keys, and the data keys encrypt the content. The service caches decrypted data keys in memory for up to 5 minutes.

The service uses your key with two identities:
+ **The caller.** Before each request that reads or writes the project's content, the service checks with AWS KMS, using the caller's credentials, that the caller is allowed to decrypt with the key.
+ **A key role.** An IAM role in your account that the service assumes to create and decrypt the project's data keys, including for work that continues after a request returns, such as a running turn.

## Choose a key
<a name="claude-managed-agents-bedrock-encryption-choose-a-key"></a>
+ The key must be a symmetric encryption KMS key (key spec `SYMMETRIC_DEFAULT`, key usage `ENCRYPT_DECRYPT`).
+ The key must be in the same Region as the project.
+ Name the key by its key ARN, not an alias.
+ The key can be in another account if its key policy allows the callers and the key role. AWS KMS then also needs IAM policies in the project's account that allow the key role and each caller to use the key.

## Set up a customer managed key
<a name="claude-managed-agents-bedrock-encryption-set-up"></a>

The examples use account `111122223333`, the US West (Oregon) Region, project `proj_example`, a caller role named `AppRole`, and a key role named `CmaKeyRole`. Replace them with your values. Requests use the `cma` function from [Run your first agent](claude-managed-agents-bedrock-first-agent.md), Step 1.

### Step 1: Create the key role
<a name="claude-managed-agents-bedrock-encryption-step-1"></a>

Create an IAM role in the project's account with this trust policy:

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "bedrock.amazonaws.com" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": { "aws:SourceAccount": "111122223333" },
      "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-west-2:111122223333:project/proj_example" }
    }
  }]
}
```
+ Tag the role `ManagedAgentsKeyRole` with the value `enabled`.
+ Don't tag it `ManagedAgentsExecutionRole`, and don't use it as a session role. Sessions that run as a key role fail.
+ To use one key role for several projects, list each project's ARN in `aws:SourceArn`.

The role needs no permissions policy when the key policy in Step 2 allows it to use the key. In AWS CloudTrail, its sessions are named `ClaudeManagedAgents-key-{{project-id}}`.

### Step 2: Create the KMS key
<a name="claude-managed-agents-bedrock-encryption-step-2"></a>

Create a symmetric encryption key in the project's Region. Add these statements to its key policy, beside your administrator statement. List every role that calls the API for the project where the examples name `AppRole`.

```json
[
  {
    "Sid": "CallersDescribeTheKeyThroughBedrock",
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::111122223333:role/AppRole" },
    "Action": "kms:DescribeKey",
    "Resource": "*",
    "Condition": { "StringEquals": { "kms:ViaService": "bedrock.us-west-2.amazonaws.com" } }
  },
  {
    "Sid": "CallersUseTheKeyForTheirProjectsThroughBedrock",
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::111122223333:role/AppRole" },
    "Action": ["kms:Decrypt", "kms:GenerateDataKey"],
    "Resource": "*",
    "Condition": {
      "StringEquals": { "kms:ViaService": "bedrock.us-west-2.amazonaws.com" },
      "StringLike": {
        "kms:EncryptionContext:aws:bedrock:arn": "arn:aws:bedrock:us-west-2:111122223333:project/*"
      }
    }
  },
  {
    "Sid": "TheKeyRoleDescribesTheKey",
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::111122223333:role/CmaKeyRole" },
    "Action": "kms:DescribeKey",
    "Resource": "*"
  },
  {
    "Sid": "TheKeyRoleMakesAndReadsItsProjectsDataKeys",
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::111122223333:role/CmaKeyRole" },
    "Action": [
      "kms:Decrypt",
      "kms:Encrypt",
      "kms:GenerateDataKeyWithoutPlaintext",
      "kms:ReEncryptFrom",
      "kms:ReEncryptTo"
    ],
    "Resource": "*",
    "Condition": {
      "StringLike": {
        "kms:EncryptionContext:aws:bedrock:arn": "arn:aws:bedrock:us-west-2:111122223333:project/*"
      }
    }
  }
]
```

To allow one project only, replace `project/*` with that project's ARN.


| Statement | Why the service needs it | 
| --- | --- | 
| `CallersDescribeTheKeyThroughBedrock` | When you set the project's key, the service calls `DescribeKey` as you to check that the key exists and is a symmetric encryption key. | 
| `CallersUseTheKeyForTheirProjectsThroughBedrock` | Before each request that reads or writes the project's content, the service calls `Decrypt` as the caller, with `DryRun`, to check the caller's access. When you set the key, it also calls `GenerateDataKey` with `DryRun`. Neither call returns key material. | 
| `TheKeyRoleDescribesTheKey` | When you set the key, the service calls `DescribeKey` as the key role to check that the role can use the key. | 
| `TheKeyRoleMakesAndReadsItsProjectsDataKeys` | `GenerateDataKeyWithoutPlaintext` creates the project's data keys, encrypted under your key. `ReEncryptFrom` and `ReEncryptTo` are used when they're created, when you set the key, and when the service rotates them. `Decrypt` decrypts them when the service needs them, and `Encrypt` is used when the service rotates them. Keep all of them in the key policy, or setting the key and creating the project's first resources fail. | 

The caller statements use `kms:ViaService` because the service makes those calls on the caller's behalf. The key role makes its calls with its own credentials, so its statements don't.

### Step 3: Let an administrator set the key
<a name="claude-managed-agents-bedrock-encryption-step-3"></a>

The principal that sets the configuration needs these permissions:
+ `iam:PassRole` on the key role, with the encryption configuration's ARN as `iam:AssociatedResourceArn`.
+ `bedrock:PutAnthropicEncryptionConfiguration` and `bedrock:GetAnthropicEncryptionConfiguration` on `arn:aws:bedrock:us-west-2:111122223333:project/proj_example/anthropic-encryption-configuration/default`.
+ The caller statements from Step 2, because the service checks that the caller can use the key.

Every caller who uses the project's agents, sessions, or memory stores needs the key policy's caller statements, as well as the IAM actions in [The caller's permissions](claude-managed-agents-bedrock-security.md#claude-managed-agents-bedrock-security-the-caller-s-permissions).

### Step 4: Set the key on the project
<a name="claude-managed-agents-bedrock-encryption-step-4"></a>

Send `PUT /bedrock/encryption_configuration` with the project in the `anthropic-workspace-id` header. Name the key by its ARN:

```bash
cma PUT bedrock/encryption_configuration -d '{
  "kmsKeyArn": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
  "roleArn": "arn:aws:iam::111122223333:role/CmaKeyRole"
}'
```


| Field | Value | 
| --- | --- | 
| `kmsKeyArn` | The key's ARN, or `null` for the AWS owned key. Required. | 
| `roleArn` | The key role's ARN, in the project's account. Required with a key, and not allowed with `null`. | 

Before it stores anything, the service checks `iam:PassRole` on the role, then that the caller and the key role can both use the key. If a check fails, nothing is saved, and the response names what failed:


| Status | Cause | 
| --- | --- | 
| 400 | The key role can't be assumed, lacks the `ManagedAgentsKeyRole` tag, or the key policy refuses it an operation. Or the key is disabled, pending deletion, not found, or not a symmetric encryption key. Or an ARN isn't one the project can use: an alias, a key in another Region, a role in another account, a key ARN over 2,048 characters, or a role name over 64 characters. | 
| 403 | The key policy refuses the caller the KMS action that the message names. | 
| 409 | The project's key is being set up, is already changing to another key, or changed while the request ran. The message says which. | 
| 503 | AWS KMS didn't answer. Retry. | 

Putting the configuration the project already has changes nothing.

### Step 5: Check the setup
<a name="claude-managed-agents-bedrock-encryption-step-5"></a>

1. Run `cma GET bedrock/encryption_configuration`. It answers with your `kmsKeyArn` and `roleArn`, and no `keySwitch`.

1. Create an agent and a session in the project, and run a turn.

1. In CloudTrail, check that the KMS calls for the project come from the key role, with the session name `ClaudeManagedAgents-key-proj_example`.

## Change the key
<a name="claude-managed-agents-bedrock-encryption-change-the-key"></a>

You can change a project's key at any time. Put another key and role, or `{"kmsKeyArn": null}` to return to the AWS owned key. If the project has content, the service re-encrypts the project's data keys under the new key in the background, and the content stays readable throughout. While it does, `GET /bedrock/encryption_configuration` shows the change in `keySwitch`, with a `status` of `IN_PROGRESS`, or `FAILED` and a `failureReason`. To retry a failed change, put the same key again.

Until the change finishes, the service still needs the old key, so keep it enabled. When you move from one of your keys to another, let the new key role use both keys.

Automatic rotation of your KMS key needs nothing from you or the service.

## Limit access to the key
<a name="claude-managed-agents-bedrock-encryption-limit-access"></a>
+ **Encryption context.** Every KMS call the service makes for a project, and every check of a caller's access, includes the project's ARN as `aws:bedrock:arn`. Use the `kms:EncryptionContext:aws:bedrock:arn` condition key to limit a statement to the projects you name.
+ **`kms:ViaService`.** Use `bedrock.{{region}}.amazonaws.com` in the caller statements so that a caller can use the key only through Amazon Bedrock.
+ **`kms:CallerAccount`.** Limits the caller statements to principals in your account.
+ **Confused deputy protection.** The key role's trust policy names your account in `aws:SourceAccount` and each project in `aws:SourceArn`, so the service can assume the role only for those projects.
+ **Per caller.** Each request that reads or writes the project's content is checked against the key policy as its caller. Removing one caller's access refuses that caller's next such request and leaves other callers unaffected. An event stream that is already open stays connected until the service closes it for a new check, at most about every 15 minutes. Deletes, AWS tags, and the project's encryption configuration are authorized by IAM, not checked against the key.

## When the key is unavailable
<a name="claude-managed-agents-bedrock-encryption-when-the-key-is-unavailable"></a>
+ If you disable the key or schedule it for deletion, new requests in the project are refused at once with HTTP 400 `invalid_request_error`, with a message that names the key. Running turns stop within about 5 minutes.
+ If the key policy no longer lets the key role use the key, requests return, within about 5 minutes, HTTP 400 with `error_code` `cmek_key_disabled`. The message says that the key is disabled or deleted, or that the role isn't allowed to use it.
+ If you remove the key role's trust policy or its `ManagedAgentsKeyRole` tag, requests fail with a retryable error within about 15 minutes.
+ If you remove one caller's access, that caller's requests are refused with HTTP 403.

Deletes, AWS tags, and the encryption configuration operations keep working while the key is unavailable. The service never falls back to the AWS owned key. When you enable the key again or restore the access, the project's content is readable again. If AWS KMS deletes the key, the project's content can't be recovered.

## Monitor the service's use of your key
<a name="claude-managed-agents-bedrock-encryption-monitor"></a>

AWS CloudTrail records every call the service makes to AWS KMS with your key. See [Logging AWS KMS API calls with AWS CloudTrail](https://docs.aws.amazon.com/kms/latest/developerguide/logging-using-cloudtrail.html).


| `eventName` | Identity | When | 
| --- | --- | --- | 
| `Decrypt` (dry run) | The caller, with `invokedBy` `bedrock.amazonaws.com` | Before each request that reads or writes the project's content | 
| `DescribeKey`, `GenerateDataKey` (dry run) | The caller, with `invokedBy` `bedrock.amazonaws.com` | When the key is set | 
| `DescribeKey`, `Decrypt`, `Encrypt`, `GenerateDataKeyWithoutPlaintext`, `ReEncrypt` | The key role, as `arn:aws:sts::111122223333:assumed-role/CmaKeyRole/ClaudeManagedAgents-key-{{project-id}}` | When the key is set, and when the service creates, decrypts, or rotates the project's data keys | 

Each of these calls except `DescribeKey`, which takes no encryption context, includes `aws:bedrock:arn` in its `encryptionContext`.

AWS STS also records `AssumeRole`, with event source `sts.amazonaws.com`, each time the service assumes the key role.