@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/seal-key.js
CHANGED
|
@@ -1,26 +1,46 @@
|
|
|
1
1
|
// The seal key every secret is kept under (tool keys, MCP credentials, sign-ins, trigger secrets: store/seal.ts). The
|
|
2
|
-
// server never starts without one: AGENTRUN_SEAL_KEY as it was handed (the launcher's pipe, or the environment), else
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// server never starts without one: AGENTRUN_SEAL_KEY as it was handed (the launcher's pipe, or the environment), else the
|
|
3
|
+
// one in seal/seal.key in the data directory, beside the store, made there at the server's first start. There is no other
|
|
4
|
+
// place a key is read from. It lives and dies with the data (a disk, a volume): a copy of the data directory is a copy of
|
|
5
|
+
// the secrets, so it is backed up with them.
|
|
5
6
|
// - made as 32 random bytes in base64, 0600, in a directory of its own that is 0700, written whole beside its name and
|
|
6
7
|
// then linked to it, so two starts at once read one key, and only its path is ever printed;
|
|
7
8
|
// - a plain mkdir's directory (0755) with no key yet, this user's own, is tightened to 0700 before the key is made;
|
|
8
|
-
// - a key or a directory another user can read is refused, never changed; a linked directory
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
// - a key or a directory another user can read is refused, never changed; a linked directory, or one another user owns,
|
|
10
|
+
// is refused, never followed or written into.
|
|
11
|
+
// The store records the key's fingerprint (an HMAC of a fixed label under the key: never the key, nor a hash of it alone),
|
|
12
|
+
// and every process that opens the store (the server, a runner, the `import` command) checks the key it holds against it
|
|
13
|
+
// (bootSealKey). A store whose secrets were sealed with another key is refused, in words, and no key is ever made over
|
|
14
|
+
// sealed secrets, in the store or beside it in the data directory: a lost key file is not replaced by a new one. A store
|
|
15
|
+
// with no fingerprint takes a key that opens every value it keeps sealed, or any key when it keeps none. The server's
|
|
16
|
+
// start makes a key and records it (and the import's, which sets a data directory up as the server does); a runner reads
|
|
17
|
+
// one and checks it, and never makes or records one. Several data directories in one process each keep their own key.
|
|
18
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
11
19
|
import { chmodSync, closeSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, rmSync, writeSync } from "node:fs";
|
|
12
20
|
import { join } from "node:path";
|
|
21
|
+
import { unseal } from "./sealing.js";
|
|
13
22
|
import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
|
|
14
|
-
import { handedSecret,
|
|
15
|
-
|
|
23
|
+
import { handedSecret, holdSealKey } from "./secrets.js";
|
|
24
|
+
/** The seal key's own directory in the data directory, and its file there. */
|
|
25
|
+
export const SEAL_KEY_DIR = "seal";
|
|
16
26
|
export const SEAL_KEY_FILE = "seal.key";
|
|
27
|
+
/** The store setting that records the key's fingerprint. */
|
|
28
|
+
export const SEAL_KEY_SETTING = "seal_key";
|
|
29
|
+
/** The fixed label the fingerprint is an HMAC of, under the key. */
|
|
30
|
+
const FINGERPRINT_LABEL = "agentrun seal key fingerprint v1";
|
|
31
|
+
/** The refusal of a store whose secrets another key sealed, word for word. */
|
|
32
|
+
export const SEALED_ELSEWHERE = `this store's secrets were sealed with another key; hand the server the original ${SEAL_KEY_ENV}`;
|
|
17
33
|
/** The server has no seal key it can use, in words: it does not start. */
|
|
18
34
|
export class SealKeyRefused extends Error {
|
|
19
35
|
name = "SealKeyRefused";
|
|
20
36
|
}
|
|
21
|
-
/** The
|
|
22
|
-
export
|
|
23
|
-
|
|
37
|
+
/** The key held is not the one the store's secrets were sealed with: it does not start. */
|
|
38
|
+
export class SealKeyNotTheStores extends SealKeyRefused {
|
|
39
|
+
name = "SealKeyNotTheStores";
|
|
40
|
+
}
|
|
41
|
+
/** Where the data directory `dataDir` keeps its seal key. */
|
|
42
|
+
export const sealKeyPath = (dataDir) => join(dataDir, SEAL_KEY_DIR, SEAL_KEY_FILE);
|
|
43
|
+
const HOW = `Hand the server ${SEAL_KEY_ENV} (32 random bytes in base64, e.g. \`openssl rand -base64 32\`), or let it keep one in ${SEAL_KEY_DIR}/${SEAL_KEY_FILE} in its data directory, made at the first start.`;
|
|
24
44
|
const refused = (why) => new SealKeyRefused(`No seal key: ${why}. ${HOW}`);
|
|
25
45
|
function lstatOf(path) {
|
|
26
46
|
try {
|
|
@@ -37,105 +57,235 @@ function lstatOf(path) {
|
|
|
37
57
|
/** No group or other permission bits: only its owner can read it. */
|
|
38
58
|
const ownerOnly = (stats) => (stats.mode & 0o077) === 0;
|
|
39
59
|
const mine = (stats) => typeof process.getuid !== "function" || stats.uid === process.getuid();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
const linked = (dir) => refused(`${dir} is a link, and a seal key's directory is never followed through one: make it a directory of its own (mode 0700)`);
|
|
61
|
+
/** The key kept in `dir`, checked: undefined when there is none (no directory, or no file in it). Throws SealKeyRefused
|
|
62
|
+
* for a linked directory, a key or directory another user can read, or a file that holds no key: never changed. */
|
|
63
|
+
function keptIn(dir) {
|
|
64
|
+
const file = join(dir, SEAL_KEY_FILE);
|
|
65
|
+
const held = lstatOf(dir);
|
|
66
|
+
if (!held)
|
|
67
|
+
return undefined;
|
|
68
|
+
if (held.isSymbolicLink())
|
|
69
|
+
throw linked(dir);
|
|
70
|
+
if (!held.isDirectory())
|
|
71
|
+
throw refused(`${dir} is not a directory`);
|
|
72
|
+
const stats = lstatOf(file);
|
|
73
|
+
if (!stats)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (!mine(held) || !ownerOnly(held)) {
|
|
76
|
+
throw refused(`${dir} can be read by another user, or is not this user's: make it 0700 (chmod 700 ${dir}); it is never changed for you once a key is in it`);
|
|
50
77
|
}
|
|
51
|
-
if (!
|
|
52
|
-
throw refused(`${
|
|
53
|
-
|
|
78
|
+
if (!stats.isFile() || !mine(stats) || !ownerOnly(stats)) {
|
|
79
|
+
throw refused(`${file} is not a file only this user can read: make it 0600 (chmod 600 ${file})`);
|
|
80
|
+
}
|
|
81
|
+
const text = readFileSync(file, "utf8").split("\n")[0].trim();
|
|
82
|
+
const key = sealKeyOf(text);
|
|
83
|
+
if (!key)
|
|
84
|
+
throw refused(`${file} does not hold 32 bytes in base64`);
|
|
85
|
+
return { key, text, path: file, generated: false };
|
|
86
|
+
}
|
|
87
|
+
/** Writes `text` as the key in `dir` (made 0700, or a plain mkdir's directory of this user's tightened to it), whole
|
|
88
|
+
* beside its name and then linked, so a start racing another reads the one there. Whether this call wrote it. */
|
|
89
|
+
function writeIn(dir, text) {
|
|
54
90
|
const file = join(dir, SEAL_KEY_FILE);
|
|
55
91
|
const before = lstatOf(dir);
|
|
56
92
|
if (before?.isSymbolicLink())
|
|
57
|
-
throw
|
|
93
|
+
throw linked(dir);
|
|
58
94
|
if (before && !before.isDirectory())
|
|
59
95
|
throw refused(`${dir} is not a directory`);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw refused(`${dir} could not be made (${error.code ?? String(error)})`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const text = randomBytes(32).toString("base64");
|
|
74
|
-
const temp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
96
|
+
if (before && !mine(before))
|
|
97
|
+
throw refused(`${dir} is not this user's: a seal key is never written into another user's directory`);
|
|
98
|
+
// A plain mkdir's directory, this user's own, with no key yet: tightened before a key is written in it.
|
|
99
|
+
if (before && mine(before) && !ownerOnly(before))
|
|
100
|
+
chmodSync(dir, 0o700);
|
|
101
|
+
if (!before) {
|
|
75
102
|
try {
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
writeSync(fd, `${text}\n`);
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
closeSync(fd);
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
linkSync(temp, file);
|
|
85
|
-
generated = true;
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
// Another start made it first: each start reads the one there.
|
|
89
|
-
if (error.code !== "EEXIST")
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
103
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
92
104
|
}
|
|
93
105
|
catch (error) {
|
|
94
|
-
throw refused(`${
|
|
106
|
+
throw refused(`${dir} could not be made (${error.code ?? String(error)})`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const temp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
110
|
+
try {
|
|
111
|
+
const fd = openSync(temp, "wx", 0o600);
|
|
112
|
+
try {
|
|
113
|
+
writeSync(fd, `${text}\n`);
|
|
95
114
|
}
|
|
96
115
|
finally {
|
|
97
|
-
|
|
116
|
+
closeSync(fd);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
linkSync(temp, file);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
// Another start made it first: each start reads the one there.
|
|
124
|
+
if (error.code !== "EEXIST")
|
|
125
|
+
throw error;
|
|
126
|
+
return false;
|
|
98
127
|
}
|
|
99
128
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw refused(`${dir} can be read by another user, or is not this user's: make it 0700 (chmod 700 ${dir}); it is never changed for you once a key is in it`);
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw refused(`${file} could not be written (${error.code ?? String(error)})`);
|
|
103
131
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
throw refused(`${file} is not a file only this user can read: make it 0600 (chmod 600 ${file}), or remove it to have a new one made at the next start`);
|
|
132
|
+
finally {
|
|
133
|
+
rmSync(temp, { force: true });
|
|
107
134
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
135
|
+
}
|
|
136
|
+
/** The key file's rules alone, with no store to check against: `given` (AGENTRUN_SEAL_KEY as it was handed) when set,
|
|
137
|
+
* else the one kept in `dataDir`, made there when there is none. A start never calls this by itself: bootSealKey checks
|
|
138
|
+
* the key against the store first, and makes one only for a store that holds no secret. */
|
|
139
|
+
export function ensureSealKey(given, { dataDir }) {
|
|
140
|
+
if (given) {
|
|
141
|
+
const key = sealKeyOf(given);
|
|
142
|
+
if (!key)
|
|
143
|
+
throw refused(`${SEAL_KEY_ENV} is set but is not 32 bytes in base64`);
|
|
144
|
+
return { key, text: given, path: null, generated: false };
|
|
145
|
+
}
|
|
146
|
+
const dir = join(dataDir, SEAL_KEY_DIR);
|
|
147
|
+
const kept = keptIn(dir);
|
|
148
|
+
if (kept)
|
|
149
|
+
return kept;
|
|
150
|
+
const generated = writeIn(dir, randomBytes(32).toString("base64"));
|
|
151
|
+
const made = keptIn(dir);
|
|
152
|
+
if (!made)
|
|
153
|
+
throw refused(`${join(dir, SEAL_KEY_FILE)} could not be read back`);
|
|
154
|
+
return { ...made, generated };
|
|
155
|
+
}
|
|
156
|
+
/** The fingerprint the store records of `key`: an HMAC of a fixed label under it. Neither the key nor a hash of it alone. */
|
|
157
|
+
export const sealKeyFingerprint = (key) => createHmac("sha256", key).update(FINGERPRINT_LABEL).digest("base64url");
|
|
158
|
+
/** The fingerprint a store setting's value records: undefined with none, null for one that does not read. */
|
|
159
|
+
function recordedIn(value) {
|
|
160
|
+
if (value === undefined)
|
|
161
|
+
return undefined;
|
|
162
|
+
const record = value;
|
|
163
|
+
return record?.v === 1 && typeof record.fingerprint === "string" ? record.fingerprint : null;
|
|
164
|
+
}
|
|
165
|
+
const sameText = (a, b) => a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
166
|
+
function opensUnder(key, sealed, aad) {
|
|
167
|
+
try {
|
|
168
|
+
unseal(key, Buffer.from(sealed), aad);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async function storeSealOf(store) {
|
|
176
|
+
const fingerprint = recordedIn(await store.settings.get(SEAL_KEY_SETTING));
|
|
177
|
+
if (fingerprint !== undefined)
|
|
178
|
+
return { fingerprint, sealed: [] };
|
|
179
|
+
const rows = (await store.sealedSecrets.all()).map((row) => (key) => opensUnder(key, row.sealed, row.aad));
|
|
180
|
+
return { fingerprint, sealed: rows };
|
|
181
|
+
}
|
|
182
|
+
const holdsSecrets = (seal) => seal.fingerprint !== undefined || seal.sealed.length > 0;
|
|
183
|
+
/** Whether `key` is the store's, or why not: the one its fingerprint records; with none recorded, one that opens every
|
|
184
|
+
* value it keeps sealed (some opening and some not is values sealed under more than one key: no key is taken over
|
|
185
|
+
* that), or any key for a store that keeps none. */
|
|
186
|
+
function notTheStoresWhy(seal, key) {
|
|
187
|
+
if (seal.fingerprint === null)
|
|
188
|
+
return ` (the store's record of its key, setting ${SEAL_KEY_SETTING}, does not read)`;
|
|
189
|
+
if (seal.fingerprint !== undefined)
|
|
190
|
+
return sameText(seal.fingerprint, sealKeyFingerprint(key)) ? undefined : "";
|
|
191
|
+
const shut = seal.sealed.filter((opens) => !opens(key)).length;
|
|
192
|
+
if (shut === 0)
|
|
193
|
+
return undefined;
|
|
194
|
+
return shut === seal.sealed.length ? "" : ` (${shut} of the ${seal.sealed.length} values it keeps sealed do not open under this key: they were sealed under more than one)`;
|
|
195
|
+
}
|
|
196
|
+
const notTheStores = (why) => new SealKeyNotTheStores(`${SEALED_ELSEWHERE}. ${why}`);
|
|
197
|
+
const PUT_BACK = `put the original there (mode 0600, in a 0700 directory), or hand it as ${SEAL_KEY_ENV}`;
|
|
198
|
+
async function sealKeyFor(store, dataDir, given, role, write) {
|
|
199
|
+
const kept = await storeSealOf(store);
|
|
200
|
+
const dir = join(dataDir, SEAL_KEY_DIR);
|
|
201
|
+
const file = join(dir, SEAL_KEY_FILE);
|
|
202
|
+
let seal;
|
|
203
|
+
if (given) {
|
|
204
|
+
const key = sealKeyOf(given);
|
|
205
|
+
if (!key)
|
|
206
|
+
throw refused(`${SEAL_KEY_ENV} is set but is not 32 bytes in base64`);
|
|
207
|
+
const why = notTheStoresWhy(kept, key);
|
|
208
|
+
if (why !== undefined)
|
|
209
|
+
throw notTheStores(`The ${SEAL_KEY_ENV} handed now is not it${why}.`);
|
|
210
|
+
seal = { key, text: given, path: null, generated: false };
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
seal = keptIn(dir);
|
|
214
|
+
if (seal) {
|
|
215
|
+
const why = notTheStoresWhy(kept, seal.key);
|
|
216
|
+
if (why !== undefined)
|
|
217
|
+
throw notTheStores(`${file} holds another key${why}: ${PUT_BACK}.`);
|
|
218
|
+
}
|
|
219
|
+
else if (holdsSecrets(kept)) {
|
|
220
|
+
// No key here, over a store that holds secrets: never a new one.
|
|
221
|
+
throw notTheStores(`There is no key in ${file}: ${PUT_BACK}.`);
|
|
222
|
+
}
|
|
223
|
+
else if (role === "runner") {
|
|
224
|
+
// A runner never makes a key: it reads the one the server made.
|
|
225
|
+
throw refused(`there is none in ${file}, and this store records none: start the server on this data directory first, which makes it, or hand ${SEAL_KEY_ENV}`);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// A store that holds no secret: its key is made here, at the server's first start (or the import's, which sets a data
|
|
229
|
+
// directory up as the server does when none has); a dry run makes none, and has none.
|
|
230
|
+
if (!write)
|
|
231
|
+
return undefined;
|
|
232
|
+
seal = ensureSealKey(undefined, { dataDir });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (write && role !== "runner" && kept.fingerprint === undefined) {
|
|
236
|
+
// Recorded once: the first server to record it wins, and one that loses to another key's record is refused.
|
|
237
|
+
const fingerprint = sealKeyFingerprint(seal.key);
|
|
238
|
+
const now = recordedIn(await store.settings.putIfAbsent(SEAL_KEY_SETTING, { v: 1, fingerprint }));
|
|
239
|
+
if (now === undefined || now === null || !sameText(now, fingerprint)) {
|
|
240
|
+
// A key this start made for a store another process recorded first seals nothing: it goes.
|
|
241
|
+
if (seal.generated && seal.path)
|
|
242
|
+
rmSync(seal.path, { force: true });
|
|
243
|
+
throw notTheStores("Another process recorded its key in this store first.");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return seal;
|
|
247
|
+
}
|
|
248
|
+
/** `env` (one withSecrets made) with `text` as its seal key, read by name and never enumerated, as withSecrets gives a
|
|
249
|
+
* secret: so what reads the key from it gets the one its start checked against its store. */
|
|
250
|
+
export function withSealKey(env, text) {
|
|
251
|
+
// A copy, every property as it is (a withSecrets secret stays unenumerable, its saved-keys mark too), the key in place of
|
|
252
|
+
// whatever it held.
|
|
253
|
+
const out = {};
|
|
254
|
+
for (const name of Reflect.ownKeys(env))
|
|
255
|
+
if (name !== SEAL_KEY_ENV)
|
|
256
|
+
Object.defineProperty(out, name, Object.getOwnPropertyDescriptor(env, name));
|
|
257
|
+
Object.defineProperty(out, SEAL_KEY_ENV, { value: text, enumerable: false, writable: false, configurable: false });
|
|
258
|
+
return out;
|
|
113
259
|
}
|
|
114
260
|
/** The line a start prints about its seal key: where it is, never the key. */
|
|
115
261
|
export function sealKeyLine(seal) {
|
|
116
262
|
if (!seal.path)
|
|
117
263
|
return `agentrun-serve: the seal key is ${SEAL_KEY_ENV}, as it was handed`;
|
|
118
|
-
return `agentrun-serve: ${seal.generated ? "made a new seal key" : "the seal key is"} at ${seal.path} (0600): every secret saved here opens with it alone, so
|
|
264
|
+
return `agentrun-serve: ${seal.generated ? "made a new seal key" : "the seal key is"} at ${seal.path} (0600), beside the store: every secret saved here opens with it alone, so back it up with the data directory, and keep the two together`;
|
|
119
265
|
}
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
266
|
+
/** A refusal in the words a start says: a key that is not the store's, or none it can use. */
|
|
267
|
+
function startRefusal(error) {
|
|
268
|
+
if (error instanceof SealKeyNotTheStores)
|
|
269
|
+
return new SealKeyNotTheStores(`agentrun-serve does not start: ${error.message}`, { cause: error });
|
|
270
|
+
return new SealKeyRefused(`agentrun-serve does not start without a seal key. ${error.message}`, { cause: error });
|
|
271
|
+
}
|
|
272
|
+
export async function bootSealKey(store, dataDir, options = {}) {
|
|
273
|
+
const given = "given" in options ? options.given : handedSecret(SEAL_KEY_ENV);
|
|
274
|
+
const say = options.say ?? ((line) => void process.stderr.write(line));
|
|
127
275
|
let seal;
|
|
128
276
|
try {
|
|
129
|
-
seal =
|
|
277
|
+
seal = await sealKeyFor(store, dataDir, given, options.role ?? "server", options.write !== false);
|
|
130
278
|
}
|
|
131
279
|
catch (error) {
|
|
132
280
|
if (error instanceof SealKeyRefused)
|
|
133
|
-
throw
|
|
281
|
+
throw startRefusal(error);
|
|
134
282
|
throw error;
|
|
135
283
|
}
|
|
136
|
-
if (!
|
|
137
|
-
|
|
284
|
+
if (!seal)
|
|
285
|
+
return undefined;
|
|
286
|
+
// On this process's redaction list while it is open (secrets.ts holdSealKey); each holder passes its own key on.
|
|
287
|
+
const release = holdSealKey(seal.text);
|
|
138
288
|
if (seal.generated)
|
|
139
289
|
say(`${sealKeyLine(seal)}\n`);
|
|
140
|
-
return seal;
|
|
290
|
+
return { ...seal, release };
|
|
141
291
|
}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import type { SettingsSpec } from "./sealed-settings.js";
|
|
2
1
|
import type { TriggerSettings } from "./store/index.js";
|
|
3
|
-
|
|
2
|
+
/** What an adapter keeps sealed, and where: `server`, one set for the server; `trigger`, one set per trigger, by its id.
|
|
3
|
+
* A field with `mint` is a Standard Webhooks secret this server makes (standard-webhooks.ts), shown once; any other is
|
|
4
|
+
* given (set). `minBytes`: the fewest bytes its value may hold (standard-webhooks.ts keyBytes), MIN_KEY_BYTES for a key
|
|
5
|
+
* a request is verified with. `public`: a value that is no secret (an app's id, its name), kept with the rest but never
|
|
6
|
+
* in the list of the server's secrets, so no run's text is cut of it, and of any length. `format: "pem"`: a PEM private
|
|
7
|
+
* key, whose lines each are listed as secrets. */
|
|
8
|
+
export type SettingsSpec = {
|
|
9
|
+
scope: "server" | "trigger";
|
|
10
|
+
fields: Record<string, {
|
|
11
|
+
mint?: true;
|
|
12
|
+
minBytes?: number;
|
|
13
|
+
public?: true;
|
|
14
|
+
format?: "pem";
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
/** The scope of a server-scoped adapter's settings. */
|
|
18
|
+
export declare const SERVER_SCOPE = "server";
|
|
4
19
|
/** The store slice this layer reads and writes. */
|
|
5
20
|
type SealedSettingsStore = {
|
|
6
21
|
readonly triggerSettings: Pick<TriggerSettings, "get" | "put" | "removeScope">;
|
|
@@ -66,6 +81,6 @@ declare class SealedSettingsOverStore {
|
|
|
66
81
|
private remember;
|
|
67
82
|
}
|
|
68
83
|
export type { SealedSettingsOverStore };
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
84
|
+
/** An adapter's sealed settings over the one store; the server awaits load() once at start before the first
|
|
85
|
+
* get()/values(). */
|
|
71
86
|
export declare function sealedSettingsOverStore(store: SealedSettingsStore, adapterId: string, spec: SettingsSpec, key: Buffer, say: (fields: Record<string, string>) => void): SealedSettingsOverStore;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// A trigger source's sealed settings over the one store (store.triggerSettings)
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// `new SealedSettings(data, ...)` for `sealedSettingsOverStore(store, ...)` then awaits load() once: get()/values() are
|
|
1
|
+
// A trigger source's sealed settings over the one store (store.triggerSettings): the trigger kernel's one store of them.
|
|
2
|
+
// Each (scope, field) is a sealed row, bound to its adapter, scope and field by the store's documented AAD
|
|
3
|
+
// trigger_settings|<adapter>|<scope>|<field>; the store holds base64 ciphertext and never opens it, and none is kept in
|
|
4
|
+
// the clear (the server always has its seal key: seal-key.ts). The server awaits load() once: get()/values() are
|
|
6
5
|
// synchronous off a snapshot the server (the one writer) loads once and keeps in step with every write; set/mint/remove
|
|
7
6
|
// are durable before they resolve.
|
|
8
|
-
import { seal, unseal } from "
|
|
7
|
+
import { seal, unseal } from "./sealing.js";
|
|
9
8
|
import { invalid } from "./errors.js";
|
|
10
9
|
import { keyBytes, MIN_KEY_BYTES, mintSecret, SECRET_PREFIX } from "./standard-webhooks.js";
|
|
11
10
|
import { SEAL_KEY_ENV } from "./tool-keys.js";
|
|
12
|
-
|
|
11
|
+
/** The scope of a server-scoped adapter's settings. */
|
|
12
|
+
export const SERVER_SCOPE = "server";
|
|
13
13
|
/** The store's documented AAD for a trigger setting (store schema `trigger_settings`): the composite row key is in the
|
|
14
14
|
* AAD, not store/seal.ts's single-row aadOf, which refuses a key holding the separator. */
|
|
15
15
|
const aad = (adapterId, scope, field) => `trigger_settings|${adapterId}|${scope}|${field}`;
|
|
@@ -198,8 +198,8 @@ class SealedSettingsOverStore {
|
|
|
198
198
|
this.retired.add(secret);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
/**
|
|
202
|
-
*
|
|
201
|
+
/** An adapter's sealed settings over the one store; the server awaits load() once at start before the first
|
|
202
|
+
* get()/values(). */
|
|
203
203
|
export function sealedSettingsOverStore(store, adapterId, spec, key, say) {
|
|
204
204
|
return new SealedSettingsOverStore(store, adapterId, spec, key, say);
|
|
205
205
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** AES-256-GCM over `plain`, bound to `aad`: the IV, the ciphertext and the tag, in that order. */
|
|
2
|
+
export declare function seal(key: Buffer, plain: Buffer, aad: string): Buffer;
|
|
3
|
+
/** `seal`'s inverse; it throws when the bytes, the key or the `aad` differ from the sealing's. */
|
|
4
|
+
export declare function unseal(key: Buffer, sealed: Buffer, aad: string): Buffer;
|
package/dist/sealing.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// AES-256-GCM sealing, the one primitive every secret this server keeps at rest is sealed with (copied from
|
|
2
|
+
// @parcha/pi-durable-agent's vault.ts): the store's sealed columns (store/seal.ts), the
|
|
3
|
+
// trigger settings, the outbound webhook's secret, and what a runner opens under the server's seal key.
|
|
4
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
5
|
+
const IV_BYTES = 12;
|
|
6
|
+
const TAG_BYTES = 16;
|
|
7
|
+
/** AES-256-GCM over `plain`, bound to `aad`: the IV, the ciphertext and the tag, in that order. */
|
|
8
|
+
export function seal(key, plain, aad) {
|
|
9
|
+
const iv = randomBytes(IV_BYTES);
|
|
10
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv).setAAD(Buffer.from(aad, "utf8"));
|
|
11
|
+
return Buffer.concat([iv, cipher.update(plain), cipher.final(), cipher.getAuthTag()]);
|
|
12
|
+
}
|
|
13
|
+
/** `seal`'s inverse; it throws when the bytes, the key or the `aad` differ from the sealing's. */
|
|
14
|
+
export function unseal(key, sealed, aad) {
|
|
15
|
+
if (sealed.length < IV_BYTES + TAG_BYTES)
|
|
16
|
+
throw new Error("too short");
|
|
17
|
+
const decipher = createDecipheriv("aes-256-gcm", key, sealed.subarray(0, IV_BYTES)).setAAD(Buffer.from(aad, "utf8"));
|
|
18
|
+
decipher.setAuthTag(sealed.subarray(sealed.length - TAG_BYTES));
|
|
19
|
+
return Buffer.concat([decipher.update(sealed.subarray(IV_BYTES, sealed.length - TAG_BYTES)), decipher.final()]);
|
|
20
|
+
}
|
package/dist/secret-cut.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { keyShaped } from "
|
|
1
|
+
import { keyShaped } from "./secret-name.js";
|
|
2
2
|
/** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
|
|
3
3
|
* KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
|
|
4
4
|
* The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
|
package/dist/secret-cut.js
CHANGED
|
@@ -6,7 +6,7 @@ import { secretLintProfiler } from "@secretlint/profiler";
|
|
|
6
6
|
import { rules as recommended } from "@secretlint/secretlint-rule-preset-recommend";
|
|
7
7
|
// No performance marks: the profiler would leave about 14 a call in the process's global buffer.
|
|
8
8
|
secretLintProfiler.setEnabled(false);
|
|
9
|
-
import { keyShaped } from "
|
|
9
|
+
import { keyShaped } from "./secret-name.js";
|
|
10
10
|
/** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
|
|
11
11
|
* KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
|
|
12
12
|
* The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The `_`-separated segments, in any case, that make a name a secret's. */
|
|
2
|
+
export declare const SECRET_SEGMENTS: readonly string[];
|
|
3
|
+
/**
|
|
4
|
+
* Whether `name` is a secret's name: one of its `_`-separated segments, in any case, is one of SECRET_SEGMENTS, or its last
|
|
5
|
+
* segment is PWD after another (DB_PWD). Segments, not suffixes, so MODAL_TOKEN_ID, FOO_TOKEN_BAR and MY_TOKEN_FILE are
|
|
6
|
+
* secrets' names, and CACHE_KEY_PREFIX too, which is the cheaper error; KEYBOARD, TOKENIZER, SECRETARY and PATTERN are
|
|
7
|
+
* not. PWD alone and OLDPWD are the shell's working directories, never a secret's.
|
|
8
|
+
*/
|
|
9
|
+
export declare function keyShaped(name: string): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The one rule for whether a variable's name is a secret's, by its name alone: what serve keeps out of a run's
|
|
2
|
+
// environment, cuts out of what an import keeps and out of a harness's log (secret-cut.ts).
|
|
3
|
+
/** The `_`-separated segments, in any case, that make a name a secret's. */
|
|
4
|
+
export const SECRET_SEGMENTS = Object.freeze(["KEY", "TOKEN", "SECRET", "PASSWORD", "PASSWD", "PASS", "PAT", "CREDENTIAL", "CREDENTIALS", "DSN"]);
|
|
5
|
+
const SEGMENTS = new Set(SECRET_SEGMENTS);
|
|
6
|
+
/**
|
|
7
|
+
* Whether `name` is a secret's name: one of its `_`-separated segments, in any case, is one of SECRET_SEGMENTS, or its last
|
|
8
|
+
* segment is PWD after another (DB_PWD). Segments, not suffixes, so MODAL_TOKEN_ID, FOO_TOKEN_BAR and MY_TOKEN_FILE are
|
|
9
|
+
* secrets' names, and CACHE_KEY_PREFIX too, which is the cheaper error; KEYBOARD, TOKENIZER, SECRETARY and PATTERN are
|
|
10
|
+
* not. PWD alone and OLDPWD are the shell's working directories, never a secret's.
|
|
11
|
+
*/
|
|
12
|
+
export function keyShaped(name) {
|
|
13
|
+
const segments = name.toUpperCase().split("_");
|
|
14
|
+
return segments.some((segment) => SEGMENTS.has(segment)) || (segments.length > 1 && segments.at(-1) === "PWD");
|
|
15
|
+
}
|
package/dist/secret-writes.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export type SecretWriterFacts = {
|
|
|
26
26
|
* off on a loopback-bound server, open the console from the launch link); no_accounts, accounts are off and the server is
|
|
27
27
|
* reachable off loopback, where no one writes one until accounts are on. */
|
|
28
28
|
export type SecretsReason = "token" | "sign_in" | "no_accounts";
|
|
29
|
-
export declare const SECRETS_REASONS: readonly SecretsReason[];
|
|
30
29
|
/** The one decision: whether a caller with these facts may write a secret, and if not, why. The owner's password session
|
|
31
30
|
* always may; the accounts-off console on a loopback-bound server may where `loopbackConsoleIsOwner`
|
|
32
31
|
* (LOOPBACK_CONSOLE_IS_OWNER); the API token never may, anywhere. */
|
package/dist/secret-writes.js
CHANGED
|
@@ -11,7 +11,6 @@ export const SECRET_WRITE_REFUSAL = "Saving, replacing or removing a secret take
|
|
|
11
11
|
* secrets_writable) follows it.
|
|
12
12
|
*/
|
|
13
13
|
export const LOOPBACK_CONSOLE_IS_OWNER = true;
|
|
14
|
-
export const SECRETS_REASONS = ["token", "sign_in", "no_accounts"];
|
|
15
14
|
/** The one decision: whether a caller with these facts may write a secret, and if not, why. The owner's password session
|
|
16
15
|
* always may; the accounts-off console on a loopback-bound server may where `loopbackConsoleIsOwner`
|
|
17
16
|
* (LOOPBACK_CONSOLE_IS_OWNER); the API token never may, anywhere. */
|
package/dist/secrets.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export type StoredKeys = (name: string) => string | undefined;
|
|
|
23
23
|
* every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
|
|
24
24
|
* whitespace aside, matches too much text by chance to be refused, and is left out. */
|
|
25
25
|
export declare const hostSecrets: (env: NodeJS.ProcessEnv, stored?: StoredKeys) => string[];
|
|
26
|
-
/**
|
|
27
|
-
export declare function
|
|
26
|
+
/** Lists `text` among this process's seal keys, for redaction alone, until the returned release is called. */
|
|
27
|
+
export declare function holdSealKey(text: string): () => void;
|
|
28
28
|
/** A secret this process was handed (over its pipe, or in its environment), never one it made itself: what a start asks
|
|
29
29
|
* to tell a handed seal key from none, so a second server in one process makes or reads its own and is not handed the
|
|
30
30
|
* first one's. */
|
|
@@ -58,14 +58,6 @@ export declare function mcpCredentials(): Record<string, {
|
|
|
58
58
|
export declare const mcpSecretValues: (credentials: Record<string, {
|
|
59
59
|
headers?: Record<string, string>;
|
|
60
60
|
}>) => string[];
|
|
61
|
-
/** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
|
|
62
|
-
export declare const mcpHandover: (credentials: Record<string, unknown>) => Buffer;
|
|
63
|
-
/** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
|
|
64
|
-
export declare const handoverSignIn: (value: {
|
|
65
|
-
provider: string;
|
|
66
|
-
ref: string;
|
|
67
|
-
save: boolean;
|
|
68
|
-
}) => Buffer;
|
|
69
61
|
/** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
|
|
70
62
|
export declare function handedSignIn(): {
|
|
71
63
|
provider: string;
|
package/dist/secrets.js
CHANGED
|
@@ -94,23 +94,31 @@ const SECRET_NAME = /(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD)$/i;
|
|
|
94
94
|
* every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
|
|
95
95
|
* whitespace aside, matches too much text by chance to be refused, and is left out. */
|
|
96
96
|
export const hostSecrets = (env, stored) => {
|
|
97
|
-
const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials())];
|
|
97
|
+
const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials()), ...sealKeys.keys()];
|
|
98
98
|
const named = Object.entries(env).filter(([name]) => SECRET_NAME.test(name) && !SECRET_NAMES.includes(name)).map(([, value]) => value ?? "");
|
|
99
99
|
return [...new Set([...held, ...named])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
|
|
100
100
|
};
|
|
101
|
-
/** The
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
const
|
|
105
|
-
/**
|
|
106
|
-
export function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
/** The seal keys this process's open stores were booted with (seal-key.ts bootSealKey), by how many hold each: several
|
|
102
|
+
* data directories in one process each keep their own. Never read as a secret by name (each holder passes its own key
|
|
103
|
+
* on): only listed by hostSecrets, so what a run writes is cut of every one. */
|
|
104
|
+
const sealKeys = new Map();
|
|
105
|
+
/** Lists `text` among this process's seal keys, for redaction alone, until the returned release is called. */
|
|
106
|
+
export function holdSealKey(text) {
|
|
107
|
+
sealKeys.set(text, (sealKeys.get(text) ?? 0) + 1);
|
|
108
|
+
let released = false;
|
|
109
|
+
return () => {
|
|
110
|
+
if (released)
|
|
111
|
+
return;
|
|
112
|
+
released = true;
|
|
113
|
+
const left = (sealKeys.get(text) ?? 1) - 1;
|
|
114
|
+
if (left > 0)
|
|
115
|
+
sealKeys.set(text, left);
|
|
116
|
+
else
|
|
117
|
+
sealKeys.delete(text);
|
|
118
|
+
};
|
|
110
119
|
}
|
|
111
|
-
/** A secret this process was started with: as handed over, else (no launcher) as its environment has it now
|
|
112
|
-
|
|
113
|
-
const own = (name) => held.get(name) ?? process.env[name] ?? made.get(name);
|
|
120
|
+
/** A secret this process was started with: as handed over, else (no launcher) as its environment has it now. */
|
|
121
|
+
const own = (name) => held.get(name) ?? process.env[name];
|
|
114
122
|
/** A secret this process was handed (over its pipe, or in its environment), never one it made itself: what a start asks
|
|
115
123
|
* to tell a handed seal key from none, so a second server in one process makes or reads its own and is not handed the
|
|
116
124
|
* first one's. */
|
|
@@ -168,10 +176,6 @@ export function mcpCredentials() {
|
|
|
168
176
|
}
|
|
169
177
|
/** Every header value of `credentials`: what a secret scan refuses. */
|
|
170
178
|
export const mcpSecretValues = (credentials) => Object.values(credentials).flatMap((server) => Object.values(server.headers ?? {})).flatMap((value) => [value, value.replace(/^Bearer\s+/i, "")]);
|
|
171
|
-
/** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
|
|
172
|
-
export const mcpHandover = (credentials) => encode([[MCP_AUTH, JSON.stringify(credentials)]]);
|
|
173
|
-
/** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
|
|
174
|
-
export const handoverSignIn = (value) => encode([[SIGN_IN_PAIR, JSON.stringify(value)]]);
|
|
175
179
|
/** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
|
|
176
180
|
export function handedSignIn() {
|
|
177
181
|
try {
|