# Monitor Your Vault

`octet-vault monitor` reads every log event since its last run and tells you about anything you did not expect: a key you did not register, a policy change you were not told about, a recipient key without your owner signature, or a log that no longer extends the one it saw before. Run it on a schedule with a `vaults:read` token.

## Run it

```bash
octet-vault --token-file read.token monitor --state monitor-state.json --allow-list allow.txt
```

- `--state` is a file `monitor` creates on its first run. It holds the last checkpoint it verified and the next event to read, so each run reads only new events.
- `--allow-list` is the list of events you expect. See below. The file must exist: `monitor` stops with exit code `4` when it does not. To allow nothing, create an empty file.
- `--dry-run` runs the checks without updating the state file.

It exits with:

| Exit code | Meaning | What to do |
|---|---|---|
| `0` | Every check passed, and every new event was on the allow-list | Nothing |
| `1` | A check failed, for example the log does not extend the saved checkpoint | Read the FAIL lines and investigate before you rely on the vault again. Write to Octet with the output. |
| `2` | An ALERT, for example an event that is not on the allow-list | Read the ALERT lines. If you made the change, add its line to the allow-list. |
| `4` | The run could not complete: the token, the network, the state file, a server error, or a notification that could not be sent | Read the error. Fix the token or the network, then run again. |
| `64` | A usage error, such as a wrong flag | Fix the command |

With `--notify-webhook`, a notification that fails turns exit code `0` into `4`. The other exit codes stay as they are.

## The allow-list

The allow-list is a text file with one expected event per line: the event type and its subject, separated by a space. Such a line allows every event of that type and subject.

```text
policy_changed <policy hash>
key_registered ovk-2026-11-1a2b3c4d
key_activated ovk-2026-11-1a2b3c4d
```

A line can carry a third field, a log index in decimal: `<event type> <subject> <log index>` allows only the event at that index. A third field that is not a decimal number, or a fourth field, is an error that names the file and the line, and `monitor` stops before any request.

You rarely write it by hand. Every CLI command that changes your vault takes `--allow-list allow.txt` and appends the events it causes. Octet sends you the hash for each `policy_changed` line when it changes your vault's settings.

An auditor's `grant_fetched` event always raises an ALERT, by design: `grant` adds `grant_created` to the allow-list but never the fetch, so you hear about each fetch once, on the run that first sees it. See [Delegate to an Auditor](/docs/vaults/integration/delegate/).

A delegation root certified by an owner key that had already been replaced raises the ALERT `delegation_root_retired_owner`, which no allow-list line silences. Treat that owner key as stolen, and report the ALERT to Octet.

## Get notified

`monitor` can post a JSON summary of each run to a URL you choose, such as an incident tool, a chat channel or a mail gateway:

```bash
octet-vault --token-file read.token monitor --state monitor-state.json --allow-list allow.txt \
    --notify-webhook https://hooks.example.com/octet-vault --notify-secret-file webhook.secret
```

| Option | Environment variable | Meaning |
|---|---|---|
| `--notify-webhook <URL>` | `OCTET_VAULT_NOTIFY_WEBHOOK` | Where to post. An `https://` or `http://` URL. |
| `--notify-secret-file <file>` | `OCTET_VAULT_NOTIFY_SECRET` (the secret itself) | A shared secret that signs each request. Without one, requests are unsigned. |
| `--notify-always` | | Post after every run, a clean one included |

By default `monitor` posts only when a run has an ALERT or a FAIL line, or stops with an error before it finishes. With `--notify-always` it posts after every run, so your receiver can alert you when the posts stop arriving.

A post that can't be delivered, or that gets an answer other than `2xx`, is printed on standard error. `monitor` still prints its report and saves its state file.

### The summary

`monitor` posts `Content-Type: application/json`:

```json
{
  "format": "octet-vault.monitor-notification/1",
  "generated_at": "2026-11-06T10:17:04.512339Z",
  "vault": {
    "license_id": "<licence ID>",
    "env": "release",
    "origin": "octetproof.com/vaults/v1/prod"
  },
  "result": "ALERT",
  "exit_code": 2,
  "title": "monitor <licence ID> (release)",
  "checks": [
    { "name": "key-event", "status": "ALERT", "detail": "key_registered ovk-2026-11-1a2b3c4d at index 4711 is not on the allow-list" }
  ],
  "alerts": [
    "key-event: key_registered ovk-2026-11-1a2b3c4d at index 4711 is not on the allow-list"
  ]
}
```

| Field | Content |
|---|---|
| `format` | Always `octet-vault.monitor-notification/1` |
| `generated_at` | When the run finished, RFC 3339, UTC |
| `vault` | Your licence ID, the environment (`release` or `sandbox`), and the log origin |
| `result` | `OK`, `ALERT`, `FAIL`, or `ERROR` when the run stopped before its report |
| `exit_code` | The run's exit code: `0`, `1` or `2`, or `4` for `ERROR` |
| `title` | The report's title |
| `checks` | Every check line, with its `name`, `status` and `detail` |
| `alerts` | The ALERT lines again, as `<check>: <detail>` |
| `error` | For `ERROR` only: why the run stopped |

The summary never holds your token, a key, a passphrase or the state file.

### Verify the signature

With a secret, each request carries an `Octet-Signature` header:

```text
Octet-Signature: t=<Unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>
```

In your receiver, recompute the HMAC over the raw request body, compare it in constant time, and reject a `t` more than five minutes old, so a captured request can't be replayed later. In Python:

```python
import hashlib, hmac, time

def verify(secret: bytes, header: str, body: bytes) -> bool:
    fields = dict(part.split("=", 1) for part in header.split(","))
    t = int(fields["t"])
    if abs(time.time() - t) > 300:
        return False
    expected = hmac.new(secret, f"{t}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, fields["v1"])
```

The secret file is read as bytes, with a trailing newline removed. Use the same bytes as `secret`.

## Schedule it

Run `monitor` every hour. Three ways follow: a cron job on your own machine, a GitHub Actions workflow, or the container image on your own scheduler.

### With cron

This script runs `monitor` and mails you when it does not exit `0`. Adapt the last line to your alerting, or use `--notify-webhook` instead.

```bash
#!/bin/sh
cd "$HOME/octet-vault" || exit 1
octet-vault --token-file read.token monitor \
    --state monitor-state.json --allow-list allow.txt > monitor-last.txt 2>&1
status=$?
[ "$status" -eq 0 ] || mail -s "octet-vault monitor exited $status" you@example.com < monitor-last.txt
```

Run it from cron every hour:

```text
0 * * * * /path/to/octet-vault-monitor.sh
```

### With GitHub Actions

The action `octetproof/octet-vault/action` runs `monitor` on a GitHub Actions schedule. It downloads the CLI release you name, checks its signature and checksum as in the [Quickstart](/docs/vaults/getting-started/quickstart/), and fails the job on an ALERT line or a failed check.

Commit your allow-list to the repository, store a `vaults:read` token as a repository secret, and add this workflow:

```yaml
name: Vault monitor
on:
  schedule:
    - cron: '17 * * * *'   # hourly
  workflow_dispatch:

jobs:
  monitor:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4   # for the allow-list
      - uses: octetproof/octet-vault/action@v1.0.2
        with:
          version: 1.0.2
          token: ${{ secrets.OCTET_VAULT_TOKEN }}
          allow-list: vault/allow.txt
          notify-webhook: ${{ secrets.VAULT_WEBHOOK_URL }}
          notify-secret: ${{ secrets.VAULT_WEBHOOK_SECRET }}
```

| Input | Default | Meaning |
|---|---|---|
| `version` | Required | The `octet-vault` release, for example `1.0.2` |
| `token` | Required | Your `vaults:read` token, from a repository secret. The action never needs `vaults:admin`. |
| `allow-list` | None | Path to your allow-list. Without it, every key event, policy change and delegation event is an ALERT. |
| `witnesses` | None | Witness keys to require, one per line (see [Pin a witness](#pin-a-witness)) |
| `min-cosignatures` | All | How many of those witnesses must have cosigned |
| `state-key` | `octet-vault-monitor` | Cache key prefix for the state file. Use one per vault. |
| `notify-webhook` | None | URL that receives the summary |
| `notify-secret` | None | Shared secret for the `Octet-Signature` header |
| `notify-always` | `false` | Also post after a clean run |

The action's output `exit-code` is the run's exit code: `0` clean, `1` a failed check, `2` ALERT lines, `4` the run could not complete (the token, the network, a server error, or a notification that could not be sent).

The action keeps the state file in your repository's GitHub Actions cache, and each run restores the newest one. GitHub evicts a cache entry that nobody reads for 7 days. The next run then starts from the beginning of the log: it reads every event again and checks the whole log against the current checkpoint. With an allow-list that covers your past events, that run is clean.

### With the container image

The image `ghcr.io/octetproof/octet-vault` holds the same CLI, with `octet-vault monitor` as its entrypoint. The 1.0.2 image is also tagged `ghcr.io/octetproof/octet-vault:1.0.2`. Each release names its image by digest in `octet-vault-image.txt`. That file is listed in the release's `SHA256SUMS`, and the workflow that signs `SHA256SUMS` also signs the image digest. With `SHA256SUMS` verified as in the [quickstart](/docs/vaults/getting-started/quickstart/#1-install-the-cli), check the image file and the image signature:

```bash
VERSION=1.0.2
BASE=https://github.com/octetproof/octet-vault/releases/download/v$VERSION
IDENTITY="https://github.com/octetproof/octet-vault/.github/workflows/sign-release.yml@refs/tags/v$VERSION"
curl -fsSLO "$BASE/octet-vault-image.txt"
grep " octet-vault-image.txt\$" SHA256SUMS | shasum -a 256 -c -   # must print "octet-vault-image.txt: OK"
IMAGE="$(cat octet-vault-image.txt)"                                # ghcr.io/octetproof/octet-vault@sha256:...

cosign verify "$IMAGE" \
  --certificate-identity "$IDENTITY" \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com > /dev/null
```

Run the image by that digest, so you run exactly what you verified. The arguments after the image are `monitor`'s options:

```bash
export OCTET_VAULT_TOKEN="$(cat read.token)"
docker run --rm \
  -e OCTET_VAULT_TOKEN \
  -v "$PWD/state:/state" -v "$PWD/allow.txt:/config/allow.txt:ro" \
  "$IMAGE" \
  --state /state/state.json --allow-list /config/allow.txt
```

- The token comes from the environment, never from the image. Set `OCTET_VAULT_NOTIFY_WEBHOOK` and `OCTET_VAULT_NOTIFY_SECRET` the same way.
- The image runs as user `65532`. Make the `state` directory writable by that user, or run the container with `--user`.
- The container exits with `monitor`'s exit code.
- The image carries the man pages in `/usr/share/man/man1`, and the licences of the CLI and its open source components in `/usr/share/doc/octet-vault/`.

A `vaults:read` token lasts at most 90 days. Mint the next one before it expires, or every run fails with `401`.

## Pin a witness

A witness cosigns each checkpoint only if it extends the last one the witness saw. Pin a witness's verifier key with `--witness`, and `monitor` checks that the witness cosigned the checkpoint. Octet's witness has this key:

```bash
octet-vault --token-file read.token monitor --state monitor-state.json --allow-list allow.txt \
    --witness 'witness.octetproof.com/vaults+99265bea+BGkKndgz3F3xzByfKpUXmWMUUHH38o0GJM0Y4dxfjmBW'
```

Repeat `--witness` for each witness you pin, and set `--min-cosignatures <n>` if fewer than all of them must have cosigned. Without `--witness`, the `cosignatures` line reads NOT-CHECKED.

### Octet's witness

Octet runs the only witness for its log today. The witness detects a log rolled back to an earlier state. Octet operates both the log and the witness, so the witness does not detect a split view made by Octet itself.

## Check retention

With `--retention-sample <n>`, each run also picks `n` live objects at random, from 1 to 60, and sends each one a [retention challenge](/docs/vaults/concepts/integrity/#proof-of-retention) with the default 16 chunks:

```bash
octet-vault --token-file read.token monitor --state monitor-state.json --allow-list allow.txt \
    --retention-sample 5
```

The report has one `retention <object-id>` line per object: PASS, FAIL when a check failed or the vault answered `500 blob_missing`, ABSENT when the object's retention root is not committed or not in a checkpoint yet, or NOT-CHECKED when the vault gave any other error answer (the line names the HTTP status and code). A FAIL makes the run exit `1`. ABSENT and NOT-CHECKED lines raise no ALERT and don't change the exit code.

- Each sampled challenge is an `object_read` event in your log.
- The vault answers at most 60 challenges per licence in each clock hour. When a run reaches that limit, the sampling ends with one NOT-CHECKED `retention-sample` line, never a FAIL.
- The GitHub Action has no input for it. Use cron or the container image, where the arguments after the image are `monitor`'s options.

## What it checks

`monitor` prints the lines that are not PASS, then its result. `--verbose` prints every line. See [Check Lines and Exit Codes](/docs/vaults/reference/checks/#monitor) for each line.
