@songsid/agend 2.3.5-alpha.10 → 2.3.5-alpha.11
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/accounts-view.d.ts +14 -0
- package/dist/accounts-view.js +22 -6
- package/dist/accounts-view.js.map +1 -1
- package/dist/agent-cli-instructions.md +2 -2
- package/dist/auth-api.d.ts +48 -16
- package/dist/auth-api.js +99 -32
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/settings-role.d.ts +56 -0
- package/dist/authority/settings-role.js +48 -0
- package/dist/authority/settings-role.js.map +1 -0
- package/dist/backend/claude-code.d.ts +2 -0
- package/dist/backend/claude-code.js +16 -3
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/cli-env-probe.js +6 -2
- package/dist/backend/cli-env-probe.js.map +1 -1
- package/dist/backend/codex.d.ts +5 -3
- package/dist/backend/codex.js +31 -13
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/credential-profile.d.ts +2 -0
- package/dist/backend/credential-profile.js +2 -0
- package/dist/backend/credential-profile.js.map +1 -1
- package/dist/backend/kiro.js +1 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +5 -1
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-availability.d.ts +15 -0
- package/dist/backend-availability.js +37 -1
- package/dist/backend-availability.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/bundled-tmux-guard.d.ts +4 -0
- package/dist/bundled-tmux-guard.js +7 -0
- package/dist/bundled-tmux-guard.js.map +1 -1
- package/dist/claude-auth-status.d.ts +20 -8
- package/dist/claude-auth-status.js +38 -22
- package/dist/claude-auth-status.js.map +1 -1
- package/dist/cli-audited.d.ts +60 -0
- package/dist/cli-audited.js +84 -0
- package/dist/cli-audited.js.map +1 -0
- package/dist/cli-capability.d.ts +36 -5
- package/dist/cli-capability.js +2 -2
- package/dist/cli-capability.js.map +1 -1
- package/dist/cli-caps-module.d.ts +5 -1
- package/dist/cli-caps-module.js +4 -2
- package/dist/cli-caps-module.js.map +1 -1
- package/dist/cli-registry-check.js +16 -2
- package/dist/cli-registry-check.js.map +1 -1
- package/dist/cli-registry.d.ts +56 -4
- package/dist/cli-registry.js +1 -1
- package/dist/cli-registry.js.map +1 -1
- package/dist/cli-spec-antigravity.d.ts +12 -1
- package/dist/cli-spec-antigravity.js +13 -1
- package/dist/cli-spec-antigravity.js.map +1 -1
- package/dist/cli-spec-claude-code.d.ts +9 -0
- package/dist/cli-spec-claude-code.js +4 -2
- package/dist/cli-spec-claude-code.js.map +1 -1
- package/dist/cli-spec-codex.d.ts +10 -1
- package/dist/cli-spec-codex.js +5 -3
- package/dist/cli-spec-codex.js.map +1 -1
- package/dist/cli-spec-grok.d.ts +5 -0
- package/dist/cli-spec-grok.js +6 -1
- package/dist/cli-spec-grok.js.map +1 -1
- package/dist/cli-spec-kiro-cli.d.ts +7 -1
- package/dist/cli-spec-kiro-cli.js +7 -3
- package/dist/cli-spec-kiro-cli.js.map +1 -1
- package/dist/cli-spec-muse.d.ts +2 -0
- package/dist/cli-spec-muse.js +3 -1
- package/dist/cli-spec-muse.js.map +1 -1
- package/dist/cli-spec-opencode.d.ts +11 -1
- package/dist/cli-spec-opencode.js +7 -2
- package/dist/cli-spec-opencode.js.map +1 -1
- package/dist/cli.js +28 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon.d.ts +3 -0
- package/dist/daemon.js +17 -2
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-context.d.ts +5 -1
- package/dist/fleet-manager.d.ts +337 -69
- package/dist/fleet-manager.js +1247 -355
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-process-handlers.d.ts +1 -1
- package/dist/fleet-process-handlers.js +3 -2
- package/dist/fleet-process-handlers.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +21 -14
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +9 -8
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +9 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +27 -20
- package/dist/instance-lifecycle.js +4 -2
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/instructions.js +29 -6
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +119 -75
- package/dist/locale.js.map +1 -1
- package/dist/login-manager.d.ts +2 -2
- package/dist/login-manager.js +3 -2
- package/dist/login-manager.js.map +1 -1
- package/dist/native-model-catalog.d.ts +20 -0
- package/dist/native-model-catalog.js +107 -2
- package/dist/native-model-catalog.js.map +1 -1
- package/dist/public-web-gateway.js +1 -1
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/runtime-api.d.ts +1 -1
- package/dist/runtime-api.js +104 -12
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-autostart.d.ts +61 -0
- package/dist/runtime-autostart.js +161 -0
- package/dist/runtime-autostart.js.map +1 -0
- package/dist/runtime-background.d.ts +200 -0
- package/dist/runtime-background.js +480 -0
- package/dist/runtime-background.js.map +1 -0
- package/dist/runtime-build-info.js +5 -5
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-background.d.ts +92 -0
- package/dist/runtime-cli-background.js +336 -0
- package/dist/runtime-cli-background.js.map +1 -0
- package/dist/runtime-cli-install.d.ts +148 -8
- package/dist/runtime-cli-install.js +253 -59
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-cli.d.ts +8 -1
- package/dist/runtime-cli.js +206 -44
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client-store.d.ts +11 -0
- package/dist/runtime-client-store.js +20 -5
- package/dist/runtime-client-store.js.map +1 -1
- package/dist/runtime-client.d.ts +23 -1
- package/dist/runtime-client.js +92 -6
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-connection.d.ts +1 -1
- package/dist/runtime-connection.js +1 -1
- package/dist/runtime-connection.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +95 -1
- package/dist/runtime-coordinator.js +344 -10
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-enroll-notice.d.ts +4 -0
- package/dist/runtime-enroll-notice.js +21 -0
- package/dist/runtime-enroll-notice.js.map +1 -0
- package/dist/runtime-enrollment.d.ts +21 -0
- package/dist/runtime-enrollment.js +52 -0
- package/dist/runtime-enrollment.js.map +1 -0
- package/dist/runtime-pane-native.js +4 -4
- package/dist/runtime-pane-native.js.map +1 -1
- package/dist/runtime-protocol.d.ts +78 -1
- package/dist/runtime-protocol.js +95 -5
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/runtime-remote-accounts.d.ts +12 -0
- package/dist/runtime-remote-accounts.js +56 -5
- package/dist/runtime-remote-accounts.js.map +1 -1
- package/dist/runtime-remote-setup.d.ts +4 -1
- package/dist/runtime-remote-setup.js +4 -1
- package/dist/runtime-remote-setup.js.map +1 -1
- package/dist/runtime-update-controller.d.ts +11 -0
- package/dist/runtime-update-controller.js +56 -4
- package/dist/runtime-update-controller.js.map +1 -1
- package/dist/settings-api.d.ts +13 -1
- package/dist/settings-api.js +39 -3
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.d.ts +5 -13
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-confirmation.d.ts +11 -13
- package/dist/settings-confirmation.js +2 -6
- package/dist/settings-confirmation.js.map +1 -1
- package/dist/settings-effect.d.ts +5 -0
- package/dist/settings-effect.js +76 -10
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-http-confirmation.d.ts +8 -1
- package/dist/settings-http-confirmation.js +39 -13
- package/dist/settings-http-confirmation.js.map +1 -1
- package/dist/settings-request-capability.d.ts +7 -0
- package/dist/settings-request-capability.js +3 -1
- package/dist/settings-request-capability.js.map +1 -1
- package/dist/setup-i18n.js +4 -4
- package/dist/setup-i18n.js.map +1 -1
- package/dist/subagent-records.d.ts +45 -0
- package/dist/subagent-records.js +214 -0
- package/dist/subagent-records.js.map +1 -0
- package/dist/subagent-service.d.ts +27 -0
- package/dist/subagent-service.js +199 -0
- package/dist/subagent-service.js.map +1 -0
- package/dist/tmux-manager.d.ts +2 -2
- package/dist/tmux-manager.js +5 -3
- package/dist/tmux-manager.js.map +1 -1
- package/dist/ui/account-identity.js +7 -5
- package/dist/ui/accounts-keepalive.js +17 -17
- package/dist/ui/accounts-manage.js +34 -34
- package/dist/ui/accounts-view.js +63 -21
- package/dist/ui/agent-runtime-settings.js +1 -1
- package/dist/ui/backend-signin.js +67 -67
- package/dist/ui/chat-msg-actions.js +50 -4
- package/dist/ui/chat-quote.js +256 -0
- package/dist/ui/chat-store.js +9 -4
- package/dist/ui/cli-caps.js +7 -7
- package/dist/ui/credential-profile-select.js +4 -4
- package/dist/ui/general-location.js +1 -1
- package/dist/ui/host-install.js +290 -0
- package/dist/ui/hub-company-join-strings.js +3 -0
- package/dist/ui/hub-company-join.js +20 -2
- package/dist/ui/hub-owner-strings.js +5 -4
- package/dist/ui/hub-pairing-progress-strings.js +1 -1
- package/dist/ui/hub-quick-strings.js +4 -4
- package/dist/ui/machine-signin.js +4 -4
- package/dist/ui/model-picker.js +68 -0
- package/dist/ui/panel-chat.js +73 -13
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-hub.js +8 -4
- package/dist/ui/panel-needs.js +2 -2
- package/dist/ui/panel-runtimes.js +232 -33
- package/dist/ui/panel-windows-cli.js +1 -1
- package/dist/ui/runtime-cli-install.js +99 -20
- package/dist/ui/runtime-commands.d.ts +2 -0
- package/dist/ui/runtime-commands.js +34 -1
- package/dist/ui/runtime-update-status.js +2 -2
- package/dist/ui/search-dialog.js +1 -0
- package/dist/ui/settings-access-strings.js +1 -1
- package/dist/ui/settings-catalog.js +19 -3
- package/dist/ui/settings-confirm.js +2 -2
- package/dist/ui/settings-devices.js +59 -25
- package/dist/ui/settings-dialogs.js +12 -13
- package/dist/ui/settings-guests.js +1 -1
- package/dist/ui/settings-hub-company-join.js +10 -7
- package/dist/ui/settings-hub-connection.js +121 -0
- package/dist/ui/settings-hub-membership.js +1 -1
- package/dist/ui/settings-hub-run.js +5 -6
- package/dist/ui/settings-hub-section.js +3 -6
- package/dist/ui/settings-hub.js +12 -7
- package/dist/ui/settings-layout.js +6 -6
- package/dist/ui/settings-outside.js +87 -19
- package/dist/ui/settings-registry.js +2 -1
- package/dist/ui/settings-revoke-strings.js +28 -0
- package/dist/ui/settings-strings.js +19 -19
- package/dist/ui/settings-web-authority.js +11 -4
- package/dist/ui/shared/accounts.css +11 -1
- package/dist/ui/shared/agend-auth.js +8 -1
- package/dist/ui/shared/app-i18n.js +10 -12
- package/dist/ui/shared/app-session.js +13 -16
- package/dist/ui/shared/app-shell.js +36 -36
- package/dist/ui/shared/app.css +35 -2
- package/dist/ui/shared/chat-strings.js +4 -4
- package/dist/ui/shared/device-roles.js +27 -0
- package/dist/ui/shared/host-install.css +10 -0
- package/dist/ui/shared/hub-owner.css +6 -0
- package/dist/ui/shared/model-picker.css +21 -0
- package/dist/ui/shared/runtime-install.css +26 -1
- package/dist/ui/shared/setup-host-text.js +4 -4
- package/dist/ui/shared/signin-authenticator.js +60 -0
- package/dist/ui/shared/signin.js +45 -25
- package/dist/ui/shared/subagent-row.css +15 -0
- package/dist/ui/shared/usage-dialog.js +1 -1
- package/dist/ui/shared/view-strings.js +7 -7
- package/dist/ui/shared/web-authorize.js +53 -3
- package/dist/ui/signin-authenticator.html +60 -0
- package/dist/ui/structured-signin.js +30 -30
- package/dist/ui/subagent-row.js +72 -0
- package/dist/ui/web-terminal/terminal.js +9 -9
- package/dist/update-launch.js +4 -1
- package/dist/update-launch.js.map +1 -1
- package/dist/update-npm-env.d.ts +70 -0
- package/dist/update-npm-env.js +128 -0
- package/dist/update-npm-env.js.map +1 -0
- package/dist/usage/providers.js +2 -2
- package/dist/usage/providers.js.map +1 -1
- package/dist/web-api.d.ts +33 -4
- package/dist/web-api.js +312 -18
- package/dist/web-api.js.map +1 -1
- package/dist/web-auth.js +1 -1
- package/dist/web-auth.js.map +1 -1
- package/dist/web-channel-echo.js +3 -1
- package/dist/web-channel-echo.js.map +1 -1
- package/dist/web-commands.d.ts +9 -1
- package/dist/web-commands.js +7 -1
- package/dist/web-commands.js.map +1 -1
- package/dist/web-host-install.d.ts +127 -0
- package/dist/web-host-install.js +165 -0
- package/dist/web-host-install.js.map +1 -0
- package/dist/web-remote-access.d.ts +126 -11
- package/dist/web-remote-access.js +267 -34
- package/dist/web-remote-access.js.map +1 -1
- package/dist/web-session.d.ts +11 -3
- package/dist/web-session.js.map +1 -1
- package/dist/web-signin-device.d.ts +16 -0
- package/dist/web-signin-device.js +81 -0
- package/dist/web-signin-device.js.map +1 -0
- package/dist/web-update.js +3 -1
- package/dist/web-update.js.map +1 -1
- package/dist/windows-cli-api.js +2 -1
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +14 -0
- package/dist/windows-cli-worker.js +145 -1
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/windows-cli.d.ts +4 -0
- package/dist/windows-cli.js +9 -1
- package/dist/windows-cli.js.map +1 -1
- package/launcher/agend-install.cjs +16 -3
- package/package.json +1 -1
- package/templates/runtime-install/install.ps1 +219 -12
|
@@ -16,7 +16,8 @@ import { parseRuntimeUpdateReport, parseRuntimeUpdateStatusFrame, RUNTIME_UPDATE
|
|
|
16
16
|
import { validatePaneMcpBody } from "./runtime-pane-mcp-protocol.js";
|
|
17
17
|
import { validateRuntimePaneRequest, validateRuntimePaneSnapshot, validateRuntimePaneShutdown } from "./runtime-pane-protocol.js";
|
|
18
18
|
import { withNativePaneVerification } from "./runtime-pane-native.js";
|
|
19
|
-
import {
|
|
19
|
+
import { ENROLL_TTL_MS, enrollTokenMatches, generateEnrollToken, hashEnrollToken, isEnrollToken, loadRuntimeServerIdentity } from "./runtime-enrollment.js";
|
|
20
|
+
import { RUNTIME_CLAIM_PATH, RUNTIME_CONNECT_PATH, RUNTIME_MAX_FRAME_BYTES, RUNTIME_PAIR_PATH, RUNTIME_ROTATE_PATH, RUNTIME_ENROLL_PATH, RUNTIME_ENROLL_HELLO_PATH, RUNTIME_SERVER_FINGERPRINT_PATTERN, RUNTIME_ENROLL_TID_PATTERN, RUNTIME_ENROLL_REFUSALS, runtimeEnrollHelloMessage, newRuntimeEnrollEphemeral, runtimeEnrollChannel, sealRuntimeEnroll, openRuntimeEnroll, runtimeEnrollTokenId, runtimeFingerprintFromHash, parseRuntimeInfo, runtimeInfoCompatible, RUNTIME_REINSTALL_CLOSE_REASON, isRuntimeRemoteOperation, parseRuntimeRemotePayload } from "./runtime-protocol.js";
|
|
20
21
|
const PAIR_TTL = 10 * 60_000;
|
|
21
22
|
const MAX_STORE_BYTES = 64 * 1024 * 1024;
|
|
22
23
|
const UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
|
|
@@ -27,6 +28,14 @@ const record = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
|
27
28
|
/** A deliberate validation failure whose static message is safe to show the runtime; every other error (I/O, internal) is not. */
|
|
28
29
|
class RuntimeProtocolError extends Error {
|
|
29
30
|
}
|
|
31
|
+
/** An enrollment the server refused. `reason` is a closed word the Runtime turns into a sentence; the message never contains the token. */
|
|
32
|
+
class RuntimeEnrollError extends RuntimeProtocolError {
|
|
33
|
+
reason;
|
|
34
|
+
constructor(reason, message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.reason = reason;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
30
39
|
const text = (v, max) => typeof v === "string" && v.length > 0 && v.length <= max && !/[\0\r\n]/.test(v);
|
|
31
40
|
const terminal = (task) => !!task.finishedAt && ["completed", "failed", "cancelled"].includes(task.status);
|
|
32
41
|
const loopback = (address) => address === "127.0.0.1" || address === "::1" || address === "::ffff:127.0.0.1";
|
|
@@ -113,11 +122,45 @@ function inventory(value) {
|
|
|
113
122
|
}
|
|
114
123
|
return probe;
|
|
115
124
|
}
|
|
116
|
-
function machineView(machine) {
|
|
117
|
-
return { ...structuredClone(machine), ...(machine.inventory ? { inventory: withNativePaneVerification(machine.inventory) } : {}), runtimeCompatibility: machine.runtimeInfo
|
|
125
|
+
function machineView(machine, claimExpiresAt, now = Date.now()) {
|
|
126
|
+
return { ...structuredClone(machine), ...(machine.status === "pending" && claimExpiresAt !== undefined && claimExpiresAt <= now ? { pairingExpired: true } : {}), ...(machine.inventory ? { inventory: withNativePaneVerification(machine.inventory) } : {}), runtimeCompatibility: machine.runtimeInfo
|
|
118
127
|
? runtimeInfoCompatible(machine.runtimeInfo) ? "compatible" : "incompatible"
|
|
119
128
|
: machine.bootId ? "legacy" : "unknown" };
|
|
120
129
|
}
|
|
130
|
+
/** `reject` of a computer that is not waiting for approval any more. */
|
|
131
|
+
export class RuntimeNotPendingError extends Error {
|
|
132
|
+
constructor() { super("This computer was already handled"); this.name = "RuntimeNotPendingError"; }
|
|
133
|
+
}
|
|
134
|
+
/** Every event is kept in the journal's bounded trail; a refusal on a known token and a throttling summary are kept too. */
|
|
135
|
+
const PERSISTED_AUDIT_EVENTS = ["issued", "used", "revoked", "superseded", "rejected", "throttled"];
|
|
136
|
+
const SOURCE_PATTERN = /^[0-9a-fx.:]{1,45}$/;
|
|
137
|
+
/** The eight groups of an IPv6 address with its `::` written out (so `fe80::abcd:1` is fe80:0:0:0:0:0:abcd:1), or undefined when it is not one. */
|
|
138
|
+
function ipv6Groups(address) {
|
|
139
|
+
const text = address.split("%")[0].toLowerCase();
|
|
140
|
+
if (!/^[0-9a-f:]+$/.test(text) || text.includes(":::"))
|
|
141
|
+
return undefined;
|
|
142
|
+
const halves = text.split("::");
|
|
143
|
+
if (halves.length > 2)
|
|
144
|
+
return undefined;
|
|
145
|
+
const head = halves[0] ? halves[0].split(":") : [], tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
146
|
+
const fill = 8 - head.length - tail.length;
|
|
147
|
+
if (halves.length === 2 ? fill < 1 : fill !== 0)
|
|
148
|
+
return undefined;
|
|
149
|
+
const groups = [...head, ...new Array(halves.length === 2 ? fill : 0).fill("0"), ...tail];
|
|
150
|
+
return groups.length === 8 && groups.every(group => /^[0-9a-f]{1,4}$/.test(group)) ? groups.map(group => group.replace(/^0+(?=.)/, "")) : undefined;
|
|
151
|
+
}
|
|
152
|
+
/** An address for the trail with its host part hidden (IPv4 keeps two octets, IPv6 the first two of its eight groups); nothing for loopback or an unknown address. */
|
|
153
|
+
export function maskedSource(address) {
|
|
154
|
+
if (!address || loopback(address))
|
|
155
|
+
return undefined;
|
|
156
|
+
const v4 = /^(?:::ffff:)?(\d{1,3})\.(\d{1,3})\.\d{1,3}\.\d{1,3}$/i.exec(address);
|
|
157
|
+
if (v4)
|
|
158
|
+
return `${v4[1]}.${v4[2]}.x.x`;
|
|
159
|
+
const groups = ipv6Groups(address);
|
|
160
|
+
return groups && groups.some(group => group !== "0") ? `${groups[0]}:${groups[1]}:x:x` : undefined;
|
|
161
|
+
}
|
|
162
|
+
const HELLO_TTL_MS = 2 * 60_000, HELLO_CAP = 512, THROTTLE_SUMMARY_MS = 60_000;
|
|
163
|
+
const ENROLLMENT_CAP = 64, ENROLLMENT_AUDIT_CAP = 512, ENROLLMENT_KEEP_MS = 7 * 24 * 3_600_000;
|
|
121
164
|
/**
|
|
122
165
|
* M-2239 P2-1 (#2936 review): the journal is compacted, never just capped. A settled command (failed, or accepted with a
|
|
123
166
|
* terminal, process-confirmed outcome) older than COMMAND_KEEP_MS, or the oldest settled ones beyond COMMAND_SOFT_CAP,
|
|
@@ -133,6 +176,7 @@ const TOMBSTONE_CAP = 65_536, TOMBSTONE_KEEP_MS = 30 * 24 * 3_600_000;
|
|
|
133
176
|
*/
|
|
134
177
|
const interrupted = (command) => command.operation === "probe" ? "failed" : "uncertain";
|
|
135
178
|
export class RuntimeCoordinator {
|
|
179
|
+
home;
|
|
136
180
|
options;
|
|
137
181
|
paneEpoch = randomUUID();
|
|
138
182
|
path;
|
|
@@ -150,7 +194,12 @@ export class RuntimeCoordinator {
|
|
|
150
194
|
limits = new Map();
|
|
151
195
|
heartbeat;
|
|
152
196
|
closed = false;
|
|
197
|
+
identityValue;
|
|
198
|
+
/** `enroll-hello` sessions: the fresh private key made for one request, kept in memory only for two minutes and spent by its one `enroll` (or dropped). Keyed by the caller's nonce. */
|
|
199
|
+
hellos = new Map();
|
|
200
|
+
throttledAt = new Map();
|
|
153
201
|
constructor(home, options = {}) {
|
|
202
|
+
this.home = home;
|
|
154
203
|
this.options = options;
|
|
155
204
|
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
156
205
|
this.path = join(home, "runtime-machines.json");
|
|
@@ -161,9 +210,16 @@ export class RuntimeCoordinator {
|
|
|
161
210
|
}
|
|
162
211
|
this.state = existsSync(this.path) ? JSON.parse(readFileSync(this.path, "utf8")) : { version: 1, machines: [], pairings: [], commands: [] };
|
|
163
212
|
if (this.state.version !== 1 || !Array.isArray(this.state.machines) || !Array.isArray(this.state.pairings) || !Array.isArray(this.state.commands)
|
|
164
|
-
|| this.state.tombstones !== undefined && !Array.isArray(this.state.tombstones)
|
|
213
|
+
|| this.state.tombstones !== undefined && !Array.isArray(this.state.tombstones)
|
|
214
|
+
|| this.state.enrollments !== undefined && !Array.isArray(this.state.enrollments)
|
|
215
|
+
|| this.state.enrollmentAudit !== undefined && !Array.isArray(this.state.enrollmentAudit))
|
|
165
216
|
throw Error("Invalid runtime machine store");
|
|
166
217
|
this.state.tombstones ??= [];
|
|
218
|
+
this.state.enrollments ??= [];
|
|
219
|
+
this.state.enrollmentAudit ??= [];
|
|
220
|
+
// A trail longer than its cap is cut to the newest entries (never a reason to refuse to start).
|
|
221
|
+
if (this.state.enrollmentAudit.length > ENROLLMENT_AUDIT_CAP)
|
|
222
|
+
this.state.enrollmentAudit = this.state.enrollmentAudit.slice(-ENROLLMENT_AUDIT_CAP);
|
|
167
223
|
if (this.state.machines.length > 256 || this.state.pairings.length > 16 || this.state.commands.length > COMMAND_HARD_CAP || this.state.tombstones.length > TOMBSTONE_CAP
|
|
168
224
|
|| this.state.tombstones.some(row => !record(row) || !text(row.id, 128) || !UUID.test(String(row.machineId)) || !/^[a-f0-9]{64}$/.test(row.digest) || !Number.isFinite(row.at))
|
|
169
225
|
|| this.state.machines.some(row => !record(row) || !record(row.machine) || !UUID.test(String(row.machine.id)) || !text(row.machine.name, 100)
|
|
@@ -173,6 +229,17 @@ export class RuntimeCoordinator {
|
|
|
173
229
|
|| row.credentialHash !== undefined && !/^[a-f0-9]{64}$/.test(row.credentialHash)
|
|
174
230
|
|| row.claimHash !== undefined && !/^[a-f0-9]{64}$/.test(row.claimHash))
|
|
175
231
|
|| new Set(this.state.machines.map(row => row.machine.id)).size !== this.state.machines.length
|
|
232
|
+
|| this.state.machines.some(row => row.machine.enrolledVia !== undefined && (row.machine.enrolledVia !== "install-command" || row.machine.enrollmentId !== undefined && !UUID.test(String(row.machine.enrollmentId))))
|
|
233
|
+
|| this.state.enrollments.length > ENROLLMENT_CAP
|
|
234
|
+
|| this.state.enrollments.some(row => !record(row) || !UUID.test(String(row.id)) || !/^[a-f0-9]{64}$/.test(String(row.tokenHash)) || !/^[a-f0-9]{64}$/.test(String(row.fingerprint))
|
|
235
|
+
|| !Number.isFinite(row.createdAt) || !Number.isFinite(row.expiresAt) || !text(row.createdBy, 64)
|
|
236
|
+
|| row.usedAt !== undefined && !Number.isFinite(row.usedAt) || row.revokedAt !== undefined && !Number.isFinite(row.revokedAt) || row.machineId !== undefined && !UUID.test(String(row.machineId)))
|
|
237
|
+
|| new Set(this.state.enrollments.map(row => row.id)).size !== this.state.enrollments.length
|
|
238
|
+
|| this.state.enrollmentAudit.some(row => !record(row) || !Number.isFinite(row.at) || !PERSISTED_AUDIT_EVENTS.includes(String(row.event))
|
|
239
|
+
|| (row.event === "throttled" ? row.enrollmentId !== undefined : !UUID.test(String(row.enrollmentId)))
|
|
240
|
+
|| row.actor !== undefined && !text(row.actor, 64) || row.machineId !== undefined && !UUID.test(String(row.machineId))
|
|
241
|
+
|| row.reason !== undefined && !RUNTIME_ENROLL_REFUSALS.includes(row.reason) || row.source !== undefined && !SOURCE_PATTERN.test(String(row.source))
|
|
242
|
+
|| row.scope !== undefined && row.scope !== "enroll" && row.scope !== "hello")
|
|
176
243
|
|| this.state.pairings.some(row => !record(row) || !UUID.test(String(row.id)) || !/^[a-f0-9]{64}$/.test(row.codeHash) || !Number.isFinite(row.expiresAt))
|
|
177
244
|
|| this.state.commands.some(row => !record(row) || !text(row.id, 128) || !UUID.test(String(row.machineId)) || !/^[a-f0-9]{64}$/.test(row.digest)
|
|
178
245
|
|| !["probe", "workspace", "run", "cancel", "reconcile", "recover"].includes(row.operation)
|
|
@@ -245,8 +312,8 @@ export class RuntimeCoordinator {
|
|
|
245
312
|
}
|
|
246
313
|
entry(id) { const row = this.state.machines.find(v => v.machine.id === id); if (!row)
|
|
247
314
|
throw Error("Runtime machine not found"); return row; }
|
|
248
|
-
listMachines() { return this.state.machines.map(row => machineView(row.machine)); }
|
|
249
|
-
machine(id) { const row = this.state.machines.find(v => v.machine.id === id); return row ? machineView(row.machine) : null; }
|
|
315
|
+
listMachines() { const now = this.now(); return this.state.machines.map(row => machineView(row.machine, row.claimExpiresAt, now)); }
|
|
316
|
+
machine(id) { const row = this.state.machines.find(v => v.machine.id === id); return row ? machineView(row.machine, row.claimExpiresAt, this.now()) : null; }
|
|
250
317
|
subscribe(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); }
|
|
251
318
|
createPairing() {
|
|
252
319
|
this.state.pairings = this.state.pairings.filter(row => row.expiresAt > this.now());
|
|
@@ -257,6 +324,239 @@ export class RuntimeCoordinator {
|
|
|
257
324
|
this.save();
|
|
258
325
|
return { pairingId, code: code.match(/.{4}/g).join("-"), expiresAt };
|
|
259
326
|
}
|
|
327
|
+
/** The key a command pins. Created on first use and kept for the life of this AgEnD data folder. */
|
|
328
|
+
identity() { return this.identityValue ??= loadRuntimeServerIdentity(this.home); }
|
|
329
|
+
/** SHA-256 fingerprint of this AgEnD's enrollment key: the "who the server is" value an install command carries. */
|
|
330
|
+
serverFingerprint() { return this.identity().fingerprint; }
|
|
331
|
+
enrollmentStatus(row) {
|
|
332
|
+
return row.usedAt !== undefined ? "used" : row.revokedAt !== undefined ? "revoked" : row.expiresAt <= this.now() ? "expired" : "unused";
|
|
333
|
+
}
|
|
334
|
+
/** Appends to the persisted trail, keeping it within its cap. Returns how to take the entries back out if the journal then cannot be saved. */
|
|
335
|
+
trail(...entries) {
|
|
336
|
+
const log = this.state.enrollmentAudit, before = log.slice();
|
|
337
|
+
log.push(...entries);
|
|
338
|
+
while (log.length > ENROLLMENT_AUDIT_CAP)
|
|
339
|
+
log.shift();
|
|
340
|
+
return () => { this.state.enrollmentAudit = before; };
|
|
341
|
+
}
|
|
342
|
+
/** Reports an entry to the log hook (after it is saved, or for an entry that is only logged). */
|
|
343
|
+
audit(entry) {
|
|
344
|
+
try {
|
|
345
|
+
this.options.audit?.({ ...entry });
|
|
346
|
+
}
|
|
347
|
+
catch { /* a logging hook never changes the verdict */ }
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* issues a one-time install-command token. The same people who may create a pairing code may issue one (the caller checked
|
|
351
|
+
* for an administrator session on the dashboard, never the bare header token, #3327); `actor` is only the opaque handle recorded for them. A new token ends every earlier unused one. The token is returned
|
|
352
|
+
* here and nowhere else: the journal keeps its SHA-256 only.
|
|
353
|
+
*/
|
|
354
|
+
createEnrollment(actor) {
|
|
355
|
+
if (this.closed)
|
|
356
|
+
throw Error("Runtime coordinator is closed");
|
|
357
|
+
if (!text(actor, 64))
|
|
358
|
+
throw Error("Invalid enrollment actor");
|
|
359
|
+
const now = this.now(), identity = this.identity(), previousRows = structuredClone(this.state.enrollments);
|
|
360
|
+
const events = [];
|
|
361
|
+
// A week after it ended, a token leaves the list (the audit keeps the history); a full list drops its oldest ended token first.
|
|
362
|
+
let rows = this.state.enrollments.filter(row => (row.usedAt ?? row.revokedAt ?? row.expiresAt) + ENROLLMENT_KEEP_MS > now);
|
|
363
|
+
while (rows.length >= ENROLLMENT_CAP) {
|
|
364
|
+
const ended = rows.findIndex(row => this.enrollmentStatus(row) !== "unused");
|
|
365
|
+
if (ended < 0)
|
|
366
|
+
throw Error("Too many install-command tokens");
|
|
367
|
+
rows = rows.filter((_, index) => index !== ended);
|
|
368
|
+
}
|
|
369
|
+
this.state.enrollments = rows;
|
|
370
|
+
for (const row of rows)
|
|
371
|
+
if (this.enrollmentStatus(row) === "unused") {
|
|
372
|
+
row.revokedAt = now;
|
|
373
|
+
events.push({ at: now, event: "superseded", enrollmentId: row.id, actor });
|
|
374
|
+
}
|
|
375
|
+
const token = generateEnrollToken(), id = randomUUID(), expiresAt = now + ENROLL_TTL_MS;
|
|
376
|
+
rows.push({ id, tokenHash: hashEnrollToken(token), fingerprint: identity.fingerprint, createdAt: now, expiresAt, createdBy: actor });
|
|
377
|
+
events.push({ at: now, event: "issued", enrollmentId: id, actor });
|
|
378
|
+
const undo = this.trail(...events);
|
|
379
|
+
try {
|
|
380
|
+
this.save();
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
this.state.enrollments = previousRows;
|
|
384
|
+
undo();
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
for (const entry of events)
|
|
388
|
+
this.audit(entry);
|
|
389
|
+
return { id, token, fingerprint: identity.fingerprint, createdAt: now, expiresAt };
|
|
390
|
+
}
|
|
391
|
+
/** Newest first, at most the last few: what the page shows next to the token it just issued. Never a token or a hash. */
|
|
392
|
+
listEnrollments() {
|
|
393
|
+
return [...this.state.enrollments].reverse().slice(0, 8).map(row => ({ id: row.id, status: this.enrollmentStatus(row), createdAt: row.createdAt, expiresAt: row.expiresAt,
|
|
394
|
+
...(row.usedAt !== undefined ? { usedAt: row.usedAt } : {}), ...(row.revokedAt !== undefined ? { revokedAt: row.revokedAt } : {}), ...(row.machineId ? { machineId: row.machineId } : {}) }));
|
|
395
|
+
}
|
|
396
|
+
/** Ends a token that has not been used. A used token cannot be revoked (revoke the computer that used it); an ended one needs nothing. */
|
|
397
|
+
revokeEnrollment(id, actor) {
|
|
398
|
+
if (this.closed)
|
|
399
|
+
throw Error("Runtime coordinator is closed");
|
|
400
|
+
if (!text(actor, 64))
|
|
401
|
+
throw Error("Invalid enrollment actor");
|
|
402
|
+
const row = this.state.enrollments.find(row => row.id === id);
|
|
403
|
+
if (!row)
|
|
404
|
+
throw Error("Install-command token not found");
|
|
405
|
+
if (this.enrollmentStatus(row) !== "unused")
|
|
406
|
+
throw Error("Only an unused install-command token can be revoked");
|
|
407
|
+
const now = this.now(), entry = { at: now, event: "revoked", enrollmentId: row.id, actor };
|
|
408
|
+
row.revokedAt = now;
|
|
409
|
+
const undo = this.trail(entry);
|
|
410
|
+
try {
|
|
411
|
+
this.save();
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
delete row.revokedAt;
|
|
415
|
+
undo();
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
418
|
+
this.audit(entry);
|
|
419
|
+
return this.listEnrollments().find(view => view.id === id);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Step 1 of joining with a token. The server makes a fresh X25519 key for this request and signs the caller's nonce together with it, using its enrollment key. The
|
|
423
|
+
* Runtime checks that key against the fingerprint in its command and, if it matches, seals the token to the fresh key. Anyone can ask; the answer is public by
|
|
424
|
+
* design and spends nothing, but the private half of the fresh key never leaves this process, so only this server can read what is sent next. A relay that
|
|
425
|
+
* forwards this call to the real server gets the real server's valid answer and still cannot read the token or the credential that follow.
|
|
426
|
+
*/
|
|
427
|
+
enrollHello(input) {
|
|
428
|
+
const invalid = () => { throw new RuntimeEnrollError("invalid", "Invalid runtime enrollment request"); };
|
|
429
|
+
if (!record(input) || Object.keys(input).some(key => key !== "nonce" && key !== "tid") || typeof input.nonce !== "string" || input.tid !== undefined && (typeof input.tid !== "string" || !RUNTIME_ENROLL_TID_PATTERN.test(input.tid)))
|
|
430
|
+
return invalid();
|
|
431
|
+
const now = this.now();
|
|
432
|
+
for (const [nonce, entry] of this.hellos)
|
|
433
|
+
if (entry.expiresAt <= now)
|
|
434
|
+
this.hellos.delete(nonce);
|
|
435
|
+
if (this.hellos.has(input.nonce))
|
|
436
|
+
return invalid(); // a nonce is used once: it cannot be re-asked to get a second key for the same exchange
|
|
437
|
+
const ephemeral = newRuntimeEnrollEphemeral();
|
|
438
|
+
let message;
|
|
439
|
+
try {
|
|
440
|
+
message = runtimeEnrollHelloMessage(input.nonce, ephemeral.publicKey);
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
return invalid();
|
|
444
|
+
}
|
|
445
|
+
while (this.hellos.size >= HELLO_CAP)
|
|
446
|
+
this.hellos.delete(this.hellos.keys().next().value);
|
|
447
|
+
this.hellos.set(input.nonce, { privateKey: ephemeral.privateKey, ephemeral: ephemeral.publicKey, tid: input.tid ?? "", expiresAt: now + HELLO_TTL_MS });
|
|
448
|
+
const identity = this.identity();
|
|
449
|
+
return { publicKey: identity.publicKey, ephemeral: ephemeral.publicKey, signature: identity.signature(message) };
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Step 2 as the Runtime sends it: the request is sealed to the fresh key that `enrollHello` made for this nonce (X25519, HKDF-SHA256, AES-256-GCM). The key is
|
|
453
|
+
* spent by this call, whatever happens, so a request cannot be replayed. A box that does not open, a nonce that was never asked for or has aged out are all "invalid".
|
|
454
|
+
* The answer is sealed under the other direction's key: nobody between the Runtime and this server can read the credential or forge the answer.
|
|
455
|
+
*/
|
|
456
|
+
enrollSealed(input, context = {}) {
|
|
457
|
+
const invalid = () => { throw new RuntimeEnrollError("invalid", "Invalid runtime enrollment request"); };
|
|
458
|
+
if (!record(input) || Object.keys(input).some(key => !["nonce", "tid", "clientKey", "iv", "ciphertext"].includes(key)) || typeof input.nonce !== "string" || typeof input.tid !== "string" || !RUNTIME_ENROLL_TID_PATTERN.test(input.tid)
|
|
459
|
+
|| typeof input.clientKey !== "string")
|
|
460
|
+
return invalid();
|
|
461
|
+
const entry = this.hellos.get(input.nonce);
|
|
462
|
+
this.hellos.delete(input.nonce);
|
|
463
|
+
if (!entry || entry.expiresAt <= this.now() || entry.tid !== "" && entry.tid !== input.tid)
|
|
464
|
+
return invalid();
|
|
465
|
+
let channel;
|
|
466
|
+
try {
|
|
467
|
+
channel = runtimeEnrollChannel(entry.privateKey, input.clientKey, input.nonce, input.tid, entry.ephemeral, input.clientKey);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
return invalid();
|
|
471
|
+
}
|
|
472
|
+
const plain = openRuntimeEnroll(channel.requestKey, channel.context, "request", { iv: input.iv, ciphertext: input.ciphertext });
|
|
473
|
+
if (!plain)
|
|
474
|
+
return invalid();
|
|
475
|
+
let fields;
|
|
476
|
+
try {
|
|
477
|
+
fields = JSON.parse(plain.toString("utf8"));
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
return invalid();
|
|
481
|
+
}
|
|
482
|
+
if (record(fields) && typeof fields.token === "string" && isEnrollToken(fields.token) && runtimeEnrollTokenId(fields.token) !== input.tid)
|
|
483
|
+
return invalid();
|
|
484
|
+
const grant = this.enroll(fields, context);
|
|
485
|
+
return { box: sealRuntimeEnroll(channel.replyKey, channel.context, "reply", Buffer.from(JSON.stringify(grant), "utf8")) };
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Spends the token. The computer is created already approved (the token IS the approval: it could only come from an authorised administrator's page) and gets its
|
|
489
|
+
* credential in the grant. Every refusal says why in one closed word; a token that is unknown to the server says only "invalid". Called with the opened request.
|
|
490
|
+
*/
|
|
491
|
+
enroll(input, context = {}) {
|
|
492
|
+
if (!record(input) || Object.keys(input).some(key => !["token", "fingerprint", "name", "platform", "hostname"].includes(key)) || !isEnrollToken(input.token)
|
|
493
|
+
|| typeof input.fingerprint !== "string" || !RUNTIME_SERVER_FINGERPRINT_PATTERN.test(input.fingerprint)
|
|
494
|
+
|| !text(input.name, 100) || !input.name.trim() || input.platform !== "win32" || input.hostname !== undefined && !text(input.hostname, 255))
|
|
495
|
+
throw new RuntimeEnrollError("invalid", "Invalid runtime enrollment request");
|
|
496
|
+
const token = input.token, now = this.now(), identity = this.identity(), source = maskedSource(context.remote);
|
|
497
|
+
const row = this.state.enrollments.find(candidate => enrollTokenMatches(token, candidate.tokenHash));
|
|
498
|
+
if (!row)
|
|
499
|
+
throw new RuntimeEnrollError("invalid", "Install-command token is not valid");
|
|
500
|
+
const refuse = (reason, message) => {
|
|
501
|
+
// A refusal on a KNOWN token goes in the trail (a token that is not known is only counted, by the throttling summary). Not being able to save it never changes the answer.
|
|
502
|
+
const entry = { at: now, event: "rejected", enrollmentId: row.id, reason, ...(source ? { source } : {}) }, undo = this.trail(entry);
|
|
503
|
+
try {
|
|
504
|
+
this.save();
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
undo();
|
|
508
|
+
}
|
|
509
|
+
this.audit(entry);
|
|
510
|
+
throw new RuntimeEnrollError(reason, message);
|
|
511
|
+
};
|
|
512
|
+
if (row.usedAt !== undefined)
|
|
513
|
+
refuse("used", "Install-command token was already used");
|
|
514
|
+
if (row.revokedAt !== undefined)
|
|
515
|
+
refuse("revoked", "Install-command token was revoked");
|
|
516
|
+
if (row.expiresAt <= now)
|
|
517
|
+
refuse("expired", "Install-command token expired");
|
|
518
|
+
if (input.fingerprint !== identity.fingerprint || row.fingerprint !== identity.fingerprint)
|
|
519
|
+
refuse("mismatch", "Install-command token is for a different AgEnD");
|
|
520
|
+
if (this.state.machines.length >= 256 || this.state.machines.filter(machine => machine.machine.status !== "revoked").length >= 64)
|
|
521
|
+
refuse("limit", "Runtime machine limit reached");
|
|
522
|
+
const machineId = randomUUID(), credential = secret(), entry = { at: now, event: "used", enrollmentId: row.id, machineId, ...(source ? { source } : {}) };
|
|
523
|
+
const machine = { machine: { id: machineId, name: input.name.trim(), platform: "win32", ...(input.hostname ? { hostname: input.hostname } : {}), status: "offline", createdAt: now, approvedAt: now,
|
|
524
|
+
generation: 0, enrolledVia: "install-command", enrollmentId: row.id }, credentialHash: hash(credential) };
|
|
525
|
+
row.usedAt = now;
|
|
526
|
+
row.machineId = machineId;
|
|
527
|
+
this.state.machines.push(machine);
|
|
528
|
+
const undo = this.trail(entry);
|
|
529
|
+
try {
|
|
530
|
+
this.save();
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
delete row.usedAt;
|
|
534
|
+
delete row.machineId;
|
|
535
|
+
this.state.machines.pop();
|
|
536
|
+
undo();
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
this.audit(entry);
|
|
540
|
+
this.emit({ type: "machine", machineId });
|
|
541
|
+
return { status: "enrolled", machineId, credential };
|
|
542
|
+
}
|
|
543
|
+
/** One summary in the trail per bucket and minute when an enrollment-related bucket starts refusing: what is throttled names no known token, so it is counted, not listed. */
|
|
544
|
+
noteThrottled(key, scope, remote) {
|
|
545
|
+
const now = this.now(), last = this.throttledAt.get(key);
|
|
546
|
+
if (last !== undefined && now - last < THROTTLE_SUMMARY_MS)
|
|
547
|
+
return;
|
|
548
|
+
this.throttledAt.set(key, now);
|
|
549
|
+
while (this.throttledAt.size > 256)
|
|
550
|
+
this.throttledAt.delete(this.throttledAt.keys().next().value);
|
|
551
|
+
const source = maskedSource(remote), entry = { at: now, event: "throttled", scope, ...(source ? { source } : {}) }, undo = this.trail(entry);
|
|
552
|
+
try {
|
|
553
|
+
this.save();
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
undo();
|
|
557
|
+
}
|
|
558
|
+
this.audit(entry);
|
|
559
|
+
}
|
|
260
560
|
pair(input) {
|
|
261
561
|
if (!record(input) || Object.keys(input).some(k => !["code", "name", "platform", "hostname"].includes(k))
|
|
262
562
|
|| !text(input.code, 32) || !text(input.name, 100) || !input.name.trim() || input.platform !== "win32"
|
|
@@ -311,6 +611,16 @@ export class RuntimeCoordinator {
|
|
|
311
611
|
this.emit({ type: "machine", machineId: id });
|
|
312
612
|
return structuredClone(row.machine);
|
|
313
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Drops a computer's request to pair while it is still waiting (an expired request too: that is how it is cleared). A computer that is no longer waiting, because it was approved
|
|
616
|
+
* meanwhile (another tab, another administrator) or was revoked, is left exactly as it is and the call says so: rejecting is never a way to revoke a computer that was approved.
|
|
617
|
+
*/
|
|
618
|
+
reject(id) {
|
|
619
|
+
const row = this.entry(id);
|
|
620
|
+
if (row.machine.status !== "pending")
|
|
621
|
+
throw new RuntimeNotPendingError();
|
|
622
|
+
return this.revoke(id);
|
|
623
|
+
}
|
|
314
624
|
revoke(id) {
|
|
315
625
|
const row = this.entry(id);
|
|
316
626
|
row.machine.status = "revoked";
|
|
@@ -356,6 +666,15 @@ export class RuntimeCoordinator {
|
|
|
356
666
|
return `rotate:${row.machine.id}`;
|
|
357
667
|
}
|
|
358
668
|
else if (record(input)) {
|
|
669
|
+
// A request that names an existing token by its non-secret id (the first 64 bits of its SHA-256) is that token's own traffic: it gets that token's bucket, so
|
|
670
|
+
// nobody who floods the address bucket (every client behind a local proxy shares one address) can keep a real installer out. The id reveals nothing of the token.
|
|
671
|
+
if ((path === RUNTIME_ENROLL_PATH || path === RUNTIME_ENROLL_HELLO_PATH) && typeof input.tid === "string" && RUNTIME_ENROLL_TID_PATTERN.test(input.tid)) {
|
|
672
|
+
const row = this.state.enrollments.find(row => row.tokenHash.startsWith(input.tid));
|
|
673
|
+
if (row)
|
|
674
|
+
return `${path === RUNTIME_ENROLL_PATH ? "enroll" : "hello-id"}:${row.id}`;
|
|
675
|
+
}
|
|
676
|
+
if (path === RUNTIME_ENROLL_HELLO_PATH)
|
|
677
|
+
return `enroll-hello:${req.socket.remoteAddress ?? "unknown"}`;
|
|
359
678
|
if (path === RUNTIME_PAIR_PATH && text(input.code, 32)) {
|
|
360
679
|
const code = input.code.replaceAll("-", "").toUpperCase();
|
|
361
680
|
const row = this.state.pairings.find(row => row.expiresAt > this.now() && equal(code, row.codeHash));
|
|
@@ -399,7 +718,7 @@ export class RuntimeCoordinator {
|
|
|
399
718
|
return { machineId: row.machine.id, status: "rotated" };
|
|
400
719
|
}
|
|
401
720
|
handlePublicRequest(req, res, url) {
|
|
402
|
-
if (![RUNTIME_PAIR_PATH, RUNTIME_CLAIM_PATH, RUNTIME_ROTATE_PATH].includes(url.pathname))
|
|
721
|
+
if (![RUNTIME_PAIR_PATH, RUNTIME_CLAIM_PATH, RUNTIME_ROTATE_PATH, RUNTIME_ENROLL_HELLO_PATH, RUNTIME_ENROLL_PATH].includes(url.pathname))
|
|
403
722
|
return false;
|
|
404
723
|
const answer = (status, body) => { if (!res.destroyed && !res.writableEnded) {
|
|
405
724
|
res.writeHead(status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
@@ -418,7 +737,9 @@ export class RuntimeCoordinator {
|
|
|
418
737
|
}
|
|
419
738
|
const key = this.requestRateKey(url.pathname, value, req);
|
|
420
739
|
charged = true;
|
|
421
|
-
if (!this.rate(key, key.startsWith("claim:") ? 120 : 30)) {
|
|
740
|
+
if (!this.rate(key, key.startsWith("claim:") || key.startsWith("enroll-hello:") ? 120 : 30)) {
|
|
741
|
+
if (url.pathname === RUNTIME_ENROLL_PATH || url.pathname === RUNTIME_ENROLL_HELLO_PATH)
|
|
742
|
+
this.noteThrottled(key, url.pathname === RUNTIME_ENROLL_PATH ? "enroll" : "hello", req.socket.remoteAddress);
|
|
422
743
|
answer(429, { error: "Too many runtime pairing requests" });
|
|
423
744
|
return;
|
|
424
745
|
}
|
|
@@ -430,14 +751,27 @@ export class RuntimeCoordinator {
|
|
|
430
751
|
answer(200, this.rotateCredential(req.headers.authorization, value));
|
|
431
752
|
return;
|
|
432
753
|
}
|
|
754
|
+
if (url.pathname === RUNTIME_ENROLL_HELLO_PATH) {
|
|
755
|
+
answer(200, this.enrollHello(value));
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (url.pathname === RUNTIME_ENROLL_PATH) {
|
|
759
|
+
answer(201, this.enrollSealed(value, { remote: req.socket.remoteAddress }));
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
433
762
|
if (url.pathname === RUNTIME_PAIR_PATH)
|
|
434
763
|
answer(201, this.pair(value));
|
|
435
764
|
else {
|
|
436
765
|
const result = this.claim(value);
|
|
437
766
|
answer(result.status === "pending" ? 202 : 200, result);
|
|
438
767
|
}
|
|
439
|
-
}).catch(() => {
|
|
768
|
+
}).catch((error) => {
|
|
440
769
|
const allowed = charged || this.rate(`invalid:${req.socket.remoteAddress ?? "unknown"}`, 30);
|
|
770
|
+
// A refused enrollment says why (a closed word and a fixed sentence, never the token); every other failure keeps the one generic answer.
|
|
771
|
+
if (allowed && error instanceof RuntimeEnrollError) {
|
|
772
|
+
answer(error.reason === "invalid" ? 400 : error.reason === "limit" ? 409 : 403, { error: error.message, reason: error.reason });
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
441
775
|
answer(allowed ? 400 : 429, { error: "Runtime pairing request is invalid, expired or already used" });
|
|
442
776
|
});
|
|
443
777
|
return true;
|
|
@@ -1038,7 +1372,7 @@ export class RuntimeCoordinator {
|
|
|
1038
1372
|
const machine = this.entry(machineId).machine, connection = this.connections.get(machineId);
|
|
1039
1373
|
if (this.closed || machine.status !== "online" || !connection?.ready || !this.current(connection))
|
|
1040
1374
|
throw Error("Runtime machine is offline");
|
|
1041
|
-
const needed = operation === "cli.install" ? "cli-install" : "remote-signin";
|
|
1375
|
+
const needed = operation === "models.refresh" ? "model-catalog-refresh" : operation === "cli.install" ? "cli-install" : operation === "cli.update" ? "cli-update" : "remote-signin";
|
|
1042
1376
|
if (!machine.runtimeInfo?.capabilities.includes(needed))
|
|
1043
1377
|
throw Error("Update the Runtime on that computer to use this; it does not offer it yet");
|
|
1044
1378
|
if (this.accountPending.size >= 16)
|