docs · control plane
Run Keys and key custody#
Unreleased: after 0.11.0. Run Keys are on Hekma's main branch and ship in the next release; Hekma 0.11.0 does not have them. Key custody, Scent-Check Modes, bypass detection and the authenticated proxy beyond loopback are still planned, and their names, commands and defaults may change before they ship. See Status and roadmap.
A Run Key is a Run's own credential. Whoever holds it can act on that Run and the child Runs beneath it as the Run's Caller: open a child Run, close a child, and tighten limits. It cannot read the fleet, change configuration, set Policies, raise a limit, or touch any other Run.
A Run Key is not yet a replacement for your provider key: today the agent still holds the provider key you configured. Key custody, which puts the Run Key in the agent's API-key slot and keeps the real key inside Hekma, is planned (below).
What works on main#
| Area | What you get |
|---|---|
| A key per launch | Every supervised start, and every Restart Policy relaunch, issues a fresh Run Key and hands it to the agent in HEKMA_RUN_KEY. |
| A pair per child Run | POST /v0/runs (and hekma run open --print-key) returns the child's Run Key and a refresh credential, once. |
| Hash-only storage | Hekma stores the SHA-256 of each credential, never the value. A short token id (12 hex characters) labels it in records and reports. |
| Revocation | A key is revoked when its process exits, when its Run ends, after a refresh, when it shows up in a URL, and on demand with hekma run revoke-keys. The next request presenting it is refused. |
| Refresh with reuse detection | A refresh credential trades itself once for a new pair. Presenting a used one again — or seeing one in a URL — revokes the current pair of its own launch (for a Run opened over the Control API, the Run's current pair) and raises the credential-reuse Anomaly. |
| Secret references | secret:NAME keeps a provider key out of Hekma's config and output, but the agent receives the real key. See Secrets. |
The format#
hk_run_<52 characters> a Run Key
hk_ref_<52 characters> a refresh credential
hk_ann_<52 characters> an announce credential (format only; nothing issues one yet)Each is 32 bytes from the operating system's random source, written in Crockford base32. If the random source fails, nothing is issued and nothing changes: a start is refused before the agent is spawned, an open or refresh before anything is written. There is no fallback.
Shown once#
The value exists in three places only: the environment of the agent it was issued to, the 201 of the child open that asked for it, and the 200 of a refresh. No other route, event, SSE frame, export row, --json document or log line carries it, and nothing can show it again. A lost Run Key is replaced by a relaunch (a supervised agent) or a refresh, never re-read.
hekma run open --parent run_01JZ6Q9G3S8V2X7K4M1N5P0R2T --print-keyWithout --print-key, hekma run open issues no credential at all, so nothing lands in your terminal scrollback or CI logs. With it, the Run Key and refresh credential are printed once, with a note on stderr:
These credentials are shown once and are not stored. Keep them somewhere safe; `hekma run revoke-keys` revokes them.A supervised agent's key#
Every supervised agent gets its launch's Run Key in the HEKMA_RUN_KEY environment variable, so the agent and any in-process helper can open and close child Runs under it and tighten their limits through the Control API on loopback. An Adapter may also deliver it to its own environment variable by mapping the reserved run.key key with an env target; a flag or file target is refused at registration. See the manifest's reserved keys.
- A key per launch. A Restart Policy relaunch keeps the Run, its id, budgets and labels, and gets a new key. The previous launch's key is revoked when its process is confirmed exited, before the relaunch starts. Recording the exit and revoking the key are one write: if the revocation cannot be written, the exit is not recorded either. Issuing a launch's key also revokes anything an earlier launch of the Run still holds, so only one launch's key is ever live. An engine restart that adopts a live agent changes nothing: the agent keeps its key.
- Loopback only. A supervised agent's key, and its refresh credential if it has one, have no network use, so they are refused on a
--listenlistener that is not loopback. A listener bound to0.0.0.0counts as beyond loopback. Keys of Runs opened over the Control API are accepted there. - Never in a file or an argument. The key reaches only the agent's environment.
effective-config.jsonandhekma agent config getnever show it, and settingrun.keyorrun.refresh_keyin configuration is refused. - Children inherit it. Processes the agent starts inherit its environment,
HEKMA_RUN_KEYincluded. That is expected: they act within the same Run. - A short window at start. The key is recognised once the launch has been recorded, a few hundred milliseconds after spawn. A request in that window is refused as unknown; retry it.
- No refresh credential by default. A supervised agent gets one only if its Adapter maps
run.refresh_keyto anenvtarget. Its rotation is the relaunch. - Runs that started before Run Keys. An agent running when you upgrade keeps running without a key and gets one at its next launch.
hekma run keyssays so.
No clock expiry#
A Run Key does not expire on a timer: agents do not refresh an API key mid-run, and a supervised Run can last months. It is bounded instead by its process (revoked at exit), its Run (revoked at end), a refresh, an Operator revocation and URL exposure. The Run's budgets bound what it can spend.
Refresh#
curl -s -X POST -H "Authorization: Bearer $REFRESH_CREDENTIAL" http://127.0.0.1:<port>/v0/runs/refreshA refresh retires the presented credential, revokes its Run Key at once, and returns a new Run Key and refresh credential for the same Run. Possession is the binding: Hekma does not check which process presents it. A used refresh credential presented again revokes the current pair of its own launch (for a Run opened over the Control API, the Run's current pair), raises the credential-reuse Anomaly (listed by hekma ps), and answers 401 credential-revoked, so a silent takeover becomes a visible one. It also revokes every used refresh credential of the Run. A credential from an earlier launch never revokes a later launch's key. A used refresh credential also leaves service wherever the credentials it belonged to do: at its launch's exit, at its Run's end, and under a revoke-keys cascade. Seen in a URL it is reuse evidence — only a holder of the value can put it there — and takes the same response as presenting it: the current pair of its own launch is revoked, every used refresh credential of the Run is revoked, and the credential-reuse Anomaly is raised, so one unauthenticated request cannot quietly disarm the detection. hekma run revoke-keys on the Run acknowledges and clears the Anomaly, and revokes the Run's used refresh credentials too, so an old one found later in a log is a plain 401 credential-revoked that changes nothing.
Revocation#
hekma run keys run_01JZ6Q9G3S8V2X7K4M1N5P0R2T # token ids, classes, states; never a key
hekma run revoke-keys run_01JZ6Q9G3S8V2X7K4M1N5P0R2T # and every key issued under them
hekma run revoke-keys run_01JZ6Q9G3S8V2X7K4M1N5P0R2T --no-cascadeA revocation is committed and published before the command returns, so the very next request presenting the key is refused, and a hard kill of the Service Host cannot undo it. Like every write to state.db, it is not forced to disk on each commit: an operating-system crash or a power loss can lose the last moment of writes, a revocation included. After one, check with hekma run keys and revoke again if needed. By default it cascades: keys of child Runs opened with the revoked keys, and their refresh chains, are revoked too. Revocation never ends a Run; children opened under a revoked key stay open.
A Run that ends revokes its own keys; its child Runs that outlive it keep theirs. When a supervised agent's process exits and its Run ends, the in-process child Runs that end with it lose their keys in the same write as the exit. Removing an instance (hekma agent remove --force) removes its Runs and their keys with it.
Never in a URL#
Credentials go in the Authorization header. A request whose path or query carries one, raw or percent-encoded, is refused with 400 credential-in-url before it is authenticated, and the exposed credential is revoked: it has reached someone's access log. An active credential Hekma still honours is revoked. A used refresh credential is reuse evidence — only a holder of the value can put it in a URL — so it takes the same response as presenting it: the current pair of its own launch is revoked, every used refresh credential of the Run is revoked, and the credential-reuse Anomaly is raised. A value that was never issued, or is already revoked, is just refused. The scan keeps at most 16 distinct tokens per URL; a request carrying more is refused all the same, and a rate-limited diagnostic says how many could not be revoked. The per-agent metering listener applies the same rule: it answers a typed hekma_credential_in_url error, forwards nothing upstream, and the exposed credential is revoked a moment later. Between two checks the listener holds at most 64 distinct exposed values. Past that, or past the scan's own cap of 16 in one URL, it still refuses the request, and the next check writes a diagnostic saying how many it could not revoke; if one may be the Run's, run hekma run revoke-keys. The listener also strips any x-hekma-run-key header before forwarding a call to the provider.
External ids#
A child open's external_id makes a retry safe: the same id returns the same Run. Ids are scoped by who opens. The Operator and Hosts share one namespace; each Run's keys have their own, so a Run Key can neither take over nor discover an id the Operator or a Host uses.
What is coming#
Key custody#
When you configure a supervised agent's provider key through Hekma, custody will be the default. Hekma will put the Run Key in the agent's API-key slot and the proxy's address in its base URL. The real key will never appear in the agent's environment, arguments or Agent Home, and the proxy will send it only to its configured upstream origin, over HTTPS.
An agent that brings its own key cannot be identified on the wire. A self-reported one will show at Control Depth supervised (no wire), metered from its own reports and without wire controls; an engine-observed one will be refused at start.
Scent-Check Modes#
A Scent-Check Mode, set per Policy, will decide what happens to a call without a valid Run Key:
| Mode | An unscented call is |
|---|---|
off | Not checked. |
shadow | Served and recorded as an Anomaly: listed and counted in OTLP, never acting on the Run. |
enforce | Refused with a typed response. |
The default Policy starts at off, and enforce is never a default. Only off is accepted today. The mode governs identity only and never changes what a Breach Action does. A caller cannot lower it.
The shared proxy reading Run Keys#
A shared Metering Proxy will read the Run Key on each call, find the Run, apply its Policy and forward, refusing a revoked key from its next call. Calls held at the proxy will be re-checked when they are released.
Bypass detection#
The small supervisor that will own each supervised process (the Shim) will watch its process tree for direct connections to known provider hosts. A bypass will show as an Anomaly naming the Run and host, and as an OTLP counter; it never stops the Run. Where an OS gives no reliable signal, detection is reported as "unavailable", never as clean.
An authenticated proxy beyond loopback#
A proxy reachable from other machines will require TLS and a credential, and will not start without them. Clients that can only change their base URL will get a proxy-access credential per endpoint binding, shown once and stored as a hash; it is not a Run's identity for Scent-Check.
What it does not promise#
- A process running as your user can read the agent's environment, and could already act as the Operator through
control.json.state.dbholds only hashes, so a copy of it reveals no key. - An agent that prints its own environment to its output log puts its key there. Revoke it with
hekma run revoke-keys. - Possession is the only binding: whoever holds a Run Key or a refresh credential can use it.
- Key custody keeps the provider key away from the agent's process and files once it ships. It does not contain a compromised agent. Hekma is not a sandbox, and key custody will get a security review before these docs describe it as supported.
Open questions#
- The default Scent-Check Mode per environment. The proposal is
offon a laptop,shadowunder a long-running host, andenforceonly by choice. Until it is decided, the default Policy starts atoff, and the decision will never overwrite a default Policy you have edited.
Read next#
- Runs: what a Run is and the Control Depth ladder.
- Control API: the credential classes, the routes and the error codes.
- Commands:
hekma run keysandhekma run revoke-keys. - Policies: Selectors, limits and the default Policy.
- Meter token usage: the metering that works today.