@verax-ai/body 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/canary-cli.d.ts +5 -0
- package/dist/canary-cli.js +213 -0
- package/dist/cli.js +56 -2
- package/dist/config.d.ts +6 -0
- package/dist/config.js +1 -0
- package/dist/demo.js +3 -0
- package/dist/doctor.d.ts +11 -0
- package/dist/doctor.js +76 -2
- package/dist/downstream-pin.js +11 -1
- package/dist/downstream.d.ts +51 -0
- package/dist/downstream.js +329 -4
- package/dist/explain-cli.d.ts +5 -0
- package/dist/explain-cli.js +132 -0
- package/dist/init-local.d.ts +5 -0
- package/dist/init-local.js +1 -0
- package/dist/install.js +1 -1
- package/dist/policy-cli.d.ts +8 -0
- package/dist/policy-cli.js +169 -0
- package/dist/policy-rehearsal.d.ts +39 -0
- package/dist/policy-rehearsal.js +512 -0
- package/dist/server.js +38 -5
- package/dist/taint-cli.d.ts +5 -0
- package/dist/taint-cli.js +80 -0
- package/dist/wiring.d.ts +5 -0
- package/dist/wiring.js +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -31,12 +31,13 @@ Bearer token the configured issuer did not sign.
|
|
|
31
31
|
| `VERAX_ISSUER` | yes | Issuer the agent's token must carry. |
|
|
32
32
|
| `VERAX_JWKS_URL` | one of | Where the body fetches the keys that verify that token. Set this or `VERAX_JWKS_FILE`, not both. |
|
|
33
33
|
| `VERAX_JWKS_FILE` | one of | Path to a JWKS JSON file read once at start, instead of fetching `VERAX_JWKS_URL`. Accepted only with a loopback bind. |
|
|
34
|
+
| `VERAX_INSTALLED` | no | `1` when `verax install` wrote `verax.env`. A body without a JWKS file refuses the HTTP credential check; a body with a JWKS file refuses when this is `1`. Absent, a JWKS file is local mode and that check only warns. |
|
|
34
35
|
| `VERAX_AUDIENCE` | yes | Audience the token must name, so a token minted for something else is refused. Use the MCP URL, for example `https://verax.example/mcp`: a 401 then names the resource metadata a client reads to find the issuer. Any other string works for tokens, but the 401 carries a plain `Bearer` challenge and `verax doctor` warns. |
|
|
35
36
|
| `VERAX_STATE_DIR` | yes | Directory the ledger, keys and approvals live in. It stays on this machine. |
|
|
36
37
|
| `VERAX_POLICY_FILE` | yes | Policy the gate applies. `@verax-ai/proxy` ships `policy/default.json`, which denies what it does not name. |
|
|
37
38
|
| `VERAX_BIND` | no | `host:port` to listen on. Default `127.0.0.1:8787`; anything but loopback needs `VERAX_TLS_TERMINATED=1`. |
|
|
38
39
|
| `VERAX_INVENTORY_FILE` | no | Roster document the body serves. The format is `@verax-ai/inventory`. |
|
|
39
|
-
| `VERAX_DOWNSTREAM` | no | Path to a JSON document naming MCP servers to put behind this gate: one `{ prefix, command?, args?, cwd?, env?, url?, headers?, timeoutMs?, trust? }` or an array of them. Each child names exactly one way in — `command` to spawn it over stdio, or `url` to reach one already running over Streamable HTTP, with `headers`
|
|
40
|
+
| `VERAX_DOWNSTREAM` | no | Path to a JSON document naming MCP servers to put behind this gate: one `{ prefix, command?, args?, cwd?, env?, url?, headers?, timeoutMs?, trust?, unauthenticated? }` or an array of them. Each child names exactly one way in — `command` to spawn it over stdio, or `url` to reach one already running over Streamable HTTP. An HTTP child must require a credential that only the Verax service holds, set in `headers`. A body without a JWKS file, and a body with a JWKS file when `VERAX_INSTALLED=1` (`verax install` writes it into `verax.env`), refuses a child that has no such header, one that answers an initialize without those headers (`downstream-http-credential-required`), or one the probe cannot decide (`downstream-http-credential-undecided`). Only 401 and 403 count as the child refusing that initialize. `"unauthenticated": "acknowledged"` attaches it anyway. The probe sends the protocol version the real connection sends, reads the stream as it arrives, and counts only the message whose `id` is its request. A JSON-RPC `result` counts, `"error": null` included, and so does a 2xx that times out after the headers, passes 1 MiB, or does not parse. A JSON-RPC `error`, any other status, a connection error, or a timeout before the headers is undecided. The acknowledgement is part of the child's pin. `verax doctor --env-file <file>` loads that file the way `verax serve --env-file` does, fails when the probe sees a result or cannot decide, and warns for the acknowledgement. Doctor does not open `verax.env` unless the flag names it. `verax init --local` does not write `VERAX_INSTALLED` and only warns, including one line on stderr at attach. Verax can check that the downstream refuses an unauthenticated call; it cannot check where else the downstream's own credential is stored. A stdio child requires `"trust": "same-user"` (it runs as the same user as the body and can read the signing keys); an HTTP child does not ask for that field and must not carry it. This is a breaking change: existing stdio documents do not open until the field is added. A path and not the JSON itself, because the document may name a key in `env` or `headers`. Their tools are served as `prefix.childName` and need an exact policy rule under that name; a named child that cannot be opened stops the body. |
|
|
40
41
|
|
|
41
42
|
The agent's token is a JWT signed with ES256, EdDSA or RS256 by a key in that JWKS. An RSA key must be at least 2048 bits; HS256 and other shared-secret algorithms are refused.
|
|
42
43
|
It must carry `iss` (`VERAX_ISSUER`), `aud` (`VERAX_AUDIENCE`), `sub`, `iat`,
|
|
@@ -44,14 +45,16 @@ It must carry `iss` (`VERAX_ISSUER`), `aud` (`VERAX_AUDIENCE`), `sub`, `iat`,
|
|
|
44
45
|
without `jti` is refused with 401, because a revocation names a token by its
|
|
45
46
|
`jti`. Check that your issuer sets it on the tokens it gives agents.
|
|
46
47
|
|
|
47
|
-
`verax doctor` names what is missing.
|
|
48
|
-
|
|
48
|
+
`verax doctor` names what is missing. `verax doctor --env-file verax.env` reads
|
|
49
|
+
the file an install wrote; without that flag a `VERAX_DOWNSTREAM` that lives
|
|
50
|
+
only there is not checked. A misconfigured body exits with code 78 before it
|
|
51
|
+
listens.
|
|
49
52
|
|
|
50
53
|
## Run
|
|
51
54
|
|
|
52
55
|
```sh
|
|
53
56
|
verax # serve MCP at http://127.0.0.1:8787/mcp
|
|
54
|
-
verax doctor
|
|
57
|
+
verax doctor --env-file verax.env # same check, after loading that file
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
Point an MCP client at `http://127.0.0.1:8787/mcp` with a Bearer token from
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { chmodSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CANARY_FILE, CANARY_SHAPES, FileLedger, activeCanaryValue, addCanary, CanaryStoreError, listCanaries, retireCanary, tenantKey, } from "@verax-ai/proxy";
|
|
4
|
+
import { memoryQuotaBytes } from "./config.js";
|
|
5
|
+
import { restrictToOwnerWin32 } from "./install.js";
|
|
6
|
+
import { loadOrCreateSigners } from "./keys.js";
|
|
7
|
+
import { memoryStoreFor } from "./memory-store.js";
|
|
8
|
+
const USAGE = `verax canary add [--state <dir>] [--label <text>] [--shape api-key|bearer|password|card]
|
|
9
|
+
verax canary list [--state <dir>]
|
|
10
|
+
verax canary remove [--state <dir>] <id>
|
|
11
|
+
verax canary plant memory [--state <dir>] [--iss <iss>] [--sub <sub>] <id>
|
|
12
|
+
`;
|
|
13
|
+
function parseFlags(argv) {
|
|
14
|
+
const out = { state: null, label: null, shape: null, iss: null, sub: null, rest: [] };
|
|
15
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
16
|
+
const arg = argv[i];
|
|
17
|
+
if (arg === "--state" || arg === "--label" || arg === "--shape" || arg === "--iss" || arg === "--sub") {
|
|
18
|
+
const value = argv[i + 1];
|
|
19
|
+
if (value === undefined || value.startsWith("-"))
|
|
20
|
+
return { error: `missing value for ${arg}` };
|
|
21
|
+
const key = arg.slice(2);
|
|
22
|
+
if (out[key] !== null)
|
|
23
|
+
return { error: `duplicate ${arg}` };
|
|
24
|
+
out[key] = value;
|
|
25
|
+
i += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (arg.startsWith("-"))
|
|
29
|
+
return { error: `unknown option: ${arg}` };
|
|
30
|
+
out.rest.push(arg);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
function resolveState(flags, env) {
|
|
35
|
+
const dir = (flags.state ?? env.VERAX_STATE_DIR ?? "").trim();
|
|
36
|
+
if (dir === "")
|
|
37
|
+
return { error: "canary: set --state or VERAX_STATE_DIR", code: 78 };
|
|
38
|
+
try {
|
|
39
|
+
if (!statSync(dir).isDirectory())
|
|
40
|
+
return { error: "canary: state path is not a directory", code: 78 };
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { error: "canary: state directory is missing", code: 78 };
|
|
44
|
+
}
|
|
45
|
+
return dir;
|
|
46
|
+
}
|
|
47
|
+
/** POSIX mode 0600. Windows: the current user, Administrators and SYSTEM, as init --local does. */
|
|
48
|
+
function ownerOnly(path) {
|
|
49
|
+
if (process.platform === "win32") {
|
|
50
|
+
restrictToOwnerWin32(path);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
chmodSync(path, 0o600);
|
|
54
|
+
}
|
|
55
|
+
function asShape(raw) {
|
|
56
|
+
if (raw === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (CANARY_SHAPES.includes(raw))
|
|
59
|
+
return raw;
|
|
60
|
+
return "bad";
|
|
61
|
+
}
|
|
62
|
+
function storeForPlant(stateDir) {
|
|
63
|
+
try {
|
|
64
|
+
return memoryStoreFor(stateDir);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
if (!(err instanceof Error) || err.message !== "memory-store-unopened")
|
|
68
|
+
throw err;
|
|
69
|
+
const keys = loadOrCreateSigners(stateDir);
|
|
70
|
+
return memoryStoreFor(stateDir, {
|
|
71
|
+
publicKeyPem: keys.recordSigner.publicKeyPem,
|
|
72
|
+
privateKeyPem: keys.recordSigner.privateKeyPem,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function runCanary(argv, stdout, stderr, env) {
|
|
77
|
+
const command = argv[0];
|
|
78
|
+
if (command !== "add" && command !== "list" && command !== "remove" && command !== "plant") {
|
|
79
|
+
stderr.write(USAGE);
|
|
80
|
+
return 64;
|
|
81
|
+
}
|
|
82
|
+
const parsed = parseFlags(argv.slice(1));
|
|
83
|
+
if ("error" in parsed) {
|
|
84
|
+
stderr.write(`${parsed.error}\n`);
|
|
85
|
+
stderr.write(USAGE);
|
|
86
|
+
return 64;
|
|
87
|
+
}
|
|
88
|
+
const state = resolveState(parsed, env);
|
|
89
|
+
if (typeof state !== "string") {
|
|
90
|
+
stderr.write(`${state.error}\n`);
|
|
91
|
+
return state.code;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
if (command === "add") {
|
|
95
|
+
if (parsed.rest.length !== 0 || parsed.iss !== null || parsed.sub !== null) {
|
|
96
|
+
stderr.write(USAGE);
|
|
97
|
+
return 64;
|
|
98
|
+
}
|
|
99
|
+
const shape = asShape(parsed.shape);
|
|
100
|
+
if (shape === "bad") {
|
|
101
|
+
stderr.write("canary: shape must be api-key, bearer, password or card\n");
|
|
102
|
+
return 64;
|
|
103
|
+
}
|
|
104
|
+
const created = addCanary(state, {
|
|
105
|
+
...(parsed.label !== null ? { label: parsed.label } : {}),
|
|
106
|
+
...(shape !== undefined ? { shape } : {}),
|
|
107
|
+
});
|
|
108
|
+
try {
|
|
109
|
+
ownerOnly(join(state, CANARY_FILE));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
try {
|
|
113
|
+
retireCanary(state, created.id);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// The value stays in the file. It is not printed.
|
|
117
|
+
}
|
|
118
|
+
stderr.write("canary: owner-only failed\n");
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
stdout.write(`${created.id}\n${created.value}\n`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
if (command === "list") {
|
|
125
|
+
if (parsed.rest.length !== 0 || parsed.label !== null || parsed.shape !== null || parsed.iss !== null || parsed.sub !== null) {
|
|
126
|
+
stderr.write(USAGE);
|
|
127
|
+
return 64;
|
|
128
|
+
}
|
|
129
|
+
stdout.write("id\tlabel\tcreatedAt\tstatus\n");
|
|
130
|
+
for (const row of listCanaries(state)) {
|
|
131
|
+
stdout.write(`${row.id}\t${row.label.replace(/\t/g, " ")}\t${row.createdAt}\t${row.status}\n`);
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
if (command === "remove") {
|
|
136
|
+
if (parsed.rest.length !== 1 || parsed.label !== null || parsed.shape !== null || parsed.iss !== null || parsed.sub !== null) {
|
|
137
|
+
stderr.write(USAGE);
|
|
138
|
+
return 64;
|
|
139
|
+
}
|
|
140
|
+
const result = retireCanary(state, parsed.rest[0]);
|
|
141
|
+
if (result === "missing") {
|
|
142
|
+
stderr.write("canary-not-found\n");
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
ownerOnly(join(state, CANARY_FILE));
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
stderr.write("canary: owner-only failed\n");
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
stdout.write(`retired ${parsed.rest[0]}\n`);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
if (parsed.rest.length !== 2 || parsed.rest[0] !== "memory" || parsed.label !== null || parsed.shape !== null) {
|
|
156
|
+
stderr.write(USAGE);
|
|
157
|
+
return 64;
|
|
158
|
+
}
|
|
159
|
+
const id = parsed.rest[1];
|
|
160
|
+
const value = activeCanaryValue(state, id);
|
|
161
|
+
if (value === null) {
|
|
162
|
+
stderr.write("canary-not-found\n");
|
|
163
|
+
return 1;
|
|
164
|
+
}
|
|
165
|
+
let held;
|
|
166
|
+
try {
|
|
167
|
+
held = new FileLedger(state);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
const msg = err instanceof Error ? err.message : "";
|
|
171
|
+
if (msg.startsWith("ledger-locked")) {
|
|
172
|
+
stderr.write("canary-plant-body-running\n");
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const memoryId = `note-${id}`;
|
|
179
|
+
const principal = {
|
|
180
|
+
brain: parsed.sub ?? "local-agent",
|
|
181
|
+
iss: parsed.iss ?? "verax-local",
|
|
182
|
+
scopes: new Set(["verax:read", "verax:memory", "verax:act"]),
|
|
183
|
+
};
|
|
184
|
+
const store = storeForPlant(state);
|
|
185
|
+
const written = await store.put({
|
|
186
|
+
tenantKey: tenantKey(principal),
|
|
187
|
+
id: memoryId,
|
|
188
|
+
body: { title: "staging access", secret: value },
|
|
189
|
+
source: { uri: "note://staging-access", retrievedAtMs: 0 },
|
|
190
|
+
validFromMs: 0,
|
|
191
|
+
validUntilMs: 4_102_444_800_000,
|
|
192
|
+
putRef: `plant-${id}`,
|
|
193
|
+
quotaBytes: memoryQuotaBytes(),
|
|
194
|
+
});
|
|
195
|
+
if (!written.ok) {
|
|
196
|
+
stderr.write(`canary-plant-failed: ${written.error}\n`);
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
199
|
+
stdout.write(`planted ${memoryId}\n`);
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
held.close();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
if (err instanceof CanaryStoreError) {
|
|
208
|
+
stderr.write(`${err.message}\n`);
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -8,11 +8,13 @@ import { runApprove } from "./approve-cli.js";
|
|
|
8
8
|
import { attachBodyLog } from "./body-log.js";
|
|
9
9
|
import { bodyVersion } from "./body-version.js";
|
|
10
10
|
import { runDemo } from "./demo.js";
|
|
11
|
-
import { doctorBodyLog, doctorExit, runDoctor } from "./doctor.js";
|
|
11
|
+
import { doctorBodyLog, doctorExit, downstreamCredentialChecks, runDoctor } from "./doctor.js";
|
|
12
12
|
import { runDownstreamPin } from "./downstream-pin.js";
|
|
13
13
|
import { clearVeraxEnv, envFileJwksMissing, loadEnvFile, runInitLocal } from "./init-local.js";
|
|
14
14
|
import { clearCliCodeCheckPassed, defaultElevated, directoryAccess, doctorStateTarget, elevatedCommandCodeRefusal, linuxNodeLabelCheck, linuxSelinuxCheck, liveInstalledChecks, markCliCodeCheckPassed, runInstall, runUninstall, SystemToolError, unreadableSentence } from "./install.js";
|
|
15
|
+
import { runExplain } from "./explain-cli.js";
|
|
15
16
|
import { runHalt, runResume } from "./halt.js";
|
|
17
|
+
import { runTaint } from "./taint-cli.js";
|
|
16
18
|
import { main } from "./main.js";
|
|
17
19
|
import { runOperator } from "./operator-cli.js";
|
|
18
20
|
import { runAnchor } from "./anchor-cli.js";
|
|
@@ -22,8 +24,10 @@ import { runVerify } from "./verify-cli.js";
|
|
|
22
24
|
import { clearStaleLockAtStart, runUnlock } from "./unlock.js";
|
|
23
25
|
import { runWitness } from "./witness.js";
|
|
24
26
|
import { runWatch } from "./watch.js";
|
|
27
|
+
import { runCanary } from "./canary-cli.js";
|
|
25
28
|
import { runMemoryRehead } from "./memory-rehead-cli.js";
|
|
26
29
|
import { runMemoryReattest } from "./memory-reattest-cli.js";
|
|
30
|
+
import { runPolicy } from "./policy-cli.js";
|
|
27
31
|
const HELP = `verax - the body an agent asks before it acts, and the ledger it answers from.
|
|
28
32
|
|
|
29
33
|
Usage: verax <command> [options]
|
|
@@ -44,7 +48,11 @@ Usage: verax <command> [options]
|
|
|
44
48
|
uninstall [--keep-state]
|
|
45
49
|
stop that body and remove its code. Needs an elevated shell
|
|
46
50
|
and the same administrator-owned copy.
|
|
47
|
-
doctor [--json]
|
|
51
|
+
doctor [--json] [--env-file <file>]
|
|
52
|
+
check the configuration this process would run with.
|
|
53
|
+
--env-file loads that file the way serve does. An install
|
|
54
|
+
keeps VERAX_DOWNSTREAM in verax.env; doctor does not open
|
|
55
|
+
that file unless this flag names it.
|
|
48
56
|
downstream pin --file <file> --prefix <prefix>
|
|
49
57
|
list that child's tools once and, after a typed yes,
|
|
50
58
|
write a manifest beside the document. The document is not edited.
|
|
@@ -66,6 +74,11 @@ Usage: verax <command> [options]
|
|
|
66
74
|
report <stateDir> --from <YYYY-MM-DD> --to <YYYY-MM-DD> [--out <file.html>] [--json]
|
|
67
75
|
period counts from the ledger offline: decisions, approvals,
|
|
68
76
|
checkpoints, and the same verification verdict as verify
|
|
77
|
+
policy rehearse --policy <file> [--since <duration>] [--brain <id>] [--json] <stateDir>
|
|
78
|
+
re-evaluate recorded decisions under a policy that is not
|
|
79
|
+
switched on. Writes nothing and runs no tool.
|
|
80
|
+
Exit 0 when no rehearsed decision changes, 1 when a decision changes,
|
|
81
|
+
2 on usage or a read error.
|
|
69
82
|
anchor <stateDir> --service <url>
|
|
70
83
|
register each checkpoint's hash with a transparency service
|
|
71
84
|
someone else runs and keep its receipt for verify --anchor-key
|
|
@@ -73,6 +86,12 @@ Usage: verax <command> [options]
|
|
|
73
86
|
watch <stateDir> [--max-silence 30s] [--once] [--on-silence halt|exec] [--exec <command>]
|
|
74
87
|
halt on silence; --url <https://host/healthz> --token-file <path>
|
|
75
88
|
reports remotely (remote halt is out of scope)
|
|
89
|
+
explain <stateDir> <ref>
|
|
90
|
+
prints the decision and the reason. When the inputs name
|
|
91
|
+
a taint source, also the source and the rule
|
|
92
|
+
taint clear <stateDir> --session <jti>
|
|
93
|
+
clear that token's session taint. The body signs the
|
|
94
|
+
clear the next time it syncs. A tool call cannot do this.
|
|
76
95
|
halt <stateDir> stop the body from allowing anything further
|
|
77
96
|
resume <stateDir> lift a halt; who and when go to halt-history.jsonl
|
|
78
97
|
unlock [--force] <stateDir> clear a stale ledger lock
|
|
@@ -82,6 +101,14 @@ Usage: verax <command> [options]
|
|
|
82
101
|
memory rehead <stateDir>
|
|
83
102
|
write a signed head from the current commit chain.
|
|
84
103
|
The body must be stopped.
|
|
104
|
+
canary add [--state <dir>] [--label <text>] [--shape api-key|bearer|password|card]
|
|
105
|
+
create a canary and print the value once. State is --state or VERAX_STATE_DIR.
|
|
106
|
+
canary list [--state <dir>]
|
|
107
|
+
ids, labels and creation times. Never the values.
|
|
108
|
+
canary remove [--state <dir>] <id>
|
|
109
|
+
retire one canary. It no longer matches.
|
|
110
|
+
canary plant memory [--state <dir>] [--iss <iss>] [--sub <sub>] <id>
|
|
111
|
+
write that canary into memory as an ordinary note, through the memory store.
|
|
85
112
|
|
|
86
113
|
--help, -h print this
|
|
87
114
|
--version, -v print the version
|
|
@@ -98,6 +125,7 @@ const version = bodyVersion;
|
|
|
98
125
|
*/
|
|
99
126
|
const ANSWERED_BY_HELP = new Set([
|
|
100
127
|
"approve",
|
|
128
|
+
"canary",
|
|
101
129
|
"demo",
|
|
102
130
|
"desktop",
|
|
103
131
|
"doctor",
|
|
@@ -338,6 +366,19 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
338
366
|
await new Promise(() => { });
|
|
339
367
|
}
|
|
340
368
|
if (argv[0] === "doctor") {
|
|
369
|
+
const fileFlag = argv.indexOf("--env-file");
|
|
370
|
+
if (fileFlag !== -1) {
|
|
371
|
+
const file = argv[fileFlag + 1];
|
|
372
|
+
if (!file || file.startsWith("-")) {
|
|
373
|
+
stderr.write("verax doctor --env-file <file>\n");
|
|
374
|
+
return 78;
|
|
375
|
+
}
|
|
376
|
+
const loaded = loadEnvFile(file, env);
|
|
377
|
+
if (!loaded.ok) {
|
|
378
|
+
stderr.write(`${terminalText(loaded.reason)}\n`);
|
|
379
|
+
return 78;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
341
382
|
const json = argv.includes("--json");
|
|
342
383
|
const target = doctorStateTarget(env);
|
|
343
384
|
if (target && directoryAccess(target) === "unreadable") {
|
|
@@ -347,6 +388,7 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
347
388
|
const nodeLabel = process.platform === "linux" ? linuxNodeLabelCheck() : null;
|
|
348
389
|
const checks = [
|
|
349
390
|
...runDoctor(env, process.argv),
|
|
391
|
+
...(await downstreamCredentialChecks(env)),
|
|
350
392
|
...liveInstalledChecks(),
|
|
351
393
|
...(process.platform === "linux" ? [linuxSelinuxCheck()] : []),
|
|
352
394
|
...(nodeLabel ? [nodeLabel] : []),
|
|
@@ -370,6 +412,12 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
370
412
|
if (argv[0] === "verify") {
|
|
371
413
|
return runVerify(argv.slice(1), (s) => stdout.write(`${s}\n`));
|
|
372
414
|
}
|
|
415
|
+
if (argv[0] === "explain") {
|
|
416
|
+
return runExplain(argv.slice(1), stdout, stderr);
|
|
417
|
+
}
|
|
418
|
+
if (argv[0] === "taint") {
|
|
419
|
+
return runTaint(argv.slice(1), stdout, stderr);
|
|
420
|
+
}
|
|
373
421
|
if (argv[0] === "report") {
|
|
374
422
|
return runReport(argv.slice(1), (s) => stdout.write(`${s}\n`));
|
|
375
423
|
}
|
|
@@ -394,12 +442,18 @@ async function dispatchCli(argv, stdout, stderr, env) {
|
|
|
394
442
|
await runWitness(stateDir);
|
|
395
443
|
return 0;
|
|
396
444
|
}
|
|
445
|
+
if (argv[0] === "canary") {
|
|
446
|
+
return runCanary(argv.slice(1), stdout, stderr, env);
|
|
447
|
+
}
|
|
397
448
|
if (argv[0] === "memory") {
|
|
398
449
|
if (argv[1] === "rehead") {
|
|
399
450
|
return runMemoryRehead(argv.slice(1), stdout, stderr, env);
|
|
400
451
|
}
|
|
401
452
|
return runMemoryReattest(argv.slice(1), stdout, stderr, env);
|
|
402
453
|
}
|
|
454
|
+
if (argv[0] === "policy") {
|
|
455
|
+
return runPolicy(argv.slice(1), stdout, stderr);
|
|
456
|
+
}
|
|
403
457
|
const head = argv[0];
|
|
404
458
|
if (head !== undefined && !head.startsWith("--")) {
|
|
405
459
|
stderr.write(`unknown command: ${terminalText(head)}\n`);
|
package/dist/config.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export type BodyConfig = {
|
|
|
15
15
|
* Loopback binds only.
|
|
16
16
|
*/
|
|
17
17
|
jwksFile?: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* `verax install` writes `VERAX_INSTALLED=1` into verax.env. The HTTP
|
|
20
|
+
* credential check then refuses. Absent, a JWKS file is local mode and that
|
|
21
|
+
* check only warns.
|
|
22
|
+
*/
|
|
23
|
+
installed?: boolean;
|
|
18
24
|
/**
|
|
19
25
|
* JWKS captured once at desktop start. Verification uses this set and does
|
|
20
26
|
* not refetch `jwksUrl`. Null when the body should use the remote set.
|
package/dist/config.js
CHANGED
package/dist/demo.js
CHANGED
|
@@ -95,6 +95,9 @@ function writeConariumDownstream(stateDir, child) {
|
|
|
95
95
|
args: [...child.args],
|
|
96
96
|
trust: "same-user",
|
|
97
97
|
timeoutMs: CONARIUM_TIMEOUT_MS,
|
|
98
|
+
// The operator labelled this demonstration child as neither. An unlabelled
|
|
99
|
+
// child is reads-untrusted and egress, and the second query would be held.
|
|
100
|
+
labels: { query: [], list_tables: [] },
|
|
98
101
|
};
|
|
99
102
|
writeFileSync(path, `${JSON.stringify(document, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
100
103
|
return path;
|
package/dist/doctor.d.ts
CHANGED
|
@@ -11,6 +11,17 @@ export type DoctorOptions = {
|
|
|
11
11
|
keyOwner?: (path: string) => "self" | "other" | "unknown";
|
|
12
12
|
};
|
|
13
13
|
export declare function runDoctor(env: NodeJS.ProcessEnv, argv: readonly string[], opts?: DoctorOptions): DoctorCheck[];
|
|
14
|
+
/**
|
|
15
|
+
* One initialize per HTTP child, with none of its headers. `verax doctor`
|
|
16
|
+
* appends these to `runDoctor`. An acknowledged child is a warning. A child
|
|
17
|
+
* with no credential, or one the probe saw answer, fails
|
|
18
|
+
* `downstream-http-credential-required`. Any other outcome except 401 and
|
|
19
|
+
* 403 fails `downstream-http-credential-undecided`. Local mode, a JWKS file
|
|
20
|
+
* without `VERAX_INSTALLED=1`, only warns. A body with no JWKS file is not
|
|
21
|
+
* local mode. A child that refuses the probe (401 or 403) and carries a
|
|
22
|
+
* header adds nothing. Header values are not written here.
|
|
23
|
+
*/
|
|
24
|
+
export declare function downstreamCredentialChecks(env: NodeJS.ProcessEnv): Promise<DoctorCheck[]>;
|
|
14
25
|
/** Last 20 lines of `<stateDir>/body.log`, or a missing-file sentence. */
|
|
15
26
|
export declare function doctorBodyLog(stateDir: string): string;
|
|
16
27
|
/**
|
package/dist/doctor.js
CHANGED
|
@@ -3,10 +3,10 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { defaultElevated, readWindowsMachineRoots, SystemToolError, windowsAgentTokenPath, windowsFileOwner } from "./install.js";
|
|
5
5
|
import { readLogTail } from "./body-log.js";
|
|
6
|
-
import { indexCoverage, listPieceFiles } from "@verax-ai/proxy";
|
|
6
|
+
import { indexCoverage, listPieceFiles, loadPolicy, unlabelledDownstreamNames } from "@verax-ai/proxy";
|
|
7
7
|
import { loadConfig, isLoopbackHost } from "./config.js";
|
|
8
8
|
import { resourceMetadataUrl } from "./auth.js";
|
|
9
|
-
import { parseDownstreamDocument } from "./downstream.js";
|
|
9
|
+
import { httpCredentialFinding, httpCredentialIsLocal, parseDownstreamDocument, probeHttpDownstream } from "./downstream.js";
|
|
10
10
|
import { lockHolderAlive, lockState } from "@verax-ai/proxy";
|
|
11
11
|
import { readLockFile } from "./unlock.js";
|
|
12
12
|
import { pendingAnchors } from "./anchor-cli.js";
|
|
@@ -278,6 +278,31 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
+
let policyLabels = {};
|
|
282
|
+
let unlabelledMode = "both";
|
|
283
|
+
const policyPath = env.VERAX_POLICY_FILE?.trim() ?? "";
|
|
284
|
+
if (policyPath !== "") {
|
|
285
|
+
try {
|
|
286
|
+
const policy = loadPolicy(JSON.parse(readFileSync(policyPath, "utf8")));
|
|
287
|
+
policyLabels = policy.toolLabels ?? {};
|
|
288
|
+
unlabelledMode = policy.unlabelledDownstream ?? "both";
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
// A policy this process cannot read is already a failed start. Doctor
|
|
292
|
+
// does not invent labels for it.
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
for (const name of unlabelledDownstreamNames(specs, policyLabels)) {
|
|
296
|
+
const prefixOnly = !name.includes(".");
|
|
297
|
+
const detail = unlabelledMode === "neither"
|
|
298
|
+
? prefixOnly
|
|
299
|
+
? `${name} has no tool list, so a tool it does not label is unlabelled. The policy says an unlabelled downstream tool is neither reads-untrusted nor egress.`
|
|
300
|
+
: `${name} has no reads-untrusted or egress label in the downstream document or the policy`
|
|
301
|
+
: prefixOnly
|
|
302
|
+
? `${name} has no tool list, so a tool it does not label is unlabelled and is treated as reads-untrusted and egress`
|
|
303
|
+
: `${name} has no label in the downstream document or the policy, so it is treated as reads-untrusted and egress`;
|
|
304
|
+
checks.push({ id: `downstream-unlabelled:${name}`, level: "warn", detail });
|
|
305
|
+
}
|
|
281
306
|
}
|
|
282
307
|
catch (err) {
|
|
283
308
|
checks.push({
|
|
@@ -290,6 +315,55 @@ export function runDoctor(env, argv, opts = {}) {
|
|
|
290
315
|
checks.push(...jwksFileChecks(env, stateDir));
|
|
291
316
|
return checks;
|
|
292
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* One initialize per HTTP child, with none of its headers. `verax doctor`
|
|
320
|
+
* appends these to `runDoctor`. An acknowledged child is a warning. A child
|
|
321
|
+
* with no credential, or one the probe saw answer, fails
|
|
322
|
+
* `downstream-http-credential-required`. Any other outcome except 401 and
|
|
323
|
+
* 403 fails `downstream-http-credential-undecided`. Local mode, a JWKS file
|
|
324
|
+
* without `VERAX_INSTALLED=1`, only warns. A body with no JWKS file is not
|
|
325
|
+
* local mode. A child that refuses the probe (401 or 403) and carries a
|
|
326
|
+
* header adds nothing. Header values are not written here.
|
|
327
|
+
*/
|
|
328
|
+
export async function downstreamCredentialChecks(env) {
|
|
329
|
+
const downstreamPath = env.VERAX_DOWNSTREAM?.trim() ?? "";
|
|
330
|
+
if (downstreamPath === "")
|
|
331
|
+
return [];
|
|
332
|
+
let specs;
|
|
333
|
+
try {
|
|
334
|
+
specs = parseDownstreamDocument(readFileSync(downstreamPath, "utf8"));
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
const local = httpCredentialIsLocal({
|
|
340
|
+
jwksFile: env.VERAX_JWKS_FILE,
|
|
341
|
+
installed: env.VERAX_INSTALLED?.trim() === "1",
|
|
342
|
+
});
|
|
343
|
+
const checks = [];
|
|
344
|
+
for (const spec of specs) {
|
|
345
|
+
if (spec.url === undefined)
|
|
346
|
+
continue;
|
|
347
|
+
const outcome = await probeHttpDownstream(spec);
|
|
348
|
+
if (spec.unauthenticated === "acknowledged") {
|
|
349
|
+
checks.push({
|
|
350
|
+
id: `downstream-http-unauthenticated:${spec.prefix}`,
|
|
351
|
+
level: "warn",
|
|
352
|
+
detail: `child ${spec.prefix} is acknowledged as unauthenticated. An agent that can reach it can call it with no decision record.`,
|
|
353
|
+
});
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const finding = httpCredentialFinding(spec, outcome);
|
|
357
|
+
if (!finding)
|
|
358
|
+
continue;
|
|
359
|
+
checks.push({
|
|
360
|
+
id: finding.id,
|
|
361
|
+
level: local ? "warn" : "fail",
|
|
362
|
+
detail: finding.detail,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return checks;
|
|
366
|
+
}
|
|
293
367
|
function commandBase(command) {
|
|
294
368
|
const slash = Math.max(command.lastIndexOf("/"), command.lastIndexOf("\\"));
|
|
295
369
|
const base = (slash === -1 ? command : command.slice(slash + 1)).toLowerCase();
|
package/dist/downstream-pin.js
CHANGED
|
@@ -130,6 +130,10 @@ function showDifference(out, spec, tools, docDir) {
|
|
|
130
130
|
if (rec.prefix !== spec.prefix) {
|
|
131
131
|
say(out, escapeLine(`manifest prefix differs from ${spec.prefix}`));
|
|
132
132
|
}
|
|
133
|
+
const manifestAck = rec.unauthenticated === "acknowledged" ? "acknowledged" : null;
|
|
134
|
+
if (manifestAck !== (spec.unauthenticated ?? null)) {
|
|
135
|
+
say(out, escapeLine("manifest acknowledgement differs from the document"));
|
|
136
|
+
}
|
|
133
137
|
try {
|
|
134
138
|
if (canonical(rec.selected ?? null) !== canonical(spec.tools ?? null)) {
|
|
135
139
|
say(out, escapeLine("manifest selection differs from the document"));
|
|
@@ -255,7 +259,13 @@ export async function runDownstreamPin(input, io) {
|
|
|
255
259
|
}
|
|
256
260
|
if (answer !== "yes")
|
|
257
261
|
return 1;
|
|
258
|
-
const manifest = {
|
|
262
|
+
const manifest = {
|
|
263
|
+
v: 1,
|
|
264
|
+
prefix: spec.prefix,
|
|
265
|
+
selected: spec.tools ?? null,
|
|
266
|
+
tools,
|
|
267
|
+
...(spec.unauthenticated === "acknowledged" ? { unauthenticated: "acknowledged" } : {}),
|
|
268
|
+
};
|
|
259
269
|
let written;
|
|
260
270
|
try {
|
|
261
271
|
written = writeManifest(dirname(input.file), manifest);
|
package/dist/downstream.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export type DownstreamSpec = {
|
|
|
19
19
|
url?: string;
|
|
20
20
|
/** HTTP: headers the operator sends to the child, such as its own bearer. */
|
|
21
21
|
headers?: Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* HTTP only. The operator wrote that this child may be called with no
|
|
24
|
+
* credential. Absent, a body that enforces the check refuses a child that
|
|
25
|
+
* has no `headers`, that answers an initialize without them, or whose
|
|
26
|
+
* probe cannot decide.
|
|
27
|
+
*/
|
|
28
|
+
unauthenticated?: "acknowledged";
|
|
22
29
|
timeoutMs?: number;
|
|
23
30
|
/**
|
|
24
31
|
* stdio only. The operator wrote that this child runs as the same user
|
|
@@ -38,6 +45,11 @@ export type DownstreamSpec = {
|
|
|
38
45
|
* comparing definitions.
|
|
39
46
|
*/
|
|
40
47
|
pins?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Child tool name to labels. A key that is present is a label, including
|
|
50
|
+
* an empty list (neither). A missing key is unlabelled.
|
|
51
|
+
*/
|
|
52
|
+
labels?: Readonly<Record<string, readonly ("reads-untrusted" | "egress")[]>>;
|
|
41
53
|
};
|
|
42
54
|
export type DownstreamTool = {
|
|
43
55
|
name: string;
|
|
@@ -67,6 +79,45 @@ export declare function parseDownstreamJson(raw: string, bodyPublicKeyPems?: rea
|
|
|
67
79
|
* document at all — the operator wrote it, so it is honoured.
|
|
68
80
|
*/
|
|
69
81
|
export declare function parseDownstreamDocument(raw: string, bodyPublicKeyPems?: readonly string[]): DownstreamSpec[];
|
|
82
|
+
/**
|
|
83
|
+
* Talks to a server already running. The headers are the operator's, from the
|
|
84
|
+
* document — the body's own bearer is never forwarded, for the same
|
|
85
|
+
* confused-deputy reason the stdio child does not inherit `VERAX_*`.
|
|
86
|
+
*/
|
|
87
|
+
/** A non-empty header value is the credential the probe must not send. */
|
|
88
|
+
export declare function downstreamHasCredential(spec: DownstreamSpec): boolean;
|
|
89
|
+
/** What the headerless initialize came back as. Only 401 and 403 are `refused`. */
|
|
90
|
+
export type HttpProbeOutcome = "answered" | "refused" | "undecided";
|
|
91
|
+
/**
|
|
92
|
+
* Installed attach refuses this HTTP child. An acknowledgement is the only
|
|
93
|
+
* way past it. No header, or a JSON-RPC result (a 2xx the probe could not
|
|
94
|
+
* read counts the same way), is `downstream-http-credential-required`. Any
|
|
95
|
+
* other outcome is `downstream-http-credential-undecided`. A 401 or 403 with
|
|
96
|
+
* a header is not a finding.
|
|
97
|
+
*/
|
|
98
|
+
export declare function httpCredentialFinding(spec: DownstreamSpec, outcome: HttpProbeOutcome): {
|
|
99
|
+
id: string;
|
|
100
|
+
detail: string;
|
|
101
|
+
} | null;
|
|
102
|
+
/**
|
|
103
|
+
* Local mode only warns. `verax install` sets `installed` (`VERAX_INSTALLED=1`
|
|
104
|
+
* in verax.env). A JWKS file without that flag is `verax init --local`, not an install.
|
|
105
|
+
*/
|
|
106
|
+
export declare function httpCredentialIsLocal(input: {
|
|
107
|
+
jwksFile?: string | null;
|
|
108
|
+
installed?: boolean;
|
|
109
|
+
}): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* One `initialize`, the same one `httpDownstreamClient` sends, and none of
|
|
112
|
+
* the operator's headers. When the answer carries `Mcp-Session-Id`, one
|
|
113
|
+
* `DELETE` for that session, again with none of those headers. A JSON-RPC
|
|
114
|
+
* result means the child is reachable with no credential. A 2xx the probe
|
|
115
|
+
* cannot read counts the same way. Only 401 and 403 are a refusal. Every
|
|
116
|
+
* other outcome (another status, a JSON-RPC error, a connection error, a
|
|
117
|
+
* timeout before the headers) is undecided. Header values are not sent and
|
|
118
|
+
* are not written into an error.
|
|
119
|
+
*/
|
|
120
|
+
export declare function probeHttpDownstream(spec: DownstreamSpec): Promise<HttpProbeOutcome>;
|
|
70
121
|
/**
|
|
71
122
|
* Connects the child once, takes `tools/list` under the same bounds as
|
|
72
123
|
* `openDownstream`, collects stderr, and closes. The returned tools are the
|