---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://truto.one/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Bring your own key store

> Source: https://truto.one/docs/guides/team-security/key-store/

By default, Truto encrypts and stores the secrets of your connected accounts. Connect a **key store** to keep an environment's secrets in your own AWS Secrets Manager instead, encrypted with your own KMS key if you name one. Truto keeps only a reference to each secret, reads it from your store when it needs it, and loses access the moment you revoke its key.

:::callout{type="info"}
Only team admins can manage key stores, from **Settings → Key store** ([app.truto.one/settings/key-store](https://app.truto.one/settings/key-store)). The API refuses every key store change made with an API token: it has to come from a signed-in admin.
:::

## What goes in your store

A key store belongs to one environment. Once it's in use, these secrets of that environment go to it:

- **Connected accounts' credentials**: OAuth access and refresh tokens, API keys, passwords and anything else in the account's `context`.
- **Overrides on a connected account**, such as an account's own OAuth app credentials.
- **Overrides on an integration in the environment**, such as your own OAuth app's client ID and secret.

OAuth apps that Truto provides stay with Truto. Everything else about an account (its ID, tenant, integration, status) stays in Truto as before.

Each secret is stored under your secret name prefix (`truto/` unless you change it):

| Secret | Name in AWS Secrets Manager |
|---|---|
| A connected account's credentials | `truto/<environment_id>/<integrated_account_id>` |
| A connected account's overrides | `truto/<environment_id>/<integrated_account_id>/integration-override` |
| An integration's overrides in the environment | `truto/<environment_id>/environment-integration/<environment_integration_id>` |

## Supported stores

| Provider | Encryption | How Truto signs in |
|---|---|---|
| AWS Secrets Manager | Your KMS key, or the AWS-managed key if you don't name one | An access key of an IAM user you create for Truto |

Truto supports the `aws` and `aws-us-gov` partitions. AWS China regions aren't supported.

## 1. Create an IAM user for Truto

In the AWS account that will hold the secrets, create an IAM user for Truto and an access key for it. Don't attach any policy yet: Truto shows you the exact policy once it knows your settings.

## 2. Connect the key store

1. Open **Settings → Key store** and pick the environment.
2. Click **Connect key store** (or **Add key store** if the environment already has one).
3. Fill in the form:

| Field | Required | Notes |
|---|---|---|
| **Name** | Yes | A label for you, for example `Production AWS`. |
| **AWS region** | Yes | The region your secrets are stored in, for example `us-east-1`. Can't be changed later. |
| **Secret name prefix** | No | Defaults to `truto/`. Letters, digits and `/_+=.@-`, up to 256 characters. Can't be changed later. |
| **KMS key** | No | A KMS key ARN (recommended), key ID, alias name or alias ARN. Without one, Secrets Manager uses its AWS-managed key. A change applies only to secrets created afterwards. |
| **Access key ID** | Yes | The IAM user's access key ID. |
| **Secret access key** | Yes | The IAM user's secret access key. Truto stores it encrypted and never returns it. |

4. Click **Connect**.

Truto checks the access key with AWS (`sts:GetCallerIdentity`, which needs no permissions) and records which AWS account it belongs to. A key AWS rejects is refused right away. The key store starts as **Connecting**: nothing is written to it until it's verified.

An environment can't have two key stores at the same location (the same AWS account, region and prefix).

## 3. Give the IAM user access

Open the key store's **Set up access** section. It shows the permissions policy built for your settings. Attach it to the IAM user as an inline policy.

For prefix `truto/`, region `us-east-1`, account `123456789012` and a KMS key ARN, it looks like this:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "TrutoKeyStoreSecrets",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:CreateSecret",
        "secretsmanager:GetSecretValue",
        "secretsmanager:PutSecretValue",
        "secretsmanager:DeleteSecret",
        "secretsmanager:RestoreSecret"
      ],
      "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:truto/*"
    },
    {
      "Sid": "TrutoKeyStoreKms",
      "Effect": "Allow",
      "Action": ["kms:GenerateDataKey", "kms:Decrypt"],
      "Resource": "arn:aws:kms:us-east-1:123456789012:key/<key_id>",
      "Condition": {
        "StringEquals": {
          "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com"
        }
      }
    }
  ]
}
```

The policy only reaches secrets under your prefix. Without a KMS key, the second statement is left out. If you name the KMS key by alias, the policy grants the keys that carry that alias, because KMS checks permissions against the key, not the alias.

If you use a customer managed KMS key, its key policy must also let the IAM user use it, as with any KMS key.

## 4. Verify it

Click **Verify**. Truto writes a test secret under `truto-verify/` in your prefix, reads it back, deletes it, restores it and deletes it for good. That proves the access key, every permission in the policy and the KMS key all work, and leaves nothing behind.

- If it passes, the key store becomes **Active**. If it's the environment's first key store, it's also marked **In use**: from now on, new connections and credential changes in the environment store their secrets there.
- If it fails, the key store shows **Validation error** with AWS's reason, for example a missing permission. Fix it in AWS and click **Verify** again.

## Move existing secrets

Secrets written before the key store was in use stay encrypted by Truto until they move. They move:

- **on their next change**: when an account's token refreshes, it reconnects, or you edit its credentials or an override; or
- **all at once**: click **Move all now** on the key store in use.

**Move all now** runs in the background. The **Secrets** section counts where the environment's secrets are (in this key store, still in Truto, or in another key store), so you can watch the numbers go down. You can click it again at any time: a secret is never moved twice.

Once a secret has moved and the write has landed, Truto holds only a reference to it and keeps no copy of its own. While a write to your store is in flight or held back (see **Token refreshes** below), Truto keeps the newest value encrypted until the write lands.

## How Truto uses your store

- **Reads.** Truto reads a secret when a request needs it, and caches the value in memory for up to 5 minutes.
- **No fallback.** If Truto can't reach your store, or AWS refuses access, a request that needs the secret fails with a `503` and `truto_error_code: key_store_unavailable`. Truto never falls back to a copy of its own for a secret that's in your store. Each call to AWS times out after 3 seconds and is tried up to 3 times in all. After 5 failed calls in a row (timeouts, throttling or AWS errors), calls to that store fail fast for 30 seconds instead of waiting out the timeout each time.
- **Token refreshes.** AWS Secrets Manager keeps at most 100 versions of a secret, so Truto writes each secret at most once every 15 minutes. If an integration's tokens refresh faster than that, Truto keeps the newest token encrypted until the next write. Integrations whose tokens last longer are never held back.
- **API responses.** Endpoints that return an account's credentials to callers allowed to see them still return them. Truto reads the values from your store to answer.
- **Deletes.** When an account or integration is deleted, Truto deletes its secret with a 7-day recovery window, so you can restore it in AWS if it was a mistake. The same happens to a secret's old copy after **Move all now** or a switch to another store. Deletes run in the background and are best effort: if your store keeps failing (for about 14 hours, over 10 tries) or refuses the delete, Truto logs it and the secret stays in your store under your prefix. Check the prefix for leftovers if you revoked access or had an outage while accounts were being deleted or moved.

## Revoke access

Deactivate or delete the IAM user's access key in AWS. Truto loses access straight away. Values it already read stay cached for up to 5 minutes, then every request that needs a secret from the store fails with `key_store_unavailable`. Reactivate the key, or save a new one with **Edit**, to restore access.

Revoking also stops writes. When an account's token refreshes, Truto keeps the new token encrypted and keeps retrying the write to your store. If your store keeps refusing it (after about 20 retries), Truto gives up: the account goes to `needs_reauth` with `last_error` "The key store refused to store this account's credentials: ...", the `integrated_account:authentication_error` webhook fires, and Truto drops its copy of the new token. The account then needs to be reconnected.

## Switch to another key store

An environment can have several key stores, but only one is **In use** at a time. To switch, for example to a new AWS account, without downtime:

1. Click **Add key store**, connect the new one, attach its policy and click **Verify**. The current store stays in use, and once verified the new one shows **Not in use**.
2. Click **Activate** on the new store. Truto verifies it again, then makes it the store in use and stops writing to the old one, in one step.
3. Click **Move all now** on the new store. Secrets still in the old store keep being read from there until they move.
4. When the old store's **Secrets** section says nothing keeps secrets in it, **Delete** it.

## Edit, disable or delete

- **Edit** changes the name, the KMS key or the access key. The region, prefix and AWS account can't change: create a new key store instead. A change to a store that's in use or holds secrets is verified before it's saved, so a bad key can't break it. On a store that isn't in use and holds nothing, a change to its settings or access key is saved without a check and puts the store back to **Connecting** until you click **Verify** again. Renaming never needs a check.
- **Disable** stops new secrets going to the store. Secrets already in it stay there and keep being read from it. While no other store is in use, their updates (a token refresh, say) are still written to it, and new secrets are encrypted by Truto. Nothing moves back into Truto. Once you activate another store, updates go to that store instead, and the old copy in this one is deleted. Click **Activate** to use it again.
- **Delete** works only on a store that isn't in use, at least a minute after it was disabled, and only once no connected account or integration keeps secrets in it. Until then Truto refuses with `409` and says why.

Truto can't delete an environment, or a team, while it has a key store, because deleting it would also delete the access key needed to clean up your store. If you ask Truto to delete an environment or your team, delete its key stores first.

## Manage key stores with the API

The dashboard uses these endpoints. Every change (`POST`, `PATCH`, `DELETE`) needs a signed-in team admin: API tokens are refused.

| Method | Path | What it does |
|---|---|---|
| `GET` | `/key-store-provider` | The providers Truto supports and the fields each one takes. |
| `GET` | `/key-store` | List the key stores of your environments. |
| `POST` | `/key-store` | Create a key store (`environment_id`, `name`, `provider`, `config`, `credentials`). |
| `GET` | `/key-store/:id` | Get one. Credentials are never returned. |
| `GET` | `/key-store/:id/setup` | The policy to attach on your side. |
| `PATCH` | `/key-store/:id` | Change `name`, `config` or `credentials`, or disable it with `is_current: false`. |
| `POST` | `/key-store/:id/verify` | Run the verification. |
| `POST` | `/key-store/:id/activate` | Make it the store in use. |
| `GET` | `/key-store/:id/usage` | Where the environment's secrets are. |
| `POST` | `/key-store/:id/move-secrets` | Start **Move all now**. |
| `DELETE` | `/key-store/:id` | Delete it. |

See the [key stores API reference](/docs/api-reference/admin/key-stores) for request and response details.

A key store has a `status` (`connecting`, `active` or `validation_error`, with the reason in `last_error`) and `is_current`, which is `true` for the store in use.
