owenloop 0.4.1 → 0.5.1
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/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Credential WRITE + OAuth refresh library surface.
|
|
3
3
|
*
|
|
4
4
|
* Extracted from `src/cli.ts` (where these were module-private) so external
|
|
5
|
-
* consumers — a future `owenloop mcp` stdio server, an `
|
|
5
|
+
* consumers — a future `owenloop mcp` stdio server, an `owenloop work join` command —
|
|
6
6
|
* can store credentials and keep an OAuth access token fresh without depending
|
|
7
7
|
* on the CLI module. The exported `storeCredential` / `deleteCredential` /
|
|
8
8
|
* `ensureFreshOAuth` are re-imported by `cli.ts`, so every existing subcommand
|
|
@@ -33,9 +33,10 @@ import type { Credential, CredentialSlotSelector, Keychain } from './hub.ts';
|
|
|
33
33
|
export interface CredentialIO {
|
|
34
34
|
env: Record<string, string | undefined>;
|
|
35
35
|
/**
|
|
36
|
-
* OS
|
|
37
|
-
*
|
|
38
|
-
* failure is a hard error, never a
|
|
36
|
+
* OS Keychain backend. `OWENLOOP_NO_KEYCHAIN=1` excludes this backend from
|
|
37
|
+
* ordinary reads and writes, but defensive logout still inspects and clears
|
|
38
|
+
* an injected backend. A keychain write failure is a hard error, never a
|
|
39
|
+
* silent file fallback (REL-6).
|
|
39
40
|
*/
|
|
40
41
|
keychain?: Keychain;
|
|
41
42
|
/** Injectable for hermetic tests — the OAuth-refresh network calls use this. */
|
|
@@ -182,13 +183,19 @@ export interface MintAgentResult {
|
|
|
182
183
|
id: string;
|
|
183
184
|
/** The minted agent's id — a non-secret handle. */
|
|
184
185
|
agentId: string;
|
|
185
|
-
/** Resolved
|
|
186
|
-
|
|
186
|
+
/** Resolved crew NAMES from the server. */
|
|
187
|
+
crews: string[];
|
|
188
|
+
/**
|
|
189
|
+
* The minted token's scopes — the client-resolved request value (the H3 route
|
|
190
|
+
* requires non-empty scopes and honors them verbatim, so request == minted).
|
|
191
|
+
* Non-secret; lets callers print the truth instead of a hard-coded literal.
|
|
192
|
+
*/
|
|
193
|
+
scopes: string[];
|
|
187
194
|
/** Which local backend the token landed in. */
|
|
188
195
|
storage: 'keychain' | 'file';
|
|
189
196
|
}
|
|
190
197
|
/**
|
|
191
|
-
* Mint a new
|
|
198
|
+
* Mint a new Scoped Identity on `origin` as the human `cred` and persist the
|
|
192
199
|
* returned `olp_` token to slot `agent:<name>`. CLI-free (no `Args`, no exit
|
|
193
200
|
* codes — the caller maps failures to exit codes) so both `owenloop agent new`
|
|
194
201
|
* (O3) and `owenloop mcp`'s `create_agent` (O2) can reuse it.
|
|
@@ -209,12 +216,12 @@ export interface MintAgentResult {
|
|
|
209
216
|
* today; explicit for symmetry with the store/refresh signatures).
|
|
210
217
|
* @param params.scopes defaults to `['work']` — the H3 route REQUIRES a
|
|
211
218
|
* non-empty `scopes`; an empty list is server-refused.
|
|
212
|
-
* @param params.
|
|
213
|
-
* personal
|
|
219
|
+
* @param params.crews omitted when absent so the server defaults to the minter's
|
|
220
|
+
* personal crew (`crews: []` is server-refused with `crew_invalid`).
|
|
214
221
|
*/
|
|
215
222
|
export declare function mintAgentCredential(io: CredentialIO, origin: string, humanSlot: CredentialSlotSelector, cred: Credential, params: {
|
|
216
223
|
name: string;
|
|
217
|
-
|
|
224
|
+
crews?: string[];
|
|
218
225
|
scopes?: string[];
|
|
219
226
|
}): Promise<MintAgentResult>;
|
|
220
227
|
/**
|
|
@@ -224,8 +231,8 @@ export declare function mintAgentCredential(io: CredentialIO, origin: string, hu
|
|
|
224
231
|
*
|
|
225
232
|
* `revokedTokenIds` are the ids the rekey invalidated server-side — the OLD
|
|
226
233
|
* installation's credential(s). Their presence is the honest signal that any
|
|
227
|
-
* still-running copy of this agent elsewhere is now disconnected. No `
|
|
228
|
-
* field: rekey changes no
|
|
234
|
+
* still-running copy of this agent elsewhere is now disconnected. No `crews`
|
|
235
|
+
* field: rekey changes no crew membership.
|
|
229
236
|
*/
|
|
230
237
|
export interface RekeyAgentResult {
|
|
231
238
|
/** New token id — a non-secret revocation handle. */
|
|
@@ -240,14 +247,14 @@ export interface RekeyAgentResult {
|
|
|
240
247
|
storage: 'keychain' | 'file';
|
|
241
248
|
}
|
|
242
249
|
/**
|
|
243
|
-
* Re-key an EXISTING
|
|
250
|
+
* Re-key an EXISTING Scoped Identity on `origin` as the human `cred`: the hub
|
|
244
251
|
* mints a fresh `olp_` token for `agentId`, REVOKES the identity's current
|
|
245
252
|
* token(s), and this function persists the new token into the SAME
|
|
246
253
|
* `agent:<name>` slot — overwriting the old one. Sibling of
|
|
247
254
|
* `mintAgentCredential` with the identical §6 discipline; the only shape
|
|
248
255
|
* differences are the endpoint (`/api/rekey_agent_token`), the request body
|
|
249
|
-
* (`{agentId}` — no name/scopes/
|
|
250
|
-
* guard (`asRekeyAgentTokenOk` — no `
|
|
256
|
+
* (`{agentId}` — no name/scopes/crews; rekey preserves crews), and the response
|
|
257
|
+
* guard (`asRekeyAgentTokenOk` — no `crews` field).
|
|
251
258
|
*
|
|
252
259
|
* **The token NEVER leaves this function.** It flows exactly one hop —
|
|
253
260
|
* `asRekeyAgentTokenOk(body).token` → `storeCredential` — and is never returned,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Credential WRITE + OAuth refresh library surface.
|
|
3
3
|
*
|
|
4
4
|
* Extracted from `src/cli.ts` (where these were module-private) so external
|
|
5
|
-
* consumers — a future `owenloop mcp` stdio server, an `
|
|
5
|
+
* consumers — a future `owenloop mcp` stdio server, an `owenloop work join` command —
|
|
6
6
|
* can store credentials and keep an OAuth access token fresh without depending
|
|
7
7
|
* on the CLI module. The exported `storeCredential` / `deleteCredential` /
|
|
8
8
|
* `ensureFreshOAuth` are re-imported by `cli.ts`, so every existing subcommand
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* avoids an import cycle.
|
|
24
24
|
*/
|
|
25
25
|
import { join } from 'node:path';
|
|
26
|
-
import { asMintAgentTokenOk, asRekeyAgentTokenOk, configDir, credentialBackend, credentialFilePath, credentialSlot, externalCredentialCommand, keychainServiceFor, readCredentialFile, readStoredCredential, resolveEndpoint,
|
|
26
|
+
import { asMintAgentTokenOk, asRekeyAgentTokenOk, configDir, credentialBackend, credentialFilePath, credentialSlot, externalCredentialCommand, keychainServiceFor, readCredentialFile, readStoredCredential, resolveEndpoint, resolveLocalKeychain, writeCredentialFile, } from "./hub.js";
|
|
27
27
|
import { CliError, nowMs } from "./util.js";
|
|
28
28
|
import { acquireFileLock, FileLockTimeoutError, releaseFileLock } from "./lock.js";
|
|
29
29
|
/**
|
|
@@ -33,7 +33,7 @@ import { acquireFileLock, FileLockTimeoutError, releaseFileLock } from "./lock.j
|
|
|
33
33
|
* refreshed — adopt it").
|
|
34
34
|
*/
|
|
35
35
|
const FRESH_WINDOW_MS = 60_000;
|
|
36
|
-
// ---- the refresh/store
|
|
36
|
+
// ---- the refresh/store SQLite lock -----------------------------------------
|
|
37
37
|
/** The credential lock path — sibling of `credentials.json` in the config dir. */
|
|
38
38
|
function credLockPath(env) {
|
|
39
39
|
return join(configDir(env), 'credentials.lock');
|
|
@@ -44,12 +44,10 @@ function envNum(env, key, fallback) {
|
|
|
44
44
|
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* Lock timings for the credential lock. Defaults 45s wait /
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* `lockIsStale` never age-reclaims a lock whose recorded pid is alive; age only
|
|
52
|
-
* governs an abandoned/unparseable lockfile.
|
|
47
|
+
* Lock timings for the credential lock. Defaults 45s wait / 100ms poll, each
|
|
48
|
+
* overridable via `OWENLOOP_CRED_LOCK_{WAIT,POLL}_MS`. The STALE knob remains in
|
|
49
|
+
* the options for source and environment compatibility, but SQLite connection
|
|
50
|
+
* ownership makes age-based pathname reclamation both unnecessary and unsafe.
|
|
53
51
|
*/
|
|
54
52
|
function credLockOpts(env) {
|
|
55
53
|
return {
|
|
@@ -62,11 +60,10 @@ function credLockOpts(env) {
|
|
|
62
60
|
/**
|
|
63
61
|
* Acquire the credential lock, mapping a clean acquire timeout to a loud
|
|
64
62
|
* `CliError` — never falling through to an unlocked refresh (that would silently
|
|
65
|
-
* reintroduce the double-refresh race). A real filesystem
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* token).
|
|
63
|
+
* reintroduce the double-refresh race). A real filesystem or SQLite error
|
|
64
|
+
* (EACCES/EROFS/corruption) is NOT a timeout and propagates untouched. No token
|
|
65
|
+
* value ever appears in the message; the diagnostic sidecar contains only
|
|
66
|
+
* pid/host/timestamps plus a random acquisition token.
|
|
70
67
|
*/
|
|
71
68
|
async function acquireCredLock(io) {
|
|
72
69
|
try {
|
|
@@ -75,8 +72,11 @@ async function acquireCredLock(io) {
|
|
|
75
72
|
catch (e) {
|
|
76
73
|
if (e instanceof FileLockTimeoutError) {
|
|
77
74
|
const who = e.holderPid !== undefined ? `pid ${e.holderPid}` : 'another process';
|
|
75
|
+
const legacyHelp = e.legacy
|
|
76
|
+
? '; found a legacy lockfile that Owenloop will not delete automatically — verify that no old process owns it, then remove it manually'
|
|
77
|
+
: '';
|
|
78
78
|
throw new CliError(`another owenloop process is using the credential store (${who}) — holds ${e.lockPath}; ` +
|
|
79
|
-
`timed out waiting after ${Math.round(e.waitMs / 1000)}s`);
|
|
79
|
+
`timed out waiting after ${Math.round(e.waitMs / 1000)}s${legacyHelp}`);
|
|
80
80
|
}
|
|
81
81
|
throw e;
|
|
82
82
|
}
|
|
@@ -148,15 +148,17 @@ export async function storeCredential(io, origin, slot, cred) {
|
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Delete body WITHOUT the lock — the caller holds it. Deletes the stored
|
|
151
|
-
* credential for `(origin, slot)` from BOTH backends (a
|
|
152
|
-
* a live refresh token can never be stranded in the
|
|
153
|
-
*
|
|
154
|
-
*
|
|
151
|
+
* credential for `(origin, slot)` from BOTH locally available backends (a
|
|
152
|
+
* defensive dual-clear, so a live refresh token can never be stranded in the
|
|
153
|
+
* store that ordinary reads currently ignore). `OWENLOOP_NO_KEYCHAIN=1` selects
|
|
154
|
+
* the file for ordinary operations but does not hide an available Keychain from
|
|
155
|
+
* this cleanup path. Returns whether anything was removed. Only the NAMED slot
|
|
156
|
+
* is removed.
|
|
155
157
|
*/
|
|
156
158
|
function deleteCredentialUnlocked(io, origin, slot) {
|
|
157
159
|
const account = credentialSlot(slot);
|
|
158
160
|
let removed = false;
|
|
159
|
-
const kc =
|
|
161
|
+
const kc = resolveLocalKeychain(io.keychain);
|
|
160
162
|
const service = keychainServiceFor(origin);
|
|
161
163
|
if (kc && kc.get(service, account) !== null) {
|
|
162
164
|
kc.delete(service, account);
|
|
@@ -460,7 +462,7 @@ export async function refreshOAuth(io, origin, slot, cred, persist = true) {
|
|
|
460
462
|
}
|
|
461
463
|
}
|
|
462
464
|
/**
|
|
463
|
-
* Mint a new
|
|
465
|
+
* Mint a new Scoped Identity on `origin` as the human `cred` and persist the
|
|
464
466
|
* returned `olp_` token to slot `agent:<name>`. CLI-free (no `Args`, no exit
|
|
465
467
|
* codes — the caller maps failures to exit codes) so both `owenloop agent new`
|
|
466
468
|
* (O3) and `owenloop mcp`'s `create_agent` (O2) can reuse it.
|
|
@@ -481,8 +483,8 @@ export async function refreshOAuth(io, origin, slot, cred, persist = true) {
|
|
|
481
483
|
* today; explicit for symmetry with the store/refresh signatures).
|
|
482
484
|
* @param params.scopes defaults to `['work']` — the H3 route REQUIRES a
|
|
483
485
|
* non-empty `scopes`; an empty list is server-refused.
|
|
484
|
-
* @param params.
|
|
485
|
-
* personal
|
|
486
|
+
* @param params.crews omitted when absent so the server defaults to the minter's
|
|
487
|
+
* personal crew (`crews: []` is server-refused with `crew_invalid`).
|
|
486
488
|
*/
|
|
487
489
|
export async function mintAgentCredential(io, origin, humanSlot, cred, params) {
|
|
488
490
|
// 1. Validate the agent name before any I/O. The client regex is byte-identical
|
|
@@ -508,12 +510,12 @@ export async function mintAgentCredential(io, origin, humanSlot, cred, params) {
|
|
|
508
510
|
'Content-Type': 'application/json',
|
|
509
511
|
Accept: 'application/json',
|
|
510
512
|
},
|
|
511
|
-
// `
|
|
513
|
+
// `crews` omitted entirely when absent (server default = personal crew);
|
|
512
514
|
// never sent as `[]` (server-refused).
|
|
513
515
|
body: JSON.stringify({
|
|
514
516
|
name: params.name,
|
|
515
517
|
scopes,
|
|
516
|
-
...(params.
|
|
518
|
+
...(params.crews !== undefined ? { crews: params.crews } : {}),
|
|
517
519
|
}),
|
|
518
520
|
});
|
|
519
521
|
// 4 + 5. POST; on a 401 with an oauth credential, refresh once and retry once —
|
|
@@ -530,7 +532,7 @@ export async function mintAgentCredential(io, origin, humanSlot, cred, params) {
|
|
|
530
532
|
throw new CliError('credential rejected by the hub — run `owenloop login`');
|
|
531
533
|
}
|
|
532
534
|
// 6. Any other non-2xx: surface the hub's typed `message` VERBATIM (this is how
|
|
533
|
-
// H1's `agent name already taken: "…"`, `
|
|
535
|
+
// H1's `agent name already taken: "…"`, `crew_invalid`, `bad_request`, and
|
|
534
536
|
// `forbidden` all surface uniformly). Never include raw body text.
|
|
535
537
|
if (!res.ok) {
|
|
536
538
|
let message;
|
|
@@ -580,18 +582,20 @@ export async function mintAgentCredential(io, origin, humanSlot, cred, params) {
|
|
|
580
582
|
`The agent '${params.name}' now exists on the hub — recover via the console (Reconnect/re-key) ` +
|
|
581
583
|
`once storage works; re-running \`agent new ${params.name}\` will refuse the taken name`);
|
|
582
584
|
}
|
|
583
|
-
// 9. Return non-secret handles only — no token field exists to leak.
|
|
584
|
-
|
|
585
|
+
// 9. Return non-secret handles only — no token field exists to leak. `scopes`
|
|
586
|
+
// is the client-resolved request value (server honors it verbatim), not a
|
|
587
|
+
// server-body field — the mint response guard does not parse scopes.
|
|
588
|
+
return { id: ok.id, agentId: ok.agentId, crews: ok.crews, scopes, storage };
|
|
585
589
|
}
|
|
586
590
|
/**
|
|
587
|
-
* Re-key an EXISTING
|
|
591
|
+
* Re-key an EXISTING Scoped Identity on `origin` as the human `cred`: the hub
|
|
588
592
|
* mints a fresh `olp_` token for `agentId`, REVOKES the identity's current
|
|
589
593
|
* token(s), and this function persists the new token into the SAME
|
|
590
594
|
* `agent:<name>` slot — overwriting the old one. Sibling of
|
|
591
595
|
* `mintAgentCredential` with the identical §6 discipline; the only shape
|
|
592
596
|
* differences are the endpoint (`/api/rekey_agent_token`), the request body
|
|
593
|
-
* (`{agentId}` — no name/scopes/
|
|
594
|
-
* guard (`asRekeyAgentTokenOk` — no `
|
|
597
|
+
* (`{agentId}` — no name/scopes/crews; rekey preserves crews), and the response
|
|
598
|
+
* guard (`asRekeyAgentTokenOk` — no `crews` field).
|
|
595
599
|
*
|
|
596
600
|
* **The token NEVER leaves this function.** It flows exactly one hop —
|
|
597
601
|
* `asRekeyAgentTokenOk(body).token` → `storeCredential` — and is never returned,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the stock OpenSSH `allowed_signers` file format (ssh-keygen(1)
|
|
3
|
+
* SSH SIGNATURES). The parser is STRUCTURAL only: it extracts principals,
|
|
4
|
+
* options, key type, key blob, and trailing comment with line numbers. It does
|
|
5
|
+
* NOT implement OpenSSH pattern matching, timestamp policy, certificate
|
|
6
|
+
* validation, or authorization — `ssh-keygen -Y verify` remains the policy
|
|
7
|
+
* authority (this repo's `SshSigner` delegates to it).
|
|
8
|
+
*
|
|
9
|
+
* Line structure:
|
|
10
|
+
*
|
|
11
|
+
* principals[,principal...] [options] keytype base64key [comment...]
|
|
12
|
+
*
|
|
13
|
+
* - principals: comma-separated pattern list (no spaces);
|
|
14
|
+
* - options (optional): one comma-separated `name` / `name="value"` field.
|
|
15
|
+
* Quoted values may contain commas, spaces, and `\"` / `\\` escapes.
|
|
16
|
+
* Recognized stock options: `cert-authority`, `namespaces=`, `valid-after=`,
|
|
17
|
+
* `valid-before=`. Principal/namespace pattern text is
|
|
18
|
+
* retained verbatim.
|
|
19
|
+
* - keytype: e.g. `ssh-ed25519`, `ssh-rsa`, `ecdsa-sha2-nistp256`;
|
|
20
|
+
* - base64key: the key blob, standard Base64;
|
|
21
|
+
* - comment: everything after the key blob (may contain spaces).
|
|
22
|
+
*
|
|
23
|
+
* Blank lines and full-line `#` comments are ignored; LF and CRLF both
|
|
24
|
+
* accepted. All parse errors carry their 1-indexed line number and never
|
|
25
|
+
* include secret material (the format carries only public keys).
|
|
26
|
+
*/
|
|
27
|
+
/** Structured options recognized on an allowed_signers line. */
|
|
28
|
+
export interface AllowedSignerOptions {
|
|
29
|
+
/** `cert-authority` singleton. */
|
|
30
|
+
certAuthority: boolean;
|
|
31
|
+
/** `namespaces="a,b"` — retained pattern text, one entry per comma item. */
|
|
32
|
+
namespaces: string[] | undefined;
|
|
33
|
+
/** `valid-after="..."` — retained verbatim (no timestamp policy here). */
|
|
34
|
+
validAfter: string | undefined;
|
|
35
|
+
/** `valid-before="..."` — retained verbatim. */
|
|
36
|
+
validBefore: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** One parsed allowed_signers entry. */
|
|
39
|
+
export interface AllowedSignerEntry {
|
|
40
|
+
/** The principal pattern list (split on unquoted commas). */
|
|
41
|
+
principals: string[];
|
|
42
|
+
options: AllowedSignerOptions;
|
|
43
|
+
keyType: string;
|
|
44
|
+
/** The raw Base64 key text as written in the file. */
|
|
45
|
+
keyBase64: string;
|
|
46
|
+
/** The decoded key blob. */
|
|
47
|
+
keyBlob: Buffer;
|
|
48
|
+
/** Trailing comment (may be empty). */
|
|
49
|
+
comment: string;
|
|
50
|
+
/** 1-indexed source line. */
|
|
51
|
+
line: number;
|
|
52
|
+
}
|
|
53
|
+
/** A line-numbered parse error. Non-secret by construction. */
|
|
54
|
+
export interface AllowedSignersParseError {
|
|
55
|
+
line: number;
|
|
56
|
+
message: string;
|
|
57
|
+
}
|
|
58
|
+
/** The parse result: every well-formed entry plus every error. */
|
|
59
|
+
export interface AllowedSignersFile {
|
|
60
|
+
entries: AllowedSignerEntry[];
|
|
61
|
+
errors: AllowedSignersParseError[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse stock `allowed_signers` text. Returns every well-formed entry plus
|
|
65
|
+
* line-numbered errors for malformed lines; parsing never throws. Blank lines
|
|
66
|
+
* and full-line comments are skipped silently.
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseAllowedSigners(text: string): AllowedSignersFile;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for the stock OpenSSH `allowed_signers` file format (ssh-keygen(1)
|
|
3
|
+
* SSH SIGNATURES). The parser is STRUCTURAL only: it extracts principals,
|
|
4
|
+
* options, key type, key blob, and trailing comment with line numbers. It does
|
|
5
|
+
* NOT implement OpenSSH pattern matching, timestamp policy, certificate
|
|
6
|
+
* validation, or authorization — `ssh-keygen -Y verify` remains the policy
|
|
7
|
+
* authority (this repo's `SshSigner` delegates to it).
|
|
8
|
+
*
|
|
9
|
+
* Line structure:
|
|
10
|
+
*
|
|
11
|
+
* principals[,principal...] [options] keytype base64key [comment...]
|
|
12
|
+
*
|
|
13
|
+
* - principals: comma-separated pattern list (no spaces);
|
|
14
|
+
* - options (optional): one comma-separated `name` / `name="value"` field.
|
|
15
|
+
* Quoted values may contain commas, spaces, and `\"` / `\\` escapes.
|
|
16
|
+
* Recognized stock options: `cert-authority`, `namespaces=`, `valid-after=`,
|
|
17
|
+
* `valid-before=`. Principal/namespace pattern text is
|
|
18
|
+
* retained verbatim.
|
|
19
|
+
* - keytype: e.g. `ssh-ed25519`, `ssh-rsa`, `ecdsa-sha2-nistp256`;
|
|
20
|
+
* - base64key: the key blob, standard Base64;
|
|
21
|
+
* - comment: everything after the key blob (may contain spaces).
|
|
22
|
+
*
|
|
23
|
+
* Blank lines and full-line `#` comments are ignored; LF and CRLF both
|
|
24
|
+
* accepted. All parse errors carry their 1-indexed line number and never
|
|
25
|
+
* include secret material (the format carries only public keys).
|
|
26
|
+
*/
|
|
27
|
+
/** Key types the parser recognizes syntactically (any stock type is accepted). */
|
|
28
|
+
const KEYTYPE_RE = /^(?:ssh-[a-z0-9@._+-]+|ecdsa-[a-z0-9@._+-]+|sk-[a-z0-9@._+-]+)$/i;
|
|
29
|
+
/** Singleton option names (no `=value`). */
|
|
30
|
+
const SINGLETON_OPTIONS = new Set(['cert-authority']);
|
|
31
|
+
/** Assignment option names (`name="value"`). */
|
|
32
|
+
const ASSIGN_OPTIONS = new Set(['namespaces', 'valid-after', 'valid-before']);
|
|
33
|
+
/** Split a single options field on commas outside quoted spans. */
|
|
34
|
+
function tokenizeOptions(text) {
|
|
35
|
+
const tokens = [];
|
|
36
|
+
let current = '';
|
|
37
|
+
let inQuotes = false;
|
|
38
|
+
for (let i = 0; i < text.length; i++) {
|
|
39
|
+
const ch = text[i];
|
|
40
|
+
if (ch === '\\') {
|
|
41
|
+
const next = text[i + 1];
|
|
42
|
+
if (next === undefined)
|
|
43
|
+
throw new Error('dangling escape in option value');
|
|
44
|
+
current += ch + next;
|
|
45
|
+
i += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (ch === '"')
|
|
49
|
+
inQuotes = !inQuotes;
|
|
50
|
+
if (ch === ',' && !inQuotes) {
|
|
51
|
+
// OpenSSH tolerates empty option slots between commas. A trailing comma
|
|
52
|
+
// is different: stock reports an unexpected end-of-options error.
|
|
53
|
+
tokens.push(current);
|
|
54
|
+
current = '';
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
current += ch;
|
|
58
|
+
}
|
|
59
|
+
if (inQuotes)
|
|
60
|
+
throw new Error('unterminated quoted option value');
|
|
61
|
+
if (current === '')
|
|
62
|
+
throw new Error('empty option');
|
|
63
|
+
tokens.push(current);
|
|
64
|
+
return tokens;
|
|
65
|
+
}
|
|
66
|
+
/** Split the principals field on commas (patterns carry no quoting). */
|
|
67
|
+
function splitPrincipals(text) {
|
|
68
|
+
return text.split(',').map((p) => p.trim()).filter((p) => p !== '');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Read the fields needed to identify one line, then treat the rest as opaque
|
|
72
|
+
* comment text. OpenSSH only applies quote rules to the optional options field;
|
|
73
|
+
* quotes in a trailing comment must never turn a valid line into a parse error.
|
|
74
|
+
*/
|
|
75
|
+
function splitLineTokens(line) {
|
|
76
|
+
const tokens = [];
|
|
77
|
+
let offset = 0;
|
|
78
|
+
const skipWhitespace = () => {
|
|
79
|
+
while (offset < line.length && (line[offset] === ' ' || line[offset] === '\t'))
|
|
80
|
+
offset += 1;
|
|
81
|
+
};
|
|
82
|
+
const readToken = () => {
|
|
83
|
+
skipWhitespace();
|
|
84
|
+
if (offset >= line.length)
|
|
85
|
+
return '';
|
|
86
|
+
let token = '';
|
|
87
|
+
let inQuotes = false;
|
|
88
|
+
while (offset < line.length) {
|
|
89
|
+
const ch = line[offset];
|
|
90
|
+
if (ch === '\\' && inQuotes) {
|
|
91
|
+
const next = line[offset + 1];
|
|
92
|
+
if (next === undefined)
|
|
93
|
+
throw new Error('dangling escape in quoted token');
|
|
94
|
+
token += ch + next;
|
|
95
|
+
offset += 2;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (ch === '"') {
|
|
99
|
+
inQuotes = !inQuotes;
|
|
100
|
+
token += ch;
|
|
101
|
+
offset += 1;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!inQuotes && (ch === ' ' || ch === '\t'))
|
|
105
|
+
break;
|
|
106
|
+
token += ch;
|
|
107
|
+
offset += 1;
|
|
108
|
+
}
|
|
109
|
+
if (inQuotes)
|
|
110
|
+
throw new Error('unterminated quoted option value');
|
|
111
|
+
return token;
|
|
112
|
+
};
|
|
113
|
+
const first = readToken();
|
|
114
|
+
if (first === '')
|
|
115
|
+
return tokens;
|
|
116
|
+
tokens.push(first);
|
|
117
|
+
const second = readToken();
|
|
118
|
+
if (second === '')
|
|
119
|
+
return tokens;
|
|
120
|
+
tokens.push(second);
|
|
121
|
+
// A bare line needs principals, key type, and key blob. An options line
|
|
122
|
+
// needs one additional field. Stop scanning immediately after the blob.
|
|
123
|
+
const requiredFields = KEYTYPE_RE.test(second) ? 3 : 4;
|
|
124
|
+
while (tokens.length < requiredFields) {
|
|
125
|
+
const before = offset;
|
|
126
|
+
const token = readToken();
|
|
127
|
+
if (token === '' && before === offset)
|
|
128
|
+
break;
|
|
129
|
+
tokens.push(token);
|
|
130
|
+
}
|
|
131
|
+
skipWhitespace();
|
|
132
|
+
if (offset < line.length)
|
|
133
|
+
tokens.push(line.slice(offset));
|
|
134
|
+
return tokens;
|
|
135
|
+
}
|
|
136
|
+
/** Decode only standard RFC 4648 Base64, which is what OpenSSH accepts. */
|
|
137
|
+
function decodeStandardBase64(text) {
|
|
138
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(text) || text.length % 4 === 1)
|
|
139
|
+
throw new Error('bad base64');
|
|
140
|
+
const body = text.replace(/=+$/, '');
|
|
141
|
+
const expectedPadding = body.length % 4 === 0 ? 0 : 4 - (body.length % 4);
|
|
142
|
+
if (text.length - body.length !== expectedPadding)
|
|
143
|
+
throw new Error('bad base64 padding');
|
|
144
|
+
return Buffer.from(text, 'base64');
|
|
145
|
+
}
|
|
146
|
+
/** Parse and unescape one stock quoted assignment value. */
|
|
147
|
+
function parseQuotedValue(raw) {
|
|
148
|
+
if (!raw.startsWith('"') || !raw.endsWith('"'))
|
|
149
|
+
throw new Error('assignment value must be quoted');
|
|
150
|
+
let value = '';
|
|
151
|
+
for (let i = 1; i < raw.length - 1; i++) {
|
|
152
|
+
const ch = raw[i];
|
|
153
|
+
if (ch !== '\\') {
|
|
154
|
+
if (ch === '"')
|
|
155
|
+
throw new Error('unescaped quote in assignment value');
|
|
156
|
+
value += ch;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const next = raw[++i];
|
|
160
|
+
if (next !== '"' && next !== '\\')
|
|
161
|
+
throw new Error('unsupported escape in assignment value');
|
|
162
|
+
value += next;
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Parse stock `allowed_signers` text. Returns every well-formed entry plus
|
|
168
|
+
* line-numbered errors for malformed lines; parsing never throws. Blank lines
|
|
169
|
+
* and full-line comments are skipped silently.
|
|
170
|
+
*/
|
|
171
|
+
export function parseAllowedSigners(text) {
|
|
172
|
+
const entries = [];
|
|
173
|
+
const errors = [];
|
|
174
|
+
const lines = text.split(/\r?\n/);
|
|
175
|
+
for (let idx = 0; idx < lines.length; idx++) {
|
|
176
|
+
const lineNo = idx + 1;
|
|
177
|
+
const raw = lines[idx];
|
|
178
|
+
const trimmed = raw.trim();
|
|
179
|
+
if (trimmed === '' || trimmed.startsWith('#'))
|
|
180
|
+
continue;
|
|
181
|
+
const fail = (message) => {
|
|
182
|
+
errors.push({ line: lineNo, message });
|
|
183
|
+
return null;
|
|
184
|
+
};
|
|
185
|
+
let tokens;
|
|
186
|
+
try {
|
|
187
|
+
tokens = splitLineTokens(trimmed);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
fail(e.message);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (tokens.length < 3) {
|
|
194
|
+
fail('missing fields: expected principals, key type, and base64 key');
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const principals = splitPrincipals(tokens[0]);
|
|
198
|
+
if (principals.length === 0) {
|
|
199
|
+
fail('missing principals');
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const options = {
|
|
203
|
+
certAuthority: false,
|
|
204
|
+
namespaces: undefined,
|
|
205
|
+
validAfter: undefined,
|
|
206
|
+
validBefore: undefined,
|
|
207
|
+
};
|
|
208
|
+
let keyIndex = 1;
|
|
209
|
+
if (!KEYTYPE_RE.test(tokens[1])) {
|
|
210
|
+
// Stock grammar has exactly one options field. If the next token is not
|
|
211
|
+
// the key type, whitespace-separated options are rejected rather than
|
|
212
|
+
// silently normalized into a different policy line.
|
|
213
|
+
if (tokens.length < 4 || KEYTYPE_RE.test(tokens[2])) {
|
|
214
|
+
// The branch with a key type at token 2 is the valid one-option form.
|
|
215
|
+
keyIndex = 2;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
fail('options must be one comma-separated field');
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
let optionTokens;
|
|
222
|
+
try {
|
|
223
|
+
optionTokens = tokenizeOptions(tokens[1]);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
fail(`options: ${e.message}`);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
let optionError = null;
|
|
230
|
+
for (const rawOption of optionTokens) {
|
|
231
|
+
if (rawOption === '')
|
|
232
|
+
continue;
|
|
233
|
+
const eq = rawOption.indexOf('=');
|
|
234
|
+
const rawName = eq < 0 ? rawOption : rawOption.slice(0, eq);
|
|
235
|
+
const name = rawName.toLowerCase();
|
|
236
|
+
if (eq < 0) {
|
|
237
|
+
if (!SINGLETON_OPTIONS.has(name)) {
|
|
238
|
+
optionError = `unsupported option syntax: '${rawOption}'`;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
// OpenSSH accepts repeated cert-authority options. Preserve the
|
|
242
|
+
// boolean representation without treating repetition as a grammar error.
|
|
243
|
+
options.certAuthority = true;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (!ASSIGN_OPTIONS.has(name)) {
|
|
247
|
+
optionError = `unsupported option syntax: '${rawOption}'`;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
let value;
|
|
251
|
+
try {
|
|
252
|
+
value = parseQuotedValue(rawOption.slice(eq + 1));
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
optionError = `option '${name}': ${e.message}`;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
if (name === 'namespaces') {
|
|
259
|
+
if (options.namespaces !== undefined) {
|
|
260
|
+
optionError = 'duplicate option: namespaces';
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
options.namespaces = value.split(',').map((s) => s.trim()).filter((s) => s !== '');
|
|
264
|
+
}
|
|
265
|
+
else if (name === 'valid-after') {
|
|
266
|
+
if (options.validAfter !== undefined) {
|
|
267
|
+
optionError = 'duplicate option: valid-after';
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
options.validAfter = value;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
if (options.validBefore !== undefined) {
|
|
274
|
+
optionError = 'duplicate option: valid-before';
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
options.validBefore = value;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (optionError !== null) {
|
|
281
|
+
fail(optionError);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const keyType = tokens[keyIndex];
|
|
286
|
+
if (!KEYTYPE_RE.test(keyType)) {
|
|
287
|
+
fail(`invalid key type: '${keyType}'`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (keyIndex + 1 >= tokens.length) {
|
|
291
|
+
fail('missing base64 key');
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const keyBase64 = tokens[keyIndex + 1];
|
|
295
|
+
let keyBlob;
|
|
296
|
+
try {
|
|
297
|
+
keyBlob = decodeStandardBase64(keyBase64);
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
fail('bad base64 key blob');
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
const comment = tokens.slice(keyIndex + 2).join(' ');
|
|
304
|
+
entries.push({ principals, options, keyType, keyBase64, keyBlob, comment, line: lineNo });
|
|
305
|
+
}
|
|
306
|
+
return { entries, errors };
|
|
307
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a JSON value deterministically for value-level trust records.
|
|
3
|
+
* Object keys are sorted recursively; array order is preserved. The output is
|
|
4
|
+
* separator-tight JSON encoded as UTF-8 bytes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalValueBytes(value: unknown): Uint8Array;
|
|
7
|
+
/** Compute the lowercase SHA-256 digest of a canonical JSON value. */
|
|
8
|
+
export declare function valueDigestHex(value: unknown): string;
|