---
title: "Keys and the vault"
description: "The forge is its own key management service. The cluster's key lives only in memory, every other key is sealed under it, and recovery shares are sealed with a post-quantum hybrid."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.forge.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Keys and the vault

Atoll Forge keeps its own keys and your organization's, with no key service outside it, as AWS KMS keeps its keys inside its own hardware. Every key the forge holds is sealed under one key, the cluster's, which is never written to disk.

## The cluster's key

The cluster's key exists only in the memory of running nodes. Every other key, a log's signing key, an organization's receipts key or one of its own keys, is a row in its group's database, sealed under the cluster's key with AES-256-GCM and bound to its group and its use, so a sealed key copied anywhere else opens to nothing.

The memory that holds a key is kept as libsodium keeps a secret: its pages are locked so they never reach swap, left out of core dumps, set between guard pages, and wiped before they are released. `af-server` also makes itself undumpable when it starts, so no other process of its user can read its memory, as OpenSSH's `sshd` does.

## Starting again

A node that restarts while others are running takes the cluster's key from one of them, over the mutually authenticated connection nodes use for Raft, sealed to the restarting node's own key.

When every node is down, the key comes back from **recovery shares**. A cluster's first start splits the key k of n with Shamir's scheme, as HashiCorp Vault splits its unseal key, and seals each share to one holder's recovery key. Until k holders give their shares, a node that starts alone stays **sealed** and answers nothing but the vault's own requests.

```sh
af vault status      # sealed, and how many shares it has
af vault unseal      # give your share, opened on your own machine
```

Each share is sealed by HPKE with X-Wing, a hybrid of ML-KEM-768 (FIPS 203) and X25519, as the IETF's draft for post-quantum HPKE uses it: a share recorded today stays sealed as long as either of the two holds, even against a quantum computer that breaks X25519. Who holds the shares changes by a **rekey**, which the current holders approve by giving their shares, as in Vault.

The cluster's key is the root of a keyring. **Rotating** it adds a term: what is sealed from then on is sealed under the new term, and what was sealed before still opens under its own.

## Your organization's keys

On top of its own keys, the forge serves your organization's, as a key management service: encrypt and decrypt, data keys for larger data, and signing with Ed25519 or ML-DSA-65 (FIPS 204), a post-quantum signature. Each key names who may use it, fully or only to encrypt (or verify), and creating a key or changing who may use it is a request. An administrator's takes effect at once, on their word, unless the forge requires a second administrator; anyone else's waits until an administrator, or someone who holds the key as the grant gives, approves it. On a development server you are the administrator:

```console server
$ af-server --dev
...
```

```console check
$ source ~/af-dev/dev/env
$ af kms create app-secrets --use-person dev@localhost
done: it took effect at once, on your word as an administrator
$ printf 'hunter2' | af kms encrypt app-secrets --context env=prod > token.enc
$ af kms decrypt --context env=prod < token.enc
hunter2
```

Decrypting needs the same context the data was encrypted with:

```console check
$ af kms decrypt --context env=test < token.enc
Error: InvalidState: the ciphertext does not open: another key, version or context, or changed
[1]
```

A post-quantum signing key works the same way:

```console check
$ af kms create releases --spec ml-dsa-65 --use-person dev@localhost
done: it took effect at once, on your word as an administrator
$ printf 'v1.0' | af kms sign releases > v1.sig
$ printf 'v1.0' | af kms verify releases --signature "$(cat v1.sig)"
valid
```

An agent is born with no more keys than its parent allows, and every use of a key is recorded.

A development server keeps its cluster's key in a file beside its data. That is the development seal, named so, and never the default: any other cluster's first start must say how its key is kept, by naming its recovery key holders (or by asking for the key file with `--dev-key-file`), or it does not start.

## Next

- [`af kms`](https://docs.forge.workreef.dev/reference/af/kms/) and [`af vault`](https://docs.forge.workreef.dev/reference/af/vault/) in the reference.
- [People and agents](https://docs.forge.workreef.dev/concepts/agents/): how an agent's birth limits its keys.

Source: https://docs.forge.workreef.dev/concepts/keys/index.mdx
