@cotal-ai/core 0.169.0 → 0.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-endpoint.d.ts +146 -5
- package/dist/agent-endpoint.d.ts.map +1 -1
- package/dist/agent-endpoint.js +69 -12
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-file.d.ts +9 -5
- package/dist/agent-file.d.ts.map +1 -1
- package/dist/agent-file.js +18 -8
- package/dist/agent-file.js.map +1 -1
- package/dist/anycast-requests.d.ts +8 -1
- package/dist/anycast-requests.d.ts.map +1 -1
- package/dist/anycast-requests.js +47 -0
- package/dist/anycast-requests.js.map +1 -1
- package/dist/backup-config.d.ts +5 -2
- package/dist/backup-config.d.ts.map +1 -1
- package/dist/backup-config.js +7 -2
- package/dist/backup-config.js.map +1 -1
- package/dist/backup.d.ts +6 -0
- package/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +11 -4
- package/dist/backup.js.map +1 -1
- package/dist/connector-setup.d.ts +2 -0
- package/dist/connector-setup.d.ts.map +1 -1
- package/dist/endpoint-action.d.ts +2 -2
- package/dist/endpoint-action.js +6 -7
- package/dist/endpoint-action.js.map +1 -1
- package/dist/endpoint-binding.d.ts.map +1 -1
- package/dist/endpoint-binding.js +2 -0
- package/dist/endpoint-binding.js.map +1 -1
- package/dist/endpoint-boot-memberships.d.ts +71 -0
- package/dist/endpoint-boot-memberships.d.ts.map +1 -0
- package/dist/endpoint-boot-memberships.js +119 -0
- package/dist/endpoint-boot-memberships.js.map +1 -0
- package/dist/endpoint-channel-discovery.d.ts +102 -0
- package/dist/endpoint-channel-discovery.d.ts.map +1 -0
- package/dist/endpoint-channel-discovery.js +170 -0
- package/dist/endpoint-channel-discovery.js.map +1 -0
- package/dist/endpoint-control-plane.d.ts +204 -0
- package/dist/endpoint-control-plane.d.ts.map +1 -0
- package/dist/endpoint-control-plane.js +627 -0
- package/dist/endpoint-control-plane.js.map +1 -0
- package/dist/endpoint-durable-backstop.d.ts +249 -0
- package/dist/endpoint-durable-backstop.d.ts.map +1 -0
- package/dist/endpoint-durable-backstop.js +485 -0
- package/dist/endpoint-durable-backstop.js.map +1 -0
- package/dist/endpoint-journal.d.ts.map +1 -1
- package/dist/endpoint-journal.js +14 -6
- package/dist/endpoint-journal.js.map +1 -1
- package/dist/endpoint-liveness.d.ts +105 -0
- package/dist/endpoint-liveness.d.ts.map +1 -0
- package/dist/endpoint-liveness.js +223 -0
- package/dist/endpoint-liveness.js.map +1 -0
- package/dist/endpoint-messaging.d.ts +229 -0
- package/dist/endpoint-messaging.d.ts.map +1 -0
- package/dist/endpoint-messaging.js +420 -0
- package/dist/endpoint-messaging.js.map +1 -0
- package/dist/endpoint-presence.d.ts +15 -0
- package/dist/endpoint-presence.d.ts.map +1 -1
- package/dist/endpoint-presence.js +35 -0
- package/dist/endpoint-presence.js.map +1 -1
- package/dist/endpoint-provisioning.d.ts +73 -0
- package/dist/endpoint-provisioning.d.ts.map +1 -0
- package/dist/endpoint-provisioning.js +122 -0
- package/dist/endpoint-provisioning.js.map +1 -0
- package/dist/endpoint-subscriptions.d.ts +199 -0
- package/dist/endpoint-subscriptions.d.ts.map +1 -0
- package/dist/endpoint-subscriptions.js +543 -0
- package/dist/endpoint-subscriptions.js.map +1 -0
- package/dist/endpoint.d.ts +42 -124
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/endpoint.js +299 -1903
- package/dist/endpoint.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/provision-jwt.d.ts.map +1 -1
- package/dist/provision-jwt.js +1 -0
- package/dist/provision-jwt.js.map +1 -1
- package/dist/provision-permission-builders.d.ts +356 -0
- package/dist/provision-permission-builders.d.ts.map +1 -0
- package/dist/provision-permission-builders.js +1383 -0
- package/dist/provision-permission-builders.js.map +1 -0
- package/dist/provision-permissions.d.ts +3 -48
- package/dist/provision-permissions.d.ts.map +1 -1
- package/dist/provision-permissions.js +12 -1378
- package/dist/provision-permissions.js.map +1 -1
- package/dist/run-host.d.ts +4 -1
- package/dist/run-host.d.ts.map +1 -1
- package/dist/run-record.d.ts +4 -0
- package/dist/run-record.d.ts.map +1 -1
- package/dist/run-record.js +36 -0
- package/dist/run-record.js.map +1 -1
- package/dist/space-quiescence-resources.d.ts +30 -0
- package/dist/space-quiescence-resources.d.ts.map +1 -0
- package/dist/space-quiescence-resources.js +45 -0
- package/dist/space-quiescence-resources.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,23 +1,17 @@
|
|
|
1
|
+
import { spaceQuiescenceReaderGrants } from "./space-quiescence-resources.js";
|
|
1
2
|
import { eventPayloadReadSubjects, eventPayloadStream, eventPayloadSubject } from "./event-payloads.js";
|
|
2
|
-
import {
|
|
3
|
-
import { spaceDeletionStreams } from "./space-deletion-targets.js";
|
|
4
|
-
import { BROKER_USER_INFO_SUBJECT } from "./broker-identity.js";
|
|
5
|
-
import { spacePrefix, chatSubject, assertValidChannel, principalKey, deprovisionTargetPrincipal, assertInboxConnId, unicastSubject, anycastSubject, controlServiceSubject, CONTROL_DELIVERY, CONTROL_DELIVERY_ADMIN, artifactBucket, objectStoreStream, chatStream, dmStream, taskStream, dlvStream, inboxStream, chatHistDurable, historyReaderConsumer, HISTORY_READERS, dmDurable, taskDurable, dlvDurable, presenceBucket, presenceKeySubject, channelBucket, membersBucket, aclBucket, aclKey, memberKey, assertLifecycleToken, membershipBucket, deliveryBucket, managerBucket, MANAGER_LEASE_KEY, MANAGER_RENEWAL_LEASE_KEY, connzRequestSubject, accountConnectSubject, accountDisconnectSubject, MEMBERSHIP_INBOX_PREFIX, INBOX_READER_DURABLE, livenessSubject, livenessServeFilter, livenessReplyGrant, isTransferStream, takeSubject, takeServeFilter, takeReplyGrant, anycastBucket } from "./subjects.js";
|
|
3
|
+
import { spacePrefix, chatSubject, assertValidChannel, principalKey, assertInboxConnId, unicastSubject, anycastSubject, controlServiceSubject, CONTROL_DELIVERY, CONTROL_DELIVERY_ADMIN, chatStream, dmStream, taskStream, dlvStream, chatHistDurable, historyReaderConsumer, HISTORY_READERS, dmDurable, taskDurable, dlvDurable, presenceBucket, presenceKeySubject, channelBucket, assertLifecycleToken, membershipBucket, deliveryBucket, livenessSubject, takeSubject } from "./subjects.js";
|
|
6
4
|
import { LIVENESS_PLANES } from "./liveness.js";
|
|
7
|
-
import { epCallerGrantRows,
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { acceptedReadGrant, acceptedBucket, issuedBucket, issuedStoreStreamNames } from "./issued-authority.js";
|
|
5
|
+
import { epCallerGrantRows, epBaselineGrantRows, spawnCallerCapabilities, runCallerCapabilities, epRequestGrantRows, epPrincipalServeGrantRows, epPrincipalOwnerGrantRows, operatorInstrumentCapabilities, epDescribeAllGrantRow } from "./endpoint-grants.js";
|
|
6
|
+
import { epcStreamName } from "./endpoint-binding.js";
|
|
7
|
+
import { epCallerReplyFilter, AUTH_ENDPOINT, EP_CMD_RETIRE_LIFECYCLE } from "./endpoint-subjects.js";
|
|
8
|
+
import { acceptedReadGrant } from "./issued-authority.js";
|
|
12
9
|
import { REGISTRY_ENDPOINTS_GRANT } from "./registry-contract.js";
|
|
13
|
-
import { admissionBucket, admissionKey, revocationKey } from "./run-admission.js";
|
|
14
|
-
import { runSubmissionKey } from "./run-submission.js";
|
|
15
10
|
import { runDriverGrants, runMediatorGrants, runOperatorGrants } from "./run-driver-grants.js";
|
|
16
11
|
import { transferReaderGrants, transferWriterGrants } from "./transfer.js";
|
|
17
|
-
import { recordsBucket, recordSpecKey, recordStatusKey, recordAtomicKey, RECORD_KINDS, GOVERN_HEAD } from "./endpoint-records.js";
|
|
18
|
-
import { lifecycleHeadKey, uidReservationKey, issuanceGateKey, staticSlotKey, STATIC_SLOT_PREFIX, epgateKey, epcredFamilyPrefix, eprepairKey } from "./lifecycle-state.js";
|
|
19
12
|
import { environmentManagerPermissions, isEnvironmentManagerProfile } from "./environment-manager-grants.js";
|
|
20
|
-
import { backupProfilePermissions, restoreProfilePermissions
|
|
13
|
+
import { backupProfilePermissions, restoreProfilePermissions } from "./backup.js";
|
|
14
|
+
import { managerCallerPermissions, supervisorPermissions, remoteManagerPermissions, operatorPermissions, probePermissions, channelWriterPermissions, channelPurgerPermissions, teardownPermissions, membershipStoreRecreatePermissions, issuedStoreRecreatePermissions, controlCallerPermissions, issuedCallerFor, listingGrantRows, deployerPermissions, purgerPermissions, provisionerPermissions, issuerPermissions, registryReaderPermissions, runAdmitterPermissions, lifecycleExecutorPermissions, goalWriterPermissions, sessionCallerPermissions, dmReaderPermissions, sessionServingPermissions, sessionLedgerPermissions, endpointServeExecutorPermissions, deprovisionerPermissions, deliveryPermissions, membershipRwPermissions } from "./provision-permission-builders.js";
|
|
21
15
|
const ROLE_CAPABILITY = /^role:([A-Za-z0-9_-]+)$/;
|
|
22
16
|
/** The role a `role:<r>` capability token names, or `undefined` for any other token. */
|
|
23
17
|
export function capabilityRole(token) {
|
|
@@ -154,6 +148,8 @@ export function permissionsFor(profile, space, pr, opts) {
|
|
|
154
148
|
throw new Error('permissionsFor: "remote-manager" requires opts.remoteManager ({instanceId, owner} of the authorized manager lifecycle)');
|
|
155
149
|
return remoteManagerPermissions(space, pr, opts.remoteManager);
|
|
156
150
|
}
|
|
151
|
+
if (profile === "space-quiescence-reader")
|
|
152
|
+
return spaceQuiescenceReaderGrants(space, pr.connId);
|
|
157
153
|
if (profile === "issuer")
|
|
158
154
|
return issuerPermissions(space, pr);
|
|
159
155
|
if (profile === "registry-reader")
|
|
@@ -648,1368 +644,6 @@ export function permissionsFor(profile, space, pr, opts) {
|
|
|
648
644
|
const takeReplies = roles.map((role) => `${takeSubject(space, role, pr.owner, pr.actor)}.>`);
|
|
649
645
|
return { pub: { allow: pubAllow, deny: pubDeny }, sub: { allow: [inbox, deliveryReplies, ...takeReplies, ...livenessReplies, ...subChat, ...payloadReads, ...epSub] } };
|
|
650
646
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
* directory) and `list-dir` (directory navigation). The remaining read, `ps`,
|
|
654
|
-
* lists the caller's own agents: the Manager bounds it to the caller's owner unless the caller
|
|
655
|
-
* holds admin. The standing spawn set carries none of them, because it reaches every manager in
|
|
656
|
-
* the space through the class rail. */
|
|
657
|
-
const SPAWN_VIEW_READS = Object.freeze(["status", "models", "resolve-cwd", "list-dir", "ps"]);
|
|
658
|
-
/** One seat's manager control view. It carries no agent messaging or delivery surface, and every
|
|
659
|
-
* manager request, including describe, is pinned to one exact registered instance. */
|
|
660
|
-
function managerCallerPermissions(space, pr, opts) {
|
|
661
|
-
if (!pr.lifecycleUid)
|
|
662
|
-
throw new Error("permissionsFor(manager-caller): a lifecycleUid is required");
|
|
663
|
-
const instanceId = opts.managerInstanceId === undefined
|
|
664
|
-
? (() => { throw new Error("permissionsFor(manager-caller): managerInstanceId is required"); })()
|
|
665
|
-
: assertLifecycleToken(opts.managerInstanceId, "managerInstanceId");
|
|
666
|
-
const caps = opts.capabilities ?? [];
|
|
667
|
-
const ordinary = [
|
|
668
|
-
{ endpoint: BASELINE_LIFECYCLE_ENDPOINT, command: "describe" },
|
|
669
|
-
...baselineCallerCapabilities().filter((cap) => cap.endpoint === BASELINE_LIFECYCLE_ENDPOINT),
|
|
670
|
-
...(caps.includes("spawn") ? spawnCallerCapabilities(pr.owner) : []),
|
|
671
|
-
...(caps.includes("spawn") ? SPAWN_VIEW_READS.map((command) => ({ endpoint: BASELINE_LIFECYCLE_ENDPOINT, command })) : []),
|
|
672
|
-
...(caps.includes(MANAGER_VITALS_SCOPE) ? [{ endpoint: BASELINE_LIFECYCLE_ENDPOINT, command: MANAGER_VITALS_COMMAND }] : []),
|
|
673
|
-
...(caps.includes("run") ? runCallerCapabilities(pr.owner) : []),
|
|
674
|
-
...(caps.includes("admin") ? operatorInstrumentCapabilities("admin", pr.owner) : []),
|
|
675
|
-
];
|
|
676
|
-
const caller = issuedCallerFor({ owner: pr.owner, actor: pr.actor, uid: assertLifecycleToken(pr.lifecycleUid) }, opts);
|
|
677
|
-
const rows = epCallerGrantRows(space, instanceOnlyManagerCapabilities(ordinary, instanceId), caller);
|
|
678
|
-
const listing = opts.listing ? listingGrantRows(space, caller, opts.listing) : { pub: [], sub: [] };
|
|
679
|
-
return {
|
|
680
|
-
pub: {
|
|
681
|
-
allow: [
|
|
682
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}.${spacePrefix(space)}.epc.>`,
|
|
683
|
-
...(opts.issued ? [acceptedReadGrant(space, opts.issued.acceptedToken)] : []),
|
|
684
|
-
...rows.pub,
|
|
685
|
-
...(opts.issued?.listing ? epRequestGrantRows(space, REGISTRY_ENDPOINTS_GRANT, caller) : []),
|
|
686
|
-
...listing.pub,
|
|
687
|
-
],
|
|
688
|
-
},
|
|
689
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`, ...rows.sub, ...listing.sub] },
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
/** The long-lived SUPERVISOR permission set — the always-on manager daemon
|
|
693
|
-
* (`manager.ts` `this.ep`), carved down from the former allow-all `manager`. Its breadth is
|
|
694
|
-
* STANDING, so tightening it removes the always-on DM/DLV body-read AND the stream-admin tamper
|
|
695
|
-
* from the one connection that never goes away. It holds the manager bucket's `lease.*` instance keys
|
|
696
|
-
* and the per-space renewal lease key, its own presence key + the roster watch, the ONE delivery-admin
|
|
697
|
-
* call (request + bounded reply subtree), the manager-plane liveness serve + reply rows, and a
|
|
698
|
-
* read-only point read of the delivery lease row — and nothing else. It serves no manager control:
|
|
699
|
-
* that is the v0.4 `service` endpoint, served on a SEPARATE connection under its own
|
|
700
|
-
* `endpoint-serve` credential. Provisioning (DM/DLV/TASK consumer-create + ACL
|
|
701
|
-
* writes) moves to the EPHEMERAL `provisioner` (opened per-spawn); destructive history-purge moves to the
|
|
702
|
-
* EPHEMERAL `purger`. So the supervisor holds NO chat/inst/svc publish (it never posts — only
|
|
703
|
-
* `setActivity`, a presence write), NO DM/DLV read of any kind (no consumer-create, no native sub), NO
|
|
704
|
-
* stream CREATE/DELETE/PURGE/UPDATE, NO channel-registry access (the daemon sets `watchChannels:false`).
|
|
705
|
-
* `$JS` is an ENUMERATED allow-list — exactly the presence-watch + lease-KV verbs — never `$JS.>`. A
|
|
706
|
-
* leaked supervisor cred can hold the lease and read the public roster; it cannot read a DM, forge an
|
|
707
|
-
* actor, provision, purge, or tamper with a stream. */
|
|
708
|
-
function supervisorPermissions(space, pr) {
|
|
709
|
-
const PKV = `KV_${presenceBucket(space)}`, MKV = `KV_${managerBucket(space)}`;
|
|
710
|
-
const SUP_DLVKV = `KV_${deliveryBucket(space)}`;
|
|
711
|
-
return {
|
|
712
|
-
pub: {
|
|
713
|
-
allow: [
|
|
714
|
-
"$JS.API.INFO",
|
|
715
|
-
// Transcript startup checks read retained subject counts, never message bodies.
|
|
716
|
-
`$JS.API.STREAM.INFO.${chatStream(space)}`,
|
|
717
|
-
// Per-instance manager liveness lease (managerBucket, pre-created at `cotal up`): OPEN-ONLY bind +
|
|
718
|
-
// CAS this instance's own `lease.<instanceId>` key (acquire/renew/release) + read the subtree. The
|
|
719
|
-
// lease is per instance, so the write grant spans `lease.*` (every instance of this space
|
|
720
|
-
// shares this one supervisor principal — the isolation between instances is the logical-id/CAS
|
|
721
|
-
// boundary, not a cred boundary). NO STREAM.CREATE (pre-created), DELETE, or PURGE.
|
|
722
|
-
`$JS.API.STREAM.INFO.${MKV}`,
|
|
723
|
-
`$JS.API.STREAM.MSG.GET.${MKV}`, // readManagerLease (last_by_subj lease.*) + CAS-conflict kv.get
|
|
724
|
-
`$KV.${managerBucket(space)}.${MANAGER_LEASE_KEY}.*`, // this instance's lease.<id> key (create/update/delete = $KV publishes)
|
|
725
|
-
// #1634: the per-space daemon-credential renewal lease, the CAS that picks ONE renewal owner
|
|
726
|
-
// when several managers share the daemon's store. Same bucket, its own key outside `lease.*`.
|
|
727
|
-
`$KV.${managerBucket(space)}.${MANAGER_RENEWAL_LEASE_KEY}`,
|
|
728
|
-
// Presence: publish OWN key + watch the roster. Own key only (no peer-key forge); no
|
|
729
|
-
// presence-stream purge/delete (no force-offline tamper). No presence kv.get (roster is the in-memory
|
|
730
|
-
// watch cache + sweep), so no STREAM.MSG.GET on presence.
|
|
731
|
-
`$KV.${presenceBucket(space)}.${principalKey(pr.owner, pr.actor).key}`,
|
|
732
|
-
`$JS.API.STREAM.INFO.${PKV}`,
|
|
733
|
-
`$JS.API.CONSUMER.CREATE.${PKV}.>`, // kv.watch ordered consumer (roster)
|
|
734
|
-
`$JS.API.CONSUMER.INFO.${PKV}.>`,
|
|
735
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
736
|
-
// The ONE control service the supervisor CALLS: the delivery daemon's privileged
|
|
737
|
-
// admin rail — the manager is the daemon's renewal owner, and after re-signing the daemon creds
|
|
738
|
-
// files it requests `reloadCreds` here so adoption is an explicit, auditable event. Self-scoped
|
|
739
|
-
// request subject (its own owner+actor slots), bounded reply subtree in sub.allow below.
|
|
740
|
-
controlServiceSubject(space, CONTROL_DELIVERY_ADMIN, pr.owner, pr.actor),
|
|
741
|
-
// LIVENESS REPLIES for the MANAGER plane (#1577), bounded to the `.reply.` leaf under a
|
|
742
|
-
// caller's own request subject. The supervisor is the natural responder for this plane: it
|
|
743
|
-
// is the process that HOLDS the manager lease, so it is the one that can answer the
|
|
744
|
-
// question honestly without anyone else being granted a read of the lease row.
|
|
745
|
-
//
|
|
746
|
-
// REPLIES ONLY, exactly like the delivery daemon's `ctl.delivery.*.*.reply.>`. The row stops
|
|
747
|
-
// at the leaf, so the supervisor cannot publish to the liveness REQUEST subjects themselves
|
|
748
|
-
// and therefore cannot forge a probe from a peer.
|
|
749
|
-
livenessReplyGrant(space, "manager"),
|
|
750
|
-
// #1694: a POINT READ of the delivery lease row, so the store-identity challenge can verify
|
|
751
|
-
// that the process which answered the queue-grouped admin rail is the holder that actually
|
|
752
|
-
// reloads the standing credentials. Without it the challenge can only report what some
|
|
753
|
-
// responder sent, and a non-holder's store stands in for the reloading process's.
|
|
754
|
-
//
|
|
755
|
-
// READ ONLY, and that is the half that matters: a credential able to WRITE this row could
|
|
756
|
-
// manufacture the very fact the challenge reads, which would put the determination back in
|
|
757
|
-
// the hands of a participant. No `$KV.${deliveryBucket(space)}` publish, no watch consumer,
|
|
758
|
-
// no STREAM.DELETE or PURGE.
|
|
759
|
-
`$JS.API.STREAM.INFO.${SUP_DLVKV}`,
|
|
760
|
-
`$JS.API.STREAM.MSG.GET.${SUP_DLVKV}`,
|
|
761
|
-
`$JS.API.DIRECT.GET.${SUP_DLVKV}.>`,
|
|
762
|
-
],
|
|
763
|
-
},
|
|
764
|
-
sub: {
|
|
765
|
-
// Own reply inbox + the delivery-admin reply subtree for its OWN requests. NO chat/inst/dlv
|
|
766
|
-
// native sub (the supervisor reads no feed), NO manager control-tier serve (that is
|
|
767
|
-
// the endpoint-serve credential's), NO broad `$JS.>`/`$KV.>`.
|
|
768
|
-
//
|
|
769
|
-
// PLUS the manager-plane liveness SERVE filter (#1577): `live.manager.*.*`, queue-grouped, so
|
|
770
|
-
// any credentialed peer's presence probe reaches the lease holder. This is a serve
|
|
771
|
-
// subscription on a presence-only rail, not a widening of what the supervisor may read: the
|
|
772
|
-
// request body is empty and the subject carries only the caller's own principal.
|
|
773
|
-
allow: [
|
|
774
|
-
`_INBOX_${pr.connId}.>`,
|
|
775
|
-
`${controlServiceSubject(space, CONTROL_DELIVERY_ADMIN, pr.owner, pr.actor)}.>`,
|
|
776
|
-
livenessServeFilter(space, "manager"),
|
|
777
|
-
],
|
|
778
|
-
},
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
/** The long-lived REMOTE MANAGER base credential. This is intentionally smaller than the local
|
|
782
|
-
* supervisor+provisioner union: it registers only its own manager presence, holds only its own
|
|
783
|
-
* manager-instance lease key, and may provision only lifecycle-keyed resources under its derived
|
|
784
|
-
* owner. Endpoint registration, contract publication and serving use separate instance-pinned
|
|
785
|
-
* credentials returned by the same typed host protocol. Per-agent provisioning deliberately does
|
|
786
|
-
* NOT ride this credential: NATS consumer names are single tokens, so a broker grant cannot safely
|
|
787
|
-
* express a prefix wildcard inside `dm_<owner>-<actor>-<uid>`. That operation stays on the host's
|
|
788
|
-
* authenticated provisioning protocol, where the requested descendant is fresh-validated before
|
|
789
|
-
* an exact one-shot grant is used. */
|
|
790
|
-
function remoteManagerPermissions(space, pr, pin) {
|
|
791
|
-
if (pin.owner !== pr.owner)
|
|
792
|
-
throw new Error(`permissionsFor: remote-manager owner ${JSON.stringify(pin.owner)} does not match the authenticated principal owner ${JSON.stringify(pr.owner)}`);
|
|
793
|
-
const iid = assertLifecycleToken(pin.instanceId, "remote manager instanceId");
|
|
794
|
-
const allowedActors = new Set([`manager_${iid}`, `manager_exec_${iid}`]);
|
|
795
|
-
if (!allowedActors.has(pin.actor) || pr.actor !== pin.actor)
|
|
796
|
-
throw new Error(`permissionsFor: remote-manager actor must be the server-selected manager_${iid} or manager_exec_${iid} for instance ${iid}`);
|
|
797
|
-
const PKV = `KV_${presenceBucket(space)}`;
|
|
798
|
-
const MKV = `KV_${managerBucket(space)}`;
|
|
799
|
-
const AUTH = epAuthBucket(space);
|
|
800
|
-
const REC = recordsBucket(space);
|
|
801
|
-
const gateKey = epgateKey("manager", iid);
|
|
802
|
-
const credPrefix = epcredFamilyPrefix("manager", iid);
|
|
803
|
-
const repairKey = eprepairKey("manager", iid);
|
|
804
|
-
// The SUPERVISOR actor of the pair, which is the one that runs `Manager.start()` and therefore
|
|
805
|
-
// the only one that binds the manager plane's liveness responder (`service.ts` hands
|
|
806
|
-
// `credentials.supervisor` to the manager; the executor gets the instance-scoped registration
|
|
807
|
-
// surface). The liveness rows below are pinned to it so the executor does not carry authority to
|
|
808
|
-
// answer a probe it never serves.
|
|
809
|
-
const isSupervisorActor = pin.actor === `manager_${iid}`;
|
|
810
|
-
const recordKeys = [
|
|
811
|
-
recordSpecKey(RECORD_KINDS.svc, ["manager", iid]),
|
|
812
|
-
recordStatusKey(RECORD_KINDS.svc, ["manager", iid]),
|
|
813
|
-
recordAtomicKey(GOVERN_HEAD, ["manager"]),
|
|
814
|
-
];
|
|
815
|
-
return {
|
|
816
|
-
pub: {
|
|
817
|
-
allow: [
|
|
818
|
-
"$JS.API.INFO",
|
|
819
|
-
// Only the supervisor allocates names against retained transcript counts. This metadata
|
|
820
|
-
// grant carries no consumer or message-body read, just like the agent CHAT info grant.
|
|
821
|
-
...(isSupervisorActor ? [`$JS.API.STREAM.INFO.${chatStream(space)}`] : []),
|
|
822
|
-
// Own manager-instance lease only. The local supervisor profile spans lease.* because one
|
|
823
|
-
// host manages every local instance; a remote user grant must not.
|
|
824
|
-
`$JS.API.STREAM.INFO.${MKV}`,
|
|
825
|
-
`$JS.API.STREAM.MSG.GET.${MKV}`,
|
|
826
|
-
`$KV.${managerBucket(space)}.${MANAGER_LEASE_KEY}.${iid}`,
|
|
827
|
-
// Own presence key + roster watch.
|
|
828
|
-
`$KV.${presenceBucket(space)}.${principalKey(pr.owner, pr.actor).key}`,
|
|
829
|
-
`$JS.API.STREAM.INFO.${PKV}`,
|
|
830
|
-
`$JS.API.CONSUMER.CREATE.${PKV}.>`,
|
|
831
|
-
`$JS.API.CONSUMER.INFO.${PKV}.>`,
|
|
832
|
-
"$JS.FC.>",
|
|
833
|
-
// This instance's manager service registration + credential family only.
|
|
834
|
-
`$KV.${AUTH}.${gateKey}`,
|
|
835
|
-
`$KV.${AUTH}.${repairKey}`,
|
|
836
|
-
`$KV.${AUTH}.${credPrefix}.>`,
|
|
837
|
-
...recordKeys.map((key) => `$KV.${REC}.${key}`),
|
|
838
|
-
`${spacePrefix(space)}.epc.*`,
|
|
839
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}.${spacePrefix(space)}.epc.>`,
|
|
840
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}`,
|
|
841
|
-
`$JS.API.STREAM.MSG.GET.KV_${AUTH}`,
|
|
842
|
-
`$JS.API.CONSUMER.CREATE.KV_${AUTH}.>`,
|
|
843
|
-
`$JS.API.CONSUMER.INFO.KV_${AUTH}.>`,
|
|
844
|
-
`$JS.API.CONSUMER.DELETE.KV_${AUTH}.>`,
|
|
845
|
-
...recordKeys.map((key) => `$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.${key}`),
|
|
846
|
-
`$JS.API.STREAM.MSG.GET.KV_${REC}`,
|
|
847
|
-
// LIVENESS REPLIES for the MANAGER plane (#1577), bounded to the `.reply.` leaf under a
|
|
848
|
-
// caller's own request subject — the same row and the same bound as the local supervisor
|
|
849
|
-
// profile holds.
|
|
850
|
-
//
|
|
851
|
-
// WHY THIS PROFILE NEEDS IT AT ALL. `Manager.start()` binds the manager plane's liveness
|
|
852
|
-
// responder unconditionally, and a remote manager runs the same `start()` under this
|
|
853
|
-
// credential. Without the serve subscription below the bind is denied, and a peer probing
|
|
854
|
-
// the manager plane then gets the broker's own no-responders answer, which this surface
|
|
855
|
-
// grades `unbound` — a definite verdict about the plane, produced by a gap in a credential,
|
|
856
|
-
// while the remote manager is bound and serving. A surface that exists to stop a failure to
|
|
857
|
-
// find out being rendered as a finding must not render its own missing grant as one.
|
|
858
|
-
//
|
|
859
|
-
// REPLIES ONLY. The row stops at the leaf, so a remote manager cannot publish to the
|
|
860
|
-
// liveness REQUEST subjects and therefore cannot forge a probe that appears to come from a
|
|
861
|
-
// peer, exactly as the supervisor row cannot.
|
|
862
|
-
...(isSupervisorActor ? [livenessReplyGrant(space, "manager")] : []),
|
|
863
|
-
],
|
|
864
|
-
},
|
|
865
|
-
sub: {
|
|
866
|
-
allow: [
|
|
867
|
-
`_INBOX_${pr.connId}.>`,
|
|
868
|
-
// The manager-plane liveness SERVE filter (#1577): `live.manager.*.*`, queue-grouped, so a
|
|
869
|
-
// credentialed peer's presence probe reaches this instance. A serve subscription on a
|
|
870
|
-
// presence-only rail and not a widening of what a remote manager may read: the request body
|
|
871
|
-
// is empty and the subject carries only the caller's own principal. The MANAGER plane only —
|
|
872
|
-
// this credential cannot serve `delivery`, so each plane still answers for itself.
|
|
873
|
-
...(isSupervisorActor ? [livenessServeFilter(space, "manager")] : []),
|
|
874
|
-
],
|
|
875
|
-
},
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
/** The human-CLI OPERATOR permission set — the ephemeral key the headless
|
|
879
|
-
* client commands mint (`cotal send dm|msg|ask`, `cotal dm`, `personas list --running`, via
|
|
880
|
-
* `openTransient`). It does exactly what those do: POST as itself (chat/DM/anycast — self-scoped, can
|
|
881
|
-
* never forge another actor), and READ the public roster (presence) + the channel registry to resolve a
|
|
882
|
-
* name→id and a channel's delivery class. Much narrower than the old broad `manager`: NO serve-control,
|
|
883
|
-
* NO DM/DLV body read, NO chat-history read, NO stream CREATE/DELETE/PURGE, NO ACL write, NO lease, NO
|
|
884
|
-
* provisioning. A leaked operator cred can post as itself and read the roster — the same surface as the
|
|
885
|
-
* human who ran the command. (The interactive `cotal join` console — chat read + own-DM receive — is a
|
|
886
|
-
* separate, fuller surface, deferred: it needs the unprovisioned-console DM self-create fixed first.) */
|
|
887
|
-
function operatorPermissions(space, pr) {
|
|
888
|
-
const PKV = `KV_${presenceBucket(space)}`, CHKV = `KV_${channelBucket(space)}`;
|
|
889
|
-
return {
|
|
890
|
-
pub: {
|
|
891
|
-
allow: [
|
|
892
|
-
// Post AS itself only — self-scoped (owner+actor), so a leaked operator cred can never forge a
|
|
893
|
-
// message attributable to another principal.
|
|
894
|
-
chatSubject(space, pr.owner, pr.actor, ">"), // chat.<o>.<a>.> — multicast any channel as me
|
|
895
|
-
unicastSubject(space, "*", "*", pr.owner, pr.actor), // inst.*.*.<o>.<a> — DM any peer as me
|
|
896
|
-
anycastSubject(space, "*", pr.owner, pr.actor), // svc.*.<o>.<a> — anycast any role as me
|
|
897
|
-
`$KV.${presenceBucket(space)}.${principalKey(pr.owner, pr.actor).key}`, // own presence key only
|
|
898
|
-
"$JS.API.INFO",
|
|
899
|
-
// Presence read (name→id resolution + the roster). The transient endpoint reads the bucket once
|
|
900
|
-
// with a batched Direct Get, whose request subject is the bare stream (#4091); the consumer rows
|
|
901
|
-
// serve a watch. No STREAM.MSG.GET.
|
|
902
|
-
`$JS.API.STREAM.INFO.${PKV}`,
|
|
903
|
-
`$JS.API.DIRECT.GET.${PKV}`,
|
|
904
|
-
`$JS.API.CONSUMER.CREATE.${PKV}.>`,
|
|
905
|
-
`$JS.API.CONSUMER.INFO.${PKV}.>`,
|
|
906
|
-
// Channel registry read — the transient endpoint reads it once (batched Direct Get), multicast
|
|
907
|
-
// reads a channel's delivery class, and `channels list` scans it. Read-only (no `$KV.<channel>`
|
|
908
|
-
// write — that's the provisioner).
|
|
909
|
-
`$JS.API.STREAM.INFO.${CHKV}`,
|
|
910
|
-
`$JS.API.DIRECT.GET.${CHKV}`,
|
|
911
|
-
`$JS.API.STREAM.MSG.GET.${CHKV}`,
|
|
912
|
-
// Keyed KV get rides `DIRECT.GET.<stream>.$KV.<bucket>.<key>` — the key is in the SUBJECT, so
|
|
913
|
-
// the grant needs the trailing `.>` (unlike STREAM.MSG.GET, which carries it in the payload).
|
|
914
|
-
`$JS.API.DIRECT.GET.${CHKV}.>`,
|
|
915
|
-
`$JS.API.CONSUMER.CREATE.${CHKV}.>`,
|
|
916
|
-
`$JS.API.CONSUMER.INFO.${CHKV}.>`,
|
|
917
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
918
|
-
],
|
|
919
|
-
},
|
|
920
|
-
// Own reply inbox only (presence/channel watch ordered-consumer delivery + any request replies land
|
|
921
|
-
// here). NO chat/inst/dlv native sub — the operator posts and reads the roster, it receives no feed.
|
|
922
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
/** Connect-only PROBE — the liveness/auth preflight (`preflight.ts preflightTarget`, minted on
|
|
926
|
-
* ~every CLI command that resolves a mesh). `probeConnect` opens a connection to prove the broker is up
|
|
927
|
-
* and the creds are accepted, then closes it — it performs NO pub/sub. So the tightest possible grant:
|
|
928
|
-
* deny ALL publish, subscribe only to the own reply inbox. A leaked probe cred can open a socket and do
|
|
929
|
-
* nothing else. (Was the broad `manager` cred — minted on nearly every command, the worst over-grant.) */
|
|
930
|
-
function probePermissions(pr) {
|
|
931
|
-
return { pub: { deny: [">"] }, sub: { allow: [`_INBOX_${pr.connId}.>`] } };
|
|
932
|
-
}
|
|
933
|
-
/** CHANNEL-WRITER — edits the channel registry ONLY: `cotal channels set/default` and the
|
|
934
|
-
* `spawn -f` new-channel seed (`seedChannelRegistry`). It VALUE-writes `$KV.<channelBucket>` (a channel's
|
|
935
|
-
* config key) and read-before-writes it. NO stream data, NO other bucket, NO chat/DM — a leaked
|
|
936
|
-
* channel-writer can only rewrite channel config, never post, read a body, or tear a stream down. */
|
|
937
|
-
function channelWriterPermissions(space, pr) {
|
|
938
|
-
const CHKV = `KV_${channelBucket(space)}`;
|
|
939
|
-
return {
|
|
940
|
-
pub: {
|
|
941
|
-
allow: [
|
|
942
|
-
"$JS.API.INFO",
|
|
943
|
-
`$KV.${channelBucket(space)}.>`, // create/update/delete a channel config key
|
|
944
|
-
`$JS.API.STREAM.INFO.${CHKV}`, // kvm.open/create existence check
|
|
945
|
-
`$JS.API.STREAM.CREATE.${CHKV}`, // kvm.create is create-if-matching (bucket already exists post-up)
|
|
946
|
-
// read-before-write: kvm.open rides STREAM.MSG.GET; kvm.create (direct=true) rides keyed DIRECT.GET.
|
|
947
|
-
`$JS.API.STREAM.MSG.GET.${CHKV}`,
|
|
948
|
-
`$JS.API.DIRECT.GET.${CHKV}.>`,
|
|
949
|
-
],
|
|
950
|
-
},
|
|
951
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
/** CHANNEL-PURGER — the `cotal web` dashboard's ONLY write path: delete a channel
|
|
955
|
-
* (`clearChannel` = filtered `STREAM.PURGE.CHAT` to drop the channel's messages + a `$KV.<channelBucket>`
|
|
956
|
-
* key delete). Pre-minted once by `web` so the account signing seed falls out of scope; the dashboard's
|
|
957
|
-
* READ side runs on the separate read-only `admin` cred. = channel-writer + the scoped CHAT purge. */
|
|
958
|
-
function channelPurgerPermissions(space, pr) {
|
|
959
|
-
const CHKV = `KV_${channelBucket(space)}`;
|
|
960
|
-
// `clearChannel` only kvm.OPENs the (already-created) bucket, key-deletes, and purges — it never
|
|
961
|
-
// kvm.creates, so — unlike channel-writer's set/default back-compat path — this cred gets NO
|
|
962
|
-
// `STREAM.CREATE`. Compose the shared channel-KV read + delete verbs + the scoped CHAT purge explicitly.
|
|
963
|
-
return {
|
|
964
|
-
pub: {
|
|
965
|
-
allow: [
|
|
966
|
-
"$JS.API.INFO",
|
|
967
|
-
`$KV.${channelBucket(space)}.>`, // delete the channel's registry key
|
|
968
|
-
`$JS.API.STREAM.INFO.${CHKV}`, // kvm.open existence check
|
|
969
|
-
`$JS.API.STREAM.MSG.GET.${CHKV}`, // read-before-delete
|
|
970
|
-
`$JS.API.DIRECT.GET.${CHKV}.>`,
|
|
971
|
-
`$JS.API.STREAM.PURGE.${chatStream(space)}`, // drop the channel's chat messages
|
|
972
|
-
],
|
|
973
|
-
},
|
|
974
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
/** TEARDOWN — `cotal down -f` space teardown. The space-wide cred that keeps `STREAM.DELETE` (the
|
|
978
|
-
* tamper verb). `down -f` is multi-step: `connectProbe` (presence-watch + channel-registry read)
|
|
979
|
-
* → invoke the manager's `ps` + any-mode `despawn` over the ep rails to politely stop the managed
|
|
980
|
-
* agents → `readMembership` (the membership-feed read that keeps an owned channel another member
|
|
981
|
-
* still uses) → `deleteChannels`
|
|
982
|
-
* (channel-registry key delete + CHAT purge) → `deleteSpace` (STREAM.DELETE every owned stream/bucket).
|
|
983
|
-
* So it reads state, CALLS admin control, deletes channels, and deletes streams — but NEVER reads a
|
|
984
|
-
* DM/DLV body, posts chat, or forges. Isolated here so no standing operator/provisioner/supervisor cred
|
|
985
|
-
* can delete a stream; a leaked teardown can wipe a space you own + stop its agents (that IS its job),
|
|
986
|
-
* nothing else. Minted ephemerally per teardown from the local trust material (same-checkout `down -f`). */
|
|
987
|
-
function teardownPermissions(space, pr, transferStreams) {
|
|
988
|
-
// The ep-rail mirror of the admin deploy tier: teardown reads `ps` and stops owned agents
|
|
989
|
-
// it did not spawn (any-mode despawn) - the admin instrument set. Lifecycle-keyed, so a uid is
|
|
990
|
-
// required at mint (fail-loud).
|
|
991
|
-
const ep = instrumentEpRows(space, pr, "admin");
|
|
992
|
-
const CHAT = chatStream(space);
|
|
993
|
-
const PKV = `KV_${presenceBucket(space)}`, CHKV = `KV_${channelBucket(space)}`;
|
|
994
|
-
const MSHIP = `KV_${membershipBucket(space)}`;
|
|
995
|
-
const RECORDS = `KV_${recordsBucket(space)}`;
|
|
996
|
-
// The deletion path and the exact per-stream grants use one target list. Reject any caller-
|
|
997
|
-
// supplied transfer name that is not this space's transfer bucket before minting the grant.
|
|
998
|
-
for (const name of transferStreams)
|
|
999
|
-
if (!isTransferStream(space, name))
|
|
1000
|
-
throw new Error(`permissionsFor: teardown transferStreams names ${JSON.stringify(name)}, not one of ${space}'s transfer streams`);
|
|
1001
|
-
const del = spaceDeletionStreams(space, transferStreams)
|
|
1002
|
-
.flatMap((s) => [`$JS.API.STREAM.INFO.${s}`, `$JS.API.STREAM.DELETE.${s}`]);
|
|
1003
|
-
return {
|
|
1004
|
-
pub: {
|
|
1005
|
-
allow: [
|
|
1006
|
-
"$JS.API.INFO",
|
|
1007
|
-
BROKER_USER_INFO_SUBJECT, // confirm the current teardown connection's account before native impact reads
|
|
1008
|
-
// deleteSpace() enumerates the transfer streams (one per manager instance that received a
|
|
1009
|
-
// carried resume) by name shape; their names are not derivable from the space alone.
|
|
1010
|
-
"$JS.API.STREAM.NAMES",
|
|
1011
|
-
// connectProbe read: presence watch (name→id + roster) + channel registry read.
|
|
1012
|
-
`$JS.API.CONSUMER.CREATE.${PKV}.>`,
|
|
1013
|
-
`$JS.API.CONSUMER.INFO.${PKV}.>`,
|
|
1014
|
-
`$JS.API.STREAM.MSG.GET.${CHKV}`,
|
|
1015
|
-
`$JS.API.DIRECT.GET.${CHKV}.>`,
|
|
1016
|
-
`$JS.API.CONSUMER.CREATE.${CHKV}.>`,
|
|
1017
|
-
`$JS.API.CONSUMER.INFO.${CHKV}.>`,
|
|
1018
|
-
// readMembership's one-pass scan of the feed (its STREAM.INFO is in `del`). No `$KV` publish:
|
|
1019
|
-
// only `membership-rw` writes the feed.
|
|
1020
|
-
// Batched snapshots read the same feed as the watch below, without a consumer.
|
|
1021
|
-
`$JS.API.DIRECT.GET.${MSHIP}`,
|
|
1022
|
-
`$JS.API.CONSUMER.CREATE.${MSHIP}.>`,
|
|
1023
|
-
`$JS.API.CONSUMER.INFO.${MSHIP}.>`,
|
|
1024
|
-
// Space deletion names the workflow runs it removes by their status records: a non-fencing
|
|
1025
|
-
// direct get confined to run status keys (§13.9), on a stream this grant may already delete.
|
|
1026
|
-
`$JS.API.DIRECT.GET.${RECORDS}.$KV.${recordsBucket(space)}.run.*.*.status`,
|
|
1027
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
1028
|
-
// Stop the managed agents over the v0.4 ep rails only (ps + any-mode despawn) — the admin
|
|
1029
|
-
// instrument set. The manager `ctl` rail is deleted.
|
|
1030
|
-
...ep.pub,
|
|
1031
|
-
...del,
|
|
1032
|
-
// deleteChannels/clearChannel: purge the channel's chat messages + delete its registry key.
|
|
1033
|
-
`$JS.API.STREAM.PURGE.${CHAT}`,
|
|
1034
|
-
`$KV.${channelBucket(space)}.>`,
|
|
1035
|
-
],
|
|
1036
|
-
},
|
|
1037
|
-
// Own inbox (connectProbe presence-watch delivery + JS API responses) + the ep reply rail (the
|
|
1038
|
-
// ps + any-mode despawn calls reply there). The `ctl.admin.<id>.reply.>` subtree is gone.
|
|
1039
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`, ...ep.sub] },
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
/** MEMBERSHIP-STORE-RECREATE — explicit conversion of the derived membership feed from File to
|
|
1043
|
-
* Memory. The credential can inspect and delete exactly that one stream. It cannot create the
|
|
1044
|
-
* replacement, read membership values, or touch another stream; the ordinary short-lived
|
|
1045
|
-
* provisioner creates and verifies the empty Memory replacement after deletion. */
|
|
1046
|
-
function membershipStoreRecreatePermissions(space, pr) {
|
|
1047
|
-
const stream = `KV_${membershipBucket(space)}`;
|
|
1048
|
-
return {
|
|
1049
|
-
pub: {
|
|
1050
|
-
allow: [
|
|
1051
|
-
"$JS.API.INFO",
|
|
1052
|
-
`$JS.API.STREAM.INFO.${stream}`,
|
|
1053
|
-
`$JS.API.STREAM.DELETE.${stream}`,
|
|
1054
|
-
],
|
|
1055
|
-
},
|
|
1056
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
/** ISSUED-STORE-RECREATE — `cotal up --recreate-issued-stores`, and an embedder's call of
|
|
1060
|
-
* `removeIssuedStoresBeforeRetention`: back up, then delete, the two issued-authority stores of ONE
|
|
1061
|
-
* space that predate bounded retention. Exactly `STREAM.INFO`, `STREAM.SNAPSHOT` and
|
|
1062
|
-
* `STREAM.DELETE` on those two streams, the snapshot's delivery inside its own inbox, and the
|
|
1063
|
-
* snapshot ACK subjects of those two streams ({@link snapshotAckGrant}). Nothing reads a row,
|
|
1064
|
-
* writes a store or reaches another stream. */
|
|
1065
|
-
function issuedStoreRecreatePermissions(space, pr) {
|
|
1066
|
-
return {
|
|
1067
|
-
pub: {
|
|
1068
|
-
allow: [
|
|
1069
|
-
"$JS.API.INFO",
|
|
1070
|
-
...issuedStoreStreamNames(space).flatMap((s) => [`$JS.API.STREAM.INFO.${s}`, `$JS.API.STREAM.SNAPSHOT.${s}`, `$JS.API.STREAM.DELETE.${s}`, snapshotAckGrant(s)]),
|
|
1071
|
-
],
|
|
1072
|
-
},
|
|
1073
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
/** CONTROL-CALLER (ep rails only) — the operator's lifecycle commands
|
|
1077
|
-
* (`cotal ps/start/stop/attach`, `manager/commands.ts`). It invokes the manager's v0.4 service
|
|
1078
|
-
* endpoint and reads the bounded reply on the ep reply rail. That is ALL — no `$JS`, no `$KV`,
|
|
1079
|
-
* no chat/DM: it forges nothing, reads no body.
|
|
1080
|
-
*
|
|
1081
|
-
* The tiers stay SPLIT because the BROKER grant is load-bearing: an any-mode
|
|
1082
|
-
* despawn/attach row *is* cross-agent reach — the manager maps mode `any` to its admin
|
|
1083
|
-
* authorization path, so which ROWS an instrument holds is the tier boundary. Therefore:
|
|
1084
|
-
* • `control-caller-privileged` (ps/start) holds the manager reads + untargeted `spawn` +
|
|
1085
|
-
* `define-persona` — structurally barred from cross-agent ops (no any-mode row). This is the
|
|
1086
|
-
* high-frequency path; it never needs admin reach.
|
|
1087
|
-
* • `control-caller-admin` (stop/attach) adds the any-mode despawn/attach rows + the
|
|
1088
|
-
* `manager.admin` family — it genuinely needs cross-agent reach. Its containment is the
|
|
1089
|
-
* broker gating the any-mode rows + the cred being ephemeral (mint → one request →
|
|
1090
|
-
* disconnect, from the local signing seed); on a user mesh the manager's serve-time ledger
|
|
1091
|
-
* re-check sits on top. */
|
|
1092
|
-
function controlCallerPermissions(space, pr, epTier, opts = {}) {
|
|
1093
|
-
// The manager `ctl` rail is gone — an operator instrument holds ONLY its v0.4 ep rows (the
|
|
1094
|
-
// tier-matched request set, the reply rail, describe, the one epc fetch). The `epTier` selects
|
|
1095
|
-
// privileged (ps/start reads) vs admin (any-mode stop/attach) exactly as the ctl tier did.
|
|
1096
|
-
//
|
|
1097
|
-
// `--on <instanceId>`: these instruments are ONE-SHOT, minted per control call, and the
|
|
1098
|
-
// resolve that pins the instance happens BEFORE the mint. So the caller can hand the exact
|
|
1099
|
-
// instance id down and get the exact `ep.inst.<endpoint>.<iid>.<command>` row for THIS invocation
|
|
1100
|
-
// and nothing else — the least-privilege issuance, with no standing wildcard anywhere. The
|
|
1101
|
-
// `extra` seam is the same one the deployer's owner-equality `launch` row already rides, and the
|
|
1102
|
-
// emitter's `if (cap.instanceId)` branch validates the token, so a malformed id fails loud at
|
|
1103
|
-
// mint rather than widening a subject.
|
|
1104
|
-
const ep = instrumentEpRows(space, pr, epTier, opts.endpointCapabilities ?? [], opts);
|
|
1105
|
-
return {
|
|
1106
|
-
// The PRIVILEGED tier (the `cotal ps` instrument) also carries the SCOPED §13.9 records read the
|
|
1107
|
-
// class scatter's freeze rides: `freezeExpectedSet` enumerates `svc.<endpoint>.*.spec`
|
|
1108
|
-
// and LEADER-reads each frozen slot's svc spec/status before it scatters `ps` on the `all` rail.
|
|
1109
|
-
// The admin tier (stop/attach) never scatters, so it gets no records read.
|
|
1110
|
-
pub: { allow: epTier === "privileged" ? [...ep.pub, ...scatterFreezeReadRows(space)] : ep.pub },
|
|
1111
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`, ...ep.sub] },
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
/** The SCOPED §13.9 records-read rows the class-scatter freeze rides (`cotal ps`): the
|
|
1115
|
-
* `svc.*` enumeration consumer + the leader-served per-slot spec/status read of the endpoint's
|
|
1116
|
-
* `svc` registry — a READ of exactly the service-registration keys, no write, no other bucket.
|
|
1117
|
-
* The keyed Direct Get is subject-PINNED to `svc.>`; the enumeration consumer
|
|
1118
|
-
* and the leader `STREAM.MSG.GET` are STREAM-scoped because the requested key rides the PAYLOAD
|
|
1119
|
-
* (which a subject grant cannot narrow) — the SAME NAMED RESIDUAL every records reader already
|
|
1120
|
-
* accepts (the provisioner, the lifecycle/serve executors): for this EPHEMERAL one-shot instrument's
|
|
1121
|
-
* lifetime it can READ (never write) any records-store row — registration metadata, no secrets. */
|
|
1122
|
-
function scatterFreezeReadRows(space) {
|
|
1123
|
-
const REC = recordsBucket(space);
|
|
1124
|
-
return [
|
|
1125
|
-
// The `svc.<e>.*.spec` enumeration is a `STREAM.INFO` carrying a `subjects_filter` — ONE
|
|
1126
|
-
// read-only metadata verb. It replaced a `kv.keys()` that rode an ordered ephemeral consumer and
|
|
1127
|
-
// therefore needed CONSUMER.CREATE/INFO/DELETE on this bucket: three consumer-lifecycle verbs to
|
|
1128
|
-
// list keys, on a credential that only ever wanted to read them.
|
|
1129
|
-
//
|
|
1130
|
-
// MEASURED, not assumed: with the enumeration converted and this row absent, the static/operator
|
|
1131
|
-
// `cotal ps` is refused on `$JS.API.STREAM.INFO.KV_<records>` — a path that works today. The
|
|
1132
|
-
// conversion and this row land TOGETHER or the operator path regresses.
|
|
1133
|
-
`$JS.API.STREAM.INFO.KV_${REC}`,
|
|
1134
|
-
// The per-slot spec/status reads (`freezeExpectedSet` + the registration reconcile) are
|
|
1135
|
-
// leader-served `STREAM.MSG.GET` — stream-scoped (NAMED RESIDUAL above), plus the subject-pinned
|
|
1136
|
-
// keyed Direct Get form for any direct-aware read path (scoped to the `svc.` registry prefix).
|
|
1137
|
-
`$JS.API.STREAM.MSG.GET.KV_${REC}`,
|
|
1138
|
-
`$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.svc.>`,
|
|
1139
|
-
];
|
|
1140
|
-
}
|
|
1141
|
-
/** The v0.4 ep-rail rows of an operator INSTRUMENT credential: the tier-matched
|
|
1142
|
-
* {@link operatorInstrumentCapabilities} request rows + the caller's reply rail, the wildcard
|
|
1143
|
-
* `describe` form, and the ONE subject-scoped §13.7 contract-store fetch row (the same shape the
|
|
1144
|
-
* agent baseline holds). No ctl row exists, so these ARE the instrument. The caller triple pins the instrument's own mint-time lifecycle uid
|
|
1145
|
-
* ({@link MintPrincipal.lifecycleUid}) — REQUIRED here: without it the reply rail cannot be pinned
|
|
1146
|
-
* and the mint fails loud rather than emit a triple-less (unfenced) caller surface. `extra` lets a
|
|
1147
|
-
* profile append its tier-refined additions (the user-mode deployer's owner-equality `launch`). */
|
|
1148
|
-
function instrumentEpRows(space, pr, tier, extra = [], opts = {}) {
|
|
1149
|
-
if (!pr.lifecycleUid)
|
|
1150
|
-
throw new Error(`permissionsFor: an operator instrument's ep caller rows are lifecycle-keyed (SPEC 13.1/13.2) - mint with opts.lifecycleUid (mintLifecycleUid()) so the reply rail pins the instrument's own incarnation`);
|
|
1151
|
-
const epCaller = issuedCallerFor({ owner: pr.owner, actor: pr.actor, uid: pr.lifecycleUid }, opts);
|
|
1152
|
-
const rows = epCallerGrantRows(space, [...operatorInstrumentCapabilities(tier, pr.owner), ...extra], epCaller);
|
|
1153
|
-
return {
|
|
1154
|
-
pub: [
|
|
1155
|
-
epDescribeAllGrantRow(space, epCaller),
|
|
1156
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}.${spacePrefix(space)}.epc.>`,
|
|
1157
|
-
...(opts.issued ? [acceptedReadGrant(space, opts.issued.acceptedToken)] : []),
|
|
1158
|
-
...rows.pub,
|
|
1159
|
-
],
|
|
1160
|
-
sub: rows.sub,
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
/** The ep caller a mint pins: the triple, plus the issued generation when the mint is an
|
|
1164
|
-
* issuance (SPEC 13.15). One place decides the rail so a credential's request rows, its reply
|
|
1165
|
-
* read, and its describe row all land on the same one. */
|
|
1166
|
-
function issuedCallerFor(triple, opts) {
|
|
1167
|
-
if (!opts.issued)
|
|
1168
|
-
return triple;
|
|
1169
|
-
assertGeneration(opts.issued.acceptedToken, "acceptedToken");
|
|
1170
|
-
return { ...triple, generation: assertGeneration(opts.issued.generation) };
|
|
1171
|
-
}
|
|
1172
|
-
/** The rows a listing generation adds to a legacy-rail credential (SPEC 13.15, "Listing
|
|
1173
|
-
* issuance"): the registry's `endpoints` request publish and its reply subscribe on `ep.v1`, and
|
|
1174
|
-
* the per-key read of the generation's accepted row. Exactly these: one caller value emits one
|
|
1175
|
-
* rail, so these are the only `ep.v1` rows such a credential holds. */
|
|
1176
|
-
export function listingGrantRows(space, caller, listing) {
|
|
1177
|
-
if (isIssuedCaller(caller))
|
|
1178
|
-
throw new Error("listingGrantRows: an issued caller lists under its own generation");
|
|
1179
|
-
assertGeneration(listing.acceptedToken, "acceptedToken");
|
|
1180
|
-
const issued = { owner: caller.owner, actor: caller.actor, uid: caller.uid, generation: assertGeneration(listing.generation) };
|
|
1181
|
-
return {
|
|
1182
|
-
pub: [...epRequestGrantRows(space, REGISTRY_ENDPOINTS_GRANT, issued), acceptedReadGrant(space, listing.acceptedToken)],
|
|
1183
|
-
sub: [epCallerReplyFilter(space, issued)],
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
/** ENDPOINT-SERVE (v0.4, SPEC §13.9 "Serve grants") — the per-instance serve credential:
|
|
1187
|
-
* EXACTLY the instance's registered rails and nothing else. Subscribe: the queue-qualified
|
|
1188
|
-
* class rail, the plain scatter rail, and the own-instance rail for the FULL registered
|
|
1189
|
-
* command set plus the derived `describe`, and the own epoch-pinned timer-fire subjects;
|
|
1190
|
-
* publish: the epoch-pinned egress (reply / `epe` events / `ept` schedule requests / `epr`
|
|
1191
|
-
* record-write ingress) plus, from the branded snapshot only, the §13.9 bind rows: the shared
|
|
1192
|
-
* `eff_<e>` effects bind iff the surface is journal-class and each owned `pool_<e>_<pool>`
|
|
1193
|
-
* bind (bind-only + `$JS.API.INFO`; an ephemeral-only poolless endpoint emits none). No agent
|
|
1194
|
-
* baseline of any kind — no chat/DM/anycast/presence/ctl, no broad `$JS.>`. The value MUST be the
|
|
1195
|
-
* branded ARTIFACT `authorizeServeGrant` returned, and its mint context binds: same space, and
|
|
1196
|
-
* the minted principal is the registered owner. This builds the ROWS; the RELEASE fence is the
|
|
1197
|
-
* durable issuance-gate CAS `mintCreds` runs (SPEC §13.1) — a raw/copied/diverging value or a
|
|
1198
|
-
* foreign space/principal refuses here, and a stale incarnation loses the gate CAS. */
|
|
1199
|
-
function endpointServePermissions(space, pr, opts) {
|
|
1200
|
-
if (!opts.endpointServe)
|
|
1201
|
-
throw new Error("permissionsFor: endpoint-serve requires opts.endpointServe (the authorized serve artifact)");
|
|
1202
|
-
// The fence is INSEPARABLE from serve-row emission: a serve credential's rows are only ever
|
|
1203
|
-
// valid when released behind the §13.1 issuance CAS, so this builder refuses to emit them
|
|
1204
|
-
// without the gate seam — closing the exported-permissionsFor bypass where a direct signer
|
|
1205
|
-
// could obtain unfenced serve rows past the brand/space/owner check. `mintCreds` runs the CAS.
|
|
1206
|
-
if (!opts.serveIssuance)
|
|
1207
|
-
throw new Error("permissionsFor: endpoint-serve requires opts.serveIssuance (serve rows are emitted only behind the §13.1 issuance fence; mintCreds runs its CAS before release)");
|
|
1208
|
-
const snap = assertServeGrantMintable(opts.endpointServe, { space, holderOwner: pr.owner });
|
|
1209
|
-
// Rail subscribe rows cover the EPHEMERAL commands only (journal commands ride epj, never the
|
|
1210
|
-
// request rails) + the derived describe; the descriptor surface stays full. The class comes
|
|
1211
|
-
// from the brand-verified artifact surface, not the caller.
|
|
1212
|
-
const ephemeralCommands = snap.commands.filter((cmd) => opts.endpointServe.surface[cmd].class === "ephemeral");
|
|
1213
|
-
const rows = epServeGrantRows(space, {
|
|
1214
|
-
endpoint: snap.endpoint, instanceId: snap.instanceId, epoch: snap.epoch, ephemeralCommands,
|
|
1215
|
-
});
|
|
1216
|
-
// §13.9 bind rows, from the BRANDED snapshot only (journal class is registered truth,
|
|
1217
|
-
// pools are the authorizing provisioner's pre-created durables): a journal-class instance
|
|
1218
|
-
// binds the shared `eff_<e>` effects durable, a pool-owning one binds each owned
|
|
1219
|
-
// `pool_<e>_<pool>` — all bind-only (INFO/MSG.NEXT/ACK, never create/delete), plus the one
|
|
1220
|
-
// `$JS.API.INFO` a pull consumer needs. An ephemeral-only poolless endpoint emits NONE of
|
|
1221
|
-
// these rows (default-deny both directions).
|
|
1222
|
-
const bindRows = [];
|
|
1223
|
-
if (snap.journalClass)
|
|
1224
|
-
bindRows.push(...effectsBindGrants(space, snap.endpoint));
|
|
1225
|
-
for (const pool of snap.pools)
|
|
1226
|
-
bindRows.push(...poolOwnerBindGrants(space, snap.endpoint, pool));
|
|
1227
|
-
if (bindRows.length > 0)
|
|
1228
|
-
bindRows.push("$JS.API.INFO");
|
|
1229
|
-
return {
|
|
1230
|
-
pub: { allow: [...rows.pub, ...bindRows] },
|
|
1231
|
-
sub: { allow: [...rows.sub, `_INBOX_${pr.connId}.>`] },
|
|
1232
|
-
};
|
|
1233
|
-
}
|
|
1234
|
-
/** DEPLOYER — the `cotal spawn -f` manifest-deploy authority. `spawn -f` drives ONE
|
|
1235
|
-
* `connectProbe` endpoint that both READS live state (roster/presence watch, channel registry,
|
|
1236
|
-
* membership feed, manager-singleton lease) AND invokes the running manager's `launch` + `ps`
|
|
1237
|
-
* readiness over the v0.4 ep rails. Those interleave on one connection, so a strict 3-connection
|
|
1238
|
-
* split would only refactor `live.ts` for marginal gain; `deployer` is that one coherent,
|
|
1239
|
-
* ephemeral deploy cred. It is the SOLE profile that combines reads + admin-control — NOT a template a
|
|
1240
|
-
* 4th command should reach for (revisit the connection split before adding a second such caller).
|
|
1241
|
-
*
|
|
1242
|
-
* Boundaries (all enforced by omission / default-deny): NO self-post (`chat`/`inst`/`svc`), NO `$JS.>`,
|
|
1243
|
-
* NO `STREAM.DELETE`/`PURGE`/`UPDATE`, NO DM/DLV/TASK `CONSUMER.CREATE` (no body-read surface), NO `$KV`
|
|
1244
|
-
* writes (channel seeding rides a SEPARATE `channel-writer` cred). It holds the admin INSTRUMENT ep
|
|
1245
|
-
* set (any-mode despawn/attach + the manager.admin family + reads) because manifest launch/ps
|
|
1246
|
-
* genuinely need cross-agent reach — and that IS real power: the manager's any-mode authz is
|
|
1247
|
-
* subject-gated (the any-mode ep row is mintable only under operator policy), so holding it lets it
|
|
1248
|
-
* stop/attach/launch ANY agent. The BROKER gating that row is the boundary. Containment is therefore
|
|
1249
|
-
* the LIFETIME, not a manager re-check: minted from LOCAL same-checkout auth for one `spawn -f`,
|
|
1250
|
-
* memory-only, dropped after deploy. If it is ever persisted, handed to user-supplied `--creds`, or
|
|
1251
|
-
* reused as a general "read + admin" cred, revisit. */
|
|
1252
|
-
function deployerPermissions(space, pr, epTier = "admin", opts = {}) {
|
|
1253
|
-
// The v0.4 ep rows of the deploy authority: static (admin) deploys carry the admin instrument
|
|
1254
|
-
// set; the user-mode deployer VIEW (privileged) carries the privileged set PLUS an untargeted
|
|
1255
|
-
// `launch` row — its launch stays owner-equality-authorized (the manager's ledger-derived admin
|
|
1256
|
-
// flag is false for a spawn-scoped deployer), exactly the v0.3 user-mode privileged-tier launch.
|
|
1257
|
-
// `--on`: the per-invocation pin APPENDS to this profile's standing set, never replaces it -
|
|
1258
|
-
// the privileged deployer view keeps its owner-equality `launch` row and additionally gets the one
|
|
1259
|
-
// exact `ep.inst.<endpoint>.<iid>.<command>` row for the instance this deploy resolved.
|
|
1260
|
-
const pinned = opts.endpointCapabilities ?? [];
|
|
1261
|
-
const ep = epTier === "admin"
|
|
1262
|
-
? instrumentEpRows(space, pr, "admin", pinned, opts)
|
|
1263
|
-
: instrumentEpRows(space, pr, "privileged", [{ endpoint: BASELINE_LIFECYCLE_ENDPOINT, command: "launch" }, ...pinned], opts);
|
|
1264
|
-
const PKV = `KV_${presenceBucket(space)}`, CHKV = `KV_${channelBucket(space)}`;
|
|
1265
|
-
const MSHIP = `KV_${membershipBucket(space)}`, MGRKV = `KV_${managerBucket(space)}`;
|
|
1266
|
-
const DLVKV = `KV_${deliveryBucket(space)}`;
|
|
1267
|
-
// Read verbs for a KV bucket SCANNED/WATCHED via an ordered consumer (presence, channel registry, and
|
|
1268
|
-
// the membership feed — `readMembership` enumerates keys via `kv.keys()`): existence + kv.get (both
|
|
1269
|
-
// STREAM.MSG.GET and keyed DIRECT.GET forms) + the ordered consumer. NO `$KV.<bucket>` publish → no write.
|
|
1270
|
-
const kvScan = (bucket) => [
|
|
1271
|
-
`$JS.API.STREAM.INFO.${bucket}`,
|
|
1272
|
-
`$JS.API.STREAM.MSG.GET.${bucket}`,
|
|
1273
|
-
`$JS.API.DIRECT.GET.${bucket}.>`,
|
|
1274
|
-
`$JS.API.CONSUMER.CREATE.${bucket}.>`,
|
|
1275
|
-
`$JS.API.CONSUMER.INFO.${bucket}.>`,
|
|
1276
|
-
];
|
|
1277
|
-
// A KV bucket read by a KEYED point-get only (`readManagerLease` = kvm.open + `kv.get(LEASE_KEY)`, no
|
|
1278
|
-
// scan/watch): existence + kv.get, but NO ordered-consumer verbs (nothing enumerates or watches it).
|
|
1279
|
-
const kvPointRead = (bucket) => [
|
|
1280
|
-
`$JS.API.STREAM.INFO.${bucket}`,
|
|
1281
|
-
`$JS.API.STREAM.MSG.GET.${bucket}`,
|
|
1282
|
-
`$JS.API.DIRECT.GET.${bucket}.>`,
|
|
1283
|
-
];
|
|
1284
|
-
return {
|
|
1285
|
-
pub: {
|
|
1286
|
-
allow: [
|
|
1287
|
-
"$JS.API.INFO",
|
|
1288
|
-
...kvScan(PKV), // presence watch — roster + name→id
|
|
1289
|
-
...kvScan(CHKV), // channel registry read (readChannelRegistry + classifyChannels)
|
|
1290
|
-
...kvScan(MSHIP), // membership FEED read (readMembership → detectUnmanagedActors) — the membership_ bucket
|
|
1291
|
-
...kvPointRead(MGRKV), // manager-singleton lease keyed read (waitManagerReady) — point-get, NO write, NO watch
|
|
1292
|
-
...kvPointRead(DLVKV), // delivery-lease keyed read (preserve-state quiescence proof) — point-get, NO write, NO watch
|
|
1293
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
1294
|
-
// Launch + ps readiness ride the v0.4 ep rows only (the manager `ctl` rail is gone).
|
|
1295
|
-
// Static deploys carry the admin instrument set; the user-mode deployer VIEW carries the
|
|
1296
|
-
// privileged set + an owner-equality `launch` row (the manager's ledger-derived admin flag
|
|
1297
|
-
// is false for a spawn-scoped deployer, so its launch stays owner-equality-authorized).
|
|
1298
|
-
...ep.pub,
|
|
1299
|
-
],
|
|
1300
|
-
},
|
|
1301
|
-
// Own inbox (presence/registry watch delivery + JS API responses) + the ep reply rail.
|
|
1302
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`, ...ep.sub] },
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
/** The ephemeral PURGER permission set — minted per-purge inside the daemon's
|
|
1306
|
-
* `opPurge` and `cotal history clear`. Isolates the DESTRUCTIVE history-purge grant
|
|
1307
|
-
* (`STREAM.PURGE.CHAT` + `STREAM.PURGE.DM`) off the always-on supervisor: `--dms` purges the DM stream,
|
|
1308
|
-
* exactly the grant the supervisor must not hold. It PURGES but never READS — no DM/chat consumer, no
|
|
1309
|
-
* `MSG.GET` — so a leaked purger can drop history but cannot read a body. Short-lived (one purge call). */
|
|
1310
|
-
function purgerPermissions(space, pr) {
|
|
1311
|
-
const CHAT = chatStream(space), DM = dmStream(space);
|
|
1312
|
-
return {
|
|
1313
|
-
pub: {
|
|
1314
|
-
allow: [
|
|
1315
|
-
"$JS.API.INFO", // jetstreamManager bootstrap; STREAM.PURGE needs no prior STREAM.INFO
|
|
1316
|
-
`$JS.API.STREAM.PURGE.${CHAT}`, // clearSpaceHistory chat purge
|
|
1317
|
-
`$JS.API.STREAM.PURGE.${DM}`, // clearSpaceHistory includeDms — the isolated DM-purge grant
|
|
1318
|
-
],
|
|
1319
|
-
// NOTE: this profile does NOT cover `clearChannel` (web/`down -f` channel-delete) — that also does a
|
|
1320
|
-
// `$KV.<channelBucket>.<ch>` registry delete this cred lacks, which `channel-purger` and `teardown` hold.
|
|
1321
|
-
},
|
|
1322
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
/** The ephemeral PROVISIONER permission set — the onboarding authority,
|
|
1326
|
-
* carved off the long-lived manager. Minted short-lived for per-spawn provisioning (pre-create each
|
|
1327
|
-
* agent's bind-only DM/DLV/TASK durables + record its read ACL via `commitAcl`) — the daemon opens it per
|
|
1328
|
-
* spawn (`manager.ts withProvisioner`). It is ALSO the cred that creates the space's streams + KV buckets
|
|
1329
|
-
* and seeds the channel registry via `setupSpaceStreams` (exercised by the manager-split smoke) — and
|
|
1330
|
-
* `cotal up`'s ephemeral setup cred (`up.ts authSetup`) now mints THIS profile, not the broad `manager`.
|
|
1331
|
-
* NEVER minted for an agent — `cotal mint` whitelists
|
|
1332
|
-
* agent/observer/admin only, like `manager`/`delivery`.
|
|
1333
|
-
*
|
|
1334
|
-
* This profile HOLDS the DM/DLV `CONSUMER.CREATE` push-consumer surface — the irreducible onboarding
|
|
1335
|
-
* power (the create-time `deliver_subject` of a push consumer is not ACL-constrained, so whoever can
|
|
1336
|
-
* create a DM/DLV consumer can stream the bodies). That is exactly why it is split OFF the always-on
|
|
1337
|
-
* supervisor and made EPHEMERAL: the daemon opens a provisioner connection per spawn and drains it
|
|
1338
|
-
* immediately, so the surface exists only for the provisioning window, not as a standing target. The
|
|
1339
|
-
* cred is MEMORY-ONLY (never written to `.cotal`) and carries a short profile-default `exp`.
|
|
1340
|
-
*
|
|
1341
|
-
* `$JS` is an ENUMERATED allow-list, never `$JS.>`: STREAM.CREATE + INFO for the space streams/buckets,
|
|
1342
|
-
* DM/DLV/TASK consumer CREATE/DURABLE.CREATE/INFO — and deliberately NO `MSG.NEXT`/`MSG.GET`/`ACK` on
|
|
1343
|
-
* DM/DLV (it creates the bind-only mailbox but never reads it), and NO STREAM.DELETE/PURGE/MSG.DELETE
|
|
1344
|
-
* (it provisions, it does not tear down). STREAM.UPDATE is held on EXACTLY thirteen streams and no others:
|
|
1345
|
-
* the three TTL'd KV buckets (presence + the two leases, #286: an existing bucket's `max_age` cannot be
|
|
1346
|
-
* fixed by `kvm.create`, so reconciling a pre-TTL deployment requires updating it), the four hardened
|
|
1347
|
-
* authority stores (records, issued, accepted, admission), each updated once at creation, and the
|
|
1348
|
-
* membership KV and artifact Object Store, whose legacy `max_bytes` values setup reconciles to -1 (the
|
|
1349
|
-
* reservation a positive cap holds against the broker's `max_file_store` is what stopped a tenth space
|
|
1350
|
-
* from being provisioned; `Objm.create` cannot fix an existing bucket's cap either), and the CHAT,
|
|
1351
|
-
* INBOX, DLV and DM streams, whose history limits `cotal history limit` writes (`setHistoryLimit`).
|
|
1352
|
-
* Stated positively on purpose: this docblock previously read "NO …/UPDATE", which was already untrue of
|
|
1353
|
-
* the records stream and became untrue of the buckets, and a comment that denies a credential's real
|
|
1354
|
-
* power is worse than none — it is the document a reader trusts instead of checking. KV value-writes are
|
|
1355
|
-
* scoped to exactly the two
|
|
1356
|
-
* registries provisioning touches: the read-ACL bucket (`commitAcl`) and the channel registry (seed). */
|
|
1357
|
-
function provisionerPermissions(space, pr) {
|
|
1358
|
-
const CHAT = chatStream(space), DM = dmStream(space), TASK = taskStream(space);
|
|
1359
|
-
const INBOX = inboxStream(space), DLV = dlvStream(space);
|
|
1360
|
-
// Every non-endpoint KV backing stream the provisioner pre-creates. Endpoint control streams and
|
|
1361
|
-
// their records/auth/session buckets come from endpointPlaneStreamNames below, the same downstream
|
|
1362
|
-
// ownership list consumed by inventory and teardown. The provisioner holds create-or-verify only on
|
|
1363
|
-
// those authority stores; lifecycle/session writes ride their narrower executor credentials.
|
|
1364
|
-
const buckets = [
|
|
1365
|
-
presenceBucket, channelBucket, membersBucket, aclBucket, membershipBucket, anycastBucket, deliveryBucket, managerBucket,
|
|
1366
|
-
].map((b) => `KV_${b(space)}`);
|
|
1367
|
-
// STREAM.CREATE + INFO for each (idempotent setup at `cotal up`; CREATE is create-if-matching, INFO covers
|
|
1368
|
-
// the client's existence checks). NO DELETE/PURGE — provisioning never tears a stream down.
|
|
1369
|
-
// The §13.7 CONTRACT store (EPC) joins the list for the static manager's start-time
|
|
1370
|
-
// `ensureContractStore`: create-or-verify only — the provisioner holds no
|
|
1371
|
-
// artifact-publish grant on it (publication rides the scoped endpoint-serve executor).
|
|
1372
|
-
// The seven §13.12 ENDPOINT streams join the list: spawn-as-action makes the manager
|
|
1373
|
-
// the first EPF (goal facts) + EPE (progress) writer, and nothing provisioned the endpoint streams
|
|
1374
|
-
// before (no manager code wrote to them), so `createEndpointStreams` now runs at the manager's
|
|
1375
|
-
// start-time ensure over this provisioner. Create-or-verify only (idempotent, fail-loud on drift);
|
|
1376
|
-
// the provisioner holds no value-write on any of them (goal facts ride the scoped goal-writer cred).
|
|
1377
|
-
// WFJ and the EPC/records/auth/session stores join them through endpointPlaneStreamNames because
|
|
1378
|
-
// createEndpointStreams owns all twelve resources. Create-or-verify only; the provisioner appends
|
|
1379
|
-
// nothing (writes ride the narrower runtime and authority credentials).
|
|
1380
|
-
// The artifact Object Store joins the list: `setupSpaceStreams` creates it, and under auth mode the
|
|
1381
|
-
// provisioner is the cred doing that creating. Its backing stream is `OBJ_<bucket>` - named
|
|
1382
|
-
// explicitly, because `$O.<bucket>.>` is outside the `cotal.<space>.>` grammar and no space-prefix
|
|
1383
|
-
// grant reaches it. CREATE + INFO here, plus the ONE STREAM.UPDATE below (the legacy-cap reconcile):
|
|
1384
|
-
// the provisioner never publishes an object, never creates a consumer on it, and never deletes it.
|
|
1385
|
-
// That confinement is load-bearing rather than tidy - the
|
|
1386
|
-
// object-store client reads by creating an ephemeral PUSH consumer with a caller-chosen
|
|
1387
|
-
// `deliver_subject`, so a CONSUMER.CREATE here would be an exporter of every artifact in the space.
|
|
1388
|
-
const OBJ = objectStoreStream(artifactBucket(space));
|
|
1389
|
-
const streamSetup = [CHAT, DM, TASK, INBOX, DLV, eventPayloadStream(space), OBJ, ...endpointPlaneStreamNames(space), ...buckets].flatMap((s) => [
|
|
1390
|
-
`$JS.API.STREAM.CREATE.${s}`,
|
|
1391
|
-
`$JS.API.STREAM.INFO.${s}`,
|
|
1392
|
-
]);
|
|
1393
|
-
// #286: STREAM.UPDATE on EXACTLY the three TTL'd KV streams (presence + the two leases). `kvm.create`
|
|
1394
|
-
// never updates an existing bucket's config, so a bucket created by a cotal that predates the `max_age`
|
|
1395
|
-
// TTL keeps NO expiry forever — dead presence records (and stale leases) never age out. `setupSpaceStreams`
|
|
1396
|
-
// reconciles their `max_age` via STREAM.UPDATE at every `cotal up`, which needs this grant. Scoped to these
|
|
1397
|
-
// three streams here. The durable task stream and the channel/members/acl registries are never
|
|
1398
|
-
// updated (the history limits of the four message streams are the exception, below), and there is
|
|
1399
|
-
// still NO DELETE/PURGE. The supervisor profile keeps its full UPDATE
|
|
1400
|
-
// denial; this widening is provisioning-only.
|
|
1401
|
-
// Derived from the SAME inventory that creates and reconciles them, not a third hand-kept copy.
|
|
1402
|
-
// Review found this list was the last independent one: a fourth TTL'd bucket added to `ttlBuckets`
|
|
1403
|
-
// would be created and reconciled correctly and then die on a permissions violation here, because
|
|
1404
|
-
// the grant never learned about it. Same defect one seam out — a bucket the code knows to maintain
|
|
1405
|
-
// and the credential is not allowed to.
|
|
1406
|
-
const ttlStreams = ttlBuckets(space).map(([bucket]) => `KV_${bucket}`);
|
|
1407
|
-
// ...plus the membership KV and artifact Object Store. Both create at `max_bytes: -1` so they
|
|
1408
|
-
// reserve nothing against the broker's `max_file_store`, and both reconcile only their own stock
|
|
1409
|
-
// legacy caps so an EXISTING mesh releases those reservations too. The create clients never update
|
|
1410
|
-
// an existing bucket's config, so each reconcile is a STREAM.UPDATE and needs this grant — without
|
|
1411
|
-
// it the provisioner dies on a permissions violation on the first `cotal up` after the upgrade.
|
|
1412
|
-
// Still CREATE/INFO/UPDATE only:
|
|
1413
|
-
// no publish, no CONSUMER.CREATE (a push consumer's caller-chosen `deliver_subject` would export
|
|
1414
|
-
// every artifact in the space), no DELETE/PURGE.
|
|
1415
|
-
// ...plus the CHAT, INBOX, DLV and DM streams: `cotal history limit` sets their history limits
|
|
1416
|
-
// (SPEC §8). STREAM.UPDATE is a whole-config write, so the grant reaches every setting of them;
|
|
1417
|
-
// `setHistoryLimit` changes only `max_age` and `max_msgs_per_subject` and refuses a read back that is
|
|
1418
|
-
// not canonical apart from those two. TASK stays create-only.
|
|
1419
|
-
const streamReconcile = [...ttlStreams, `KV_${membershipBucket(space)}`, OBJ, CHAT, INBOX, DLV, DM]
|
|
1420
|
-
.map((s) => `$JS.API.STREAM.UPDATE.${s}`);
|
|
1421
|
-
// #404: one EXACT reserved key on each TTL bucket is the post-update enforcement canary. The
|
|
1422
|
-
// provisioner still cannot write presence identities or lease keys; it can only write this fixed
|
|
1423
|
-
// maintenance key, which expires through the policy the reconcile is proving.
|
|
1424
|
-
const ttlCanaries = ttlBuckets(space).map(([bucket]) => `$KV.${bucket}.${TTL_RECONCILE_CANARY_KEY}`);
|
|
1425
|
-
// DM/DLV/TASK durable pre-create (bind-only mailboxes): both the new-API CREATE and legacy DURABLE.CREATE
|
|
1426
|
-
// forms (the client's consumer-add path varies by version), plus INFO (the add returns ConsumerInfo).
|
|
1427
|
-
// NO MSG.NEXT/MSG.GET/ACK — the provisioner creates the consumer but MUST NOT read its body.
|
|
1428
|
-
const consumerCreate = [DM, DLV, TASK].flatMap((s) => [
|
|
1429
|
-
`$JS.API.CONSUMER.CREATE.${s}.>`,
|
|
1430
|
-
`$JS.API.CONSUMER.DURABLE.CREATE.${s}.>`,
|
|
1431
|
-
`$JS.API.CONSUMER.INFO.${s}.>`,
|
|
1432
|
-
]);
|
|
1433
|
-
return {
|
|
1434
|
-
pub: {
|
|
1435
|
-
allow: [
|
|
1436
|
-
"$JS.API.INFO",
|
|
1437
|
-
// Current-connection identity only; the broker maps the account and requesting user.
|
|
1438
|
-
// No subject containing another account/user and no system credential is granted.
|
|
1439
|
-
BROKER_USER_INFO_SUBJECT,
|
|
1440
|
-
...streamSetup,
|
|
1441
|
-
...streamReconcile,
|
|
1442
|
-
...ttlCanaries,
|
|
1443
|
-
...consumerCreate,
|
|
1444
|
-
// KV value-writes — exactly the two registries provisioning writes: the agent read-ACL registry
|
|
1445
|
-
// (`commitAcl` at provision) and the channel registry (seed defaults at `cotal up`, channel admin).
|
|
1446
|
-
// NO presence/members/membership/delivery writes (the agent's own key, the delivery cred, and the
|
|
1447
|
-
// membership-rw cred own those).
|
|
1448
|
-
`$KV.${aclBucket(space)}.>`,
|
|
1449
|
-
`$KV.${channelBucket(space)}.>`,
|
|
1450
|
-
// ...and READ both: commitAcl read-before-writes the ACL (`kvm.open`, direct=false ⇒ STREAM.MSG.GET);
|
|
1451
|
-
// the channel seed read-before-writes defaults (`kvm.create`, direct=true ⇒ DIRECT.GET). Grant both
|
|
1452
|
-
// read verbs on both buckets to cover the open/create-path variance — reads of registries it already
|
|
1453
|
-
// writes, no escalation. Without these the read-before-write rejects and provisioning/seed throws.
|
|
1454
|
-
`$JS.API.STREAM.MSG.GET.KV_${aclBucket(space)}`,
|
|
1455
|
-
`$JS.API.DIRECT.GET.KV_${aclBucket(space)}.>`, // keyed get: `.>` (the key rides the subject)
|
|
1456
|
-
`$JS.API.STREAM.MSG.GET.KV_${channelBucket(space)}`,
|
|
1457
|
-
`$JS.API.DIRECT.GET.KV_${channelBucket(space)}.>`, // keyed get: `.>` (the key rides the subject)
|
|
1458
|
-
// The static-manager start path: `ensureAuthorityStores` UPDATEs the records store's
|
|
1459
|
-
// deny-flags exactly once at fresh creation (create → update → verify), and the boot
|
|
1460
|
-
// reconciliation sweep enumerates the manager's slot rows (`keys()` → an ordered consumer)
|
|
1461
|
-
// then reads each slot BODY (phase/uid/actor) to plan resume — the reads ride the
|
|
1462
|
-
// stream-scoped MSG.GET residual named below (records lifecycle metadata, no secrets).
|
|
1463
|
-
// The issued, accepted and admission stores (SPEC 13.15, 14.8) take the same one-time
|
|
1464
|
-
// hardening UPDATE at fresh creation as the records store: their rows are create-only and
|
|
1465
|
-
// their markers permanent, and a holder's own key row would otherwise replace them as a
|
|
1466
|
-
// value write. One list in core names the hardened stores for every seam that creates them.
|
|
1467
|
-
...hardenedAuthorityStreamNames(space).map((s) => `$JS.API.STREAM.UPDATE.${s}`),
|
|
1468
|
-
`$JS.API.CONSUMER.CREATE.KV_${recordsBucket(space)}.>`,
|
|
1469
|
-
`$JS.API.CONSUMER.INFO.KV_${recordsBucket(space)}.>`,
|
|
1470
|
-
`$JS.API.CONSUMER.DELETE.KV_${recordsBucket(space)}.>`,
|
|
1471
|
-
// ...and reads the slot-mapping rows so the sweep can plan resume actions. The KV client
|
|
1472
|
-
// reads a lazily-bound bucket via leader-served `STREAM.MSG.GET` — stream-scoped, NOT
|
|
1473
|
-
// key-scoped (the requested key rides the PAYLOAD). NAMED RESIDUAL: for its one-shot
|
|
1474
|
-
// lifetime the provisioner can READ (never write) any records-store row — lifecycle
|
|
1475
|
-
// metadata, no secrets. The keyed Direct Get grant stays for direct-aware read paths.
|
|
1476
|
-
`$JS.API.STREAM.MSG.GET.KV_${recordsBucket(space)}`,
|
|
1477
|
-
`$JS.API.DIRECT.GET.KV_${recordsBucket(space)}.$KV.${recordsBucket(space)}.${STATIC_SLOT_PREFIX}.>`,
|
|
1478
|
-
],
|
|
1479
|
-
},
|
|
1480
|
-
// Replies only: every stream/consumer/KV-create PubAck and JS API response lands on the per-id inbox.
|
|
1481
|
-
// NO chat/inst/dlv/ctl subscription — the provisioner never serves control nor reads any feed.
|
|
1482
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1483
|
-
};
|
|
1484
|
-
}
|
|
1485
|
-
/** The ISSUER permission set (SPEC 13.15): value-writes on the evidence store (evidence, attempt,
|
|
1486
|
-
* source index: create-only and CAS rows, keyed by generation) and on the accepted-row store
|
|
1487
|
-
* (create-only, keyed by the client's token); `STREAM.INFO` on both, the bind-time shape check;
|
|
1488
|
-
* the leader-served point read on the evidence store; and the ordered `keys()` walk a source
|
|
1489
|
-
* retirement enumerates the reverse index with.
|
|
1490
|
-
* NAMED RESIDUAL (the contract's section 8): this profile holds a write and a raw read on ONE
|
|
1491
|
-
* stream, the pairing no peer-held profile may hold, so it is never issuable to a peer. */
|
|
1492
|
-
function issuerPermissions(space, pr) {
|
|
1493
|
-
const ISSUED = `KV_${issuedBucket(space)}`;
|
|
1494
|
-
return {
|
|
1495
|
-
pub: {
|
|
1496
|
-
allow: [
|
|
1497
|
-
"$JS.API.INFO",
|
|
1498
|
-
`$KV.${issuedBucket(space)}.>`,
|
|
1499
|
-
`$KV.${acceptedBucket(space)}.>`,
|
|
1500
|
-
// A user-auth connection's renewal finds the accepted row its nonce names (SPEC 13.15).
|
|
1501
|
-
`$JS.API.DIRECT.GET.KV_${acceptedBucket(space)}.$KV.${acceptedBucket(space)}.>`,
|
|
1502
|
-
`$JS.API.STREAM.INFO.${ISSUED}`,
|
|
1503
|
-
`$JS.API.STREAM.INFO.KV_${acceptedBucket(space)}`,
|
|
1504
|
-
`$JS.API.STREAM.MSG.GET.${ISSUED}`,
|
|
1505
|
-
// Source liveness: the leader-served point read of a static incarnation's issuance gate on
|
|
1506
|
-
// the auth store (body-selected, stream-wide: the same named residual every records
|
|
1507
|
-
// reader accepts). No auth-store WRITE of any shape.
|
|
1508
|
-
`$JS.API.STREAM.MSG.GET.KV_${epAuthBucket(space)}`,
|
|
1509
|
-
`$JS.API.CONSUMER.CREATE.${ISSUED}.>`,
|
|
1510
|
-
`$JS.API.CONSUMER.INFO.${ISSUED}.>`,
|
|
1511
|
-
`$JS.API.CONSUMER.DELETE.${ISSUED}.>`,
|
|
1512
|
-
"$JS.FC.>",
|
|
1513
|
-
],
|
|
1514
|
-
},
|
|
1515
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
/** The REGISTRY READER permission set (SPEC 13.20). The evidence store's `STREAM.MSG.GET` is
|
|
1519
|
-
* stream-scoped because the key rides the request body: NAMED RESIDUAL, the holder can read every
|
|
1520
|
-
* recorded ceiling in the space, so this credential is never a peer's. The records reads are the
|
|
1521
|
-
* key list and the per-key `svc` spec/status Direct Get, no stream-wide read; contract artifacts
|
|
1522
|
-
* ride the agent's subject-scoped fetch row. No write of any shape. */
|
|
1523
|
-
function registryReaderPermissions(space, pr) {
|
|
1524
|
-
const ISSUED = `KV_${issuedBucket(space)}`;
|
|
1525
|
-
const REC = recordsBucket(space);
|
|
1526
|
-
return {
|
|
1527
|
-
pub: {
|
|
1528
|
-
allow: [
|
|
1529
|
-
`$JS.API.STREAM.INFO.${ISSUED}`,
|
|
1530
|
-
`$JS.API.STREAM.MSG.GET.${ISSUED}`,
|
|
1531
|
-
`$JS.API.STREAM.INFO.KV_${REC}`,
|
|
1532
|
-
`$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.svc.*.*.spec`,
|
|
1533
|
-
`$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.svc.*.*.status`,
|
|
1534
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}.${spacePrefix(space)}.epc.>`,
|
|
1535
|
-
],
|
|
1536
|
-
},
|
|
1537
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1538
|
-
};
|
|
1539
|
-
}
|
|
1540
|
-
/** The RUN ADMITTER permission set (SPEC 14.8): exactly ONE run's admission record and
|
|
1541
|
-
* revocation marker on the admission store (both create-only), plus the leader-served read the
|
|
1542
|
-
* create-before-read and the marker's own re-read ride. No other run's keys, no other store. */
|
|
1543
|
-
function runAdmitterPermissions(space, pr, pin) {
|
|
1544
|
-
const bucket = admissionBucket(space);
|
|
1545
|
-
return {
|
|
1546
|
-
pub: {
|
|
1547
|
-
allow: [
|
|
1548
|
-
"$JS.API.INFO",
|
|
1549
|
-
`$KV.${bucket}.${admissionKey(pin.endpoint, pin.runId)}`,
|
|
1550
|
-
`$KV.${bucket}.${revocationKey(pin.endpoint, pin.runId)}`,
|
|
1551
|
-
...(pin.submission ? [`$KV.${bucket}.${runSubmissionKey(pin.endpoint, pin.submission.caller, pin.submission.id)}`] : []),
|
|
1552
|
-
`$JS.API.STREAM.MSG.GET.KV_${bucket}`,
|
|
1553
|
-
],
|
|
1554
|
-
},
|
|
1555
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
/** The ephemeral, LIFECYCLE-PINNED §13.1 state-write permission set for the STATIC manager's
|
|
1559
|
-
* lifecycle executor. One credential per lifecycle OPERATION (activation, terminal,
|
|
1560
|
-
* renewal ledger append): every grant names exactly ONE incarnation's keys — the alias head,
|
|
1561
|
-
* the uid reservation, the manager slot row, the issuance gate, and the `cred.<uid>.>` ledger
|
|
1562
|
-
* family — so a leaked executor cred can move one incarnation's state machine and nothing else.
|
|
1563
|
-
*
|
|
1564
|
-
* Reads: records reads ride the keyed Direct Get form (the key is ON the subject, so the read
|
|
1565
|
-
* grant stays key-pinned); the auth store is leader-served (`allow_direct=false`), so its reads
|
|
1566
|
-
* are body-selected `STREAM.MSG.GET` — stream-scoped, NOT key-scoped (the requested key rides
|
|
1567
|
-
* the PAYLOAD, which a subject grant cannot see). NAMED RESIDUAL: for its one-shot lifetime the
|
|
1568
|
-
* executor can READ (never write) other rows in the auth store. */
|
|
1569
|
-
function lifecycleExecutorPermissions(space, pr, pin) {
|
|
1570
|
-
const REC = recordsBucket(space), AUTH = epAuthBucket(space);
|
|
1571
|
-
// ALL keys DERIVED here from the pin coordinates — the slot key is `staticSlotKey(owner, alias)`,
|
|
1572
|
-
// NOT a caller-supplied literal, so a mis-constructed pin can only ever name ONE coherent
|
|
1573
|
-
// incarnation's rows (guard the core: the profile enforces the "one incarnation" promise, it
|
|
1574
|
-
// does not merely assert it). The builders throw on any non-KV-safe segment.
|
|
1575
|
-
const recordKeys = [
|
|
1576
|
-
lifecycleHeadKey(pin.owner, pin.actor), uidReservationKey(pin.lifecycleUid), staticSlotKey(pin.owner, pin.alias),
|
|
1577
|
-
recordSpecKey(RECORD_KINDS.lifecycle, [pin.owner, pin.actor, pin.lifecycleUid]),
|
|
1578
|
-
];
|
|
1579
|
-
return {
|
|
1580
|
-
pub: {
|
|
1581
|
-
allow: [
|
|
1582
|
-
"$JS.API.INFO",
|
|
1583
|
-
// Records-store CAS writes — the value-publish carries the key on the subject, so each
|
|
1584
|
-
// grant names exactly one of this incarnation's keys.
|
|
1585
|
-
...recordKeys.map((k) => `$KV.${REC}.${k}`),
|
|
1586
|
-
// Auth-store CAS writes — this incarnation's gate + its cred-ledger family (renewals
|
|
1587
|
-
// append rows here; the terminal's revoke CASes them).
|
|
1588
|
-
`$KV.${AUTH}.${issuanceGateKey(pin.lifecycleUid)}`,
|
|
1589
|
-
`$KV.${AUTH}.cred.${pin.lifecycleUid}.>`,
|
|
1590
|
-
// Keyed Direct Get reads of the same records keys (key-pinned) for direct-aware read
|
|
1591
|
-
// paths, PLUS the leader-served `STREAM.MSG.GET` the lazily-bound KV client actually
|
|
1592
|
-
// uses — stream-scoped, NOT key-scoped (the requested key rides the PAYLOAD, which a
|
|
1593
|
-
// subject grant cannot see). NAMED RESIDUAL: for its one-shot lifetime the executor can
|
|
1594
|
-
// READ (never write) other rows in BOTH authority stores — lifecycle metadata, no
|
|
1595
|
-
// secrets; every WRITE stays key-pinned above.
|
|
1596
|
-
...recordKeys.map((k) => `$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.${k}`),
|
|
1597
|
-
`$JS.API.STREAM.MSG.GET.KV_${REC}`,
|
|
1598
|
-
`$JS.API.STREAM.MSG.GET.KV_${AUTH}`,
|
|
1599
|
-
],
|
|
1600
|
-
},
|
|
1601
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1602
|
-
};
|
|
1603
|
-
}
|
|
1604
|
-
/** The SELF-MEDIATED goal-writer profile (spawn-as-action): exactly
|
|
1605
|
-
* {@link goalWriterGrants} for ITS endpoint — the goal bind + terminal facts, the goal-record KV
|
|
1606
|
-
* writes, and the leader-served fencing reads — plus the connection-scoped reply inbox. Disjoint
|
|
1607
|
-
* from the endpoint's serve credential: a serve connection carries none of these rows, so it
|
|
1608
|
-
* is broker-denied every goal write. */
|
|
1609
|
-
function goalWriterPermissions(space, pr, pin) {
|
|
1610
|
-
const g = goalWriterGrants(space, pin.endpoint, pr.connId);
|
|
1611
|
-
return { pub: { allow: g.publish }, sub: { allow: g.subscribe } };
|
|
1612
|
-
}
|
|
1613
|
-
/** The console/CLI per-session CALLER rows: RAILS-ONLY for ONE §13.6 session — pub the
|
|
1614
|
-
* session's epoch-pinned `in` rail, sub its `out` rail plus the caller's own reply inbox, and
|
|
1615
|
-
* NOTHING else. Deliberately NO KV, NO JetStream API, NO store: the caller drives the terminal over
|
|
1616
|
-
* the two core-only eps subjects and never reads the session ledger, so there is no subject-blind
|
|
1617
|
-
* store read to widen (SPEC §13.9). The endpoint+sessionId+epoch pin the EXACT pair, so a cred for
|
|
1618
|
-
* session A authorizes nothing of session B (no wildcard). `epsSubject` validates every token, so a
|
|
1619
|
-
* malformed coordinate refuses at the mint rather than emitting a broadened subject. */
|
|
1620
|
-
function sessionCallerPermissions(space, pr, pin) {
|
|
1621
|
-
if (!pin)
|
|
1622
|
-
throw new Error('permissionsFor: "session-caller" requires opts.sessionCaller ({endpoint, sessionId, epoch}) - the ONE session\'s rails this cred may use');
|
|
1623
|
-
return {
|
|
1624
|
-
pub: { allow: [epsSubject(space, pin.endpoint, pin.sessionId, pin.epoch, "in")] },
|
|
1625
|
-
sub: { allow: [epsSubject(space, pin.endpoint, pin.sessionId, pin.epoch, "out"), `_INBOX_${pr.connId}.>`] },
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
/** The own-DM reader rows (#4189): CONSUMER.INFO and MSG.NEXT on the principal's own
|
|
1629
|
-
* lifecycle-keyed `dm_` durable, its `$JS.ACK` subtree, and the connection inbox. Nothing else:
|
|
1630
|
-
* no publish of any message, no CONSUMER.CREATE (the durable is provisioned, never created), no
|
|
1631
|
-
* `$JS.API.INFO`, no STREAM.INFO, no presence, channel, CHAT or `dlv_` row. It is exactly what
|
|
1632
|
-
* `EndpointOptions.dmOnly` sends. */
|
|
1633
|
-
function dmReaderPermissions(space, pr) {
|
|
1634
|
-
if (!pr.lifecycleUid)
|
|
1635
|
-
throw new Error('permissionsFor(dm-reader): a lifecycleUid is required - the dm_ durable name is lifecycle-keyed (SPEC 13.1)');
|
|
1636
|
-
const DM = dmStream(space), dmD = dmDurable(pr.owner, pr.actor, assertLifecycleToken(pr.lifecycleUid));
|
|
1637
|
-
return {
|
|
1638
|
-
pub: { allow: [`$JS.API.CONSUMER.INFO.${DM}.${dmD}`, `$JS.API.CONSUMER.MSG.NEXT.${DM}.${dmD}`, `$JS.ACK.${DM}.${dmD}.>`] },
|
|
1639
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1640
|
-
};
|
|
1641
|
-
}
|
|
1642
|
-
/** The manager's per-session SERVING rows: the EXACT mirror of
|
|
1643
|
-
* {@link sessionCallerPermissions} with the directions swapped — sub the ONE session's epoch-pinned
|
|
1644
|
-
* `in` rail (caller→serving), pub its `out` rail (serving→caller), plus the connection-scoped reply
|
|
1645
|
-
* inbox, and NOTHING else. Same asymmetry §13.6 states: "the caller publishes `in` and subscribes
|
|
1646
|
-
* `out`; the serving instance the reverse".
|
|
1647
|
-
*
|
|
1648
|
-
* Deliberately NO KV and NO JetStream API — not even the session ledger. The serving side drives
|
|
1649
|
-
* bytes; the ledger is the standing `session-ledger` credential's, on a different connection. That
|
|
1650
|
-
* separation is what lets this credential be one-shot and die with its session while the durable
|
|
1651
|
-
* revocation authority outlives it (§13.6).
|
|
1652
|
-
*
|
|
1653
|
-
* This REPLACES a standing writer that held `eps.<endpoint>.*.<epoch>.{in,out}` and so could read
|
|
1654
|
-
* and write every live session's bytes at its epoch. The pin makes a credential for session A
|
|
1655
|
-
* authorize nothing of session B, and `epsSubject` validates every token, so a malformed
|
|
1656
|
-
* coordinate refuses at the mint rather than emitting a broadened subject. */
|
|
1657
|
-
function sessionServingPermissions(space, pr, pin) {
|
|
1658
|
-
if (!pin)
|
|
1659
|
-
throw new Error('permissionsFor: "session-serving" requires opts.sessionServing ({endpoint, sessionId, epoch}) - the ONE session\'s rails this cred may serve');
|
|
1660
|
-
return {
|
|
1661
|
-
pub: { allow: [epsSubject(space, pin.endpoint, pin.sessionId, pin.epoch, "out")] },
|
|
1662
|
-
sub: { allow: [epsSubject(space, pin.endpoint, pin.sessionId, pin.epoch, "in"), `_INBOX_${pr.connId}.>`] },
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
/** The manager's SESSION-LEDGER rows: the DEDICATED sessions-bucket rows and nothing
|
|
1666
|
-
* else — no session rail of any shape. Needs no pin: the grant carries no endpoint, epoch, or
|
|
1667
|
-
* session component, because §13.6's durable revocation authority is per-space, not per-session
|
|
1668
|
-
* (it must still be able to resolve and revoke a row after the endpoint that served it is gone).
|
|
1669
|
-
* {@link sessionLedgerGrants} carries the row rationale, the §13.9 subject-blindness confinement,
|
|
1670
|
-
* and the named `session.*` breadth residual. */
|
|
1671
|
-
function sessionLedgerPermissions(space, pr) {
|
|
1672
|
-
const g = sessionLedgerGrants(space, pr.connId);
|
|
1673
|
-
return { pub: { allow: g.publish }, sub: { allow: g.subscribe } };
|
|
1674
|
-
}
|
|
1675
|
-
/** The ephemeral, ENDPOINT-INSTANCE-PINNED endpoint-serve executor permission set:
|
|
1676
|
-
* the manager mints this per registration/serve-mint op and drives the endpoint
|
|
1677
|
-
* registration barrier's `epgate` CAS + the mint fence's `epcred` stage/revoke THROUGH it — never
|
|
1678
|
-
* its standing seed/supervisor connection. Every
|
|
1679
|
-
* WRITE is key-pinned to exactly ONE (endpoint, instanceId): the gate `epgate.<ep>.<iid>`, its
|
|
1680
|
-
* serving ledger family `epcred.<ep>.<iid>.>`, and the registration's two records keys (the
|
|
1681
|
-
* instance's `svc` spec + the endpoint's governance head — `registerServiceInstance` drives the
|
|
1682
|
-
* slot-take/promote over this same connection). A leaked/mis-constructed executor can move exactly
|
|
1683
|
-
* one endpoint instance's serve state and nothing else. The auth store is `allow_direct=false`, so
|
|
1684
|
-
* reads are leader-served `STREAM.MSG.GET` (stream-scoped, NOT key-scoped — the key rides the
|
|
1685
|
-
* payload); enumeration of the epcred family rides an ordered `keys()` consumer. NAMED RESIDUAL:
|
|
1686
|
-
* for its one-shot lifetime the executor can READ (never write) other auth rows — endpoint/
|
|
1687
|
-
* credential metadata, no bearer bytes; every WRITE stays key-pinned. */
|
|
1688
|
-
function endpointServeExecutorPermissions(space, pr, pin) {
|
|
1689
|
-
const AUTH = epAuthBucket(space), REC = recordsBucket(space);
|
|
1690
|
-
// DERIVED from (endpoint, instanceId) via the core builders — never a caller literal.
|
|
1691
|
-
const gateKey = epgateKey(pin.endpoint, pin.instanceId);
|
|
1692
|
-
const credPrefix = epcredFamilyPrefix(pin.endpoint, pin.instanceId);
|
|
1693
|
-
const repairKey = eprepairKey(pin.endpoint, pin.instanceId);
|
|
1694
|
-
// The registration writes this ONE instance's spec key plus the endpoint's governance head
|
|
1695
|
-
// (`registerServiceInstance` PHASE 1/3b: the slot-take + promote ride the SAME executor), and this
|
|
1696
|
-
// instance's own svc STATUS key (the manager writes its CONVERGED `ready` status so it
|
|
1697
|
-
// is a §13.5 scatter member — `freezeExpectedSet` requires a status caught up to the current
|
|
1698
|
-
// registration; the write is epoch-fenced by `writeServiceStatus`).
|
|
1699
|
-
const recordKeys = [
|
|
1700
|
-
recordSpecKey(RECORD_KINDS.svc, [pin.endpoint, assertLifecycleToken(pin.instanceId, "instanceId")]),
|
|
1701
|
-
recordStatusKey(RECORD_KINDS.svc, [pin.endpoint, assertLifecycleToken(pin.instanceId, "instanceId")]),
|
|
1702
|
-
recordAtomicKey(GOVERN_HEAD, [pin.endpoint]),
|
|
1703
|
-
];
|
|
1704
|
-
return {
|
|
1705
|
-
pub: {
|
|
1706
|
-
allow: [
|
|
1707
|
-
"$JS.API.INFO",
|
|
1708
|
-
// The key-pinned WRITE grants: the gate (provision create + barrier freeze/reopen CAS),
|
|
1709
|
-
// the serving ledger family (mint-fence stage + barrier revoke), and the registration's
|
|
1710
|
-
// two records-store keys (spec CAS + governance slot/promote). The value-publish carries
|
|
1711
|
-
// the key on the subject, so each grant names exactly this instance's keys.
|
|
1712
|
-
`$KV.${AUTH}.${gateKey}`,
|
|
1713
|
-
`$KV.${AUTH}.${repairKey}`,
|
|
1714
|
-
`$KV.${AUTH}.${credPrefix}.>`,
|
|
1715
|
-
...recordKeys.map((k) => `$KV.${REC}.${k}`),
|
|
1716
|
-
// §13.7 contract-artifact publication: the registration publishes the
|
|
1717
|
-
// endpoint's cluster document, closure manifests, and schema roots to the EPC store so
|
|
1718
|
-
// callers can fetch-verify-compile the registered digests. A digest subject is a SINGLE
|
|
1719
|
-
// hex token (`epc.<64hex>`), so the grant is the single-token `epc.*` form (matching
|
|
1720
|
-
// `contractPublisherGrants`), never the multi-token `epc.>`. Digest subjects cannot be
|
|
1721
|
-
// key-pinned pre-mint; the store's SHAPE is the defense (ensureContractStore): a digest
|
|
1722
|
-
// subject holds exactly one broker-immutable message (max_msgs_per_subject:1 +
|
|
1723
|
-
// discard-new-per-subject REJECTS a second publish regardless of the create-only header, so
|
|
1724
|
-
// a grant-holder CANNOT append a shadow over a published artifact), deny_delete/deny_purge
|
|
1725
|
-
// keep that message, and content addressing (verify-on-read, create-only-winner fallback)
|
|
1726
|
-
// makes a wrong-subject write unservable. NAMED RESIDUAL: for its one-shot lifetime the
|
|
1727
|
-
// executor can publish NEW digest-addressed artifacts at previously-unused subjects (a
|
|
1728
|
-
// bounded storage flood; unreferenced artifacts carry no authority) — it can NOT overwrite,
|
|
1729
|
-
// shadow, or replace an existing one.
|
|
1730
|
-
`${spacePrefix(space)}.epc.*`,
|
|
1731
|
-
// The lost-CAS verify-read `publishContractArtifact` runs when a re-publish (every re-up /
|
|
1732
|
-
// restart against an existing store) loses the create-only CAS: it fetches the recorded
|
|
1733
|
-
// artifact to confirm the idempotent no-op. BOTH Direct Get forms — the subject-scoped
|
|
1734
|
-
// `last_by_subj` (the fast path) and the bare stream form (the create-only-winner
|
|
1735
|
-
// `next_by_subj` fallback) — so the publish path never dies on a broker denial regardless
|
|
1736
|
-
// of stream config. Without this the manager exits on its SECOND boot (the tester's
|
|
1737
|
-
// upgrade-path regression). Reads public content-addressed artifacts only.
|
|
1738
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}.${spacePrefix(space)}.epc.>`,
|
|
1739
|
-
`$JS.API.DIRECT.GET.${epcStreamName(space)}`,
|
|
1740
|
-
// Leader-served reads (the auth store is allow_direct=false): stream-scoped MSG.GET (the
|
|
1741
|
-
// barrier/fence read the gate + each epcred row), plus the ordered consumer the epcred
|
|
1742
|
-
// `keys()` enumeration binds. The records store IS direct-servable, so its reads add the
|
|
1743
|
-
// key-pinned DIRECT.GET forms beside the leader-served fallback. NAMED RESIDUAL: reads
|
|
1744
|
-
// any row in both stores for its one-shot lifetime (metadata, no bearer bytes).
|
|
1745
|
-
`$JS.API.STREAM.MSG.GET.KV_${AUTH}`,
|
|
1746
|
-
`$JS.API.CONSUMER.CREATE.KV_${AUTH}.>`,
|
|
1747
|
-
`$JS.API.CONSUMER.INFO.KV_${AUTH}.>`,
|
|
1748
|
-
`$JS.API.CONSUMER.DELETE.KV_${AUTH}.>`,
|
|
1749
|
-
// Ordered value scans acknowledge flow control only for this authorized auth stream.
|
|
1750
|
-
`$JS.FC.KV_${AUTH}.>`,
|
|
1751
|
-
...recordKeys.map((k) => `$JS.API.DIRECT.GET.KV_${REC}.$KV.${REC}.${k}`),
|
|
1752
|
-
`$JS.API.STREAM.MSG.GET.KV_${REC}`,
|
|
1753
|
-
],
|
|
1754
|
-
},
|
|
1755
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
/** The ephemeral, TARGET-PINNED DEPROVISIONER permission set — the teardown counterpart
|
|
1759
|
-
* to {@link provisionerPermissions}, minted per departed agent inside the manager's `deprovision` tail
|
|
1760
|
-
* (`withProvisioner`-style: a fresh scoped cred per teardown is cheap). It deletes exactly the
|
|
1761
|
-
* dev/static principal footprint the provisioner created for ONE agent: that agent's two bind-only
|
|
1762
|
-
* durables (`dm_local-<actor>`, `dlv_local-<actor>`) and its read-ACL row — pinned BY NAME to the target
|
|
1763
|
-
* actor under {@link DEV_OWNER}, so a leaked deprovisioner cred can tear down that one already-dead
|
|
1764
|
-
* agent and NOTHING else.
|
|
1765
|
-
*
|
|
1766
|
-
* Deliberately NOT granted (least-privilege / correctness): the role-SHARED `svc_<role>` TASK durable
|
|
1767
|
-
* (one consumer for ALL agents of a role — deleting it on one agent's exit would break its siblings; it
|
|
1768
|
-
* lives until space teardown), any peer's `dm_`/`dlv_`/ACL (the grants are target-name-pinned, never
|
|
1769
|
-
* `.>`), any MSG.NEXT/MSG.GET/ACK (it deletes mailboxes, never reads a body), and any STREAM
|
|
1770
|
-
* DELETE/PURGE (it removes per-agent consumers, never a stream). The `chathist_<id>` history consumers
|
|
1771
|
-
* need no grant here — they are ephemeral (`mem_storage`, 30s inactive threshold) and agent-deleted
|
|
1772
|
-
* after each read, so they self-clean on the agent's disconnect.
|
|
1773
|
-
*
|
|
1774
|
-
* Blast radius of a leaked cred (minted for target T): it can delete T's `dm_local-<T>`/`dlv_local-<T>`
|
|
1775
|
-
* durables + purge T's ACL row — a denial-of-DELIVERY for T (broken DM/DLV bind + the reader DEFERs on
|
|
1776
|
-
* the absent ACL) if fired while T is still alive. It CANNOT read T's bodies, impersonate T, reach any peer, or
|
|
1777
|
-
* delete a stream — and it is ephemeral (one per-exit teardown, minted then dropped). Contained and
|
|
1778
|
-
* recoverable (re-provision T). */
|
|
1779
|
-
function deprovisionerPermissions(space, pr, deprovisionTarget) {
|
|
1780
|
-
const DM = dmStream(space), DLV = dlvStream(space);
|
|
1781
|
-
const t = deprovisionTargetPrincipal(deprovisionTarget);
|
|
1782
|
-
const target = principalKey(t.owner, t.actor);
|
|
1783
|
-
return {
|
|
1784
|
-
pub: {
|
|
1785
|
-
allow: [
|
|
1786
|
-
"$JS.API.INFO", // jetstreamManager bootstrap
|
|
1787
|
-
// Delete the target LIFECYCLE's two bind-only durables BY EXACT NAME — no `.>`, no cross-agent
|
|
1788
|
-
// reach, and no reach into a same-alias successor: its names carry a different uid, so a
|
|
1789
|
-
// replayed teardown is broker-DENIED there (SPEC 13.1 / Appendix "deprovisioner").
|
|
1790
|
-
`$JS.API.CONSUMER.DELETE.${DM}.${dmDurable(t.owner, t.actor, t.lifecycleUid)}`,
|
|
1791
|
-
`$JS.API.CONSUMER.DELETE.${DLV}.${dlvDurable(t.owner, t.actor, t.lifecycleUid)}`,
|
|
1792
|
-
`$JS.API.CONSUMER.INFO.${DM}.${dmDurable(t.owner, t.actor, t.lifecycleUid)}`,
|
|
1793
|
-
`$JS.API.CONSUMER.INFO.${DLV}.${dlvDurable(t.owner, t.actor, t.lifecycleUid)}`,
|
|
1794
|
-
// Purge the target lifecycle's read-ACL row (own-target exact key only — the reader then treats
|
|
1795
|
-
// it as an unknown owner). `kvm.open` binds the pre-created bucket; the purge rides
|
|
1796
|
-
// `$KV.<aclBucket>.<key>`.
|
|
1797
|
-
`$JS.API.STREAM.INFO.KV_${aclBucket(space)}`,
|
|
1798
|
-
`$JS.API.DIRECT.GET.KV_${aclBucket(space)}.$KV.${aclBucket(space)}.${aclKey(target.key, t.lifecycleUid)}`,
|
|
1799
|
-
`$KV.${aclBucket(space)}.${aclKey(target.key, t.lifecycleUid)}`,
|
|
1800
|
-
// Purge the target lifecycle's durable membership rows, one exact key per named concrete
|
|
1801
|
-
// channel or family (a family's `>` is `=` in the key, so no grant here is a wildcard). The key
|
|
1802
|
-
// embeds the uid, so a successor's row is unreachable by name.
|
|
1803
|
-
...(t.memberChannels.length > 0 ? [`$JS.API.STREAM.INFO.KV_${membersBucket(space)}`] : []),
|
|
1804
|
-
...t.memberChannels.map((ch) => `$JS.API.DIRECT.GET.KV_${membersBucket(space)}.$KV.${membersBucket(space)}.${memberKey(ch, target.key, t.lifecycleUid)}`),
|
|
1805
|
-
...t.memberChannels.map((ch) => `$KV.${membersBucket(space)}.${memberKey(ch, target.key, t.lifecycleUid)}`),
|
|
1806
|
-
],
|
|
1807
|
-
},
|
|
1808
|
-
// Replies only: the CONSUMER.DELETE PubAcks + KV purge ack land on the per-connection inbox. NO chat/DM/ctl
|
|
1809
|
-
// subscription — the deprovisioner serves nothing and reads no feed.
|
|
1810
|
-
sub: { allow: [`_INBOX_${pr.connId}.>`] },
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
/** The scoped `delivery` daemon permission set (server-side Plane-3 infra; NEVER allow-all, never
|
|
1814
|
-
* minted for an agent — `cotal mint` excludes it, like `manager`). Least-privilege: exactly what the
|
|
1815
|
-
* fan-out writer + trusted reader + activation catch-up + membership/ACL reads + members-KV writes +
|
|
1816
|
-
* the lease + the `ctl.delivery` control service touch. `sub.allow` is the per-identity inbox (all JS
|
|
1817
|
-
* pull delivery / KV-watch / request replies land there) PLUS the `ctl.delivery` control subtree it
|
|
1818
|
-
* serves; ALL stream/KV reads ride the JS API (publishes), so there is NO native `chat`/`dinbox`/`dlv`
|
|
1819
|
-
* subscription — a leaked cred can't natively sniff the mixed pre-auth store. Honest blast radius
|
|
1820
|
-
* (delivery-daemon.mdx): it can write any owner's `dlv` (the post-auth store agents trust); the future
|
|
1821
|
-
* fan-out/reader cred split bounds that. */
|
|
1822
|
-
function deliveryPermissions(space, pr) {
|
|
1823
|
-
const p = spacePrefix(space);
|
|
1824
|
-
const CHAT = chatStream(space), INBOX = inboxStream(space), DLV = dlvStream(space);
|
|
1825
|
-
const PKV = `KV_${presenceBucket(space)}`, CHKV = `KV_${channelBucket(space)}`;
|
|
1826
|
-
const MKV = `KV_${membersBucket(space)}`, AKV = `KV_${aclBucket(space)}`, DKV = `KV_${deliveryBucket(space)}`;
|
|
1827
|
-
const TASK = taskStream(space), AKVR = `KV_${anycastBucket(space)}`;
|
|
1828
|
-
const kvRead = (bucket) => [
|
|
1829
|
-
`$JS.API.STREAM.INFO.${bucket}`,
|
|
1830
|
-
`$JS.API.STREAM.MSG.GET.${bucket}`, // kv.get
|
|
1831
|
-
`$JS.API.CONSUMER.CREATE.${bucket}.>`, // kv.watch ordered consumer
|
|
1832
|
-
`$JS.API.CONSUMER.INFO.${bucket}.>`,
|
|
1833
|
-
`$JS.API.CONSUMER.DELETE.${bucket}.>`,
|
|
1834
|
-
];
|
|
1835
|
-
const pub = [
|
|
1836
|
-
"$JS.API.INFO",
|
|
1837
|
-
`$JS.API.STREAM.INFO.${CHAT}`, `$JS.API.STREAM.INFO.${INBOX}`, `$JS.API.STREAM.INFO.${DLV}`,
|
|
1838
|
-
// Fan-out durable + activation-catch-up ephemerals live on CHAT — the daemon legitimately reads ALL
|
|
1839
|
-
// chat (the fan-out consumes the whole stream), so a stream-wide CHAT consumer grant is no
|
|
1840
|
-
// escalation. The catch-up ephemeral names (`cu_<owner>_<gen>`) are dynamic, so they can't be
|
|
1841
|
-
// name-pinned; CHAT-wide is correct here.
|
|
1842
|
-
//
|
|
1843
|
-
// BOTH forms, and the bare one is not redundant: a create carrying `filter_subjects` cannot encode
|
|
1844
|
-
// its filter in the subject, so the client publishes to the BARE `…CREATE.<CHAT>` while a named
|
|
1845
|
-
// consumer goes to the `.>` form. The mediated history read (`readHistory`) builds exactly that
|
|
1846
|
-
// multi-filter ephemeral, and with only the `.>` grant it fails with a Permissions Violation on the
|
|
1847
|
-
// bare subject — measured, not predicted. The observer profile already carries both for the same
|
|
1848
|
-
// reason. Grants the daemon nothing new in substance: it may already create any named consumer on
|
|
1849
|
-
// this stream and already reads all of it.
|
|
1850
|
-
`$JS.API.CONSUMER.CREATE.${CHAT}`,
|
|
1851
|
-
`$JS.API.CONSUMER.CREATE.${CHAT}.>`,
|
|
1852
|
-
`$JS.API.CONSUMER.DURABLE.CREATE.${CHAT}.>`,
|
|
1853
|
-
`$JS.API.CONSUMER.INFO.${CHAT}.>`,
|
|
1854
|
-
`$JS.API.CONSUMER.MSG.NEXT.${CHAT}.>`,
|
|
1855
|
-
`$JS.API.CONSUMER.DELETE.${CHAT}.>`,
|
|
1856
|
-
`$JS.ACK.${CHAT}.>`,
|
|
1857
|
-
// Trusted reader on INBOX — NAME-PINNED to the single `reader` durable (the meaningful confinement:
|
|
1858
|
-
// no arbitrary INBOX consumer create against the mixed pre-auth store).
|
|
1859
|
-
`$JS.API.CONSUMER.CREATE.${INBOX}.${INBOX_READER_DURABLE}.>`,
|
|
1860
|
-
`$JS.API.CONSUMER.DURABLE.CREATE.${INBOX}.${INBOX_READER_DURABLE}`,
|
|
1861
|
-
`$JS.API.CONSUMER.INFO.${INBOX}.${INBOX_READER_DURABLE}`,
|
|
1862
|
-
`$JS.API.CONSUMER.MSG.NEXT.${INBOX}.${INBOX_READER_DURABLE}`,
|
|
1863
|
-
`$JS.API.CONSUMER.DELETE.${INBOX}.${INBOX_READER_DURABLE}`,
|
|
1864
|
-
`$JS.ACK.${INBOX}.${INBOX_READER_DURABLE}.>`,
|
|
1865
|
-
// The reader removes an entry addressed to a retired lifecycle (its ACL row is tombstoned), so the
|
|
1866
|
-
// store does not keep what no reader can ever deliver. Nothing new in substance: the reader can
|
|
1867
|
-
// already ack any INBOX entry away.
|
|
1868
|
-
`$JS.API.STREAM.MSG.DELETE.${INBOX}`,
|
|
1869
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
1870
|
-
// Reads: presence (@mention resolve) + channel registry (delivery class) + members + ACL (re-auth).
|
|
1871
|
-
...kvRead(PKV), ...kvRead(CHKV), ...kvRead(MKV), ...kvRead(AKV),
|
|
1872
|
-
// Members-KV WRITE — the daemon is the durable-membership authority (join/leave/activate/catch-up).
|
|
1873
|
-
`$KV.${membersBucket(space)}.>`,
|
|
1874
|
-
// Delivery lease/readiness KV: read the bucket (renew CAS) + write ONLY lease keys. The
|
|
1875
|
-
// CONSUMER.* rows are kv.watch's ordered consumer for the lease-loss watch (#1596) — the same
|
|
1876
|
-
// read axis the other kvRead buckets carry, on the bucket this cred already reads point-wise:
|
|
1877
|
-
// a watch is a READ of the row's changes, never a write. CONSUMER.DELETE rides with it for the
|
|
1878
|
-
// same reason it does on every watched bucket: an ordered consumer rebuilds by deleting its
|
|
1879
|
-
// predecessor, and a refused delete strands consumers on every rebuild (measured on the
|
|
1880
|
-
// presence bucket; the comment there carries the full story).
|
|
1881
|
-
`$JS.API.STREAM.INFO.${DKV}`, `$JS.API.STREAM.MSG.GET.${DKV}`,
|
|
1882
|
-
`$JS.API.CONSUMER.CREATE.${DKV}.>`,
|
|
1883
|
-
`$JS.API.CONSUMER.INFO.${DKV}.>`,
|
|
1884
|
-
`$JS.API.CONSUMER.DELETE.${DKV}.>`,
|
|
1885
|
-
`$KV.${deliveryBucket(space)}.lease.*`,
|
|
1886
|
-
// The timer writer (SPEC 13.2): the daemon hosts the pump that turns `.schedule` requests into
|
|
1887
|
-
// the authoritative `.armed` publishes — without it no workflow pause on the space ever
|
|
1888
|
-
// expires. Its consumer rows are the shared timer-writer grant set; both create forms for the
|
|
1889
|
-
// same reason CHAT carries both (the client picks by whether the create embeds a filter). The
|
|
1890
|
-
// arm itself needs the fence's two leader reads — the `.armed` head on EPT and the checkpoint
|
|
1891
|
-
// status on the records KV — and exactly ONE publish: the `.armed` subject. Never `.fire`
|
|
1892
|
-
// (the broker's own schedule delivery) and never `.schedule` (it consumes those).
|
|
1893
|
-
...timerWriterGrants(space),
|
|
1894
|
-
`$JS.API.CONSUMER.DURABLE.CREATE.${eptReqStreamName(space)}.${timerWriterDurable(space)}`,
|
|
1895
|
-
`$JS.API.STREAM.INFO.${eptReqStreamName(space)}`,
|
|
1896
|
-
`$JS.API.STREAM.INFO.${eptStreamName(space)}`,
|
|
1897
|
-
`$JS.API.STREAM.MSG.GET.${eptStreamName(space)}`,
|
|
1898
|
-
`$JS.API.STREAM.INFO.KV_${recordsBucket(space)}`,
|
|
1899
|
-
`$JS.API.STREAM.MSG.GET.KV_${recordsBucket(space)}`,
|
|
1900
|
-
`${p}.ept.*.*.*.*.armed`,
|
|
1901
|
-
// Plane-3 data writes: dinbox (fan-out target) + dlv (post-auth handoff) for ANY lifecycle — the
|
|
1902
|
-
// identity slots widen to `.*.*.*` (owner+actor+lifecycleUid: dinbox/dlv are per-LIFECYCLE now,
|
|
1903
|
-
// SPEC 13.1; NATS subject arity is exact, so the old two-token form is broker-denied on every
|
|
1904
|
-
// three-token write).
|
|
1905
|
-
`${p}.dinbox.*.*.*`, `${p}.dlv.*.*.*`,
|
|
1906
|
-
// ctl.delivery control REPLIES ONLY (requests arrive on the sub below; the daemon only ever
|
|
1907
|
-
// m.respond()s to a requester's reply subject `ctl.delivery.<owner>.<actor>.reply.<n>`). Scoped to
|
|
1908
|
-
// the `.reply.>` leaf so the daemon can't publish to the request subjects themselves — tighter than a
|
|
1909
|
-
// blanket `ctl.delivery.>` (fact-check precision, review panel). The caller slots widened to `.*.*`.
|
|
1910
|
-
`${p}.ctl.delivery.*.*.reply.>`,
|
|
1911
|
-
// The privileged delivery-admin rail: same replies-only shape. Requests reach the
|
|
1912
|
-
// daemon on the sub below; only the supervisor cred can PUBLISH them (nats-server is the boundary).
|
|
1913
|
-
`${p}.ctl.delivery-admin.*.*.reply.>`,
|
|
1914
|
-
// LIVENESS REPLIES for the DELIVERY plane (#1577) — same replies-only shape as the two control
|
|
1915
|
-
// rails above. The daemon is the only process that can grade its own responder honestly: it
|
|
1916
|
-
// knows its own incarnation, so a predecessor's `ready:true` corpse in the lease classifies as
|
|
1917
|
-
// stale rather than as its own health. Bounded to the `.reply.` leaf, so it cannot publish to
|
|
1918
|
-
// the request subjects and forge a probe from a peer.
|
|
1919
|
-
livenessReplyGrant(space, "delivery"),
|
|
1920
|
-
// Anycast request status (SPEC §8.1). The daemon reads a request at the seq a take, status or
|
|
1921
|
-
// cancel names, and deletes one its sender cancelled while it waited: a read of every request
|
|
1922
|
-
// body in the space and a delete of any of them, both bounded by the take record. It owns the
|
|
1923
|
-
// records bucket, creating it on a mesh that predates it, and lists it for the maintenance pass.
|
|
1924
|
-
// It DMs a request's sender from its own principal only, and answers takes on their bounded
|
|
1925
|
-
// reply leaf.
|
|
1926
|
-
`$JS.API.STREAM.INFO.${TASK}`,
|
|
1927
|
-
`$JS.API.STREAM.MSG.GET.${TASK}`,
|
|
1928
|
-
`$JS.API.STREAM.MSG.DELETE.${TASK}`,
|
|
1929
|
-
`$JS.API.STREAM.CREATE.${AKVR}`,
|
|
1930
|
-
...kvRead(AKVR),
|
|
1931
|
-
`$JS.API.DIRECT.GET.${AKVR}.>`,
|
|
1932
|
-
`$KV.${anycastBucket(space)}.>`,
|
|
1933
|
-
unicastSubject(space, "*", "*", pr.owner, pr.actor), // inst.*.*.<o>.<a>: a notice to a sender, as itself
|
|
1934
|
-
takeReplyGrant(space),
|
|
1935
|
-
];
|
|
1936
|
-
const sub = [
|
|
1937
|
-
`_INBOX_${pr.connId}.>`,
|
|
1938
|
-
takeServeFilter(space), // serve anycast takes (queue-grouped; role + owner+actor caller slots)
|
|
1939
|
-
`${p}.ctl.delivery.*.*`, // serve the delivery control service (queue-grouped; owner+actor caller slots)
|
|
1940
|
-
`${p}.ctl.delivery-admin.*.*`, // serve the privileged admin rail (reloadCreds; eviction executor next)
|
|
1941
|
-
// Serve the delivery plane's liveness probe (#1577), queue-grouped. Presence-only: the handler
|
|
1942
|
-
// reduces the lease row to one enum before replying, so this subscription lets the daemon ANSWER
|
|
1943
|
-
// a peer without any peer gaining a read of the lease.
|
|
1944
|
-
livenessServeFilter(space, "delivery"),
|
|
1945
|
-
];
|
|
1946
|
-
return { pub: { allow: pub }, sub: { allow: sub } };
|
|
1947
|
-
}
|
|
1948
|
-
/** The scoped DATA-account `membership-rw` permission set (the graph feed's conn B; NEVER allow-all,
|
|
1949
|
-
* never minted for an agent — `cotal mint` excludes it, like `manager`/`delivery`). Least-privilege:
|
|
1950
|
-
* READ the members registry (the durable arm of the merge) + READ/WRITE the one derived membership
|
|
1951
|
-
* bucket, and nothing else. It holds NO chat/DM/anycast/ctl grant and never touches `$SYS` (account
|
|
1952
|
-
* isolation keeps the system-account CONNZ read on the SEPARATE conn-A cred). A leaked conn-B cred can
|
|
1953
|
-
* read durable-membership records and forge the feed — bounded to "dashboard integrity" by the
|
|
1954
|
-
* display-only invariant; it reads no message bodies and admins nothing. */
|
|
1955
|
-
function membershipRwPermissions(space, pr) {
|
|
1956
|
-
const MKV = `KV_${membersBucket(space)}`; // durable arm — read
|
|
1957
|
-
const MEMKV = `KV_${membershipBucket(space)}`; // derived feed — read (diff/prune) + write
|
|
1958
|
-
const kvRead = (bucket) => [
|
|
1959
|
-
`$JS.API.STREAM.INFO.${bucket}`,
|
|
1960
|
-
`$JS.API.STREAM.MSG.GET.${bucket}`, // kv.get
|
|
1961
|
-
`$JS.API.CONSUMER.CREATE.${bucket}.>`, // kv.keys()/kv.watch ordered consumer
|
|
1962
|
-
`$JS.API.CONSUMER.INFO.${bucket}.>`,
|
|
1963
|
-
`$JS.API.CONSUMER.DELETE.${bucket}.>`,
|
|
1964
|
-
];
|
|
1965
|
-
const pub = [
|
|
1966
|
-
"$JS.API.INFO",
|
|
1967
|
-
...kvRead(MKV),
|
|
1968
|
-
...kvRead(MEMKV),
|
|
1969
|
-
`$KV.${membershipBucket(space)}.>`, // write derived feed (kv.put + kv.delete)
|
|
1970
|
-
"$JS.FC.>", // ordered-consumer flow control
|
|
1971
|
-
];
|
|
1972
|
-
return { pub: { allow: pub }, sub: { allow: [`_INBOX_${pr.connId}.>`] } };
|
|
1973
|
-
}
|
|
1974
|
-
/** The scoped SYSTEM-account `membership-observer` permission set (the graph feed's conn A). An EXPLICIT
|
|
1975
|
-
* block is MANDATORY: a system-account user with NO permissions block defaults to ALLOW-ALL = full
|
|
1976
|
-
* `$SYS` = broker admin (verified — pre-flight spike + docs). Least-privilege allowlist:
|
|
1977
|
-
* - **pub:** the account-scoped CONNZ request subject ONLY (not server-wide `PING.CONNZ`, not
|
|
1978
|
-
* `REQ.SERVER.*`/`REQ.CLAIMS.*`).
|
|
1979
|
-
* - **sub:** the scoped reply inbox (`<MEMBERSHIP_INBOX_PREFIX>.>`) + this ONE account's
|
|
1980
|
-
* CONNECT/DISCONNECT events (re-poll triggers) — never `$SYS.ACCOUNT.*.…` (cross-tenant) nor
|
|
1981
|
-
* `$SYS.ACCOUNT.<id>.>` (pulls in SUBSZ/JSZ/purge).
|
|
1982
|
-
* No `$SYS.>` deny that would shadow the allows (deny-beats-allow). A leaked conn-A cred enumerates THIS
|
|
1983
|
-
* account's connections (silent readers + nkeys) and can forge the feed; it reads no bodies, touches no
|
|
1984
|
-
* other account, and admins no server. */
|
|
1985
|
-
function membershipObserverPermissions(accountId) {
|
|
1986
|
-
return {
|
|
1987
|
-
pub: { allow: [connzRequestSubject(accountId)] },
|
|
1988
|
-
sub: {
|
|
1989
|
-
allow: [
|
|
1990
|
-
`${MEMBERSHIP_INBOX_PREFIX}.>`,
|
|
1991
|
-
accountConnectSubject(accountId),
|
|
1992
|
-
accountDisconnectSubject(accountId),
|
|
1993
|
-
],
|
|
1994
|
-
},
|
|
1995
|
-
};
|
|
1996
|
-
}
|
|
1997
|
-
/** The KICK-ONLY connection-evictor permission set — a SYSTEM-account user that can do
|
|
1998
|
-
* exactly ONE thing: `$SYS.REQ.SERVER.*.KICK` (disconnect a live client by cid). It CANNOT read
|
|
1999
|
-
* CONNZ (discovery stays on the separate observer cred — never one broad sys user that both
|
|
2000
|
-
* enumerates and kills), touch any other `$SYS` verb, or reach another account's data. A leaked
|
|
2001
|
-
* evictor cred can DoS live connections on this broker (KICK is not account-scoped — the honest
|
|
2002
|
-
* blast radius), which is why it is a HIGH-POWER standing credential: minted only at `up`,
|
|
2003
|
-
* rate-limited + audited by its one caller (the delivery daemon), and its cid/server-id inputs come
|
|
2004
|
-
* only from the observer's own CONNZ scan, never a user-facing API. Wildcard `*` over server id
|
|
2005
|
-
* because a cluster's server ids aren't known at mint time; the scan pins the exact id per KICK. */
|
|
2006
|
-
function connectionEvictorPermissions() {
|
|
2007
|
-
return {
|
|
2008
|
-
pub: { allow: ["$SYS.REQ.SERVER.*.KICK"] },
|
|
2009
|
-
// Request/reply KICK replies land on the client's default inbox; no other subscription — it
|
|
2010
|
-
// serves nothing and reads no feed.
|
|
2011
|
-
sub: { allow: ["_INBOX.>"] },
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
export { INSTRUMENT_PROFILES, connectionEvictorPermissions, endpointServePermissions, membershipObserverPermissions };
|
|
647
|
+
export { INSTRUMENT_PROFILES };
|
|
648
|
+
export { connectionEvictorPermissions, endpointServePermissions, membershipObserverPermissions, listingGrantRows } from "./provision-permission-builders.js";
|
|
2015
649
|
//# sourceMappingURL=provision-permissions.js.map
|