approval-md 0.3.0 → 0.4.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/README.md +83 -914
- package/SPEC.md +101 -13
- package/cli.js +134 -7
- package/dist/src/adapters/smtp.d.ts +18 -0
- package/dist/src/adapters/smtp.js +24 -3
- package/dist/src/adapters/smtp.js.map +1 -1
- package/dist/src/channels/contract.d.ts +72 -0
- package/dist/src/channels/contract.js +161 -1
- package/dist/src/channels/contract.js.map +1 -1
- package/dist/src/channels/relay-server.d.ts +90 -0
- package/dist/src/channels/relay-server.js +295 -0
- package/dist/src/channels/relay-server.js.map +1 -0
- package/dist/src/channels/relay.d.ts +273 -0
- package/dist/src/channels/relay.js +564 -0
- package/dist/src/channels/relay.js.map +1 -0
- package/dist/src/channels/tagging.d.ts +25 -0
- package/dist/src/channels/tagging.js +63 -6
- package/dist/src/channels/tagging.js.map +1 -1
- package/dist/src/channels/telegram-minimal.d.ts +251 -0
- package/dist/src/channels/telegram-minimal.js +618 -0
- package/dist/src/channels/telegram-minimal.js.map +1 -0
- package/dist/src/channels/telegram-webhook.d.ts +273 -0
- package/dist/src/channels/telegram-webhook.js +536 -0
- package/dist/src/channels/telegram-webhook.js.map +1 -0
- package/dist/src/channels/telegram.d.ts +725 -20
- package/dist/src/channels/telegram.js +1332 -123
- package/dist/src/channels/telegram.js.map +1 -1
- package/dist/src/cli/amend.js +358 -5
- package/dist/src/cli/amend.js.map +1 -1
- package/dist/src/cli/attest.js +43 -6
- package/dist/src/cli/attest.js.map +1 -1
- package/dist/src/cli/audit-card.d.ts +1 -1
- package/dist/src/cli/audit-card.js +40 -1
- package/dist/src/cli/audit-card.js.map +1 -1
- package/dist/src/cli/audit.d.ts +7 -5
- package/dist/src/cli/audit.js +22 -10
- package/dist/src/cli/audit.js.map +1 -1
- package/dist/src/cli/channel-relay.d.ts +108 -0
- package/dist/src/cli/channel-relay.js +334 -0
- package/dist/src/cli/channel-relay.js.map +1 -0
- package/dist/src/cli/channel-telegram-webhook.d.ts +275 -0
- package/dist/src/cli/channel-telegram-webhook.js +716 -0
- package/dist/src/cli/channel-telegram-webhook.js.map +1 -0
- package/dist/src/cli/channel-telegram.d.ts +347 -28
- package/dist/src/cli/channel-telegram.js +648 -56
- package/dist/src/cli/channel-telegram.js.map +1 -1
- package/dist/src/cli/channel.d.ts +1 -1
- package/dist/src/cli/channel.js +5 -1
- package/dist/src/cli/channel.js.map +1 -1
- package/dist/src/cli/daemon.js +37 -5
- package/dist/src/cli/daemon.js.map +1 -1
- package/dist/src/cli/doctor.d.ts +63 -0
- package/dist/src/cli/doctor.js +856 -111
- package/dist/src/cli/doctor.js.map +1 -1
- package/dist/src/cli/execute.d.ts +29 -1
- package/dist/src/cli/execute.js +387 -21
- package/dist/src/cli/execute.js.map +1 -1
- package/dist/src/cli/exit-codes.d.ts +12 -0
- package/dist/src/cli/exit-codes.js +13 -0
- package/dist/src/cli/exit-codes.js.map +1 -1
- package/dist/src/cli/gate.d.ts +2 -0
- package/dist/src/cli/gate.js +233 -2
- package/dist/src/cli/gate.js.map +1 -1
- package/dist/src/cli/help.d.ts +10 -1
- package/dist/src/cli/help.js +283 -54
- package/dist/src/cli/help.js.map +1 -1
- package/dist/src/cli/hook.d.ts +485 -6
- package/dist/src/cli/hook.js +2370 -70
- package/dist/src/cli/hook.js.map +1 -1
- package/dist/src/cli/init.js +16 -7
- package/dist/src/cli/init.js.map +1 -1
- package/dist/src/cli/instructions.js +24 -3
- package/dist/src/cli/instructions.js.map +1 -1
- package/dist/src/cli/log-anchor.d.ts +55 -0
- package/dist/src/cli/log-anchor.js +199 -60
- package/dist/src/cli/log-anchor.js.map +1 -1
- package/dist/src/cli/log-unlock.d.ts +23 -0
- package/dist/src/cli/log-unlock.js +109 -0
- package/dist/src/cli/log-unlock.js.map +1 -0
- package/dist/src/cli/main.d.ts +0 -12
- package/dist/src/cli/main.js +72 -4
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/muse.d.ts +2 -0
- package/dist/src/cli/muse.js +62 -0
- package/dist/src/cli/muse.js.map +1 -0
- package/dist/src/cli/payload.js +79 -1
- package/dist/src/cli/payload.js.map +1 -1
- package/dist/src/cli/scaffold.js +6 -0
- package/dist/src/cli/scaffold.js.map +1 -1
- package/dist/src/cli/serve.d.ts +53 -0
- package/dist/src/cli/serve.js +270 -0
- package/dist/src/cli/serve.js.map +1 -0
- package/dist/src/cli/up.js +26 -2
- package/dist/src/cli/up.js.map +1 -1
- package/dist/src/cli/verb-registry.d.ts +2 -0
- package/dist/src/cli/verb-registry.js +338 -39
- package/dist/src/cli/verb-registry.js.map +1 -1
- package/dist/src/cli/wordmark.d.ts +2 -2
- package/dist/src/cli/wordmark.js +2 -2
- package/dist/src/core/attest-bootstrap.d.ts +95 -0
- package/dist/src/core/attest-bootstrap.js +135 -0
- package/dist/src/core/attest-bootstrap.js.map +1 -0
- package/dist/src/core/attest.d.ts +20 -3
- package/dist/src/core/attest.js +25 -0
- package/dist/src/core/attest.js.map +1 -1
- package/dist/src/core/audit.d.ts +153 -12
- package/dist/src/core/audit.js +415 -20
- package/dist/src/core/audit.js.map +1 -1
- package/dist/src/core/channel-lease.d.ts +322 -0
- package/dist/src/core/channel-lease.js +663 -0
- package/dist/src/core/channel-lease.js.map +1 -0
- package/dist/src/core/command-class.d.ts +51 -0
- package/dist/src/core/command-class.js +766 -8
- package/dist/src/core/command-class.js.map +1 -1
- package/dist/src/core/daemon-host.d.ts +178 -0
- package/dist/src/core/daemon-host.js +228 -0
- package/dist/src/core/daemon-host.js.map +1 -0
- package/dist/src/core/daemon-identity.d.ts +238 -0
- package/dist/src/core/daemon-identity.js +252 -0
- package/dist/src/core/daemon-identity.js.map +1 -0
- package/dist/src/core/gate.d.ts +364 -6
- package/dist/src/core/gate.js +802 -27
- package/dist/src/core/gate.js.map +1 -1
- package/dist/src/core/harness-version.d.ts +128 -4
- package/dist/src/core/harness-version.js +179 -12
- package/dist/src/core/harness-version.js.map +1 -1
- package/dist/src/core/harness-wait.d.ts +82 -3
- package/dist/src/core/harness-wait.js +89 -3
- package/dist/src/core/harness-wait.js.map +1 -1
- package/dist/src/core/log-lock.d.ts +435 -0
- package/dist/src/core/log-lock.js +1093 -0
- package/dist/src/core/log-lock.js.map +1 -0
- package/dist/src/core/log-subscribe.d.ts +21 -0
- package/dist/src/core/log-subscribe.js +16 -6
- package/dist/src/core/log-subscribe.js.map +1 -1
- package/dist/src/core/log-write-layer.d.ts +55 -0
- package/dist/src/core/log-write-layer.js +91 -0
- package/dist/src/core/log-write-layer.js.map +1 -0
- package/dist/src/core/log.d.ts +130 -22
- package/dist/src/core/log.js +473 -50
- package/dist/src/core/log.js.map +1 -1
- package/dist/src/core/payload-census.d.ts +51 -0
- package/dist/src/core/payload-census.js +125 -2
- package/dist/src/core/payload-census.js.map +1 -1
- package/dist/src/core/payload-store.d.ts +31 -0
- package/dist/src/core/payload-store.js +113 -8
- package/dist/src/core/payload-store.js.map +1 -1
- package/dist/src/core/payload.d.ts +18 -3
- package/dist/src/core/payload.js +20 -4
- package/dist/src/core/payload.js.map +1 -1
- package/dist/src/core/policy-diff.d.ts +10 -0
- package/dist/src/core/policy-diff.js +10 -2
- package/dist/src/core/policy-diff.js.map +1 -1
- package/dist/src/core/policy-explain.d.ts +7 -1
- package/dist/src/core/policy-explain.js +16 -1
- package/dist/src/core/policy-explain.js.map +1 -1
- package/dist/src/core/policy-load.d.ts +24 -0
- package/dist/src/core/policy-load.js.map +1 -1
- package/dist/src/core/policy-match.d.ts +38 -0
- package/dist/src/core/policy-match.js +35 -0
- package/dist/src/core/policy-match.js.map +1 -1
- package/dist/src/core/policy-proposal.d.ts +40 -0
- package/dist/src/core/policy-proposal.js +37 -16
- package/dist/src/core/policy-proposal.js.map +1 -1
- package/dist/src/core/prompt-layout.d.ts +186 -1
- package/dist/src/core/prompt-layout.js +345 -3
- package/dist/src/core/prompt-layout.js.map +1 -1
- package/dist/src/core/read-scope.d.ts +10 -0
- package/dist/src/core/read-scope.js +4 -0
- package/dist/src/core/read-scope.js.map +1 -1
- package/dist/src/core/run-payload.d.ts +160 -0
- package/dist/src/core/run-payload.js +304 -0
- package/dist/src/core/run-payload.js.map +1 -0
- package/dist/src/core/sender-identity.d.ts +59 -11
- package/dist/src/core/sender-identity.js +79 -11
- package/dist/src/core/sender-identity.js.map +1 -1
- package/dist/src/core/state.d.ts +52 -1
- package/dist/src/core/state.js +52 -6
- package/dist/src/core/state.js.map +1 -1
- package/dist/src/core/telegram-config.d.ts +79 -0
- package/dist/src/core/telegram-config.js +108 -0
- package/dist/src/core/telegram-config.js.map +1 -1
- package/dist/src/core/validate.d.ts +20 -6
- package/dist/src/core/validate.js +0 -0
- package/dist/src/core/validate.js.map +1 -1
- package/dist/src/core/verify.d.ts +23 -1
- package/dist/src/core/verify.js +20 -2
- package/dist/src/core/verify.js.map +1 -1
- package/dist/src/daemon/audit.d.ts +80 -5
- package/dist/src/daemon/audit.js +126 -6
- package/dist/src/daemon/audit.js.map +1 -1
- package/dist/src/daemon/daemon.d.ts +174 -2
- package/dist/src/daemon/daemon.js +298 -7
- package/dist/src/daemon/daemon.js.map +1 -1
- package/dist/src/daemon/git-evidence.d.ts +2 -2
- package/dist/src/daemon/git-evidence.js +1 -1
- package/dist/src/daemon/projection.d.ts +13 -2
- package/dist/src/daemon/projection.js +39 -6
- package/dist/src/daemon/projection.js.map +1 -1
- package/dist/src/mcp/server.d.ts +39 -3
- package/dist/src/mcp/server.js +22 -3
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/muse/server.d.ts +16 -0
- package/dist/src/muse/server.js +238 -0
- package/dist/src/muse/server.js.map +1 -0
- package/dist/src/serve/archive.d.ts +166 -0
- package/dist/src/serve/archive.js +363 -0
- package/dist/src/serve/archive.js.map +1 -0
- package/dist/src/serve/arguments.d.ts +93 -0
- package/dist/src/serve/arguments.js +228 -0
- package/dist/src/serve/arguments.js.map +1 -0
- package/dist/src/serve/credentials.d.ts +91 -0
- package/dist/src/serve/credentials.js +143 -0
- package/dist/src/serve/credentials.js.map +1 -0
- package/dist/src/serve/follow.d.ts +86 -0
- package/dist/src/serve/follow.js +101 -0
- package/dist/src/serve/follow.js.map +1 -0
- package/dist/src/serve/hook-thread.d.ts +134 -0
- package/dist/src/serve/hook-thread.js +333 -0
- package/dist/src/serve/hook-thread.js.map +1 -0
- package/dist/src/serve/hook-worker.d.ts +134 -0
- package/dist/src/serve/hook-worker.js +173 -0
- package/dist/src/serve/hook-worker.js.map +1 -0
- package/dist/src/serve/server.d.ts +412 -0
- package/dist/src/serve/server.js +1251 -0
- package/dist/src/serve/server.js.map +1 -0
- package/docs/README-extended.md +768 -0
- package/docs/cli-reference.md +2139 -67
- package/package.json +4 -2
- package/schema/event.schema.json +413 -30
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-age-without-created.json +19 -0
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-agent-actor.json +14 -0
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-lockfile-path.json +14 -0
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-operator-cleared-system-actor.json +14 -0
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-unknown-reason.json +14 -0
- package/schema/fixtures/event/invalid/audit-lock-reclaimed-without-age.json +13 -0
- package/schema/fixtures/event/invalid/audit-reviewed-agent-actor.json +6 -1
- package/schema/fixtures/event/invalid/audit-reviewed-bad-payload-hash.json +21 -0
- package/schema/fixtures/event/invalid/audit-reviewed-loved-no-note.json +5 -0
- package/schema/fixtures/event/invalid/audit-reviewed-no-subject-hash.json +19 -0
- package/schema/fixtures/event/invalid/audit-reviewed-no-subject-seq.json +19 -0
- package/schema/fixtures/event/invalid/audit-reviewed-no-verdict-source.json +19 -0
- package/schema/fixtures/event/invalid/audit-reviewed-no-verdict.json +19 -0
- package/schema/fixtures/event/invalid/audit-reviewed-system-actor.json +6 -1
- package/schema/fixtures/event/invalid/audit-sampled-no-policy-hash.json +14 -0
- package/schema/fixtures/event/invalid/daemon-id-malformed.json +15 -0
- package/schema/fixtures/event/invalid/execution-started-truncated-policy-sha256.json +18 -0
- package/schema/fixtures/event/invalid/harness-cap-at-margin.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-fractional.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-negative.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-string.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-without-harness-execution.json +16 -0
- package/schema/fixtures/event/invalid/harness-cap-zero.json +16 -0
- package/schema/fixtures/event/valid/approval-requested-harness-cap.json +18 -0
- package/schema/fixtures/event/valid/audit-lock-reclaimed-implausible-created.json +18 -0
- package/schema/fixtures/event/valid/audit-lock-reclaimed-legacy.json +14 -0
- package/schema/fixtures/event/valid/audit-lock-reclaimed-unlock.json +19 -0
- package/schema/fixtures/event/valid/audit-lock-reclaimed.json +19 -0
- package/schema/fixtures/event/valid/audit-reviewed-reaction.json +5 -0
- package/schema/fixtures/event/valid/audit-reviewed.json +6 -1
- package/schema/fixtures/event/valid/audit-sampled.json +2 -1
- package/schema/fixtures/event/valid/daemon-identity-declared.json +17 -0
- package/schema/fixtures/event/valid/daemon-identity.json +16 -0
- package/schema/fixtures/event/valid/execution-started-policy-sha256.json +18 -0
- package/schema/fixtures/event/valid/harness-kind-hermes.json +23 -0
- package/schema/fixtures/policy/invalid/daemons-malformed-id.json +10 -0
- package/schema/fixtures/policy/valid/daemons-allowlist.json +19 -0
- package/schema/fixtures/policy-md/invalid/schema-invalid-agent-may-request.md +21 -0
- package/schema/fixtures/policy-md/valid/agent-may-request.md +24 -0
- package/schema/policy.schema.json +102 -6
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH daemon wrote this record, and the check the write boundary runs on it
|
|
3
|
+
* (APRV-383).
|
|
4
|
+
*
|
|
5
|
+
* ## The fact this module is about
|
|
6
|
+
*
|
|
7
|
+
* `core/daemon-actor.ts` answers "is this process the daemon". Every record the
|
|
8
|
+
* daemon appends carried that and nothing more: a generic `system:daemon` actor,
|
|
9
|
+
* one string, identical on every machine that ever ran one. That is enough while
|
|
10
|
+
* a gate's daemon is the operator's own process in the operator's own checkout,
|
|
11
|
+
* and it stops being enough the moment one party HOSTS a daemon for another.
|
|
12
|
+
* Three properties of that arrangement already hold: authority comes from the
|
|
13
|
+
* tenant's attested policy and never from the host (§5.2, APRV-324 and 356),
|
|
14
|
+
* credentials come from the launch environment so one process holds one tenant's
|
|
15
|
+
* token, and a decision arrives only through the tenant's own sender mapping so
|
|
16
|
+
* the host cannot mint one. What was missing is the smallest of the four and the
|
|
17
|
+
* one a tenant reads first: opening their own log and seeing which daemon acted
|
|
18
|
+
* on their behalf.
|
|
19
|
+
*
|
|
20
|
+
* So a daemon-written record carries a `daemon` field naming the instance that
|
|
21
|
+
* wrote it, and an attested policy MAY list the ids permitted to write
|
|
22
|
+
* (`daemons`, read by `core/daemon-host.ts`). An id the list does not name is
|
|
23
|
+
* refused at the write boundary.
|
|
24
|
+
*
|
|
25
|
+
* ## What the id is NOT, and this is the important half
|
|
26
|
+
*
|
|
27
|
+
* It is a SELF-REPORTED field, so SPEC.md §11.1 invariant 4 governs it
|
|
28
|
+
* completely: it may raise scrutiny and may never lower it. Concretely, in this
|
|
29
|
+
* runtime:
|
|
30
|
+
*
|
|
31
|
+
* - a listed id gains NOTHING. No verdict, no autonomy, no budget, no floor, no
|
|
32
|
+
* sampling draw, no token and no TTL reads this field or the list. Being named
|
|
33
|
+
* in `daemons` buys a daemon exactly the ability it had before the key existed;
|
|
34
|
+
* - an unlisted id is REFUSED, which is the only direction the field moves
|
|
35
|
+
* anything, and it moves it strictly towards writing less;
|
|
36
|
+
* - the id never enters a payload hash and never enters a token. It is a
|
|
37
|
+
* top-level record field, so the record's own chain hash covers it the way it
|
|
38
|
+
* covers `actor` (a record's provenance has to be part of what the chain
|
|
39
|
+
* protects, or it could be edited without breaking the chain), and no bound
|
|
40
|
+
* payload, no `payload_hash` and no `token_sha256` is computed over it.
|
|
41
|
+
*
|
|
42
|
+
* And it is ATTRIBUTION rather than authorization. A hostile host process holds
|
|
43
|
+
* the tenant's log handle and can call anything in this module the daemon calls,
|
|
44
|
+
* exactly as it can call {@link markDaemonProcess}; `core/daemon-actor.ts` states
|
|
45
|
+
* that boundary and this module inherits it word for word. What the allowlist
|
|
46
|
+
* catches is the likelier failure and the one nothing caught before: a daemon
|
|
47
|
+
* started against the wrong tenant's log, a second daemon nobody meant to leave
|
|
48
|
+
* running, a container rebuilt with a new id, each of which used to write records
|
|
49
|
+
* indistinguishable from the intended daemon's.
|
|
50
|
+
*
|
|
51
|
+
* ## Why the state is module state and not an argument
|
|
52
|
+
*
|
|
53
|
+
* For the reason `core/daemon-actor.ts` gives for taking no arguments: a field a
|
|
54
|
+
* caller passes is a field a caller chooses, and an `appendEvent` option naming
|
|
55
|
+
* the writing daemon would let any process in this runtime claim to be one. The
|
|
56
|
+
* daemon runtime declares its own identity once, at construction, through
|
|
57
|
+
* `core/daemon-host.ts`, and `core/log.ts` READS it. `EventInput` deliberately
|
|
58
|
+
* has no `daemon` member, and `buildRecord` composes a record field by field, so
|
|
59
|
+
* a caller that puts the property on its input object anyway is ignored rather
|
|
60
|
+
* than obeyed.
|
|
61
|
+
*
|
|
62
|
+
* ## Which processes declare, and why the stamp does not ask for the mark
|
|
63
|
+
*
|
|
64
|
+
* Three processes append on a gate's behalf without being a session, and since
|
|
65
|
+
* APRV-448 all three declare the same identity through the same two calls in
|
|
66
|
+
* `core/daemon-host.ts` (`declareDaemonIdentityFor` or
|
|
67
|
+
* `declareResolvedDaemonIdentity`, then `refreshDaemonAllowlist*`): the daemon
|
|
68
|
+
* loop (`daemon/daemon.ts`, at construction), `approval serve` (its verbs on the
|
|
69
|
+
* listener's thread and its hook calls on their worker threads), and `approval
|
|
70
|
+
* channel telegram webhook`. In a co-located deployment, where a facade, a
|
|
71
|
+
* daemon and a channel run in one process per tenant, a tenant reading their
|
|
72
|
+
* own log therefore sees one id on the sweeps and on the actions.
|
|
73
|
+
*
|
|
74
|
+
* The stamp is keyed on the DECLARATION, not on `core/daemon-actor.ts`'s mark.
|
|
75
|
+
* The two answer different questions: the mark says "this process is the daemon
|
|
76
|
+
* loop" and is what routes an advance under the autonomous
|
|
77
|
+
* `log.advance.daemon` class (APRV-382), while the declaration says "records
|
|
78
|
+
* this process writes name this instance". `approval serve` dispatches verbs an
|
|
79
|
+
* agent asked for, so marking it the daemon to get the stamp would hand its
|
|
80
|
+
* process the daemon's advance route, a widening nothing here needs. Declaring
|
|
81
|
+
* without marking stamps and restricts, and widens nothing.
|
|
82
|
+
*
|
|
83
|
+
* ## Why this module imports almost nothing
|
|
84
|
+
*
|
|
85
|
+
* `core/log.ts` imports it, and `core/log.ts` is the bottom of this codebase's
|
|
86
|
+
* import graph: `core/instance.ts` (where the derived id comes from) reaches
|
|
87
|
+
* `core/attest.ts` through `core/env-file.ts`, and `core/attest.ts` spreads
|
|
88
|
+
* `APPEND_ERROR_CODES` at module scope, so importing the
|
|
89
|
+
* derivation here would close a cycle whose evaluation order throws before any
|
|
90
|
+
* test ran. The split is also the right seam on its own terms: what the write
|
|
91
|
+
* boundary needs is a grammar, a state and one question, and everything that
|
|
92
|
+
* reads a policy or a filesystem to ANSWER that question lives in
|
|
93
|
+
* `core/daemon-host.ts`.
|
|
94
|
+
*/
|
|
95
|
+
/**
|
|
96
|
+
* The environment variable a launch may declare the daemon's id in.
|
|
97
|
+
*
|
|
98
|
+
* Beside `APPROVAL_HUMAN` and the credential variables, and in the launch
|
|
99
|
+
* environment for the same reason they are: SPEC.md §11.1 invariant 7 keeps this
|
|
100
|
+
* runtime from reading configuration out of the working tree, and a hosted
|
|
101
|
+
* daemon's id is configuration its OPERATOR sets, never something the tenant's
|
|
102
|
+
* repository tells the host about itself.
|
|
103
|
+
*/
|
|
104
|
+
export const DAEMON_ID_ENV = "APPROVAL_DAEMON_ID";
|
|
105
|
+
/** The longest id this runtime writes or admits. */
|
|
106
|
+
export const DAEMON_ID_MAX_LENGTH = 64;
|
|
107
|
+
/**
|
|
108
|
+
* The shape an id takes: lowercase alphanumerics, dots, dashes and underscores,
|
|
109
|
+
* starting with an alphanumeric.
|
|
110
|
+
*
|
|
111
|
+
* Narrow on purpose, and for the reason `payload.harness_version` is narrow
|
|
112
|
+
* (APRV-227): the value is a string from a launch environment being written into
|
|
113
|
+
* an append-only log, so a banner, a path, a newline or a shell fragment must not
|
|
114
|
+
* be able to arrive through it. It is also a value an operator COMPARES by eye
|
|
115
|
+
* against `approval doctor` and against the `daemons` list in their policy, and
|
|
116
|
+
* two ids differing only in case are two ids nobody can tell apart on a phone.
|
|
117
|
+
*/
|
|
118
|
+
const DAEMON_ID_PATTERN = /^[a-z0-9][a-z0-9._-]*$/u;
|
|
119
|
+
/** Is `value` a well-formed daemon id? */
|
|
120
|
+
export function isDaemonId(value) {
|
|
121
|
+
return value.length <= DAEMON_ID_MAX_LENGTH && DAEMON_ID_PATTERN.test(value);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The two ways an append can be refused for the identity of the daemon making
|
|
125
|
+
* it, spread into `APPEND_ERROR_CODES` by `core/log.ts`.
|
|
126
|
+
*
|
|
127
|
+
* Two codes rather than one, because the repairs have nothing in common and
|
|
128
|
+
* SPEC.md §11.1 invariant 6 is about a caller being able to act on the answer:
|
|
129
|
+
* one is a line to add to an attested policy, the other is a variable to fix in
|
|
130
|
+
* the launch environment of a process that should not have started.
|
|
131
|
+
*
|
|
132
|
+
* Declared here rather than in `core/log.ts`'s literal list so that the codes and
|
|
133
|
+
* the logic that emits them cannot drift apart; the union there spreads this one,
|
|
134
|
+
* exactly as `ATTEST_ERROR_CODES` spreads it.
|
|
135
|
+
*/
|
|
136
|
+
export const DAEMON_APPEND_REFUSAL_CODES = [
|
|
137
|
+
/**
|
|
138
|
+
* The daemon declared an id through {@link DAEMON_ID_ENV} that is not a
|
|
139
|
+
* well-formed id at all, so no record it wrote could be attributed to anything.
|
|
140
|
+
*
|
|
141
|
+
* Refused rather than silently falling back to the derived id, which is the
|
|
142
|
+
* fail-closed direction twice over: an operator who set the variable meant the
|
|
143
|
+
* value they set, and a runtime that quietly used a different one would write
|
|
144
|
+
* records under a name nobody chose, against an allowlist nobody wrote for it.
|
|
145
|
+
*/
|
|
146
|
+
"daemon-id-invalid",
|
|
147
|
+
/**
|
|
148
|
+
* The attested policy lists the daemon ids that may write to this log, and this
|
|
149
|
+
* daemon's id is not among them.
|
|
150
|
+
*
|
|
151
|
+
* An ABSENT list is no restriction, not an empty one: a policy that never
|
|
152
|
+
* declares the key behaves exactly as every policy written before it existed.
|
|
153
|
+
*/
|
|
154
|
+
"daemon-not-allowed",
|
|
155
|
+
];
|
|
156
|
+
/** The declaring process's own state. Never set on another process's behalf. */
|
|
157
|
+
let identity = null;
|
|
158
|
+
/**
|
|
159
|
+
* The pid that made the declaration, for the reason `core/daemon-actor.ts` keeps
|
|
160
|
+
* one: the stamp answers only while it is still this process's own. Kept beside
|
|
161
|
+
* {@link identity} rather than inside it, so the reported state is unchanged.
|
|
162
|
+
*/
|
|
163
|
+
let declaredPid = null;
|
|
164
|
+
/**
|
|
165
|
+
* Declare the id this process's records carry. Called through
|
|
166
|
+
* `core/daemon-host.ts` by the processes the header names (the daemon loop,
|
|
167
|
+
* `approval serve` and its hook threads, the Telegram webhook listener), and by
|
|
168
|
+
* nothing else.
|
|
169
|
+
*
|
|
170
|
+
* Takes the RESOLVED values rather than resolving them, because resolution reads
|
|
171
|
+
* the environment and the filesystem and this module is the one `core/log.ts`
|
|
172
|
+
* imports (see the header). Idempotent, and a second call replaces the first: a
|
|
173
|
+
* runtime that re-resolves its identity is reporting a fact about itself, and the
|
|
174
|
+
* newest reading is the one in force.
|
|
175
|
+
*/
|
|
176
|
+
export function declareDaemonIdentity(state) {
|
|
177
|
+
identity = {
|
|
178
|
+
id: state.id,
|
|
179
|
+
declared: state.declared ?? null,
|
|
180
|
+
source: state.source,
|
|
181
|
+
// A fresh declaration carries no allowlist. The daemon resolves one from its
|
|
182
|
+
// attested policy and sets it separately, so an identity re-declared mid-run
|
|
183
|
+
// cannot silently drop a restriction that was in force.
|
|
184
|
+
allowed: identity === null ? null : identity.allowed,
|
|
185
|
+
};
|
|
186
|
+
declaredPid = process.pid;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Record which daemon ids this log's ATTESTED policy admits.
|
|
190
|
+
*
|
|
191
|
+
* Called only after a successful resolution: the daemon loaded its policy, read
|
|
192
|
+
* the verified log, and the attestation matched (`core/daemon-host.ts`). A
|
|
193
|
+
* resolution that FAILED calls nothing, so the restriction last resolved stays in
|
|
194
|
+
* force rather than lapsing — a policy that becomes unreadable must not be a way
|
|
195
|
+
* to escape the list it carried a moment ago.
|
|
196
|
+
*
|
|
197
|
+
* `null` means the attested policy declares none, which is no restriction.
|
|
198
|
+
*/
|
|
199
|
+
export function setDaemonAllowlist(allowed) {
|
|
200
|
+
if (identity === null)
|
|
201
|
+
return;
|
|
202
|
+
identity = { ...identity, allowed: allowed === null ? null : [...allowed] };
|
|
203
|
+
}
|
|
204
|
+
/** Forget the declaration. For tests, and for a runtime that stops being one. */
|
|
205
|
+
export function clearDaemonIdentity() {
|
|
206
|
+
identity = null;
|
|
207
|
+
declaredPid = null;
|
|
208
|
+
}
|
|
209
|
+
/** What this process has declared about itself, or `null`. */
|
|
210
|
+
export function daemonIdentity() {
|
|
211
|
+
return identity;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The write boundary's question, answered from this process's own state
|
|
215
|
+
* (APRV-383).
|
|
216
|
+
*
|
|
217
|
+
* Both halves of the answer are here rather than in two functions, because they
|
|
218
|
+
* are one decision made in one order: a process that cannot name itself is
|
|
219
|
+
* refused before anything asks whether its name is allowed.
|
|
220
|
+
*
|
|
221
|
+
* A process that declared NO identity gets `absent`, whether or not it marked
|
|
222
|
+
* itself the daemon. That is every session, every hook process and the
|
|
223
|
+
* pre-APRV-383 daemon, and the records they write are the records they always
|
|
224
|
+
* wrote; turning an undeclared mark into a dead log would make an unrelated
|
|
225
|
+
* module's `markDaemonProcess` call a stop-the-world bug. The answer is keyed on
|
|
226
|
+
* the declaration alone (APRV-448, see the header): the daemon loop marks and
|
|
227
|
+
* declares together, while `approval serve` and the webhook listener declare
|
|
228
|
+
* without marking, because the mark carries the daemon's advance route and the
|
|
229
|
+
* declaration carries nothing but a name and a restriction.
|
|
230
|
+
*/
|
|
231
|
+
export function daemonStampForAppend() {
|
|
232
|
+
const state = identity;
|
|
233
|
+
if (state === null || declaredPid !== process.pid)
|
|
234
|
+
return { kind: "absent" };
|
|
235
|
+
if (state.id === null) {
|
|
236
|
+
return {
|
|
237
|
+
kind: "refuse",
|
|
238
|
+
code: "daemon-id-invalid",
|
|
239
|
+
message: `this daemon declared ${DAEMON_ID_ENV}=${JSON.stringify(state.declared ?? "")}, which is not a usable daemon id (lowercase letters, digits, \`.\`, \`-\` and \`_\`, starting with a letter or digit, at most ${String(DAEMON_ID_MAX_LENGTH)} characters), so no record it wrote could name which daemon wrote it. Nothing was written: fix ${DAEMON_ID_ENV} in this process's launch environment, or unset it and let the id derive from this instance`,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const allowed = state.allowed;
|
|
243
|
+
if (allowed !== null && !allowed.includes(state.id)) {
|
|
244
|
+
return {
|
|
245
|
+
kind: "refuse",
|
|
246
|
+
code: "daemon-not-allowed",
|
|
247
|
+
message: `this daemon's id is ${state.id} and the attested policy's \`daemons\` list admits ${allowed.length === 0 ? "no daemon at all" : allowed.join(", ")}, so it may not write to this log. Nothing was written: add ${state.id} to \`daemons\` and re-attest the policy, or run the daemon whose id the list already names`,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return { kind: "stamp", id: state.id };
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=daemon-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon-identity.js","sourceRoot":"","sources":["../../../src/core/daemon-identity.ts"],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