---
title: "Auth snapshot"
description: "The JSON auth file a manager mounts — API keys as hashes, revocations, request classes, worker-certificate policy — and exactly how the leader applies it."
url: "https://opod.io/docs/core-reference/auth-snapshot/"
markdown_url: "https://opod.io/docs/core-reference/auth-snapshot.md"
section: "Core reference"
last_updated: "2026-10-30"
---

# Auth snapshot

> The JSON auth file a manager mounts — API keys as hashes, revocations, request classes, worker-certificate policy — and exactly how the leader applies it.

## In short

The auth snapshot is a JSON file of SHA-256 key hashes that a manager writes and a leader reads every 10 seconds. It gives a leader its endpoint keys with no plaintext key on the leader, and it turns key enforcement on or off. A key that leaves the file is revoked.

```bash
printf '%s' 'sk-orc-<the key>' | sha256sum      # the "hash" a key entry carries
```

```json
{"revision": "1", "issuedAt": "2026-10-30T10:00:00Z", "requireKeys": true,
 "keys": [{"id": "team-search-1", "name": "team-search", "hash": "<64 hex characters>", "scope": "user"}]}
```

The auth snapshot gives a leader its endpoint keys without any plaintext key reaching it. A manager writes it, typically from a Kubernetes Secret mounted into the leader's pod; the leader reads it. Nothing else is on the request path, so the leader keeps serving from the last snapshot it read when the manager is down.

| Setting     | Value                                                                                                                    |
| ----------- | ------------------------------------------------------------------------------------------------------------------------ |
| Path        | `OPOD_AUTH_FILE`, default `/etc/opod-auth/auth.json`                                                                     |
| Off         | `OPOD_AUTH_FILE=off`: no watcher at all                                                                                  |
| Re-read     | every 10 seconds, when the file's modification time is newer than the last good read                                     |
| Typed shape | `AuthSnapshot` and `SnapshotKey` in core's [`pkg/adminapi`](https://github.com/opod-io/opod-core/tree/main/pkg/adminapi) |

- The file may appear after the leader starts; the watcher waits for it.
- A file that is not valid JSON is logged (`auth file unreadable — keeping last good snapshot`) and ignored. The last good snapshot stays in force, and the file is read again every 10 seconds until it parses.
- A snapshot that changes something records an `auth.updated` event with `requireKeys`, `keys`, `created`, `updated`, `revoked` and `revokedKeys` (and, in 0.3.0, `refused`), and logs `auth snapshot applied`. A re-issue that only moves `issuedAt` records nothing.

```json
{
  "revision": "42",
  "issuedAt": "2026-10-30T10:00:00Z",
  "requireKeys": true,
  "keys": [
    {
      "id": "team-search-1",
      "name": "team-search",
      "hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
      "scope": "user",
      "expiresAt": "2027-01-01T00:00:00Z",
      "class": "standard",
      "team": "search"
    }
  ],
  "revokedKeys": ["old-456"],
  "nodeMtls": "allow",
  "nodeCertCa": "-----BEGIN CERTIFICATE-----\n…\n-----END CERTIFICATE-----\n",
  "revokedCerts": ["4a3f9c01"]
}
```

## Fields

| Field            | Type     | Meaning                                                                                                                                                                                                                                                                                      |
| ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `revision`       | string   | A name for this version. A change of it counts as a change for the event and the log.                                                                                                                                                                                                        |
| `issuedAt`       | RFC 3339 | When the manager wrote the snapshot. Its **age** is measured from here, not from the file time (the file time changes only when the content does, so a quiet fleet would look stale forever). Empty or not RFC 3339 = age unknown, and no age bound is enforced; a bad value logs a warning. |
| `requireKeys`    | bool     | `true` = `/v1` demands a key. It is OR-ed with `auth.require_keys` in `config.yaml`: a snapshot can turn keys **on** at runtime, but `false` does not turn off a `require_keys: true` config (the default).                                                                                  |
| `keys[]`         | array    | The endpoint's keys (below).                                                                                                                                                                                                                                                                 |
| `revokedKeys[]`  | strings  | Key ids the leader refuses even when a row for them is still in `keys`.                                                                                                                                                                                                                      |
| `nodeMtls`       | string   | Worker certificate policy on register and heartbeat: `off` (or empty, or anything else), `allow`, `require`.                                                                                                                                                                                 |
| `nodeCertCa`     | PEM      | One or more CA certificates a worker certificate must chain to. Public material; rotate it here with no restart.                                                                                                                                                                             |
| `revokedCerts[]` | strings  | Certificate serial numbers to refuse even though the CA signed them. Lowercase hex, no separators.                                                                                                                                                                                           |

### Key fields

| Field       | Required | Meaning                                                                                                                                                                                                                                                                                                                           |
| ----------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`        | yes      | The key id. The leader names the key `k_cp_<id>` in its store, usage rows and events; an id that already starts with `k_cp_` is used as is. A manager strips the prefix to find its own key again.                                                                                                                                |
| `hash`      | yes      | Lowercase hex SHA-256 of the plaintext key (`sk-orc-…` or any string the callers present).                                                                                                                                                                                                                                        |
| `name`      | no       | Display name.                                                                                                                                                                                                                                                                                                                     |
| `scope`     | no       | `user` (default), `admin` or `node`.                                                                                                                                                                                                                                                                                              |
| `expiresAt` | no       | RFC 3339 expiry. The caller then gets `401 key_expired`. Up to and including 0.2.1, a value that does not parse is ignored and the key does not expire. In 0.3.0 the entry is **refused**: a new key is not created, a known key keeps its stored row, and the log says `auth snapshot: key refused — expiresAt is not RFC 3339`. |
| `class`     | no       | How this key's requests rank when the endpoint is full: `critical`, `standard` (default) or `sheddable`. A request may lower its own class with the `X-Opod-Class` header, never raise it.                                                                                                                                        |
| `team`      | no       | Requests of every key with the same team share one fair-share flow inside their class. Empty = the key is its own flow. Also the unit of prefix-cache isolation by default.                                                                                                                                                       |

A key with no `id` or no `hash` is skipped. A key carries no rate limit, quota or model allowlist: those belong to the gateway in front of the endpoint. Fields from older snapshots (`rpmLimit`, `tpmLimit`, `quotaDailyTokens`, `allowedModels`) are ignored.

Compute a hash:

```bash
printf '%s' 'sk-orc-<printed once>' | sha256sum | cut -d' ' -f1
```

## How the leader applies it

Each read runs these steps, under one lock:

1. **Tombstones first.** Every id in `revokedKeys` is mapped to `k_cp_<id>`. A key in `keys` whose id is also a tombstone is skipped.
2. **New keys.** A key id the store has not seen is written as a new row `k_cp_<id>` with its hash, name, scope and expiry. Its `class` and `team` are held in memory only.
3. **Known keys.** Up to and including 0.2.1, a key id the store already has keeps the hash, name, scope and expiry it was first written with: to rotate a key or move its expiry, publish it under a **new id** and drop the old one. In 0.3.0 a known id follows the file: a changed hash, name, scope or expiry is written to its row and counted as `updated`, and the old hash stops working at that read.
4. **Keys that left the file** are revoked: every non-revoked `k_cp_` row whose id is no longer in `keys`.
5. **Tombstones** revoke their key. A tombstone for an id the store has never seen still creates a revoked row, so that id can never be created later.
6. **Revocation is final.** The leader never un-revokes an id it has seen revoked, whether by a tombstone or by leaving the file. A key that comes back under the same id stays refused; mint a new id.
7. **Keys minted locally** with `opod token create` (ids without `k_cp_`) are never touched.
8. `requireKeys`, the classes and teams, and the certificate policy take effect for the next request, register or heartbeat, with no restart.

A tombstone list is an append: any process with write access to the mounted Secret can deliver a revocation correctly while the manager is down, where rebuilding the whole key list could not.

## Worker certificates

`nodeMtls` decides how the leader treats a worker's client certificate on `POST /admin/v1/nodes/register` and `…/heartbeat`:

| Mode      | Behaviour                                                                                                                                                                       |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `off`     | Certificates are ignored. The join token is the credential.                                                                                                                     |
| `allow`   | A worker that presents a certificate signed by `nodeCertCa` is authenticated by it, as scope `node`, and the token is not needed. A worker without one falls back to its token. |
| `require` | A register or heartbeat with no such certificate is refused: `401 this endpoint requires a worker client certificate (nodeMtls=require) and the call presented none`.           |

- `allow` or `require` with no `nodeCertCa`, or a `nodeCertCa` with no parsable certificate, falls back to `off` with a warning in the log.
- A certificate whose serial is in `revokedCerts` is refused with `403 certificate revoked (serial …)` and a `node.cert-refused` event, even while the worker's pod is still up.
- Any other certificate error is `403 client certificate: …`.
- The worker's identity is the node id in its SPIFFE SAN, `spiffe://<domain>/opod/node/<id>`. A worker that registered with a certificate is bound to it: only that certificate (or an admin key) can act as that node id.

Certificates are only seen when the leader serves TLS. See [Security](https://opod.io/docs/core/security/).

## Staleness

By default a leader serves from whatever snapshot it holds, for as long as it holds it: availability wins over revocation. To make revocation win, set `auth.maxSnapshotAgeSec` in the [policy snapshot](https://opod.io/docs/core-reference/policy-snapshot/#auth) and re-issue the auth snapshot, with a fresh `issuedAt`, more often than that bound.

Past the bound, while keys are required, every `/v1` request gets `503` with `Retry-After: 30` and this message, until a fresher snapshot arrives:

```text
this endpoint's auth snapshot was issued 6m12s ago (at 2026-10-30T10:00:00Z), past its limit of 300s (policy auth.maxSnapshotAgeSec): API keys are refused until a fresher snapshot arrives; retry later
```

It is a `503`, not a `401`, on purpose: the key may be fine, and the caller should retry, not rotate it. The snapshot in force, its age and whether it is stale are on [`/loadz`](https://opod.io/docs/core-reference/probes/) as `auth_snapshot`.

## Write it safely

- Write the file atomically (a temporary file, then a rename), or let the Secret mount do it. A half-written file fails to parse and is skipped; the next read picks up the complete one.
- Keep `revision` meaningful: it is what the log and the event name.
- Re-issue on a period shorter than `auth.maxSnapshotAgeSec` when you set one.
