@agledger/cli 1.4.1 → 1.5.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/dist/oidc.js ADDED
@@ -0,0 +1,384 @@
1
+ /**
2
+ * OIDC cert credential: exchanges a customer IdP token for a short-lived,
3
+ * Server-signed cert (`POST /v1/auth/oidc/cert`) and signs request bodies with
4
+ * the key bound to it.
5
+ *
6
+ * Nothing here touches disk except reading a token file the operator named.
7
+ * The Ed25519 key pair lives in memory for the life of one credential (one CLI
8
+ * invocation), and the cert is cached in memory only. The token source is
9
+ * called for EVERY exchange: the Server refuses a token id it has already
10
+ * exchanged (409), so a token is never reused.
11
+ */
12
+ import { spawn } from 'node:child_process';
13
+ import { createHash, generateKeyPairSync, sign } from 'node:crypto';
14
+ import { readFile } from 'node:fs/promises';
15
+ /** Env vars the CLI reads a token source from. The MCP server reads the same names. */
16
+ export const OIDC_ENV = {
17
+ TOKEN_CMD: 'AGLEDGER_OIDC_TOKEN_CMD',
18
+ TOKEN_FILE: 'AGLEDGER_OIDC_TOKEN_FILE',
19
+ AGENT_ID: 'AGLEDGER_OIDC_AGENT_ID',
20
+ };
21
+ /**
22
+ * Env vars naming an RFC 8693 delegation token, sent as `AGLedger-On-Behalf-Of`
23
+ * when the work is done for a person or another party. The MCP server reads
24
+ * the same names.
25
+ */
26
+ export const ON_BEHALF_OF_ENV = {
27
+ CMD: 'AGLEDGER_ON_BEHALF_OF_CMD',
28
+ FILE: 'AGLEDGER_ON_BEHALF_OF_FILE',
29
+ };
30
+ /** The token source could not produce a token. `origin` names the variable or profile. */
31
+ export class OidcTokenSourceError extends Error {
32
+ origin;
33
+ kind;
34
+ constructor(message, origin, kind) {
35
+ super(message);
36
+ this.origin = origin;
37
+ this.kind = kind;
38
+ this.name = 'OidcTokenSourceError';
39
+ }
40
+ }
41
+ /** The Server refused the exchange. `body` is its error response with the token scrubbed out. */
42
+ export class OidcExchangeError extends Error {
43
+ status;
44
+ body;
45
+ origin;
46
+ constructor(message, status, body, origin) {
47
+ super(message);
48
+ this.status = status;
49
+ this.body = body;
50
+ this.origin = origin;
51
+ this.name = 'OidcExchangeError';
52
+ }
53
+ }
54
+ /** Bounds on a token command. Mutable so tests can shorten the timeout. */
55
+ export const TOKEN_COMMAND_LIMITS = {
56
+ timeoutMs: 60_000,
57
+ /** A JWT is a few KiB at most; anything past this is not one token. */
58
+ stdoutBytes: 64 * 1024,
59
+ };
60
+ const STDERR_LIMIT = 2_000;
61
+ /** A compact JWS: three base64url segments, the first a JSON header (`eyJ`). */
62
+ const JWT_PATTERN = /eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g;
63
+ /** Replace anything shaped like a JWT with a placeholder. Token command stderr
64
+ * and Server error bodies are surfaced to the user, and either can carry one. */
65
+ export function redactTokens(text) {
66
+ return text.replace(JWT_PATTERN, '<redacted-token>');
67
+ }
68
+ /** Deep-copy a JSON value with every string passed through `redactTokens`,
69
+ * and any string equal to or containing `token` replaced. The Server's
70
+ * validation errors echo the offending input back, which for this route is
71
+ * the OIDC token. */
72
+ export function scrub(value, token) {
73
+ if (typeof value === 'string') {
74
+ const cut = token && token.length > 0 ? value.split(token).join('<redacted-token>') : value;
75
+ return redactTokens(cut);
76
+ }
77
+ if (Array.isArray(value))
78
+ return value.map((v) => scrub(v, token));
79
+ if (value !== null && typeof value === 'object') {
80
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, scrub(v, token)]));
81
+ }
82
+ return value;
83
+ }
84
+ function runTokenCommand(source) {
85
+ return new Promise((resolve, reject) => {
86
+ // Detached puts the shell in its own process group, so a timeout can kill
87
+ // the whole pipeline (`a | b`) rather than only the shell and orphan the rest.
88
+ const child = spawn(source.command, { shell: true, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
89
+ let stdout = '';
90
+ let stderr = '';
91
+ let settled = false;
92
+ const fail = (message) => {
93
+ if (settled)
94
+ return;
95
+ settled = true;
96
+ clearTimeout(timer);
97
+ killGroup(child.pid);
98
+ reject(new OidcTokenSourceError(`${source.origin}: ${message}`, source.origin, source.kind));
99
+ };
100
+ const { timeoutMs, stdoutBytes } = TOKEN_COMMAND_LIMITS;
101
+ const timer = setTimeout(() => fail(`the token command did not finish within ${timeoutMs / 1000}s.`), timeoutMs);
102
+ child.stdout.setEncoding('utf8').on('data', (d) => {
103
+ stdout += d;
104
+ if (stdout.length > stdoutBytes) {
105
+ fail(`the token command printed more than ${stdoutBytes / 1024} KiB. Expected one JWT on stdout.`);
106
+ }
107
+ });
108
+ child.stderr.setEncoding('utf8').on('data', (d) => {
109
+ if (stderr.length < STDERR_LIMIT * 2)
110
+ stderr += d;
111
+ });
112
+ child.on('error', (err) => fail(`could not run the token command: ${err.message}`));
113
+ child.on('close', (code, signal) => {
114
+ if (settled)
115
+ return;
116
+ if (code === 0) {
117
+ settled = true;
118
+ clearTimeout(timer);
119
+ resolve(stdout);
120
+ return;
121
+ }
122
+ const trimmed = redactTokens(stderr.trim()).slice(0, STDERR_LIMIT);
123
+ const how = signal ? `was killed by ${signal}` : `exited ${code}`;
124
+ fail(`the token command ${how}${trimmed ? `. stderr: ${trimmed}` : ' with no stderr output.'}`);
125
+ });
126
+ });
127
+ }
128
+ /** SIGKILL a detached child's whole process group. Already gone is fine. */
129
+ function killGroup(pid) {
130
+ if (pid === undefined)
131
+ return;
132
+ try {
133
+ process.kill(-pid, 'SIGKILL');
134
+ }
135
+ catch {
136
+ // The group has exited.
137
+ }
138
+ }
139
+ async function readTokenFile(source) {
140
+ try {
141
+ return await readFile(source.path, 'utf8');
142
+ }
143
+ catch (err) {
144
+ const code = err.code;
145
+ throw new OidcTokenSourceError(`${source.origin}: cannot read the token file ${source.path}${typeof code === 'string' ? ` (${code})` : ''}.`, source.origin, source.kind);
146
+ }
147
+ }
148
+ const SUB_ROLE = {
149
+ 'cert-exchange': 'which the proof of possession for the cert exchange signs',
150
+ delegation: 'which names the party the work is done on behalf of',
151
+ };
152
+ /** Call the token source once and return a validated compact JWT plus its `sub` and payload. */
153
+ export async function fetchOidcToken(source, purpose = 'cert-exchange') {
154
+ const raw = source.kind === 'command' ? await runTokenCommand(source) : await readTokenFile(source);
155
+ const token = raw.trim();
156
+ const what = source.kind === 'command' ? 'the token command printed' : 'the token file holds';
157
+ if (token.length === 0) {
158
+ throw new OidcTokenSourceError(`${source.origin}: ${what} nothing. Expected one OIDC JWT.`, source.origin, source.kind);
159
+ }
160
+ const parts = token.split('.');
161
+ let payload = {};
162
+ if (parts.length === 3 && parts[1]) {
163
+ try {
164
+ const parsed = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
165
+ if (parsed !== null && typeof parsed === 'object')
166
+ payload = parsed;
167
+ }
168
+ catch {
169
+ payload = {};
170
+ }
171
+ }
172
+ else {
173
+ // Do not echo the output: if it is a token in some other shape, it would
174
+ // land in the error message.
175
+ throw new OidcTokenSourceError(`${source.origin}: ${what} ${token.length} characters that are not a compact JWT (header.payload.signature).`, source.origin, source.kind);
176
+ }
177
+ const sub = payload.sub;
178
+ if (typeof sub !== 'string' || sub.length === 0) {
179
+ throw new OidcTokenSourceError(`${source.origin}: the JWT has no readable \`sub\` claim, ${SUB_ROLE[purpose]}.`, source.origin, source.kind);
180
+ }
181
+ return { token, sub, payload };
182
+ }
183
+ /**
184
+ * One cert credential. Generates its key pair on construction, exchanges on
185
+ * first use, re-exchanges past the refresh point or when forced (a 401), and
186
+ * shares one in-flight exchange between concurrent callers.
187
+ */
188
+ export class OidcCertCredential {
189
+ source;
190
+ agentId;
191
+ refreshFraction;
192
+ log;
193
+ now;
194
+ fetchImpl;
195
+ userAgent;
196
+ timeoutMs;
197
+ privateKey;
198
+ publicKeyX;
199
+ certJws = null;
200
+ certInfo = null;
201
+ /** Local clock times, from when the cert was received: the Server's clock may differ. */
202
+ refreshAt = 0;
203
+ expiresAt = 0;
204
+ inflight = null;
205
+ exchanges = 0;
206
+ constructor(options) {
207
+ this.source = options.source;
208
+ this.agentId = options.agentId || undefined;
209
+ this.refreshFraction = options.refreshFraction ?? 0.5;
210
+ this.log = options.log ?? (() => { });
211
+ this.now = options.now ?? Date.now;
212
+ this.fetchImpl = options.fetch ?? ((...args) => fetch(...args));
213
+ this.userAgent = options.userAgent ?? 'agledger-cli';
214
+ this.timeoutMs = options.timeoutMs ?? 30_000;
215
+ const { publicKey, privateKey } = generateKeyPairSync('ed25519');
216
+ this.privateKey = privateKey;
217
+ const jwk = publicKey.export({ format: 'jwk' });
218
+ this.publicKeyX = jwk.x;
219
+ }
220
+ /** The cert from the most recent exchange, as the Server returned it. */
221
+ get cert() {
222
+ return this.certInfo;
223
+ }
224
+ /** How many exchanges this credential has performed. */
225
+ get exchangeCount() {
226
+ return this.exchanges;
227
+ }
228
+ /**
229
+ * A bearer for the next request: the cached cert, or a fresh one when none
230
+ * is held or the refresh point has passed. Pass `rejected` (the bearer the
231
+ * Server just refused with 401) to force a re-exchange; when a concurrent
232
+ * request has already replaced that cert, the replacement is returned
233
+ * instead of exchanging again.
234
+ */
235
+ async getToken(baseUrl, rejected) {
236
+ const forced = rejected !== undefined && rejected === this.certJws;
237
+ if (!forced && this.certJws !== null && this.now() < this.refreshAt)
238
+ return this.certJws;
239
+ if (!this.inflight) {
240
+ const reason = forced ? 'rejected-401' : this.certJws === null ? 'initial' : 'refresh-point';
241
+ this.inflight = this.exchange(baseUrl, reason).finally(() => {
242
+ this.inflight = null;
243
+ });
244
+ }
245
+ if (forced || this.certJws === null)
246
+ return this.inflight;
247
+ // A refresh-point exchange that fails (IdP down, a token file that has not
248
+ // rotated yet, 429, 5xx) is not fatal while the current cert is still
249
+ // valid: keep using it and try again on the next request.
250
+ const current = this.certJws;
251
+ try {
252
+ return await this.inflight;
253
+ }
254
+ catch (err) {
255
+ if (this.now() < this.expiresAt) {
256
+ // Back off before the next attempt so a stuck source is not re-run on
257
+ // every request (the exchange route is rate-limited per IP).
258
+ this.refreshAt = this.now() + Math.min(30_000, (this.expiresAt - this.now()) / 2);
259
+ this.log({
260
+ event: 'oidc-refresh-deferred',
261
+ source: this.source.origin,
262
+ reason: err instanceof Error ? err.message : String(err),
263
+ certExpiresInSeconds: Math.floor((this.expiresAt - this.now()) / 1000),
264
+ });
265
+ return current;
266
+ }
267
+ throw err;
268
+ }
269
+ }
270
+ /** The agent signature headers for a request body, over the exact bytes sent. */
271
+ signBody(body) {
272
+ const hex = createHash('sha256').update(body, 'utf8').digest('hex');
273
+ const signature = sign(null, Buffer.from(`agledger.agent.sig.v1\n${hex}`, 'utf8'), this.privateKey);
274
+ return {
275
+ 'X-Agent-Signature-Content-Hash': `sha256:${hex}`,
276
+ 'X-Agent-Signature': signature.toString('base64'),
277
+ };
278
+ }
279
+ async exchange(baseUrl, reason) {
280
+ const { token, sub } = await fetchOidcToken(this.source);
281
+ const proofOfPossession = sign(null, Buffer.from(`agledger.oidc.cert.v1\n${sub}`, 'utf8'), this.privateKey).toString('base64');
282
+ const body = {
283
+ oidcToken: token,
284
+ publicKeyJwk: { kty: 'OKP', crv: 'Ed25519', x: this.publicKeyX },
285
+ proofOfPossession,
286
+ ...(this.agentId ? { agentId: this.agentId } : {}),
287
+ };
288
+ const controller = new AbortController();
289
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
290
+ let res;
291
+ let parsed;
292
+ try {
293
+ res = await this.fetchImpl(`${baseUrl}/v1/auth/oidc/cert`, {
294
+ method: 'POST',
295
+ headers: {
296
+ Accept: 'application/json',
297
+ 'Content-Type': 'application/json',
298
+ 'User-Agent': this.userAgent,
299
+ },
300
+ body: JSON.stringify(body),
301
+ signal: controller.signal,
302
+ });
303
+ const text = await res.text();
304
+ try {
305
+ parsed = JSON.parse(text);
306
+ }
307
+ catch {
308
+ parsed = { _raw: text };
309
+ }
310
+ }
311
+ finally {
312
+ clearTimeout(timer);
313
+ }
314
+ if (!res.ok) {
315
+ const clean = scrub(parsed, token);
316
+ const detail = typeof clean.detail === 'string' ? clean.detail : typeof clean.message === 'string' ? clean.message : '';
317
+ // The Server exchanges a token id once. A token file returns the same
318
+ // token until whatever writes it rotates it, so every CLI run after the
319
+ // first lands here until then.
320
+ const reuseHint = res.status === 409 && this.source.kind === 'file'
321
+ ? ` The file at ${this.source.path} still holds a token this Server has already exchanged, and each token can be exchanged once. ` +
322
+ 'Run again after the file rotates, or set AGLEDGER_OIDC_TOKEN_CMD to a command that mints a new token each run (for example `kubectl create token <service-account>`).'
323
+ : '';
324
+ throw new OidcExchangeError(`OIDC cert exchange failed (token from ${this.source.origin}): POST /v1/auth/oidc/cert returned ${res.status}${detail ? `: ${detail}` : ''}${reuseHint ? `.${reuseHint}` : ''}`, res.status, clean, this.source.origin);
325
+ }
326
+ const out = parsed;
327
+ if (typeof out.certJws !== 'string' || !out.cert) {
328
+ throw new OidcExchangeError(`OIDC cert exchange failed (token from ${this.source.origin}): the ${res.status} response carried no certJws.`, res.status, scrub(parsed, token), this.source.origin);
329
+ }
330
+ const issued = Date.parse(String(out.cert.issuedAt));
331
+ const expires = Date.parse(String(out.cert.expiresAt));
332
+ const lifetime = Number.isFinite(issued) && Number.isFinite(expires) ? expires - issued : 0;
333
+ // The lifetime is the Server's (expiresAt - issuedAt), timed from local
334
+ // receipt, so a local clock that disagrees with the Server's neither
335
+ // re-exchanges on every request nor holds a cert past its end. A cert
336
+ // whose times do not parse is used for this request and re-exchanged next time.
337
+ const received = this.now();
338
+ this.refreshAt = lifetime > 0 ? received + this.refreshFraction * lifetime : 0;
339
+ this.expiresAt = lifetime > 0 ? received + lifetime : 0;
340
+ this.certJws = out.certJws;
341
+ this.certInfo = out.cert;
342
+ this.exchanges += 1;
343
+ this.log({
344
+ event: 'oidc-exchange',
345
+ reason,
346
+ source: this.source.origin,
347
+ certId: out.cert.id,
348
+ agentId: out.cert.agentId,
349
+ oidcSub: out.cert.oidcSub,
350
+ issuedAt: out.cert.issuedAt,
351
+ expiresAt: out.cert.expiresAt,
352
+ });
353
+ return out.certJws;
354
+ }
355
+ }
356
+ /**
357
+ * The delegation token for one invocation, read from its source on first use.
358
+ * Unlike the cert exchange, the Server never deduplicates a delegation token,
359
+ * so one is reused until shortly before its `exp` and then read again. A token
360
+ * with no `exp` is read again for every request, since nothing says how long
361
+ * it stays good.
362
+ */
363
+ export class DelegationToken {
364
+ source;
365
+ now;
366
+ cached = null;
367
+ constructor(source, now = Date.now) {
368
+ this.source = source;
369
+ this.now = now;
370
+ }
371
+ /** The token to send. `reread` skips the cache: the Server just refused the last one. */
372
+ async get(reread = false) {
373
+ if (!reread && this.cached && this.cached.expMs - this.now() > 30_000)
374
+ return this.cached.token;
375
+ const { token, payload } = await fetchOidcToken(this.source, 'delegation');
376
+ const exp = typeof payload.exp === 'number' ? payload.exp * 1000 : null;
377
+ if (exp !== null && exp <= this.now()) {
378
+ this.cached = null;
379
+ throw new OidcTokenSourceError(`${this.source.origin}: the delegation token expired at ${new Date(exp).toISOString()}. Supply a current one.`, this.source.origin, this.source.kind);
380
+ }
381
+ this.cached = exp === null ? null : { token, expMs: exp };
382
+ return token;
383
+ }
384
+ }
@@ -2,9 +2,21 @@
2
2
  * Profile storage at ~/.agledger/config.json. Credential-sensitive: directory 0700,
3
3
  * file 0600, chmodSync belt-and-braces for pre-existing files.
4
4
  */
5
+ /**
6
+ * Where `agledger login --oidc` finds an OIDC token. The source is stored,
7
+ * never a token, cert or key: each exchange calls the source again, because
8
+ * the Server accepts a token id only once.
9
+ */
10
+ export interface OidcProfileSource {
11
+ tokenCommand?: string;
12
+ tokenFile?: string;
13
+ agentId?: string;
14
+ }
15
+ /** A profile holds an API key or an OIDC token source. */
5
16
  export interface Profile {
6
- apiKey: string;
17
+ apiKey?: string;
7
18
  apiUrl?: string;
19
+ oidc?: OidcProfileSource;
8
20
  }
9
21
  export interface Config {
10
22
  profiles: Record<string, Profile>;
@@ -61,6 +61,12 @@
61
61
  "multiple": false,
62
62
  "type": "option"
63
63
  },
64
+ "verbose": {
65
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
66
+ "name": "verbose",
67
+ "allowNo": false,
68
+ "type": "boolean"
69
+ },
64
70
  "data": {
65
71
  "description": "Request body as a JSON string. For GET/DELETE, used as query parameters.",
66
72
  "name": "data",
@@ -136,7 +142,7 @@
136
142
  "auth": {
137
143
  "aliases": [],
138
144
  "args": {},
139
- "description": "Check current authentication status. Returns `authenticated: false` when no key is configured (exit 0).",
145
+ "description": "Check current authentication status, including the OIDC cert identity when a token source is configured. Returns `authenticated: false` when no credential is configured (exit 0).",
140
146
  "flags": {
141
147
  "json": {
142
148
  "description": "Force JSON output (default when stdout is piped)",
@@ -172,6 +178,12 @@
172
178
  "hasDynamicHelp": false,
173
179
  "multiple": false,
174
180
  "type": "option"
181
+ },
182
+ "verbose": {
183
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
184
+ "name": "verbose",
185
+ "allowNo": false,
186
+ "type": "boolean"
175
187
  }
176
188
  },
177
189
  "hasDynamicHelp": false,
@@ -251,6 +263,12 @@
251
263
  "hasDynamicHelp": false,
252
264
  "multiple": false,
253
265
  "type": "option"
266
+ },
267
+ "verbose": {
268
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
269
+ "name": "verbose",
270
+ "allowNo": false,
271
+ "type": "boolean"
254
272
  }
255
273
  },
256
274
  "hasDynamicHelp": false,
@@ -307,6 +325,12 @@
307
325
  "hasDynamicHelp": false,
308
326
  "multiple": false,
309
327
  "type": "option"
328
+ },
329
+ "verbose": {
330
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
331
+ "name": "verbose",
332
+ "allowNo": false,
333
+ "type": "boolean"
310
334
  }
311
335
  },
312
336
  "hasDynamicHelp": false,
@@ -369,6 +393,12 @@
369
393
  "multiple": false,
370
394
  "type": "option"
371
395
  },
396
+ "verbose": {
397
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
398
+ "name": "verbose",
399
+ "allowNo": false,
400
+ "type": "boolean"
401
+ },
372
402
  "full": {
373
403
  "description": "Fetch the expanded llms-full.txt narrative instead of the concise llms.txt.",
374
404
  "name": "full",
@@ -436,6 +466,12 @@
436
466
  "hasDynamicHelp": false,
437
467
  "multiple": false,
438
468
  "type": "option"
469
+ },
470
+ "verbose": {
471
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
472
+ "name": "verbose",
473
+ "allowNo": false,
474
+ "type": "boolean"
439
475
  }
440
476
  },
441
477
  "hasDynamicHelp": false,
@@ -492,6 +528,12 @@
492
528
  "hasDynamicHelp": false,
493
529
  "multiple": false,
494
530
  "type": "option"
531
+ },
532
+ "verbose": {
533
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
534
+ "name": "verbose",
535
+ "allowNo": false,
536
+ "type": "boolean"
495
537
  }
496
538
  },
497
539
  "hasDynamicHelp": false,
@@ -512,7 +554,12 @@
512
554
  "login": {
513
555
  "aliases": [],
514
556
  "args": {},
515
- "description": "Verify an API key and store it in ~/.agledger/config.json (0600)",
557
+ "description": "Verify an API key, or an OIDC token source with --oidc, and store it in ~/.agledger/config.json (0600)",
558
+ "examples": [
559
+ "<%= config.bin %> login --api-url https://agledger.internal --api-key agl_agt_... --profile prod",
560
+ "<%= config.bin %> login --oidc --api-url https://agledger.internal --oidc-token-cmd 'gcloud auth print-identity-token --audiences=agledger'",
561
+ "<%= config.bin %> login --oidc --api-url https://agledger.internal --oidc-token-file /var/run/secrets/tokens/agledger"
562
+ ],
516
563
  "flags": {
517
564
  "json": {
518
565
  "description": "Force JSON output (default when stdout is piped)",
@@ -549,6 +596,42 @@
549
596
  "hasDynamicHelp": false,
550
597
  "multiple": false,
551
598
  "type": "option"
599
+ },
600
+ "verbose": {
601
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
602
+ "name": "verbose",
603
+ "allowNo": false,
604
+ "type": "boolean"
605
+ },
606
+ "oidc": {
607
+ "description": "Store an OIDC token source instead of an API key. A token command is verified by one cert exchange and a GET /v1/auth/me before it is saved. A token file is only checked to hold a JWT: the Server exchanges each token once, so exchanging it here would leave the next command a spent token until the file rotates.",
608
+ "name": "oidc",
609
+ "allowNo": false,
610
+ "type": "boolean"
611
+ },
612
+ "oidc-token-cmd": {
613
+ "description": "With --oidc: a shell command whose stdout is an OIDC JWT, run on every cert exchange.",
614
+ "env": "AGLEDGER_OIDC_TOKEN_CMD",
615
+ "name": "oidc-token-cmd",
616
+ "hasDynamicHelp": false,
617
+ "multiple": false,
618
+ "type": "option"
619
+ },
620
+ "oidc-token-file": {
621
+ "description": "With --oidc: a file holding an OIDC JWT, read on every cert exchange (a projected token in a pod).",
622
+ "env": "AGLEDGER_OIDC_TOKEN_FILE",
623
+ "name": "oidc-token-file",
624
+ "hasDynamicHelp": false,
625
+ "multiple": false,
626
+ "type": "option"
627
+ },
628
+ "oidc-agent-id": {
629
+ "description": "With --oidc: the agent the cert binds to, when the token does not map to one itself.",
630
+ "env": "AGLEDGER_OIDC_AGENT_ID",
631
+ "name": "oidc-agent-id",
632
+ "hasDynamicHelp": false,
633
+ "multiple": false,
634
+ "type": "option"
552
635
  }
553
636
  },
554
637
  "hasDynamicHelp": false,
@@ -607,6 +690,12 @@
607
690
  "multiple": false,
608
691
  "type": "option"
609
692
  },
693
+ "verbose": {
694
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
695
+ "name": "verbose",
696
+ "allowNo": false,
697
+ "type": "boolean"
698
+ },
610
699
  "all": {
611
700
  "description": "Remove all profiles",
612
701
  "name": "all",
@@ -642,6 +731,7 @@
642
731
  "examples": [
643
732
  "<%= config.bin %> verify audit-export.json",
644
733
  "<%= config.bin %> verify audit-export.json --keys vault-keys.json",
734
+ "<%= config.bin %> verify audit-export.json --agent-keys agent-jwks.json",
645
735
  "<%= config.bin %> verify audit-export.json --json",
646
736
  "cat audit-export.json | <%= config.bin %> verify -"
647
737
  ],
@@ -681,6 +771,12 @@
681
771
  "multiple": false,
682
772
  "type": "option"
683
773
  },
774
+ "verbose": {
775
+ "description": "Report which credential was used, and each OIDC cert exchange, as JSON lines on stderr. Never prints a key, token or cert.",
776
+ "name": "verbose",
777
+ "allowNo": false,
778
+ "type": "boolean"
779
+ },
684
780
  "keys": {
685
781
  "description": "Path to a JSON file holding out-of-band public keys. Accepts a {keyId: SPKI-DER-base64} map, a [{keyId, publicKey, ...}] list, or the raw GET /v1/verification-keys response envelope ({data:[...], ...}, the .data array is unwrapped automatically). Merged over any keys embedded in the export.",
686
782
  "name": "keys",
@@ -688,6 +784,13 @@
688
784
  "multiple": false,
689
785
  "type": "option"
690
786
  },
787
+ "agent-keys": {
788
+ "description": "Path to a JSON file holding Ed25519 public keys of agent certs: a JWK, a list of JWKs, or a {keys:[...]} JWK Set (an entry may wrap its key as {publicKeyJwk:{...}}). Each is the publicKeyJwk an agent sent at cert exchange (also the cnf.jwk claim in its certJws). An entry whose sealed agent signature names one of them by thumbprint has that signature re-verified offline, and fails CHAIN_AGENT_SIGNATURE_INVALID if it does not verify.",
789
+ "name": "agent-keys",
790
+ "hasDynamicHelp": false,
791
+ "multiple": false,
792
+ "type": "option"
793
+ },
691
794
  "require-key-id": {
692
795
  "description": "Require every entry to reference this keyId. Rejects otherwise-valid exports signed by a retired or unexpected key.",
693
796
  "name": "require-key-id",
@@ -718,5 +821,5 @@
718
821
  ]
719
822
  }
720
823
  },
721
- "version": "1.4.1"
824
+ "version": "1.5.0"
722
825
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agledger/cli",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "AGLedger CLI: developer and agent interface for AGLedger",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "prepublishOnly": "npm run build && npm run lint:pkg"
32
32
  },
33
33
  "dependencies": {
34
- "@agledger/verify-core": "^1.4.0",
34
+ "@agledger/verify-core": "^1.5.0",
35
35
  "@oclif/core": "^5.0.0"
36
36
  },
37
37
  "devDependencies": {