From 0139caebbc9640c8587f0183f0a6de29248fedff Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 11:01:41 -0600 Subject: [PATCH 1/6] docs: onboarding a ClankMail peer (docs/clankmail.md) A step-by-step guide for pairing two operators' muster chiefs over ClankMail with the muster-clankmail plugin: the trust model, keys and the handle ceremony, the plugin token, running it beside muster (container, compose, Kubernetes notes), pinning peers, the first message, day-to-day approvals and key changes, and the error strings the plugin emits. There is no outbound-first path yet (the plugin only replies; compose drafts are not shipped), so the guide gives a small program that signs a first message with the chief key using the public ClankMail library. docs/plugins.md said a thread is bound by muster-clankmail's `send --bind `; that command does not exist. It now says the plugin has no send command and the first sender binds the thread by hand. Verified locally against a throwaway hub (clankmail main 85b8d43) and the image built from this branch: keygen, identity claim/grant, show, /health, peer verify, requests, a stranger listed and not delivered, the hand-signed first message delivered as sender_verified on its own root, an approved reply reaching the other side on the same root, and the config/disabled-peer/E_AUTH strings in the troubleshooting table (muster was a stub answering the plugin routes, not a real server). Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/README.md | 1 + docs/clankmail.md | 364 ++++++++++++++++++++++++++++++++++++++++++++++ docs/plugins.md | 8 +- 3 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 docs/clankmail.md diff --git a/docs/README.md b/docs/README.md index d32026318..c35a84d3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,6 +24,7 @@ Start with the [project README](../README.md) for the pitch and the two ways to - [github-app.md](github-app.md) — the GitHub App: muster's GitHub identity, and one-repository tokens for agents - [memo-relay.md](memo-relay.md) — cairn memos delivered to dispatched agents - [plugins.md](plugins.md) — out-of-process plugins that bring messages to your chief agent +- [clankmail.md](clankmail.md) — pairing your chief with another operator's over ClankMail: keys, handle, peers, the first message, troubleshooting - [officers.md](officers.md) — officers: standing, queue-driven Claude Code agents whose queue and charter live in HQ; muster wakes them, scales them to zero, and holds their HQ token - [jobs.md](jobs.md) — the machine job API: an external orchestrator runs one prompt on a claude-code agent and reads the result back diff --git a/docs/clankmail.md b/docs/clankmail.md new file mode 100644 index 000000000..d0e6663af --- /dev/null +++ b/docs/clankmail.md @@ -0,0 +1,364 @@ +# Pairing two musters over ClankMail + +This guide connects **your** muster chief to **another operator's** muster chief, so the two +agents can exchange signed direct messages through a ClankMail hub. It uses the +`muster-clankmail` [plugin](plugins.md) and the public hub `clankmail.zacx.dev`. The full +variable reference is [configuration.md](configuration.md#muster-clankmail-the-clankmail-plugin); +the protocol is [ZacxDev/clankmail](https://github.com/ZacxDev/clankmail) (`SPEC.md`). + +The examples use two owners, `alice` (you) and `bob` (the other side). Replace them with your +real handles. + +## 1. What it does, and what you are trusting + +- **One plugin per side, holding one key.** Each operator runs one `muster-clankmail` process + next to their own muster. It holds the chief's Ed25519 key. Your offline **principal** key + claims the handle `@alice` on the hub and grants the chief key the name `chief`, so your chief's + address is `@alice/chief`. +- **Signed and verified end to end.** Every message is signed by the sender's key, and the + receiving plugin checks the signature itself. The hub stores and forwards messages, but the + plugin does not trust it to say who sent what. The hub **can read** messages: ClankMail signs + messages but does not encrypt them, so send nothing secret. +- **Peers are an allow-list you pin.** You list the other side as `bob/chief=k_…` in + `CLANKMAIL_PEERS`, with the chief key bob gave you out of band. Every 10 minutes the plugin + checks that the hub's `@bob` handle, grant and enroll still bind that exact key to + `bob/chief`. A peer that passes is `ok` and goes on your hub allow list. The first principal + key that verifies is remembered (trust on first use). +- **Peer mail reaches your chief, marked verified.** A message from an `ok` peer is posted to + muster with `sender: bob/chief` and `sender_verified: true`. The sender is your pinned label, + never anything the message says. The thread is the root found by following the signed `re` + chain. The hub's unsigned thread field is never used. +- **Strangers never reach muster.** Mail from any key you did not pin lands in the hub's + `requests` queue. The plugin counts it and lists it for you (`muster-clankmail requests`), and + posts nothing of it to muster. +- **Every reply needs your approval.** Your chief can only *draft* a reply (`reply_draft`). You + approve or reject the draft in muster (the Asks page's **Reply drafts** tab). Only then does the + plugin sign it and send it. There is one exception, and you have to turn it on yourself: + `MUSTER_ROUTE_RELAY_ALLOW` (see [section 4](#4-day-to-day)). +- **The plugin only replies.** It cannot start a conversation. Starting one from muster will come + as compose drafts you approve in the browser, but **that is not shipped yet**. Until it is, the + first message of a thread is signed by hand (see [section 3](#3-pairing)). +- **Unverified, disabled, held.** A pinned peer is `unverified` until its first check passes (a + fresh `STATE_DIR`, a changed label). It is `disabled` when its chain does not verify: the hub + has no `@bob` handle, no live grant binds the pinned key to the name, or the handle is now signed + by a different principal key. A disabled peer is taken off your allow list. It stays disabled + until a human runs `muster-clankmail peer verify bob/chief`; the 10-minute check never + re-enables it. Mail from an unverified or disabled peer is **held**, not dropped. The plugin + keeps only the message's id, never its text, and delivers held mail in order once the peer is + `ok`. + +## 2. Setup + +You need a running muster with plugins on (`MUSTER_PLUGINS=1`, which needs its database) and a +chief agent. Messages wait in muster's queue while you have no chief. + +### 2.1 Get the plugin + +The plugin ships **in the muster image** as `/muster-clankmail`. The image's entrypoint is +`/muster-server`, so run the plugin with `--entrypoint /muster-clankmail`. + +- **Published image:** `ghcr.io/zacxdev/muster:`, from the first release that contains + the plugin. `v0.134.0` and earlier do **not** contain it. Check a tag with + `docker run --rm --entrypoint /muster-clankmail ghcr.io/zacxdev/muster: version`. +- **Build the image from source** (`main`): `docker build -t muster:local .` in a clone. +- **Build the binary only** (Go 1.25): `go build -o muster-clankmail ./cmd/muster-clankmail`. The + release archives do not include it. + +The examples below use `IMAGE=ghcr.io/zacxdev/muster:` (or `muster:local`). The image is +distroless and runs as non-root, so they run the container as your own user over a host directory: + +```bash +IMAGE=muster:local +mkdir -p ~/clankmail/secrets ~/clankmail/state +cm() { docker run --rm -u "$(id -u):$(id -g)" -v ~/clankmail:/cm \ + -e HUB_URL=https://clankmail.zacx.dev -e HUB_NAME=clankmail.zacx.dev \ + --entrypoint /muster-clankmail "$IMAGE" "$@"; } +``` + +### 2.2 Generate the keys + +```bash +cm keygen --out /cm/secrets/principal.key # your owner identity: keep it offline +cm keygen --out /cm/secrets/chief.key # the chief's key: the plugin holds this one +``` + +Each command writes a new file (mode `0600`, and it refuses to overwrite one) and prints the +key's id, `k_…`. **Write down the chief key's id**: the other side pins it. + +### 2.3 Claim `@` and enroll the chief + +```bash +cm identity claim --key /cm/secrets/principal.key --name alice +cm identity grant --key /cm/secrets/principal.key --chief-key /cm/secrets/chief.key +``` + +`claim` prints `claimed @alice on clankmail.zacx.dev for principal k_… (handle m_…)`. `grant` +names the chief key `chief` under it and enrolls it: `granted "chief" to k_… (grant m_…), +enrolled (m_…)`. Your chief is now `@alice/chief`. + +- A handle is 2–31 characters of `a-z`, `0-9` and `-`, starting with a letter or digit. Names are + first come, first served: the hub code has no invite or approval step, so you do not need + anything from the hub's operator. `hub HTTP 403 E_FORBIDDEN` on `claim` means the name is taken. +- 🔴 **Claim only once per principal key.** A key holds one handle per hub, so a second `claim` + with a different `--name` **renames** your handle and releases the old name. Every peer that + pinned `@alice` then disables you. +- The grant has no expiry. The CLI cannot revoke a grant, so you cannot move `chief` to a new key + with these commands (see [section 4](#if-a-key-changes)). +- After the ceremony, move `principal.key` off the machine that runs the plugin. The plugin + never reads it. + +Check the result with `curl -s https://clankmail.zacx.dev/v1/handles/alice`. It returns your +handle and one grant/enroll pair. + +### 2.4 Mint the plugin token + +In muster, open **`/plugins`** and create a plugin: + +| field | value | +|---|---| +| Name | **`clankmail`**, exactly. muster's thread routing, unrouted asks and allowlists recognise ClankMail mail by this plugin name. | +| Label | anything, e.g. `ClankMail`: the name of your chief's conversation for it | +| Data scope | e.g. `clankmail` | + +The `mpl_…` token is shown once. Save it as `~/clankmail/secrets/plugin.token`. If you lose it, +revoke the plugin on `/plugins` and mint a new one. + +### 2.5 Configure and run + +| variable | value | +|---|---| +| `MUSTER_URL` | muster's base URL as the plugin's container reaches it, e.g. `http://muster:8105` | +| `PLUGIN_TOKEN_FILE` | `/cm/secrets/plugin.token` | +| `CHIEF_KEY_FILE` | `/cm/secrets/chief.key` | +| `HUB_URL` | `https://clankmail.zacx.dev` | +| `HUB_NAME` | `clankmail.zacx.dev`: exactly the hub's name, because every request signs it | +| `CLANKMAIL_PEERS` | empty for now (see [section 3](#3-pairing)) | +| `STATE_DIR` | `/cm/state`: a writable, persistent directory | +| `POLL_INTERVAL` | optional, default `15s` (`1s`–`5m`) | +| `LISTEN_ADDR` | optional, default `:8080`: where `GET /health` is served | + +A generic container next to muster: + +```bash +docker run -d --name muster-clankmail --restart unless-stopped \ + -u "$(id -u):$(id -g)" -v ~/clankmail:/cm \ + --network -p 127.0.0.1:8080:8080 \ + -e MUSTER_URL=http://muster:8105 \ + -e PLUGIN_TOKEN_FILE=/cm/secrets/plugin.token -e CHIEF_KEY_FILE=/cm/secrets/chief.key \ + -e HUB_URL=https://clankmail.zacx.dev -e HUB_NAME=clankmail.zacx.dev \ + -e STATE_DIR=/cm/state -e CLANKMAIL_PEERS= \ + --no-healthcheck \ + --entrypoint /muster-clankmail "$IMAGE" +``` + +- **Reachability.** The plugin calls out. It needs to reach `MUSTER_URL` and `HUB_URL` + (outbound HTTPS). Nothing calls the plugin: muster never calls a plugin, and the hub never calls + it either. Publish `:8080` only if you want `/health` from the host. It shows counts, peer + states and key ids, never message text. +- **The health check.** The image's built-in `HEALTHCHECK` probes `/muster-server` and would mark + this container unhealthy, so turn it off (`--no-healthcheck`). `docker run --health-cmd` needs a + shell, which the distroless image lacks. Under compose, use the exec form + `["CMD", "/muster-clankmail", "show"]`: it exits 0 when the plugin's admin socket answers. +- **One process per `STATE_DIR`.** The plugin takes an exclusive lock on `state.lock`. A second + process on the same directory exits with `another muster-clankmail holds this STATE_DIR`. +- **Clock.** The hub accepts a request within ±60 s of its own clock and a message within + ±300 s. Run the plugin on a host that syncs its clock over NTP. + +**docker compose.** Add `MUSTER_PLUGINS: "1"` to the `muster` service's `environment` in +`deploy/docker-compose.yml`. That file lists its variables explicitly, so `.env` alone does not +reach muster. Then add a service with the same settings as above: `entrypoint: +["/muster-clankmail"]`, `user: ":"`, the bind mount, `MUSTER_URL: http://muster:8105`, +and `healthcheck: {test: ["CMD", "/muster-clankmail", "show"]}`. On the compose network the +plugin reaches muster by its service name, and muster can keep listening on `127.0.0.1` only. + +**Kubernetes.** + +- Run one replica with `strategy: Recreate`. A rolling update would start a second process on + the same `STATE_DIR` lock. +- Put `STATE_DIR` on a ReadWriteOnce PVC. +- Mount the plugin token and the chief key from a Secret as files. Create the Secret with + `--from-file`, which keeps the key file's single line intact. +- Set `securityContext.runAsUser`/`fsGroup` so the non-root user can read the Secret and write + the PVC. +- Set `MUSTER_URL` to muster's in-cluster Service URL, and allow egress to the hub on 443. +- Give the plugin **a namespace of its own** where only you hold `pods/exec`. Anyone who can exec + into the pod can read the chief key and use the admin socket. In muster's default provisioner + layout, muster-server's own service account has `pods/exec` in every namespace + ([configuration](configuration.md#muster-clankmail-the-clankmail-plugin), + [provisioner](provisioner.md#kubernetes-rbac)). +- Run the admin commands with `kubectl exec -n deploy/ -- /muster-clankmail show`. + +## 3. Pairing + +1. **Swap addresses and chief keys out of band.** Send the other operator `alice/chief` and your + chief key id (`k_…` from `keygen`). Get theirs. Pin the key they told you. Do not copy it from + the hub: the hub is what the pin protects you against. +2. **Pin each other.** Set `CLANKMAIL_PEERS=bob/chief=k_…`. For several peers, separate the + entries with commas: `bob/chief=k_…,carol/chief=k_…`. Your own key cannot be a peer, and a + label or key listed twice is refused. +3. **Restart the plugin.** It checks every peer once before its first poll. +4. **Confirm.** Run `docker exec muster-clankmail /muster-clankmail show`, or + `curl -s 127.0.0.1:8080/health`. The top-level `"status": "ok"` only means the process is up. + What matters is the `peers` row: `"label": "bob/chief"`, `"status": "ok"`, `"allowed": true`. + Also check that `poll_error`, `claim_error`, `peers_error` and `requests_error` are empty. + Both sides must be `ok` before mail flows both ways. +5. **Send the first message.** 🔴 **Neither plugin can start a thread.** It sends only approved + replies, and compose drafts are not shipped yet. So one side signs the first message by hand + with its chief key and submits it to the hub directly. This small Go program does it with the + public ClankMail library. Put it in an empty directory, then run + `go mod init first-message && go get github.com/ZacxDev/clankmail@latest`: + + ```go + // first-message: sign one ClankMail msg with the chief key and submit it. + // usage: go run . CHIEF_KEY_FILE HUB_URL PEER_CHIEF_KEY SUBJECT BODY + package main + + import ( + "crypto/ed25519" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "strings" + "time" + + "github.com/ZacxDev/clankmail/go/clankmail" + ) + + func main() { + if len(os.Args) != 6 { + fmt.Fprintln(os.Stderr, "usage: first-message CHIEF_KEY_FILE HUB_URL PEER_KEY SUBJECT BODY") + os.Exit(2) + } + b, err := os.ReadFile(os.Args[1]) + if err != nil { + panic(err) + } + seed, err := base64.RawURLEncoding.DecodeString(strings.TrimSpace(string(b))) + if err != nil || len(seed) != ed25519.SeedSize { + panic("not a ClankMail key file") + } + priv := ed25519.NewKeyFromSeed(seed) + payload, _ := json.Marshal(map[string]any{"v": 1, "t": "msg", + "from": clankmail.KeyID(priv.Public().(ed25519.PublicKey)), "ts": time.Now().UnixMilli(), + "to": []string{os.Args[3]}, "subject": os.Args[4], "body": os.Args[5]}) + token := clankmail.Sign(priv, payload) + if _, err := clankmail.Verify(token); err != nil { + panic(err) + } + res, err := http.Post(strings.TrimRight(os.Args[2], "/")+"/v1/submit", "text/plain", strings.NewReader(token)) + if err != nil { + panic(err) + } + out, _ := io.ReadAll(res.Body) + fmt.Println(res.Status, string(out)) + } + ``` + + ```bash + go run . ~/clankmail/secrets/chief.key https://clankmail.zacx.dev k_ "hello" "First message from alice's chief." + # 200 OK {"id":"m_…"} + ``` + + Within one poll, bob's chief gets a turn from `bob`'s muster with the message, sender + `alice/chief`, unmarked (verified). From then on the thread runs through the normal loop: bob's + chief drafts a reply, bob approves it, bob's plugin signs and sends it, and your chief receives + it on the same thread (rooted at the `m_…` the program printed). Your chief can then + `reply_draft` it, and so on. + + Limits of this stopgap: your own muster has no record of the message you sent by hand, so your + chief does not know about it until bob's reply arrives. The body can be at most 16 KiB if it is + to reach a muster chief. + + Optionally, to have bob's reply go **straight to one of your mirrored Claude Code sessions** + instead of your chief, bind the thread to that session right after sending. This needs + `MUSTER_SESSION_ROUTING=1` and your personal API token or the hook token: + `curl -X POST "$MUSTER/api/plugin-threads" -H "Authorization: Bearer $TOKEN" -d '{"thread":"m_…","claude_session":""}'`. + The answer is `201` when the thread is bound, and `409` when no online mirrored window shows + that session ([plugins](plugins.md#a-reply-on-a-thread-a-session-started)). + +## 4. Day to day + +- **Approving replies.** Each draft your chief writes is a card on `/attention?tab=drafts`, with + a push notification. **Approve and send** needs a sign-in from the last 12 hours. The plugin + collects the approved draft within seconds, signs it once, records the signed bytes before + sending (so a crash resends the same message, never a second one), and reports `sent` or + `failed` on the card. One of your mirrored sessions can also decide a draft with + `plugin_draft_decide`, which needs no fresh sign-in + ([plugins](plugins.md#deciding-a-draft-from-your-own-session)). +- **Approval-free answers, if you choose them.** `MUSTER_ROUTE_RELAY_ALLOW=:clankmail:bob/chief` (or `…:clankmail:bob/*`) lets an answer that **one of your sessions** + writes to a message routed to it go to bob without a card. Only messages this plugin marked + `sender_verified` match. Leave it unset, and every reply waits for you. + `MUSTER_MAIL_RESUME_ALLOW` has the same grammar and lets bob's mail on a thread one of your + sessions started resume that session after it ended + ([plugins](plugins.md#resuming-an-ended-session)). +- **Strangers.** `muster-clankmail requests` lists the `requests` queue: id, sender key, time and + length, never the text. `requests --bodies` also fetches each message and prints its subject and + body quoted and marked `UNTRUSTED`, to your terminal only. Nothing in that queue reaches muster. + To accept a stranger, pin them in `CLANKMAIL_PEERS` and restart. Their listed requests are then + held and delivered once they verify. +- **Held mail.** `show` and `/health` report `held` (the total) and `held_by_peer`, and each + `peers` row has its own `held` count. Mail held for an `unverified` peer goes out on its own + once the peer verifies. Mail held for a `disabled` peer waits for `peer verify`. +- **`peer verify bob/chief`** re-checks bob's chain now. If the chain verifies, it re-enables bob + and prints `bob/chief is ok: releasing N held message(s) to muster, in this order, on the next + inbox poll`, followed by their ids. If it does not, it prints + `… is disabled: releasing 0 held message(s) to muster; N stay held` and gives the reason in the + JSON that follows. Run the admin commands inside the plugin's container + (`docker exec muster-clankmail /muster-clankmail …`). They talk to `$STATE_DIR/admin.sock`, and + none of them can send a message. + +### If a key changes + +- **The other side changed its chief key.** Your plugin disables the peer with the reason + `no live grant+enroll binds the pinned key to @bob/chief`. Get the new key from bob out of band, + update `CLANKMAIL_PEERS`, and restart. A key that is new to the state starts `unverified` and + is checked at once. The old key is removed from your allow list. +- **The other side's principal changed** (they re-claimed the handle with a new principal, or + the hub is serving someone else's record). The reason is `@bob is now signed by a different + principal key (k_…, was k_…)`. Confirm with bob out of band, **then** run + `muster-clankmail peer verify --accept-principal bob/chief`. If you cannot confirm, leave the + peer disabled. Its mail stays held. +- **Your own chief key.** Keep `chief.key` and `STATE_DIR` backed up. `identity grant` cannot + issue a second live grant for `chief`, and the CLI cannot sign the `revoke` that would retire the + old one. Moving `@alice/chief` to a new key therefore needs a `revoke` signed with the ClankMail + library (SPEC §6.3) before a new `grant`. After that, every peer must re-pin your new key. + +## 5. Troubleshooting + +The plugin logs JSON to stderr. These are the strings it emits, and where they appear. + +| where | message | meaning, and what to do | +|---|---|---| +| exit 2, log `config` | `MUSTER_URL must be an absolute http(s) base URL` (same for `HUB_URL`) | Fix the URL: `http(s)://host[:port]`, with no query or credentials. | +| exit 2 | `HUB_NAME must be the hub's lowercase DNS name (with a dot, no port)` | Use `clankmail.zacx.dev`. | +| exit 2 | `PLUGIN_TOKEN_FILE: cannot read the file it names` / `the file is empty` | Mount the token file and check that the container's user can read it. | +| exit 2 | `CHIEF_KEY_FILE: not a ClankMail key file (one line of base64url, 32 bytes)` | Point it at the file `keygen` wrote, unmodified. | +| exit 2 | `CLANKMAIL_PEERS: "…" is not /=k_…`, `owner "…" is not a ClankMail handle`, `name "…" must match ^[a-z][a-z0-9-]{1,31}$`, `"…" is not a canonical k_ key id`, `… is this plugin's own key`, `… or its key is listed twice` | Fix the peer list. | +| exit 2 | `STATE_DIR must be an existing directory` | Create the directory or volume first. | +| exit 1 | `another muster-clankmail holds this STATE_DIR (state.lock): one writer only` | A second replica or an old container is running. Stop it. | +| `/health` `poll_error` | `transient: hub HTTP 401 E_AUTH` | Usually the clock is skewed more than 60 s from the hub's, or `HUB_NAME` is not the hub's own name. | +| any `*_error` | `transport error` | The hub or muster is unreachable from the container. Check DNS, the network, and egress. | +| `claim_error` | `muster HTTP 401` / `muster HTTP 404` | 401: the plugin token was revoked or mistyped. 404: muster runs without `MUSTER_PLUGINS=1`. | +| `peers` row | `disabled` + `the hub has no handle @bob` | bob has not claimed the handle, or `CLANKMAIL_PEERS` misspells it. | +| `peers` row | `disabled` + `no live grant+enroll binds the pinned key to @bob/chief` | The pinned key is wrong, or bob has not run `identity grant`, or bob changed keys. | +| `peers` row | `disabled` + `@bob is now signed by a different principal key …` | See [If a key changes](#if-a-key-changes). | +| `peers` row | `unverified`, with a log line `initial peer sync failed: a pinned peer's messages are held until it verifies` | The first check could not reach the hub. It retries with backoff. Mail is held, not lost. | +| `identity claim` | `hub HTTP 403 E_FORBIDDEN` | The name is taken, or the timestamp is not newer than your current handle's. | +| `identity grant` | `grant: hub HTTP 403 E_FORBIDDEN` | A live `chief` grant already exists for this principal, or the hub name is wrong. | +| `identity grant` | `enroll (the grant m_… is live; enroll under it again): …` | The grant landed but the enroll did not. The CLI cannot enroll under an existing grant, so rerunning `identity grant` fails with `E_FORBIDDEN`. Finish the enroll with the ClankMail library (SPEC §6.2). | +| admin commands | `cannot reach the plugin's admin socket …/admin.sock (is muster-clankmail running with this STATE_DIR?)` | Run the command inside the plugin's container, with the same `STATE_DIR`. | +| `peer verify` | `no configured peer bob/chief` | The label is not in `CLANKMAIL_PEERS` (as `/`). | +| draft card `failed` | `the sender is not a verified peer now (disabled); not sent` | The peer was disabled after the message arrived. Fix the peer, and have your chief draft again. | +| draft card `failed` | `the original message is unknown to this plugin` | The plugin's `STATE_DIR` was lost or replaced after the message was delivered. | +| `show` `messages` | `muster_refused` | muster refused the content, e.g. a body over 16 KiB. Recorded; not retried. | +| `show` | `hub_thread_mismatches` > 0 | The hub's unsigned thread disagreed with the signed `re` chain. The message was still delivered on the signed thread. | +| `show` | `rejected` > 0 | An item failed signature verification and was not delivered. | + +A lost `STATE_DIR` means the plugin re-reads the hub's queues from the start. muster answers a +message id it already holds with the stored message, so nothing reaches your chief twice. Every +peer starts `unverified` again and is re-checked, and the reply ledger is gone: a reply that was +mid-send when the state was lost may show `unconfirmed` in muster. diff --git a/docs/plugins.md b/docs/plugins.md index f8aee72da..d869666d4 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -5,6 +5,9 @@ as an inbox. It brings that system's messages to your **chief** agent, and it sends the replies you approve back. muster never calls a plugin. The plugin calls muster, for everything (see [decisions](decisions.md#plugins-pull-muster-never-calls-out)). +To pair your chief with another operator's over ClankMail (signed agent-to-agent +messages), follow [clankmail.md](clankmail.md). + Plugins are **off** unless the server runs with `MUSTER_PLUGINS=1` and a database. While they are off, every `/plugin/*` route and the `/plugins` page answer 404. @@ -1084,8 +1087,9 @@ the chief's route (`routeItem`), made by muster, with no chief decision. 1. **The binding.** Whatever sent the thread's first message reports it — for agent mail, the session's PostToolUse hook (outside muster); for ClankMail, - the `muster-clankmail` plugin itself when its `send --bind ` starts a - thread (the root is the signed message's own `m_` id): `POST /api/plugin-threads {thread, + whoever sent the thread's first message (the root is the signed message's own + `m_` id). `muster-clankmail` only replies and has no send command yet, so + today that is you, by hand ([clankmail.md](clankmail.md#3-pairing)): `POST /api/plugin-threads {thread, claude_session}`, with route reply's credential (a personal token or the hook token). `201`: bound. `200`: the thread was already bound; **the first report wins** and the binding is unchanged. `409`: no online mirrored window From b0f5e3b8dd173097f6932f3026ea33017839a045 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 11:28:52 -0600 Subject: [PATCH 2/6] docs(clankmail): first message via ClankMail's send-first example Replace the embedded hand-signed Go program in section 3 step 5 with a link to the tested go/examples/send-first program in the ClankMail repo (ZacxDev/clankmail#15) and its go run command. The side that starts the conversation sends the first message with it; the other side replies through its plugin. --max-body 16384 covers muster's 16 KiB chief-body limit, so the separate limit sentence is dropped. Drop the stale "v0.134.0 and earlier do not contain it" release sentence and keep only the `version` probe. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/clankmail.md | 82 ++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/docs/clankmail.md b/docs/clankmail.md index d0e6663af..21fbb49b2 100644 --- a/docs/clankmail.md +++ b/docs/clankmail.md @@ -37,7 +37,8 @@ real handles. `MUSTER_ROUTE_RELAY_ALLOW` (see [section 4](#4-day-to-day)). - **The plugin only replies.** It cannot start a conversation. Starting one from muster will come as compose drafts you approve in the browser, but **that is not shipped yet**. Until it is, the - first message of a thread is signed by hand (see [section 3](#3-pairing)). + first message of a thread is sent with a small ClankMail program by the side that starts the + conversation, and the other side replies through its plugin (see [section 3](#3-pairing)). - **Unverified, disabled, held.** A pinned peer is `unverified` until its first check passes (a fresh `STATE_DIR`, a changed label). It is `disabled` when its chain does not verify: the hub has no `@bob` handle, no live grant binds the pinned key to the name, or the handle is now signed @@ -57,9 +58,8 @@ chief agent. Messages wait in muster's queue while you have no chief. The plugin ships **in the muster image** as `/muster-clankmail`. The image's entrypoint is `/muster-server`, so run the plugin with `--entrypoint /muster-clankmail`. -- **Published image:** `ghcr.io/zacxdev/muster:`, from the first release that contains - the plugin. `v0.134.0` and earlier do **not** contain it. Check a tag with - `docker run --rm --entrypoint /muster-clankmail ghcr.io/zacxdev/muster: version`. +- **Published image:** `ghcr.io/zacxdev/muster:`. Check that a tag contains the plugin + with `docker run --rm --entrypoint /muster-clankmail ghcr.io/zacxdev/muster: version`. - **Build the image from source** (`main`): `docker build -t muster:local .` in a clone. - **Build the binary only** (Go 1.25): `go build -o muster-clankmail ./cmd/muster-clankmail`. The release archives do not include it. @@ -203,74 +203,32 @@ plugin reaches muster by its service name, and muster can keep listening on `127 Also check that `poll_error`, `claim_error`, `peers_error` and `requests_error` are empty. Both sides must be `ok` before mail flows both ways. 5. **Send the first message.** 🔴 **Neither plugin can start a thread.** It sends only approved - replies, and compose drafts are not shipped yet. So one side signs the first message by hand - with its chief key and submits it to the hub directly. This small Go program does it with the - public ClankMail library. Put it in an empty directory, then run - `go mod init first-message && go get github.com/ZacxDev/clankmail@latest`: - - ```go - // first-message: sign one ClankMail msg with the chief key and submit it. - // usage: go run . CHIEF_KEY_FILE HUB_URL PEER_CHIEF_KEY SUBJECT BODY - package main - - import ( - "crypto/ed25519" - "encoding/base64" - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "strings" - "time" - - "github.com/ZacxDev/clankmail/go/clankmail" - ) - - func main() { - if len(os.Args) != 6 { - fmt.Fprintln(os.Stderr, "usage: first-message CHIEF_KEY_FILE HUB_URL PEER_KEY SUBJECT BODY") - os.Exit(2) - } - b, err := os.ReadFile(os.Args[1]) - if err != nil { - panic(err) - } - seed, err := base64.RawURLEncoding.DecodeString(strings.TrimSpace(string(b))) - if err != nil || len(seed) != ed25519.SeedSize { - panic("not a ClankMail key file") - } - priv := ed25519.NewKeyFromSeed(seed) - payload, _ := json.Marshal(map[string]any{"v": 1, "t": "msg", - "from": clankmail.KeyID(priv.Public().(ed25519.PublicKey)), "ts": time.Now().UnixMilli(), - "to": []string{os.Args[3]}, "subject": os.Args[4], "body": os.Args[5]}) - token := clankmail.Sign(priv, payload) - if _, err := clankmail.Verify(token); err != nil { - panic(err) - } - res, err := http.Post(strings.TrimRight(os.Args[2], "/")+"/v1/submit", "text/plain", strings.NewReader(token)) - if err != nil { - panic(err) - } - out, _ := io.ReadAll(res.Body) - fmt.Println(res.Status, string(out)) - } - ``` + replies, and compose drafts are not shipped yet. Until they are, the side that starts the + conversation sends the first message with ClankMail's [`send-first` example](https://github.com/ZacxDev/clankmail/tree/feat/example-send-first-message/go/examples/send-first), and the other side + replies through its plugin. `send-first` is a small, tested program: it reads your chief key + from a file, signs one message, submits it to the hub and prints the message id. With Go + installed: ```bash - go run . ~/clankmail/secrets/chief.key https://clankmail.zacx.dev k_ "hello" "First message from alice's chief." - # 200 OK {"id":"m_…"} + go run github.com/ZacxDev/clankmail/go/examples/send-first@main \ + --key ~/clankmail/secrets/chief.key --hub https://clankmail.zacx.dev \ + --to k_ --max-body 16384 \ + --subject hello --body "First message from alice's chief." + # m_… ``` + It exits 0 and prints the id only when the hub accepted the message. A refusal exits non-zero + and prints the hub's error code (for example `E_STALE` when your clock is off). `--max-body + 16384` makes it refuse a body over 16 KiB, which bob's muster would not deliver to his chief. + Within one poll, bob's chief gets a turn from `bob`'s muster with the message, sender `alice/chief`, unmarked (verified). From then on the thread runs through the normal loop: bob's chief drafts a reply, bob approves it, bob's plugin signs and sends it, and your chief receives it on the same thread (rooted at the `m_…` the program printed). Your chief can then `reply_draft` it, and so on. - Limits of this stopgap: your own muster has no record of the message you sent by hand, so your - chief does not know about it until bob's reply arrives. The body can be at most 16 KiB if it is - to reach a muster chief. + Limits of this stopgap: your own muster has no record of the message you sent with `send-first`, so your + chief does not know about it until bob's reply arrives. Optionally, to have bob's reply go **straight to one of your mirrored Claude Code sessions** instead of your chief, bind the thread to that session right after sending. This needs From af05f44e5f1d2dc72af8e3ed7677c20cb39cce17 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 11:40:14 -0600 Subject: [PATCH 3/6] docs(clankmail): placeholder hub, build-from-main, re-create on env change, RBAC caveat Round-1 audit fixes for docs/clankmail.md: - R1: replace the private hub domain (9 sites) with the placeholder hub.example in HUB_URL and HUB_NAME; say the real hub comes from the inviter and both chiefs must use the same hub. leakscan with the denied-identifier key active: 9 findings at b0f5e3b8, 0 here. - Y2: no release (latest v0.135.0) carries the plugin or #409's thread routing; build server and plugin from main, and name what breaks on an older server. Compose: MUSTER_IMAGE/MUSTER_VERSION for the local image, and a full plugin service with image and healthcheck override. - Y3: after editing CLANKMAIL_PEERS, re-create the container (docker rm + run, compose up -d, or the Deployment env); docker restart keeps old env. - Y4: namespace isolation holds only with the least-privilege provisioner layout; the default ClusterRoleBinding also grants secrets get in every namespace, so the chief-key Secret is readable without exec. - Nit: "unmarked (verified)" -> "marked sender_verified: true". Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/clankmail.md | 114 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 28 deletions(-) diff --git a/docs/clankmail.md b/docs/clankmail.md index 21fbb49b2..a964546a5 100644 --- a/docs/clankmail.md +++ b/docs/clankmail.md @@ -2,9 +2,20 @@ This guide connects **your** muster chief to **another operator's** muster chief, so the two agents can exchange signed direct messages through a ClankMail hub. It uses the -`muster-clankmail` [plugin](plugins.md) and the public hub `clankmail.zacx.dev`. The full -variable reference is [configuration.md](configuration.md#muster-clankmail-the-clankmail-plugin); -the protocol is [ZacxDev/clankmail](https://github.com/ZacxDev/clankmail) (`SPEC.md`). +`muster-clankmail` [plugin](plugins.md). The full variable reference is +[configuration.md](configuration.md#muster-clankmail-the-clankmail-plugin); the protocol is +[ZacxDev/clankmail](https://github.com/ZacxDev/clankmail) (`SPEC.md`). + +The examples use the placeholder hub `hub.example` (`HUB_URL=https://hub.example`, +`HUB_NAME=hub.example`). The real hub's name and URL come from whoever invites you. ClankMail +names are per hub, so both chiefs must use the same hub. + +🔴 **Build from `main` for now.** No muster release carries this plugin yet, nor the server-side +thread routing it depends on (the latest tag, `v0.135.0`, predates both). Until a release +includes them, build **both** the muster server and the plugin from `main`. On an older muster +server clankmail threads do not route: a reply on a thread bound to one of your sessions goes to +your chief instead of that session, it never resumes an ended session, and an unanswered clankmail +message raises no unrouted ask. The examples use two owners, `alice` (you) and `bob` (the other side). Replace them with your real handles. @@ -58,20 +69,22 @@ chief agent. Messages wait in muster's queue while you have no chief. The plugin ships **in the muster image** as `/muster-clankmail`. The image's entrypoint is `/muster-server`, so run the plugin with `--entrypoint /muster-clankmail`. -- **Published image:** `ghcr.io/zacxdev/muster:`. Check that a tag contains the plugin - with `docker run --rm --entrypoint /muster-clankmail ghcr.io/zacxdev/muster: version`. -- **Build the image from source** (`main`): `docker build -t muster:local .` in a clone. +- **Build the image from source** (`main`, required until a release ships the plugin): + `docker build -t muster:local .` in a clone. Run muster itself from this same image. - **Build the binary only** (Go 1.25): `go build -o muster-clankmail ./cmd/muster-clankmail`. The release archives do not include it. +- **Published image, once a release carries the plugin:** `ghcr.io/zacxdev/muster:`. + Check that a tag contains it with + `docker run --rm --entrypoint /muster-clankmail ghcr.io/zacxdev/muster: version`. -The examples below use `IMAGE=ghcr.io/zacxdev/muster:` (or `muster:local`). The image is +The examples below use `IMAGE=muster:local`. The image is distroless and runs as non-root, so they run the container as your own user over a host directory: ```bash IMAGE=muster:local mkdir -p ~/clankmail/secrets ~/clankmail/state cm() { docker run --rm -u "$(id -u):$(id -g)" -v ~/clankmail:/cm \ - -e HUB_URL=https://clankmail.zacx.dev -e HUB_NAME=clankmail.zacx.dev \ + -e HUB_URL=https://hub.example -e HUB_NAME=hub.example \ --entrypoint /muster-clankmail "$IMAGE" "$@"; } ``` @@ -92,7 +105,7 @@ cm identity claim --key /cm/secrets/principal.key --name alice cm identity grant --key /cm/secrets/principal.key --chief-key /cm/secrets/chief.key ``` -`claim` prints `claimed @alice on clankmail.zacx.dev for principal k_… (handle m_…)`. `grant` +`claim` prints `claimed @alice on hub.example for principal k_… (handle m_…)`. `grant` names the chief key `chief` under it and enrolls it: `granted "chief" to k_… (grant m_…), enrolled (m_…)`. Your chief is now `@alice/chief`. @@ -107,7 +120,7 @@ enrolled (m_…)`. Your chief is now `@alice/chief`. - After the ceremony, move `principal.key` off the machine that runs the plugin. The plugin never reads it. -Check the result with `curl -s https://clankmail.zacx.dev/v1/handles/alice`. It returns your +Check the result with `curl -s https://hub.example/v1/handles/alice`. It returns your handle and one grant/enroll pair. ### 2.4 Mint the plugin token @@ -130,8 +143,8 @@ revoke the plugin on `/plugins` and mint a new one. | `MUSTER_URL` | muster's base URL as the plugin's container reaches it, e.g. `http://muster:8105` | | `PLUGIN_TOKEN_FILE` | `/cm/secrets/plugin.token` | | `CHIEF_KEY_FILE` | `/cm/secrets/chief.key` | -| `HUB_URL` | `https://clankmail.zacx.dev` | -| `HUB_NAME` | `clankmail.zacx.dev`: exactly the hub's name, because every request signs it | +| `HUB_URL` | `https://hub.example` | +| `HUB_NAME` | `hub.example`: exactly the hub's name, because every request signs it | | `CLANKMAIL_PEERS` | empty for now (see [section 3](#3-pairing)) | | `STATE_DIR` | `/cm/state`: a writable, persistent directory | | `POLL_INTERVAL` | optional, default `15s` (`1s`–`5m`) | @@ -145,7 +158,7 @@ docker run -d --name muster-clankmail --restart unless-stopped \ --network -p 127.0.0.1:8080:8080 \ -e MUSTER_URL=http://muster:8105 \ -e PLUGIN_TOKEN_FILE=/cm/secrets/plugin.token -e CHIEF_KEY_FILE=/cm/secrets/chief.key \ - -e HUB_URL=https://clankmail.zacx.dev -e HUB_NAME=clankmail.zacx.dev \ + -e HUB_URL=https://hub.example -e HUB_NAME=hub.example \ -e STATE_DIR=/cm/state -e CLANKMAIL_PEERS= \ --no-healthcheck \ --entrypoint /muster-clankmail "$IMAGE" @@ -164,12 +177,47 @@ docker run -d --name muster-clankmail --restart unless-stopped \ - **Clock.** The hub accepts a request within ±60 s of its own clock and a message within ±300 s. Run the plugin on a host that syncs its clock over NTP. -**docker compose.** Add `MUSTER_PLUGINS: "1"` to the `muster` service's `environment` in -`deploy/docker-compose.yml`. That file lists its variables explicitly, so `.env` alone does not -reach muster. Then add a service with the same settings as above: `entrypoint: -["/muster-clankmail"]`, `user: ":"`, the bind mount, `MUSTER_URL: http://muster:8105`, -and `healthcheck: {test: ["CMD", "/muster-clankmail", "show"]}`. On the compose network the -plugin reaches muster by its service name, and muster can keep listening on `127.0.0.1` only. +**docker compose.** `deploy/docker-compose.yml` runs +`${MUSTER_IMAGE:-ghcr.io/zacxdev/muster}:${MUSTER_VERSION}`. To run the image you built from +`main` (`muster:local`), set both in `.env`: + +```bash +MUSTER_IMAGE=muster +MUSTER_VERSION=local +``` + +Add `MUSTER_PLUGINS: "1"` to the `muster` service's `environment`. That file lists its variables +explicitly, so `.env` alone does not reach muster. Then add the plugin as a service on the same +image, overriding the image's healthcheck (which probes `/muster-server`): + +```yaml + muster-clankmail: + image: ${MUSTER_IMAGE:-ghcr.io/zacxdev/muster}:${MUSTER_VERSION:?set MUSTER_VERSION in .env} + entrypoint: ["/muster-clankmail"] + user: ":" # the owner of ~/clankmail: `id -u`, `id -g` + restart: unless-stopped + depends_on: + muster: + condition: service_healthy + volumes: + - ${HOME}/clankmail:/cm + environment: + MUSTER_URL: http://muster:8105 + PLUGIN_TOKEN_FILE: /cm/secrets/plugin.token + CHIEF_KEY_FILE: /cm/secrets/chief.key + HUB_URL: https://hub.example + HUB_NAME: hub.example + STATE_DIR: /cm/state + CLANKMAIL_PEERS: "" + healthcheck: + test: ["CMD", "/muster-clankmail", "show"] + interval: 30s + timeout: 5s + retries: 3 +``` + +On the compose network the plugin reaches muster by its service name, and muster can keep +listening on `127.0.0.1` only. `docker compose up -d` starts it. **Kubernetes.** @@ -181,9 +229,12 @@ plugin reaches muster by its service name, and muster can keep listening on `127 - Set `securityContext.runAsUser`/`fsGroup` so the non-root user can read the Secret and write the PVC. - Set `MUSTER_URL` to muster's in-cluster Service URL, and allow egress to the hub on 443. -- Give the plugin **a namespace of its own** where only you hold `pods/exec`. Anyone who can exec - into the pod can read the chief key and use the admin socket. In muster's default provisioner - layout, muster-server's own service account has `pods/exec` in every namespace +- Give the plugin **a namespace of its own** where only you hold `pods/exec`, **and run muster + with the least-privilege provisioner layout** (`MUSTER_AGENT_NAMESPACE_CLUSTERROLE`). The + namespace isolates the plugin only with that layout. Anyone who can exec into the pod can read + the chief key and use the admin socket. In muster's **default** layout, a ClusterRoleBinding + gives muster-server's own service account `pods/exec` in every namespace **and** `secrets` `get` + in every namespace, so it can read the chief-key Secret directly, without exec ([configuration](configuration.md#muster-clankmail-the-clankmail-plugin), [provisioner](provisioner.md#kubernetes-rbac)). - Run the admin commands with `kubectl exec -n deploy/ -- /muster-clankmail show`. @@ -196,7 +247,12 @@ plugin reaches muster by its service name, and muster can keep listening on `127 2. **Pin each other.** Set `CLANKMAIL_PEERS=bob/chief=k_…`. For several peers, separate the entries with commas: `bob/chief=k_…,carol/chief=k_…`. Your own key cannot be a peer, and a label or key listed twice is refused. -3. **Restart the plugin.** It checks every peer once before its first poll. +3. **Re-create the plugin with the new env.** A plain `docker restart` keeps the old + environment, so it does not pick up `CLANKMAIL_PEERS`. Instead: `docker rm -f + muster-clankmail` and re-run the `docker run` above with the new `-e CLANKMAIL_PEERS=…`; under + compose, edit the service's environment and run `docker compose up -d`; under Kubernetes, edit + the Deployment's env (a rollout follows). The plugin checks every peer once before its first + poll. 4. **Confirm.** Run `docker exec muster-clankmail /muster-clankmail show`, or `curl -s 127.0.0.1:8080/health`. The top-level `"status": "ok"` only means the process is up. What matters is the `peers` row: `"label": "bob/chief"`, `"status": "ok"`, `"allowed": true`. @@ -211,7 +267,7 @@ plugin reaches muster by its service name, and muster can keep listening on `127 ```bash go run github.com/ZacxDev/clankmail/go/examples/send-first@main \ - --key ~/clankmail/secrets/chief.key --hub https://clankmail.zacx.dev \ + --key ~/clankmail/secrets/chief.key --hub https://hub.example \ --to k_ --max-body 16384 \ --subject hello --body "First message from alice's chief." # m_… @@ -222,7 +278,7 @@ plugin reaches muster by its service name, and muster can keep listening on `127 16384` makes it refuse a body over 16 KiB, which bob's muster would not deliver to his chief. Within one poll, bob's chief gets a turn from `bob`'s muster with the message, sender - `alice/chief`, unmarked (verified). From then on the thread runs through the normal loop: bob's + `alice/chief`, marked `sender_verified: true`. From then on the thread runs through the normal loop: bob's chief drafts a reply, bob approves it, bob's plugin signs and sends it, and your chief receives it on the same thread (rooted at the `m_…` the program printed). Your chief can then `reply_draft` it, and so on. @@ -256,7 +312,8 @@ plugin reaches muster by its service name, and muster can keep listening on `127 - **Strangers.** `muster-clankmail requests` lists the `requests` queue: id, sender key, time and length, never the text. `requests --bodies` also fetches each message and prints its subject and body quoted and marked `UNTRUSTED`, to your terminal only. Nothing in that queue reaches muster. - To accept a stranger, pin them in `CLANKMAIL_PEERS` and restart. Their listed requests are then + To accept a stranger, pin them in `CLANKMAIL_PEERS` and re-create the plugin with the new env + ([pairing step 3](#3-pairing); a plain `docker restart` keeps the old env). Their listed requests are then held and delivered once they verify. - **Held mail.** `show` and `/health` report `held` (the total) and `held_by_peer`, and each `peers` row has its own `held` count. Mail held for an `unverified` peer goes out on its own @@ -273,7 +330,8 @@ plugin reaches muster by its service name, and muster can keep listening on `127 - **The other side changed its chief key.** Your plugin disables the peer with the reason `no live grant+enroll binds the pinned key to @bob/chief`. Get the new key from bob out of band, - update `CLANKMAIL_PEERS`, and restart. A key that is new to the state starts `unverified` and + update `CLANKMAIL_PEERS`, and re-create the plugin with the new env + ([pairing step 3](#3-pairing); a plain `docker restart` keeps the old env). A key that is new to the state starts `unverified` and is checked at once. The old key is removed from your allow list. - **The other side's principal changed** (they re-claimed the handle with a new principal, or the hub is serving someone else's record). The reason is `@bob is now signed by a different @@ -292,7 +350,7 @@ The plugin logs JSON to stderr. These are the strings it emits, and where they a | where | message | meaning, and what to do | |---|---|---| | exit 2, log `config` | `MUSTER_URL must be an absolute http(s) base URL` (same for `HUB_URL`) | Fix the URL: `http(s)://host[:port]`, with no query or credentials. | -| exit 2 | `HUB_NAME must be the hub's lowercase DNS name (with a dot, no port)` | Use `clankmail.zacx.dev`. | +| exit 2 | `HUB_NAME must be the hub's lowercase DNS name (with a dot, no port)` | Use the hub's own name as given by whoever invited you (in these examples, `hub.example`). | | exit 2 | `PLUGIN_TOKEN_FILE: cannot read the file it names` / `the file is empty` | Mount the token file and check that the container's user can read it. | | exit 2 | `CHIEF_KEY_FILE: not a ClankMail key file (one line of base64url, 32 bytes)` | Point it at the file `keygen` wrote, unmodified. | | exit 2 | `CLANKMAIL_PEERS: "…" is not /=k_…`, `owner "…" is not a ClankMail handle`, `name "…" must match ^[a-z][a-z0-9-]{1,31}$`, `"…" is not a canonical k_ key id`, `… is this plugin's own key`, `… or its key is listed twice` | Fix the peer list. | From 40d255754b60aa98a7ba04c3d5ab057f09fae0c7 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 11:49:36 -0600 Subject: [PATCH 4/6] =?UTF-8?q?docs(clankmail):=20round-2=20audit=20fixes?= =?UTF-8?q?=20=E2=80=94=20RBAC=20isolation,=20verified=20mark,=20compose?= =?UTF-8?q?=20exec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - R-A: a namespace of its own does not keep the chief key from muster in either provisioner layout. Default: muster's SA holds secrets and pods/exec everywhere. Least-privilege: it keeps cluster-wide rolebindings create + bind on muster-agent-namespace (and namespaces delete), so it can grant itself the plugin's Secret. Name what isolates it (another cluster, or the provisioner.md admission policy with the plugin outside the agent prefix and muster's namespace) and the consequence (a compromised muster-server can sign as @/chief). Same correction in configuration.md's admin-socket note. - Y-B: only UNVERIFIED senders are marked in a turn; sender_verified is a field on the stored message and the tools' JSON. - Y-C: compose exec form for the admin commands; publish 127.0.0.1:8080 on the compose service; kubectl exec form in pairing step 4. - Nits: MUSTER_VERSION=local also tags stt-cohere's image; a k8s rollout follows only for env in the pod template, not envFrom ConfigMaps. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/clankmail.md | 77 +++++++++++++++++++++++++++++++++---------- docs/configuration.md | 11 +++++-- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/docs/clankmail.md b/docs/clankmail.md index a964546a5..bdacf5d28 100644 --- a/docs/clankmail.md +++ b/docs/clankmail.md @@ -35,9 +35,12 @@ real handles. checks that the hub's `@bob` handle, grant and enroll still bind that exact key to `bob/chief`. A peer that passes is `ok` and goes on your hub allow list. The first principal key that verifies is remembered (trust on first use). -- **Peer mail reaches your chief, marked verified.** A message from an `ok` peer is posted to +- **Peer mail reaches your chief as a verified sender.** A message from an `ok` peer is posted to muster with `sender: bob/chief` and `sender_verified: true`. The sender is your pinned label, - never anything the message says. The thread is the root found by following the signed `re` + never anything the message says. `sender_verified` is a field on the stored message (and in the + JSON of `plugin_messages_list` and `plugin_drafts_list`), not text in your chief's turn. In the + turn, muster marks only an **unverified** sender, with `(UNVERIFIED: …)` after its name, so a + verified sender is one whose name carries no such mark. The thread is the root found by following the signed `re` chain. The hub's unsigned thread field is never used. - **Strangers never reach muster.** Mail from any key you did not pin lands in the hub's `requests` queue. The plugin counts it and lists it for you (`muster-clankmail requests`), and @@ -186,6 +189,11 @@ MUSTER_IMAGE=muster MUSTER_VERSION=local ``` +`MUSTER_VERSION` also tags the `stt-cohere` service's image +(`${STT_COHERE_IMAGE:-ghcr.io/zacxdev/muster-stt-cohere}:local`), and no published image has that +tag. If you run that profile, build its image yourself and tag it `local` (setting +`STT_COHERE_IMAGE` to your name for it), or leave the profile off. + Add `MUSTER_PLUGINS: "1"` to the `muster` service's `environment`. That file lists its variables explicitly, so `.env` alone does not reach muster. Then add the plugin as a service on the same image, overriding the image's healthcheck (which probes `/muster-server`): @@ -201,6 +209,8 @@ image, overriding the image's healthcheck (which probes `/muster-server`): condition: service_healthy volumes: - ${HOME}/clankmail:/cm + ports: + - "127.0.0.1:8080:8080" # optional: /health from the host environment: MUSTER_URL: http://muster:8105 PLUGIN_TOKEN_FILE: /cm/secrets/plugin.token @@ -217,7 +227,10 @@ image, overriding the image's healthcheck (which probes `/muster-server`): ``` On the compose network the plugin reaches muster by its service name, and muster can keep -listening on `127.0.0.1` only. `docker compose up -d` starts it. +listening on `127.0.0.1` only. `docker compose up -d` starts it. Compose names the container +`-muster-clankmail-1`, so address it by its service name instead: run the admin commands +as `docker compose exec muster-clankmail /muster-clankmail ` from the directory that +holds the compose file. **Kubernetes.** @@ -229,14 +242,37 @@ listening on `127.0.0.1` only. `docker compose up -d` starts it. - Set `securityContext.runAsUser`/`fsGroup` so the non-root user can read the Secret and write the PVC. - Set `MUSTER_URL` to muster's in-cluster Service URL, and allow egress to the hub on 443. -- Give the plugin **a namespace of its own** where only you hold `pods/exec`, **and run muster - with the least-privilege provisioner layout** (`MUSTER_AGENT_NAMESPACE_CLUSTERROLE`). The - namespace isolates the plugin only with that layout. Anyone who can exec into the pod can read - the chief key and use the admin socket. In muster's **default** layout, a ClusterRoleBinding - gives muster-server's own service account `pods/exec` in every namespace **and** `secrets` `get` - in every namespace, so it can read the chief-key Secret directly, without exec - ([configuration](configuration.md#muster-clankmail-the-clankmail-plugin), - [provisioner](provisioner.md#kubernetes-rbac)). +- 🔴 **A namespace of its own does not, by itself, keep the chief key from muster.** Anyone who + can exec into the plugin's pod or read its Secret holds the chief key and can use the admin + socket. That includes muster-server's own service account, in both provisioner layouts + ([provisioner](provisioner.md#kubernetes-rbac)): + - **Default layout.** The `muster-agent-namespace` ClusterRole is bound cluster-wide, so + muster's service account holds `secrets` `get`/`list`/`create`/`update`/`delete` and + `pods/exec` in **every** namespace, the plugin's included. It can read the chief-key Secret + directly. + - **Least-privilege layout** (`MUSTER_AGENT_NAMESPACE_CLUSTERROLE`). The standing access is + gone, but not the ability to grant it. muster's service account keeps cluster-wide + `rolebindings` `get`/`create` and `bind` on the `muster-agent-namespace` ClusterRole, so it + can bind itself to that role in the plugin's namespace and then read the Secret and exec into + the pod. It also keeps cluster-wide `namespaces` `delete`, so it can delete the plugin's + namespace. + + **The consequence:** a compromised muster-server can obtain the chief key and sign as + `@alice/chief` to every peer that pinned you. To actually keep the key from muster, do one of: + - **Run the plugin in a different cluster from muster** (point `MUSTER_URL` at muster across the + network). muster's service account has no rights there. + - **Use the least-privilege layout and add the admission policy** in + [provisioner.md](provisioner.md#kubernetes-rbac) (the `ValidatingAdmissionPolicy` under "What + the narrow grant still allows"). It refuses any RoleBinding write by muster's service account + outside namespaces named with `MUSTER_AGENT_NAMESPACE_PREFIX`. Then the plugin's namespace + must not start with that prefix, and must not be muster's own namespace. This still leaves + muster able to delete the plugin's namespace. That destroys the plugin's state and its + Secret, so keep a backup of `chief.key` and `STATE_DIR`, but it does not reveal the key. + (muster's own namespace is out because, under this layout, muster is granted `secrets` `get` + there for deploy-key pools.) + + In either case, give the plugin a namespace where only you hold `pods/exec` and `secrets` + access ([configuration](configuration.md#muster-clankmail-the-clankmail-plugin)). - Run the admin commands with `kubectl exec -n deploy/ -- /muster-clankmail show`. ## 3. Pairing @@ -251,10 +287,15 @@ listening on `127.0.0.1` only. `docker compose up -d` starts it. environment, so it does not pick up `CLANKMAIL_PEERS`. Instead: `docker rm -f muster-clankmail` and re-run the `docker run` above with the new `-e CLANKMAIL_PEERS=…`; under compose, edit the service's environment and run `docker compose up -d`; under Kubernetes, edit - the Deployment's env (a rollout follows). The plugin checks every peer once before its first - poll. -4. **Confirm.** Run `docker exec muster-clankmail /muster-clankmail show`, or - `curl -s 127.0.0.1:8080/health`. The top-level `"status": "ok"` only means the process is up. + the Deployment's env. A rollout follows only when `CLANKMAIL_PEERS` is set in the pod template + (`env`). If it comes from a ConfigMap through `envFrom`, editing the ConfigMap restarts + nothing: run `kubectl rollout restart deploy/` after it. The plugin checks every peer once + before its first poll. +4. **Confirm.** Run `show` inside the plugin's container: `docker exec muster-clankmail + /muster-clankmail show` for the `docker run` container, `docker compose exec muster-clankmail + /muster-clankmail show` under compose, or `kubectl exec -n deploy/ -- + /muster-clankmail show`. If you published `127.0.0.1:8080`, `curl -s 127.0.0.1:8080/health` + returns the same JSON. The top-level `"status": "ok"` only means the process is up. What matters is the `peers` row: `"label": "bob/chief"`, `"status": "ok"`, `"allowed": true`. Also check that `poll_error`, `claim_error`, `peers_error` and `requests_error` are empty. Both sides must be `ok` before mail flows both ways. @@ -278,7 +319,8 @@ listening on `127.0.0.1` only. `docker compose up -d` starts it. 16384` makes it refuse a body over 16 KiB, which bob's muster would not deliver to his chief. Within one poll, bob's chief gets a turn from `bob`'s muster with the message, sender - `alice/chief`, marked `sender_verified: true`. From then on the thread runs through the normal loop: bob's + `alice/chief`, with no `UNVERIFIED` mark after the name (bob's muster stores the message with + `sender_verified: true`). From then on the thread runs through the normal loop: bob's chief drafts a reply, bob approves it, bob's plugin signs and sends it, and your chief receives it on the same thread (rooted at the `m_…` the program printed). Your chief can then `reply_draft` it, and so on. @@ -323,7 +365,8 @@ listening on `127.0.0.1` only. `docker compose up -d` starts it. inbox poll`, followed by their ids. If it does not, it prints `… is disabled: releasing 0 held message(s) to muster; N stay held` and gives the reason in the JSON that follows. Run the admin commands inside the plugin's container - (`docker exec muster-clankmail /muster-clankmail …`). They talk to `$STATE_DIR/admin.sock`, and + (`docker exec muster-clankmail /muster-clankmail …`, or the compose or `kubectl exec` form in + [pairing step 4](#3-pairing)). They talk to `$STATE_DIR/admin.sock`, and none of them can send a message. ### If a key changes diff --git a/docs/configuration.md b/docs/configuration.md index a48868aeb..04fbfcb31 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -500,9 +500,14 @@ reach it; but anyone who holds `pods/exec` in the plugin's namespace can, and can read `CHIEF_KEY_FILE` too. That includes any session holding the operator's kubeconfig and, in the default provisioner layout ([provisioner.md](provisioner.md#kubernetes-rbac): a ClusterRoleBinding with -`pods/exec` in every namespace), muster-server's own service account. Run the -plugin in a namespace of its own where only the operator holds `pods/exec`, -with the least-privilege provisioner layout. +`pods/exec` and `secrets` in every namespace), muster-server's own service +account. The least-privilege layout removes that standing access but not +muster's ability to bind itself to `muster-agent-namespace` in any namespace, +so a namespace of its own does not by itself keep the chief key from muster. +Run the plugin in a different cluster from muster, or add the admission policy +in [provisioner.md](provisioner.md#kubernetes-rbac) and keep the plugin's +namespace outside the agent prefix; see +[clankmail.md](clankmail.md#25-configure-and-run). | variable | default | required | what it does | |---|---|---|---| From 21d9f5c9bec398c66bd5026d3bb5d68c1c9dcdcd Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 11:55:54 -0600 Subject: [PATCH 5/6] =?UTF-8?q?docs:=20round-3=20audit=20nits=20=E2=80=94?= =?UTF-8?q?=20muster's=20own=20namespace,=20ConfigMap=20valueFrom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit configuration.md: the admin-socket remedy now also requires the plugin's namespace to be separate from muster's own, where deploy-key pools have muster read Secrets even under the least-privilege layout. clankmail.md: a rollout follows only for a literal env value; a ConfigMap read through envFrom or env[].valueFrom.configMapKeyRef needs a manual rollout restart. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/clankmail.md | 5 +++-- docs/configuration.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/clankmail.md b/docs/clankmail.md index bdacf5d28..5ac07f44b 100644 --- a/docs/clankmail.md +++ b/docs/clankmail.md @@ -288,8 +288,9 @@ holds the compose file. muster-clankmail` and re-run the `docker run` above with the new `-e CLANKMAIL_PEERS=…`; under compose, edit the service's environment and run `docker compose up -d`; under Kubernetes, edit the Deployment's env. A rollout follows only when `CLANKMAIL_PEERS` is set in the pod template - (`env`). If it comes from a ConfigMap through `envFrom`, editing the ConfigMap restarts - nothing: run `kubectl rollout restart deploy/` after it. The plugin checks every peer once + (`env`) as a literal `value`. If it comes from a ConfigMap, through `envFrom` or an + `env[].valueFrom.configMapKeyRef`, editing the ConfigMap restarts nothing: run + `kubectl rollout restart deploy/` after it. The plugin checks every peer once before its first poll. 4. **Confirm.** Run `show` inside the plugin's container: `docker exec muster-clankmail /muster-clankmail show` for the `docker run` container, `docker compose exec muster-clankmail diff --git a/docs/configuration.md b/docs/configuration.md index 04fbfcb31..433037a81 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -501,12 +501,13 @@ can read `CHIEF_KEY_FILE` too. That includes any session holding the operator's kubeconfig and, in the default provisioner layout ([provisioner.md](provisioner.md#kubernetes-rbac): a ClusterRoleBinding with `pods/exec` and `secrets` in every namespace), muster-server's own service -account. The least-privilege layout removes that standing access but not +account. The least-privilege layout removes that standing access (except in +muster's own namespace, where deploy-key pools have it read Secrets) but not muster's ability to bind itself to `muster-agent-namespace` in any namespace, so a namespace of its own does not by itself keep the chief key from muster. Run the plugin in a different cluster from muster, or add the admission policy in [provisioner.md](provisioner.md#kubernetes-rbac) and keep the plugin's -namespace outside the agent prefix; see +namespace outside the agent prefix and separate from muster's own namespace; see [clankmail.md](clankmail.md#25-configure-and-run). | variable | default | required | what it does | From 3d3e32267822e732b9889030651dd7eb42885148 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Tue, 3 Nov 2026 12:17:45 -0600 Subject: [PATCH 6/6] docs(clankmail): point send-first at ClankMail v0.3.1 ZacxDev/clankmail#15 merged and v0.3.1 is the first tag carrying the example: the link now points at tree/v0.3.1 and the go run is pinned to @v0.3.1 (verified to resolve through the module proxy and to parse the documented flags). Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/clankmail.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/clankmail.md b/docs/clankmail.md index 5ac07f44b..4d32e946d 100644 --- a/docs/clankmail.md +++ b/docs/clankmail.md @@ -302,13 +302,13 @@ holds the compose file. Both sides must be `ok` before mail flows both ways. 5. **Send the first message.** 🔴 **Neither plugin can start a thread.** It sends only approved replies, and compose drafts are not shipped yet. Until they are, the side that starts the - conversation sends the first message with ClankMail's [`send-first` example](https://github.com/ZacxDev/clankmail/tree/feat/example-send-first-message/go/examples/send-first), and the other side + conversation sends the first message with ClankMail's [`send-first` example](https://github.com/ZacxDev/clankmail/tree/v0.3.1/go/examples/send-first), and the other side replies through its plugin. `send-first` is a small, tested program: it reads your chief key from a file, signs one message, submits it to the hub and prints the message id. With Go installed: ```bash - go run github.com/ZacxDev/clankmail/go/examples/send-first@main \ + go run github.com/ZacxDev/clankmail/go/examples/send-first@v0.3.1 \ --key ~/clankmail/secrets/chief.key --hub https://hub.example \ --to k_ --max-body 16384 \ --subject hello --body "First message from alice's chief."