@cotal-ai/cli 0.174.4 → 0.175.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat/stdio.js +1 -1
- package/dist/chat/stdio.js.map +1 -1
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +37 -15
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/history.d.ts +2 -2
- package/dist/commands/history.d.ts.map +1 -1
- package/dist/commands/history.js +5 -6
- package/dist/commands/history.js.map +1 -1
- package/dist/commands/join.js +13 -4
- package/dist/commands/join.js.map +1 -1
- package/dist/commands/models.d.ts.map +1 -1
- package/dist/commands/models.js +9 -10
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +4 -1
- package/dist/commands/send.js.map +1 -1
- package/dist/commands/service-actions.d.ts.map +1 -1
- package/dist/commands/service-actions.js +11 -4
- package/dist/commands/service-actions.js.map +1 -1
- package/dist/commands/up-broker-auth.d.ts +78 -0
- package/dist/commands/up-broker-auth.d.ts.map +1 -0
- package/dist/commands/up-broker-auth.js +430 -0
- package/dist/commands/up-broker-auth.js.map +1 -0
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +7 -421
- package/dist/commands/up.js.map +1 -1
- package/dist/ext-loader.d.ts.map +1 -1
- package/dist/ext-loader.js +1 -0
- package/dist/ext-loader.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/commands/up.js
CHANGED
|
@@ -8,9 +8,8 @@ import { createConnection, isIP } from "node:net";
|
|
|
8
8
|
import { homedir, hostname } from "node:os";
|
|
9
9
|
import { accessSync, constants, mkdirSync, readFileSync, existsSync, statSync, closeSync, lstatSync, realpathSync, readdirSync, rmdirSync, } from "node:fs";
|
|
10
10
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
11
|
-
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR, CONTRACT_ARTIFACT_MAX_BYTES, MANAGER_START_PAYLOAD_FLOOR,
|
|
12
|
-
import {
|
|
13
|
-
import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, DEFAULT_SEAT_CAP, recordManagerName, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, commandFailureReport, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, getSoleSpaceAuth, soleSpaceOf, getSpaceAuth, hasUserAuthState, listSpaceAccounts, preloadSpaceAccounts, putSpaceAuth, brokerAddressKey, canonicalRoot, rootPathProblem, rootControlProblem, clearCurrent, findMesh, findPreparedSpace, homeCotalDir, legacyStackOtherHome, stackHomeRemedy, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, connectionEvictorCredsKey, membershipConfigPath, membershipObserverCredsKey, membershipRwCredsKey, MEMBERSHIP_CONFIG_KIND, MEMBERSHIP_RW_CREDS_KIND, WEB_CREDS_KIND, webCredsKey, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, rotateSystemCreds, setAdoptedCurrent, staleSystemCreds, SYSTEM_CREDS_FILES, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, brokerAccountResolver, removePidPair, writePidPair, verifyIdentityPin, processesNaming, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordOperationWarning, retainSystemSigningSeed, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, NATS_PIDFILE, MANAGER_PIDFILE, DELIVERY_PIDFILE, AUTH_PIDFILE, localProcessPath, UNTRUSTED_CERTIFICATE, exitCode, canonicalLocalProcessPath, DELIVERY_LOGFILE, terminalWidth, } from "@cotal-ai/workspace";
|
|
11
|
+
import { isReachable, dialerFor, DEFAULT_SERVER, DEFAULT_SPACE, SERVICE_AUTHORITY_MAX_BYTES, SERVICE_CALLER_PAYLOAD_FLOOR, CONTRACT_ARTIFACT_MAX_BYTES, MANAGER_START_PAYLOAD_FLOOR, mintCreds, mintLifecycleUid, DEV_OWNER, newIdentity, reconcileSpaceMemoryBuckets, standaloneConnectOpts, parseServerVersion, LEASE_TTL_MS, EpEnvelopeError, writeSecretFile, } from "@cotal-ai/core";
|
|
12
|
+
import { assertManagerName, processStopped, readManagerName, readManagerSeatCap, DEFAULT_SEAT_CAP, recordManagerName, parseSeatCapFlag, seatCapText, CommandFailure, codeSpan, commandFailureReport, failureEnvelope, writeEnvelope, isCommandFailure, protectedLocalDirectory, jsonFlag, plainFlag, renderReport, assertSingleSpaceBroker, assertUserAuthInfo, authDir, brokerAddressForDisplay, getSoleSpaceAuth, soleSpaceOf, getSpaceAuth, hasUserAuthState, listSpaceAccounts, brokerAddressKey, canonicalRoot, rootPathProblem, rootControlProblem, clearCurrent, findMesh, findPreparedSpace, homeCotalDir, legacyStackOtherHome, stackHomeRemedy, getCurrent, loadMeshes, preparedSpaceAt, removePreparedSpace, localMeshesForRoot, keepsRegistration, oneLine, presentationOf, writeResult, parsePositiveIntegerFlag, recordMesh, retainedLegacyBroker, meshesForRoot, removeMesh, setAdoptedCurrent, userAuthStateDir, userAuthSpacesOnDisk, workspaceSecretStore, acquireMaintenanceLock, assertStoreIdentity, assessMaintenanceClaim, assessRestoreClaim, beginOrdinaryResume, bindOrdinaryResumeListener, consumeRetiredMaintenance, markOrdinaryResumeActive, markOrdinaryResumeDegraded, replaceDeadOrdinaryResumeListener, localProcessOwnerStatus, readMaintenanceJournal, rootNamesNoSpace, readMaintenanceResumeDocument, readStoreIdentity, recordOrdinaryResumeManagerCommit, releaseMaintenanceLock, retireOrdinaryResume, settleTokenHandoff, sweepTokenHandoff, writeTokenHandoff, sameStoreIdentity, cutController, readBrokerPolicy, removePidPair, writePidPair, verifyIdentityPin, processesNaming, isLoopbackHost, connectUserControlOrThrow, userViewAuth, recordOperationSpace, recordOperationWarning, restoreLeftOut, SPACE_NAME_MAX, spaceNameTooLong, NATS_PIDFILE, MANAGER_PIDFILE, DELIVERY_PIDFILE, AUTH_PIDFILE, localProcessPath, UNTRUSTED_CERTIFICATE, exitCode, canonicalLocalProcessPath, DELIVERY_LOGFILE, terminalWidth, } from "@cotal-ai/workspace";
|
|
14
13
|
import { FlagValueRefusal } from "../lib/flag-value-refusal.js";
|
|
15
14
|
import { ensureAuthService, resolveAuthProvider, stopAuthService } from "../lib/auth-proc.js";
|
|
16
15
|
import { resolveSpace } from "../lib/status.js";
|
|
@@ -43,8 +42,8 @@ import { liveMeshProcesses } from "./clean.js";
|
|
|
43
42
|
import { checkSpaceFlagValue, checkSpaceName } from "./meshes-add.js";
|
|
44
43
|
import { checkLocalSpace } from "./space-registration.js";
|
|
45
44
|
import { checkNewUpSpace, checkPublicExchangePort, preparedUpRoot } from "./up-target.js";
|
|
46
|
-
import { cleanedManifestStart, interruptedStartBroker,
|
|
47
|
-
import { bindReaches, canonicalServer, controllerStackApplies, recheckExistingStore, requestedStackMode, refuseForegroundStackHolder, requestsTls, stackUp, stackUpForegroundNotice, stackUpInterrupted, keptOnUp, selectedOnUp,
|
|
45
|
+
import { cleanedManifestStart, interruptedStartBroker, retainedOpenSpace } from "../lib/legacy-start.js";
|
|
46
|
+
import { bindReaches, canonicalServer, controllerStackApplies, recheckExistingStore, requestedStackMode, refuseForegroundStackHolder, requestsTls, stackUp, stackUpForegroundNotice, stackUpInterrupted, keptOnUp, selectedOnUp, } from "./stack-up.js";
|
|
48
47
|
import { exitInterrupted, handOverStartupNotice, noticeOnInterrupt, releaseStartupNotice } from "../lib/interrupt-notice.js";
|
|
49
48
|
import { claimForegroundHold, foregroundHolder, foregroundStackEnd, releaseForegroundHold } from "../lib/foreground-hold.js";
|
|
50
49
|
import { settleInterruptedLaunches } from "../lib/service-process.js";
|
|
@@ -60,7 +59,7 @@ import { serviceSupervisorStore } from "../lib/service-supervision.js";
|
|
|
60
59
|
import { serviceInstallIntents } from "../lib/service-install-intent.js";
|
|
61
60
|
import { serviceUninstallIntents } from "../lib/service-uninstall-intent.js";
|
|
62
61
|
import { serviceUnitActionStore } from "../lib/service-unit-action.js";
|
|
63
|
-
import { assertStoreDirArgument,
|
|
62
|
+
import { assertStoreDirArgument, startupStoreProblem, warnForeignStoreEntries } from "../lib/store-dir.js";
|
|
64
63
|
import { extensionNames, preflightRuntime } from "../ext-loader.js";
|
|
65
64
|
import { completingFlagValue } from "../lib/completion.js";
|
|
66
65
|
import { metadataPositionals } from "../lib/command-path.js";
|
|
@@ -68,13 +67,14 @@ import { bindPreparedRestoreListener, isManagerCommitResult, isManagerFinalizeRe
|
|
|
68
67
|
import { attemptProcessesGone } from "../lib/isolated-broker.js";
|
|
69
68
|
import { assertEndpointUnreachable } from "../lib/endpoint-cut.js";
|
|
70
69
|
import { brokerAddressConflict } from "../lib/broker-service.js";
|
|
71
|
-
import {
|
|
70
|
+
import { freshStackServer, retryStackAddress, serverWithFreePort } from "../lib/up-broker-address.js";
|
|
72
71
|
import { askManager } from "@cotal-ai/workspace/control";
|
|
73
72
|
import { cliControl } from "../lib/control.js";
|
|
74
73
|
import { pendingRestores, pendingOrdinaryResumes } from "./up-pending.js";
|
|
75
74
|
import { parseMaxFileStore, parseAuthTimeout, parseMaxPayload, assertManagerPayload, parseAccountResolver, authTimeoutArgs, loadChannelsFile, refuseRunningElsewhere, refuseRecordsElsewhere, resolveTransport, assertTlsIntentServed, assertTlsAddressServed, commitTransportPolicy, tlsAddress, announceTransport, liveListenerRequiresTls, assertServesDialHost, adoptedTlsRequired, refuseUnnamedLastStore, reopenLastStore, refuseMissingNamedStore, checkStartStore, } from "./up-transport.js";
|
|
76
75
|
import { WILDCARD_HOSTS, reconcileHostAndServer, assertFreshTeamBindAvailable } from "./up-host.js";
|
|
77
76
|
import { registeredAddressHolder, refuseRegisteredAddress, membershipConversionRefusal, fileMembershipStore, postStart, recreateMemoryBuckets, recreateAdoptedMemoryBuckets, recreateDeletedStreams, } from "./up-stores.js";
|
|
77
|
+
import { brokerVersion, writeOpenBrokerConf, authSetup, provisionWebCreds } from "./up-broker-auth.js";
|
|
78
78
|
const restoreSinks = new Map();
|
|
79
79
|
/** Run the guarded `up --restore` startup and return its result instead of printing it. The
|
|
80
80
|
* restore inputs and fences are exactly `up --restore`'s; this adds no route, flag or authority. */
|
|
@@ -4618,30 +4618,6 @@ async function refuseUntrustedListener(server, creds) {
|
|
|
4618
4618
|
: /^tls:/i.test(server) ? `serve a certificate that names ${hostname}, then run \`cotal up\` again` : `pass --server tls://${hostname}:${port}, so every dial checks the certificate against ${hostname}`,
|
|
4619
4619
|
});
|
|
4620
4620
|
}
|
|
4621
|
-
/** The broker's version, and whether `space`'s presence stream exists file-backed. Cotal creates
|
|
4622
|
-
* it in memory (#1356), so only a bucket an older cotal created is file-backed; an absent one
|
|
4623
|
-
* will be created in memory by `setupSpaceStreams`. */
|
|
4624
|
-
async function brokerVersion(server, space, creds) {
|
|
4625
|
-
const nc = await dialerFor(server)({ servers: server, ...standaloneConnectOpts({ creds, tls: false }) });
|
|
4626
|
-
try {
|
|
4627
|
-
requireBrokerFloor(nc);
|
|
4628
|
-
const version = nc.info?.version ?? "";
|
|
4629
|
-
let presenceFileBacked = false;
|
|
4630
|
-
try {
|
|
4631
|
-
const info = await (await jetstreamManager(nc)).streams.info(`KV_${presenceBucket(space)}`);
|
|
4632
|
-
presenceFileBacked = info.config.storage === StorageType.File;
|
|
4633
|
-
}
|
|
4634
|
-
catch (e) {
|
|
4635
|
-
const err = e;
|
|
4636
|
-
if (err.api_error?.err_code !== 10059 && !/stream not found/i.test(err.message ?? ""))
|
|
4637
|
-
throw e;
|
|
4638
|
-
}
|
|
4639
|
-
return { version, presenceFileBacked };
|
|
4640
|
-
}
|
|
4641
|
-
finally {
|
|
4642
|
-
await drainAndClose(nc);
|
|
4643
|
-
}
|
|
4644
|
-
}
|
|
4645
4621
|
// #1356: the presence bucket's file-backed latch is fixed in nats-server 2.14.5. Below that,
|
|
4646
4622
|
// `cotal up` warns when the space's presence bucket is file-backed (never refuses: 2.14.0 meets the
|
|
4647
4623
|
// SPEC §13.12 floor and is the bundled broker). A memory-backed bucket has no file store to latch.
|
|
@@ -4655,394 +4631,4 @@ function belowPresenceSafeBroker(version) {
|
|
|
4655
4631
|
return p.minor < 14;
|
|
4656
4632
|
return p.patch < 5;
|
|
4657
4633
|
}
|
|
4658
|
-
/**
|
|
4659
|
-
* Render and write the config for an OPEN (no-auth) broker, returning its path. It names `space`,
|
|
4660
|
-
* because an open root holds no account that would ({@link namedOpenConfig}).
|
|
4661
|
-
*
|
|
4662
|
-
* The `authSetup` sibling for the no-auth mode. Open mode previously launched nats-server from
|
|
4663
|
-
* bare CLI flags and so never passed through any renderer — meaning the REQUIRED transport union
|
|
4664
|
-
* on the config renderers covered the auth path only, and a `--tls-cert`/`--tls-key` pair given to
|
|
4665
|
-
* an open-mode `up` would have been accepted while the broker came up in cleartext. Routing open
|
|
4666
|
-
* mode through a renderer is what makes the union total: there is now no route to a listener that
|
|
4667
|
-
* does not state its transport.
|
|
4668
|
-
*/
|
|
4669
|
-
function writeOpenBrokerConf(storeDir, space, opts) {
|
|
4670
|
-
const confPath = cotalPath("server-open.conf");
|
|
4671
|
-
writeBrokerConfig(confPath, namedOpenConfig(openServerConfig({ brokerVersion: opts.brokerVersion, port: opts.port, host: opts.host, storeDir: configuredStoreDir(cotalRoot(), storeDir), maxFileStore: opts.maxFileStore, maxPayload: opts.maxPayload, logFile: opts.logFile, logfileSizeLimit: opts.logfileSizeLimit, logfileMaxNum: opts.logfileMaxNum, transport: opts.transport }), space));
|
|
4672
|
-
return confPath;
|
|
4673
|
-
}
|
|
4674
|
-
/** Write a broker configuration that `up` renders again on every start. Something other than this
|
|
4675
|
-
* account's own regular file at its path, such as a symlink or a folder, is refused by name and
|
|
4676
|
-
* left as it is. Moving it aside loses nothing, because the next `up` writes the file again.
|
|
4677
|
-
* Other write failures name the path and errno, and remain known failures before a launch. */
|
|
4678
|
-
function writeBrokerConfig(path, text) {
|
|
4679
|
-
try {
|
|
4680
|
-
writeSecretFile(path, text);
|
|
4681
|
-
}
|
|
4682
|
-
catch (error) {
|
|
4683
|
-
const code = error.code;
|
|
4684
|
-
// A nonblocking write-only open can fail ENXIO for non-regular entries before the secure
|
|
4685
|
-
// writer can inspect its descriptor. An absent or regular entry still means a write failure.
|
|
4686
|
-
const entry = code === "EPERM" || code === "EISDIR" || code === "EACCES" || code === "ENXIO" ? lstatSync(path, { throwIfNoEntry: false }) : undefined;
|
|
4687
|
-
if (code !== "EPERM" && code !== "EISDIR" && code !== "EACCES" && (!entry || entry.isFile()))
|
|
4688
|
-
throw new CommandFailure("failed", "OPERATION_FAILED", `up could not write the broker configuration ${path}${code ? ` (${code})` : ""}; nothing was started`, {
|
|
4689
|
-
target: { path }, remedy: `correct the write failure at ${path}, then run \`cotal up\` again, which writes the configuration again`,
|
|
4690
|
-
});
|
|
4691
|
-
const what = entry?.isSymbolicLink() ? "is a symlink" : entry?.isDirectory() ? "is a folder" : code === "EACCES" ? "cannot be written by this account" : "is not a regular file this account owns";
|
|
4692
|
-
throw new CommandFailure("refused", "PERMISSION_DENIED", `the broker configuration ${path} ${what}, so up cannot write it; it was left as it is and nothing was started`, {
|
|
4693
|
-
target: { path }, remedy: `move it aside, as mv ${shellWord(path)} ${shellWord(`${path}.old`)} does, then run \`cotal up\` again, which writes it from the space's trust`,
|
|
4694
|
-
});
|
|
4695
|
-
}
|
|
4696
|
-
}
|
|
4697
|
-
/** The refusal for a trust record of the space that this account cannot read. It holds the space's
|
|
4698
|
-
* keys, so the step makes it readable again and never removes it. Any other error as it is. */
|
|
4699
|
-
function unreadableTrust(error) {
|
|
4700
|
-
const { code, path } = error;
|
|
4701
|
-
if (code !== "EACCES" && code !== "EPERM" || typeof path !== "string")
|
|
4702
|
-
return error;
|
|
4703
|
-
return new CommandFailure("refused", "PERMISSION_DENIED", `the space's trust record ${path} cannot be read by this account (${code}); nothing was started`, {
|
|
4704
|
-
target: { path }, remedy: `make it readable by you again, as chmod 600 ${shellWord(path)} does, then run \`cotal up\` again; it holds the space's keys, so keep it`,
|
|
4705
|
-
});
|
|
4706
|
-
}
|
|
4707
|
-
/** Ensure the space's trust material exists and render a server config. The caller can mint
|
|
4708
|
-
* the setup credential after connector reconciliation. The account signing key
|
|
4709
|
-
* in `.cotal/auth` is what `cotal mint` and the manager later use to issue per-agent creds.
|
|
4710
|
-
*
|
|
4711
|
-
* USER MODE (`user` set): additionally run the registered auth provider's `prepareServer` over the
|
|
4712
|
-
* SPACE-SCOPED state dir (`.cotal/auth/<space>/` — the multi-space-ready layout; nothing user-auth
|
|
4713
|
-
* lives flat) and preload its extra account(s) into the broker config. The inverse is fail-closed:
|
|
4714
|
-
* a space whose user-auth state exists MUST keep being started with --user-auth — regenerating the
|
|
4715
|
-
* config without the callout account would silently break every sentinel connect.
|
|
4716
|
-
*
|
|
4717
|
-
* `rotateSys` (`cotal up --rotate-sys`) is the class-3 renewal for an EXISTING space: rotate the
|
|
4718
|
-
* system account, re-mint `membership-observer.creds` + `connection-evictor.creds` against the
|
|
4719
|
-
* successor, and render the config from the ROTATED record so the broker this `up` starts is the one
|
|
4720
|
-
* that trusts them. It belongs here because this is the single site that both owns the trust record
|
|
4721
|
-
* and renders `server.conf`; anywhere else would publish creds the live broker cannot honor. */
|
|
4722
|
-
async function authSetup(storeDir, server, space, host = "127.0.0.1", user,
|
|
4723
|
-
// NON-OPTIONAL, and it used to default to `{ kind: "plaintext" }`. That default was the hole: the
|
|
4724
|
-
// manifest path called this with five arguments and silently got a cleartext listener while the
|
|
4725
|
-
// operator's `--tls-cert` sat validated and unused. A default here cannot be right, because the
|
|
4726
|
-
// safe value and the common value are different values — every caller knows its transport, and
|
|
4727
|
-
// the one that does not is the one that must not compile.
|
|
4728
|
-
transport, rotateSys = false, maxFileStore, quietBoot = false,
|
|
4729
|
-
// `--auth-timeout`, `--max-payload` and `--account-resolver`. Each absent value falls back to the one the root's broker
|
|
4730
|
-
// policy records, so a bare `up` renders what an earlier `up` set. They arrive as one object
|
|
4731
|
-
// rather than two trailing optional numbers: a transposed pair of those renders a wrong
|
|
4732
|
-
// configuration in silence.
|
|
4733
|
-
requested = {}) {
|
|
4734
|
-
const dir = authDir(cotalRoot()); // the broker config (server.conf) still lands under the FS auth dir
|
|
4735
|
-
const store = workspaceSecretStore(cotalRoot());
|
|
4736
|
-
let auth = await getSpaceAuth(store, space).catch((error) => { throw unreadableTrust(error); });
|
|
4737
|
-
if (!auth) {
|
|
4738
|
-
auth = await createSpaceAuth(space);
|
|
4739
|
-
// The trust record is written last. Until it exists the next up treats the space as fresh and
|
|
4740
|
-
// mints all of this again, so an up stopped partway never leaves a space without its $SYS creds.
|
|
4741
|
-
await provisionMembershipCreds(auth, cotalRoot(), space); // the observer is minted while the $SYS seed is in memory (fresh-space only)
|
|
4742
|
-
// Smoke only: hold a new space with part of its material written, so a signal can land there.
|
|
4743
|
-
if (process.env.COTAL_SMOKE_HOLD_IN_SPACE_AUTH === "1")
|
|
4744
|
-
await new Promise((done) => setTimeout(done, 60_000));
|
|
4745
|
-
await retainSystemSigningSeed(store, auth); // the host keeps the seed itself, beside the record, for own-broker caller issuance
|
|
4746
|
-
await putSpaceAuth(store, auth); // strips the $SYS seed at rest
|
|
4747
|
-
// A fresh space's $SYS material was just minted from the seed this branch holds in memory, so
|
|
4748
|
-
// the ASK is already satisfied, so say so rather than rotating a one-second-old account, and never
|
|
4749
|
-
// report a rotation that did not happen.
|
|
4750
|
-
if (rotateSys)
|
|
4751
|
-
console.log(c.dim("• --rotate-sys: this space is new, so its $SYS creds were just minted - nothing to rotate"));
|
|
4752
|
-
}
|
|
4753
|
-
else if (rotateSys) {
|
|
4754
|
-
// Third and last of the stopped-broker checks, at the one point every rotation path converges on.
|
|
4755
|
-
// The other two live in `up`'s reachable-listener branch: this root's recorded mesh at the
|
|
4756
|
-
// requested address, and any UNIDENTIFIED listener there (which refuses rather than free-porting
|
|
4757
|
-
// around a broker that may be serving this root's own server.conf and store). This one reads the
|
|
4758
|
-
// root's ownership records for a broker at an address nobody probed. It reports what those
|
|
4759
|
-
// records say, not what the process table says (see its own comment for the residual), and fails
|
|
4760
|
-
// CLOSED, so an ambiguous record refuses exactly like a live one.
|
|
4761
|
-
await assertRootBrokerStopped(cotalRoot());
|
|
4762
|
-
// Fails loud: a caller that swallowed this would boot the broker on the RETIRED system account
|
|
4763
|
-
// while `doctor auth` reported the rotation as done.
|
|
4764
|
-
const rot = await rotateSystemCreds(cotalRoot(), space);
|
|
4765
|
-
auth = rot.auth; // the config below MUST be rendered from the successor, never the pre-rotation copy
|
|
4766
|
-
console.log(c.green(`✓ rotated the system account for "${space}"`) +
|
|
4767
|
-
c.dim(` (generation ${rot.gen}) - re-minted ${SYSTEM_CREDS_FILES.join(" + ")}${rot.expiresAt ? `, valid to ${new Date(rot.expiresAt * 1000).toISOString().slice(0, 10)}` : ""}`));
|
|
4768
|
-
// Say exactly what is true. The retirement is CONFIG-LOAD-BOUND: an old cred dies against any
|
|
4769
|
-
// broker that loads the successor config, which is every broker started from this root from here
|
|
4770
|
-
// on, but a stale nats-server still holding the pre-rotation config in memory would keep
|
|
4771
|
-
// honoring it, so "now dead" without that qualifier oversells the guarantee.
|
|
4772
|
-
console.log(c.dim(" the data account, every agent cred and the JetStream store are untouched. The OLD $SYS creds are refused by any broker that loads this config; a stale broker still running the previous config would still honor them, so stop those first."));
|
|
4773
|
-
// A full backup binds to the trust chain it was taken against: `rootChainCommitment` hashes the
|
|
4774
|
-
// operator JWT and the system account, both of which just changed, so `cotal up --restore`
|
|
4775
|
-
// refuses every full artifact taken before this moment. That is correct (it is a different trust
|
|
4776
|
-
// root), but it is only obvious to someone who has read the fingerprint code, and rotation is
|
|
4777
|
-
// now a routine 30-day act rather than a once-per-space event. Say it at the moment it becomes
|
|
4778
|
-
// true, not in a doc the operator reads after the restore has already failed.
|
|
4779
|
-
console.log(c.dim(" NOTE: full backups taken before this rotation can no longer be restored (they are bound to the retired trust chain) - take a fresh `cotal backup` once the mesh is up."));
|
|
4780
|
-
}
|
|
4781
|
-
// The DATA half of the membership bundle, on EVERY path — see healMembershipDataCreds.
|
|
4782
|
-
await healMembershipDataCreds(auth, cotalRoot(), space, quietBoot);
|
|
4783
|
-
await provisionWebCreds(auth, cotalRoot(), space, quietBoot);
|
|
4784
|
-
// The $SYS creds must be signed by the system account THIS boot is about to put in `server.conf`.
|
|
4785
|
-
// A rotation that committed the trust record and then died leaves them stale, unexpired, and
|
|
4786
|
-
// broker-dead and, crash-before-either-write, stale in a way that no comparison between the two
|
|
4787
|
-
// FILES can see (they agree with each other; they just disagree with the record). This is the one
|
|
4788
|
-
// place holding both, on the one path that renders the config, so it is where the split is caught.
|
|
4789
|
-
//
|
|
4790
|
-
// REFUSE, do not warn. A warning is what the `--detach` path turns into an unread log line under a
|
|
4791
|
-
// green "✓ running in the background", which is the false success this whole change exists to
|
|
4792
|
-
// remove. And what stays broken is not only the display feed: live connection EVICTION rides the
|
|
4793
|
-
// same pair, so booting here would silently downgrade revocation to deny-new for the life of the
|
|
4794
|
-
// mesh. The repo's posture is to throw rather than degrade, and the recovery is one command that
|
|
4795
|
-
// this message names.
|
|
4796
|
-
const stale = staleSystemCreds(cotalRoot(), auth.sys.pub, space);
|
|
4797
|
-
if (stale.length)
|
|
4798
|
-
throw new Error(`${stale.map((x) => `${x.file} (signed by ${x.iss ? `${x.iss.slice(0, 12)}…` : "an unreadable issuer"})`).join(", ")} ` +
|
|
4799
|
-
`${stale.length === 1 ? "is" : "are"} not signed by this space's system account (${auth.sys.pub.slice(0, 12)}…) - ` +
|
|
4800
|
-
"an interrupted rotation left the $SYS creds behind the trust record, so the broker would deny them and live eviction + the membership feed would stay down. " +
|
|
4801
|
-
"Re-run the rotation to land a complete generation: `cotal up --rotate-sys`");
|
|
4802
|
-
const stateDir = userAuthStateDir(cotalRoot(), space); // the provider's space-scoped state dir
|
|
4803
|
-
if (!user && hasUserAuthState(cotalRoot(), space)) {
|
|
4804
|
-
throw new Error(`space "${space}" has user auth enabled (state under ${stateDir}) - start it with \`cotal up --user-auth\`, or remove that directory deliberately to disable user auth (existing logins/grants die with it)`);
|
|
4805
|
-
}
|
|
4806
|
-
let prepared;
|
|
4807
|
-
if (user) {
|
|
4808
|
-
// Registry composition: the provider came from the composition root (bin/cotal.ts imports
|
|
4809
|
-
// @cotal-ai/auth); this package never imports it. No provider ⇒ resolveAuthProvider throws the
|
|
4810
|
-
// exact fix. The narrow input is a capability boundary: operator seed (signs the provider's
|
|
4811
|
-
// account once) + the data account's pub/signingSeed (projected for the service's minting duty).
|
|
4812
|
-
try {
|
|
4813
|
-
prepared = await resolveAuthProvider().prepareServer({
|
|
4814
|
-
space,
|
|
4815
|
-
operatorSeed: auth.operator.seed,
|
|
4816
|
-
account: { pub: auth.account.pub, signingSeed: auth.account.signingSeed },
|
|
4817
|
-
store: workspaceSecretStore(cotalRoot()),
|
|
4818
|
-
dir: stateDir,
|
|
4819
|
-
idpUrl: user.idpUrl,
|
|
4820
|
-
});
|
|
4821
|
-
}
|
|
4822
|
-
catch (e) {
|
|
4823
|
-
throw e instanceof Error ? e : new Error(String(e));
|
|
4824
|
-
}
|
|
4825
|
-
}
|
|
4826
|
-
const port = Number(new URL(server).port) || 4222;
|
|
4827
|
-
// A reused controller manager advertises its launch-time WebSocket port.
|
|
4828
|
-
const wsPort = requested.wsPort ?? await freePort(host);
|
|
4829
|
-
const confPath = resolve(dir, "server.conf");
|
|
4830
|
-
// EVERY tenant of this root, not just the one being booted: `resolver_preload` is a whole-broker
|
|
4831
|
-
// map, so a config rendered from one space evicts the rest silently. `auth` leads the list because
|
|
4832
|
-
// this function's copy can be fresher than the disk (a space created above, or one whose trust
|
|
4833
|
-
// record `--rotate-sys` just replaced). Refuses on an unreadable record rather than dropping it.
|
|
4834
|
-
const spaces = preloadSpaceAccounts(dir, auth);
|
|
4835
|
-
const enabled = userAuthSpacesOnDisk(dir);
|
|
4836
|
-
for (const enabledSpace of enabled) {
|
|
4837
|
-
if (!spaces.some((s) => s.space === enabledSpace))
|
|
4838
|
-
throw new Error(`space "${enabledSpace}" has user auth enabled but no data account record - refusing to render an incomplete broker resolver`);
|
|
4839
|
-
}
|
|
4840
|
-
const extraAccounts = [];
|
|
4841
|
-
for (const enabledSpace of enabled) {
|
|
4842
|
-
const accounts = enabledSpace === space && prepared
|
|
4843
|
-
? prepared.extraAccounts
|
|
4844
|
-
: await resolveAuthProvider().preloadAccounts({ store, space: enabledSpace });
|
|
4845
|
-
extraAccounts.push(...accounts);
|
|
4846
|
-
}
|
|
4847
|
-
// Owner-private regardless of umask, as `writeOpenBrokerConf` writes the open configuration: the
|
|
4848
|
-
// broker preset refuses a configuration that other local users can write.
|
|
4849
|
-
const recorded = readBrokerPolicy(cotalRoot());
|
|
4850
|
-
const authTimeout = requested.authTimeout ?? recorded?.authTimeout;
|
|
4851
|
-
const maxPayload = requested.maxPayload ?? recorded?.maxPayload;
|
|
4852
|
-
if (requested.manager === true)
|
|
4853
|
-
assertManagerPayload(maxPayload);
|
|
4854
|
-
const resolverChoice = requested.accountResolver ?? recorded?.accountResolver ?? "memory";
|
|
4855
|
-
const accountResolver = brokerAccountResolver(cotalRoot(), resolverChoice === "full" ? "full" : undefined);
|
|
4856
|
-
// Owner-private like the auth dir: nats-server writes each pushed claim here.
|
|
4857
|
-
if (accountResolver.kind === "full")
|
|
4858
|
-
mkSecretDir(accountResolver.directory);
|
|
4859
|
-
const brokerBinary = await resolveNatsServer();
|
|
4860
|
-
if (!brokerBinary.version)
|
|
4861
|
-
throw unreadVersion(brokerBinary);
|
|
4862
|
-
const render = (ws) => writeBrokerConfig(confPath, serverConfig(auth, spaces, { brokerVersion: brokerBinary.version, transport, port, storeDir: configuredStoreDir(cotalRoot(), storeDir), maxFileStore, authTimeout, maxPayload, accountResolver, logFile: requested.logFile, logfileSizeLimit: requested.logfileSizeLimit, logfileMaxNum: requested.logfileMaxNum, host, wsPort: ws, wsHost: host, extraAccounts }));
|
|
4863
|
-
render(wsPort);
|
|
4864
|
-
// The chosen port is free now, but nothing holds it until the broker binds it. When another process
|
|
4865
|
-
// takes it first, the broker exits before readiness, and a controller stack start renders this
|
|
4866
|
-
// configuration again on a newly chosen port.
|
|
4867
|
-
const moveWebsocketPort = async () => { const moved = await freePort(host); render(moved); return moved; };
|
|
4868
|
-
// Connector reconciliation can outlast the provisioner's lifetime. Mint only when boot needs it
|
|
4869
|
-
// to probe the listener, create streams and buckets, or seed the channel registry.
|
|
4870
|
-
const mintProvisioner = () => mintCreds(auth, newIdentity(), "provisioner");
|
|
4871
|
-
return { brokerBinary, confPath, mintProvisioner, wsPort, moveWebsocketPort, ...(prepared ? { prepared, stateDir } : {}), ...(authTimeout !== undefined ? { authTimeout } : {}), ...(maxPayload !== undefined ? { maxPayload } : {}), accountResolver: resolverChoice };
|
|
4872
|
-
}
|
|
4873
|
-
/**
|
|
4874
|
-
* Refuse the rotation if this root's own bookkeeping still shows a broker running. This is a
|
|
4875
|
-
* BEST-EFFORT check over Cotal-managed ownership records, NOT a proof that no process is serving this
|
|
4876
|
-
* root, and the difference matters: a survivor keeps honoring the retired account from memory, and a
|
|
4877
|
-
* second broker on the successor opens that survivor's JetStream store underneath it.
|
|
4878
|
-
*
|
|
4879
|
-
* Two records, because either alone has a blind spot. The PID FILE catches a broker this root started
|
|
4880
|
-
* whose registry row was lost. The REGISTRY sweep catches one recorded for this root at some OTHER
|
|
4881
|
-
* address, which no probe of the requested URL would reach. Both fail CLOSED: an unreadable or
|
|
4882
|
-
* malformed pid file refuses exactly like a live one, since "cannot tell" and "still running" have
|
|
4883
|
-
* the same consequence.
|
|
4884
|
-
*
|
|
4885
|
-
* WHAT IT CANNOT SEE: both records are mutable, and neither is written by a broker started outside
|
|
4886
|
-
* `cotal up`. Delete both while the process lives, or run
|
|
4887
|
-
* `nats-server -c <root>/.cotal/auth/server.conf` by hand, and this returns success having probed
|
|
4888
|
-
* nothing. The requested address is covered separately (an unidentified listener there refuses the
|
|
4889
|
-
* rotation rather than moving to a free port), which leaves a hand-started broker on a DIFFERENT port
|
|
4890
|
-
* as the honest residual. Closing that needs something a survivor holds and cannot delete, an
|
|
4891
|
-
* exclusive store lock, which does not exist today; until it does, do not run `nats-server` against
|
|
4892
|
-
* this root's config outside `cotal up`.
|
|
4893
|
-
*
|
|
4894
|
-
* Not a general `up` guard: an ordinary boot adopting or replacing a listener is a supported flow with
|
|
4895
|
-
* its own claim machinery. This is specifically the precondition for retiring an authority.
|
|
4896
|
-
*/
|
|
4897
|
-
async function assertRootBrokerStopped(root) {
|
|
4898
|
-
const pidPath = join(root, ".cotal", NATS_PIDFILE);
|
|
4899
|
-
if (existsSync(pidPath)) {
|
|
4900
|
-
let raw;
|
|
4901
|
-
try {
|
|
4902
|
-
raw = readFileSync(pidPath, "utf8").trim();
|
|
4903
|
-
}
|
|
4904
|
-
catch (e) {
|
|
4905
|
-
throw new Error(`--rotate-sys: ${pidPath} exists but cannot be read (${e.message}) - refusing to rotate while a broker for this root may still be running; \`cotal down\` first`);
|
|
4906
|
-
}
|
|
4907
|
-
const pid = Number(raw);
|
|
4908
|
-
if (!Number.isInteger(pid) || pid <= 0)
|
|
4909
|
-
throw new Error(`--rotate-sys: ${pidPath} does not hold a pid (${JSON.stringify(raw)}) - refusing to rotate while a broker for this root may still be running; \`cotal down\` first`);
|
|
4910
|
-
let live;
|
|
4911
|
-
try {
|
|
4912
|
-
process.kill(pid, 0); // signal 0 is a liveness probe, it signals nothing
|
|
4913
|
-
live = true;
|
|
4914
|
-
}
|
|
4915
|
-
catch (e) {
|
|
4916
|
-
// EPERM means the process EXISTS and is not ours to signal, i.e. alive for this purpose.
|
|
4917
|
-
live = e.code === "EPERM";
|
|
4918
|
-
}
|
|
4919
|
-
if (live)
|
|
4920
|
-
throw new Error(`--rotate-sys: this root's broker is still running (pid ${pid}) - it would keep serving the retired system account, and a second broker would share its JetStream store. Stop it first: \`cotal down\``);
|
|
4921
|
-
}
|
|
4922
|
-
// A broker recorded for this root at ANY address, still answering. The rotate refusal earlier in
|
|
4923
|
-
// `up` only sees the URL this invocation asked for; this sees the ones it did not.
|
|
4924
|
-
for (const m of meshesForRoot(root)) {
|
|
4925
|
-
if (await isReachable(m.server))
|
|
4926
|
-
throw new Error(`--rotate-sys: mesh "${m.space}" for this root is still reachable at ${m.server} - stop it first (\`cotal down\`), then rotate`);
|
|
4927
|
-
}
|
|
4928
|
-
}
|
|
4929
|
-
/** Provision the DATA-account half of the membership bundle, on EVERY `up` rather than only a fresh
|
|
4930
|
-
* space. Idempotent: it writes only what is absent and is silent when both are present.
|
|
4931
|
-
*
|
|
4932
|
-
* WHY THIS IS SEPARATE FROM {@link provisionMembershipCreds}. That function mints the whole bundle
|
|
4933
|
-
* in the fresh-space branch because the `$SYS` signing seed exists only there and is never
|
|
4934
|
-
* persisted — true of `membership-observer.creds` and `connection-evictor.creds`. The delivery daemon
|
|
4935
|
-
* mints a missing evictor itself on a single-space root that retained its system-account signing
|
|
4936
|
-
* seed, so that one no longer needs a rotation; a root without the seed still needs one. It is NOT
|
|
4937
|
-
* true of the other two.
|
|
4938
|
-
* `membership-rw.creds` is signed by the DATA account, whose signing seed IS persisted, and
|
|
4939
|
-
* `membership.json` is just that account's public id. Neither needs the `$SYS` window, so binding
|
|
4940
|
-
* them to it left every space provisioned before the feature permanently without the feed.
|
|
4941
|
-
*
|
|
4942
|
-
* That gap was not theoretical. A space with a complete `$SYS` pair, missing only the rw cred,
|
|
4943
|
-
* reported `the membership bundle is incomplete here (missing membership-rw.creds)` on every
|
|
4944
|
-
* delivery-daemon start and served a traffic-only graph, and the documented remedy did not work:
|
|
4945
|
-
* `--rotate-sys` re-mints the `$SYS` pair and never calls the provisioner, so it wrote neither the
|
|
4946
|
-
* rw cred nor the account id. `mintMembershipObserverCreds` even names that rotation as the fix in
|
|
4947
|
-
* its own error text — advice that could not succeed. Healing here fixes both spellings at once:
|
|
4948
|
-
* the ordinary `up` repairs the data half with no rotation at all, and a rotation now repairs it
|
|
4949
|
-
* too, because this runs after both branches converge. */
|
|
4950
|
-
async function healMembershipDataCreds(auth, root, space, quietBoot = false) {
|
|
4951
|
-
try {
|
|
4952
|
-
const store = workspaceSecretStore(root);
|
|
4953
|
-
// THE RESOLVERS, not the bare kinds (P7 §2 rule 1). Both reads below are absent-means-MINT, which
|
|
4954
|
-
// is precisely why the location must be resolved through the choke point: a canonical read on a
|
|
4955
|
-
// root whose material is still flat answers "absent" and mints a SECOND live cred beside the one
|
|
4956
|
-
// the running daemons hold. `up` is a workstation composition by construction, so the resolver
|
|
4957
|
-
// gets the FS arm and moves the material on this first touch.
|
|
4958
|
-
const composition = { injected: false, root };
|
|
4959
|
-
const rwKey = membershipRwCredsKey(space, composition);
|
|
4960
|
-
const wrote = [];
|
|
4961
|
-
const rw = await store.get(rwKey);
|
|
4962
|
-
if (rw === undefined) {
|
|
4963
|
-
await store.put(rwKey, await mintCreds(auth, newIdentity(), "membership-rw"));
|
|
4964
|
-
wrote.push(MEMBERSHIP_RW_CREDS_KIND); // the KIND is what an operator reads, never the segmented key
|
|
4965
|
-
}
|
|
4966
|
-
else if (credsProblem(rw) !== undefined && !quietBoot)
|
|
4967
|
-
console.error(c.yellow(`! ${unparsableDaemonCredsNotice([MEMBERSHIP_RW_CREDS_KIND])}`));
|
|
4968
|
-
const configPath = membershipConfigPath(root, space);
|
|
4969
|
-
if (!existsSync(configPath)) {
|
|
4970
|
-
mkSecretDir(dirname(configPath)); // harden the per-space dir before the file lands, as the fresh path does
|
|
4971
|
-
writeSecretFile(configPath, JSON.stringify({ accountId: auth.account.pub }));
|
|
4972
|
-
wrote.push(MEMBERSHIP_CONFIG_KIND);
|
|
4973
|
-
}
|
|
4974
|
-
if (wrote.length && !quietBoot)
|
|
4975
|
-
console.log(c.dim(`• membership: provisioned ${wrote.join(" + ")} - the data-account half needs no system-account rotation`));
|
|
4976
|
-
}
|
|
4977
|
-
catch (e) {
|
|
4978
|
-
// Best-effort, exactly like the fresh-space provisioner: a failure here leaves the graph on
|
|
4979
|
-
// traffic-only and leaves delivery untouched. It must never keep the mesh from starting.
|
|
4980
|
-
console.error(c.dim(`• broker-sourced membership not repaired: ${e.message}`));
|
|
4981
|
-
}
|
|
4982
|
-
}
|
|
4983
|
-
/** The web dashboard's read-only cred, on EVERY `up` of a static space: `cotal service start web`
|
|
4984
|
-
* defaults its `--creds` to this file. Idempotent and absent-means-mint, through the resolver as
|
|
4985
|
-
* {@link healMembershipDataCreds} is. It is the `observer` profile, minted without an expiry, as the
|
|
4986
|
-
* `cotal auth mint --profile observer` recipe this replaces was: the dashboard reads the file once at
|
|
4987
|
-
* start and holds its connection, and no renewal owner reloads it. Best-effort for the same reason as
|
|
4988
|
-
* the membership heal: a failure here must never keep the mesh from starting. */
|
|
4989
|
-
async function provisionWebCreds(auth, root, space, quietBoot = false) {
|
|
4990
|
-
try {
|
|
4991
|
-
const store = workspaceSecretStore(root);
|
|
4992
|
-
const key = webCredsKey(space, { injected: false, root });
|
|
4993
|
-
if ((await store.get(key)) !== undefined)
|
|
4994
|
-
return;
|
|
4995
|
-
await store.put(key, await mintCreds(auth, newIdentity(), "observer"));
|
|
4996
|
-
if (!quietBoot)
|
|
4997
|
-
for (const line of hang("• ", `web: provisioned ${WEB_CREDS_KIND} - the dashboard's read-only credential, the \`service start web\` default`, terminalWidth(process.stdout)))
|
|
4998
|
-
console.log(c.dim(line));
|
|
4999
|
-
}
|
|
5000
|
-
catch (e) {
|
|
5001
|
-
console.error(c.dim(`• web dashboard credential not provisioned: ${e.message}`));
|
|
5002
|
-
}
|
|
5003
|
-
}
|
|
5004
|
-
/** Mint the two scoped creds the delivery daemon's membership feed loads (broker-sourced graph
|
|
5005
|
-
* membership), at the FRESH `cotal up` while the in-memory `$SYS` signing seed still exists:
|
|
5006
|
-
* - `membership-observer.creds` — SYSTEM-account CONNZ reader (the only window it is minted here:
|
|
5007
|
-
* the trust record carries no `$SYS` seed, and the retained custody record serves caller issuance only).
|
|
5008
|
-
* - `membership-rw.creds` — DATA-account members-read + feed-write.
|
|
5009
|
-
* - `membership.json` — the DATA account id (the CONNZ/event subjects pin it; non-secret, but kept
|
|
5010
|
-
* 0600 alongside the creds).
|
|
5011
|
-
* All 0600. Best-effort: a failure logs and leaves the feed disabled (the graph degrades to traffic-
|
|
5012
|
-
* only, delivery is untouched). Runs only on a FRESH space (the `if (!auth)` branch); a normal down/up
|
|
5013
|
-
* keeps `.cotal/auth` + these creds and reuses them. A space provisioned before this feature has no
|
|
5014
|
-
* in-memory `$SYS` seed, so it gains membership only when its auth is regenerated (a fresh `.cotal/auth`)
|
|
5015
|
-
* — a documented migration property, not a silent no-op.
|
|
5016
|
-
* Coupling: `cotal clean all` deletes this identity-derived set (removeLocalState in clean.ts) —
|
|
5017
|
-
* a cred added here must be added to that removal list too. `membership-rw.creds` is a MIGRATED kind:
|
|
5018
|
-
* its write/read/delete all go through the {@link SecretStore} seam (here, the feed reader, and clean),
|
|
5019
|
-
* so the renewal owner can re-sign it into a hosted store. The observer / evictor / config stay on the
|
|
5020
|
-
* raw FS (static $SYS creds + non-secret config, not renewable kinds). */
|
|
5021
|
-
async function provisionMembershipCreds(auth, root, space) {
|
|
5022
|
-
try {
|
|
5023
|
-
const observer = await mintMembershipObserverCreds(auth, newIdentity());
|
|
5024
|
-
const rw = await mintCreds(auth, newIdentity(), "membership-rw");
|
|
5025
|
-
// D5 slice 4: the KICK-only connection-evictor cred — same mint-only-at-fresh-`up` window as
|
|
5026
|
-
// the observer ($SYS seed in memory here). The delivery daemon pairs it with the observer to
|
|
5027
|
-
// close a revoked/removed principal's live connections. A space without it degrades to
|
|
5028
|
-
// deny-new-only (durable reauth) — surfaced loudly by the removal path, never silent.
|
|
5029
|
-
const evictor = await mintConnectionEvictorCreds(auth, newIdentity());
|
|
5030
|
-
// All four land through the per-kind resolvers (P7 §2 rule 1), and all four through the store's
|
|
5031
|
-
// `put`, which is the same `mkSecretDir` + atomic write the raw `writeSecretFile` did — the
|
|
5032
|
-
// difference being that it hardens the PER-SPACE dir the material now lives in rather than
|
|
5033
|
-
// `.cotal/` itself. This is the fresh-space branch, so nothing is there to migrate; it calls the
|
|
5034
|
-
// resolvers anyway because a kind with two write paths is a kind that grows two layouts.
|
|
5035
|
-
const composition = { injected: false, root };
|
|
5036
|
-
const store = workspaceSecretStore(root);
|
|
5037
|
-
await store.put(membershipObserverCredsKey(space, composition), observer);
|
|
5038
|
-
await store.put(membershipRwCredsKey(space, composition), rw);
|
|
5039
|
-
await store.put(connectionEvictorCredsKey(space, composition), evictor);
|
|
5040
|
-
const configPath = membershipConfigPath(root, space);
|
|
5041
|
-
mkSecretDir(dirname(configPath));
|
|
5042
|
-
writeSecretFile(configPath, JSON.stringify({ accountId: auth.account.pub }));
|
|
5043
|
-
}
|
|
5044
|
-
catch (e) {
|
|
5045
|
-
console.error(c.dim(`• broker-sourced membership not provisioned: ${e.message}`));
|
|
5046
|
-
}
|
|
5047
|
-
}
|
|
5048
4634
|
//# sourceMappingURL=up.js.map
|