@skrr-ai/cli 0.1.50 → 0.1.51
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/base-command.js +59 -2
- package/dist/commands/agents/chat.d.ts +14 -0
- package/dist/commands/agents/chat.js +37 -1
- package/dist/commands/agents/show.d.ts +9 -0
- package/dist/commands/agents/show.js +53 -0
- package/dist/commands/agents/update.d.ts +9 -0
- package/dist/commands/agents/update.js +27 -0
- package/dist/commands/balance/show.d.ts +34 -0
- package/dist/commands/balance/show.js +92 -2
- package/dist/commands/commitments/doctor.d.ts +1 -0
- package/dist/commands/commitments/doctor.js +19 -4
- package/dist/commands/commitments/effective-policy.js +15 -1
- package/dist/commands/commitments/next-tick.js +3 -1
- package/dist/commands/commitments/preflight.js +10 -0
- package/dist/commands/commitments/show.js +11 -1
- package/dist/commands/daemon/config.d.ts +15 -0
- package/dist/commands/daemon/config.js +38 -0
- package/dist/commands/daemon/index.js +1 -0
- package/dist/commands/daemon/status.js +15 -1
- package/dist/commands/harnesses/models.d.ts +54 -0
- package/dist/commands/harnesses/models.js +100 -7
- package/dist/commands/harnesses/show.d.ts +11 -0
- package/dist/commands/harnesses/show.js +35 -0
- package/dist/commands/harnesses/update.d.ts +28 -1
- package/dist/commands/harnesses/update.js +73 -10
- package/dist/commands/outbox/list.d.ts +12 -1
- package/dist/commands/outbox/list.js +31 -2
- package/dist/commands/revoke-daemon.js +9 -0
- package/dist/commands/spaces/create.d.ts +1 -0
- package/dist/commands/spaces/create.js +17 -0
- package/dist/commands/spaces/show.js +5 -0
- package/dist/commands/spaces/update.d.ts +1 -0
- package/dist/commands/spaces/update.js +16 -0
- package/dist/commands/tasks/create.d.ts +1 -0
- package/dist/commands/tasks/create.js +5 -0
- package/dist/commands/tasks/show.js +45 -0
- package/dist/commands/tasks/update.d.ts +1 -0
- package/dist/commands/tasks/update.js +21 -0
- package/dist/commands/tasks/upsert.d.ts +1 -0
- package/dist/commands/tasks/upsert.js +16 -0
- package/dist/lib/agentic-stream.d.ts +68 -1
- package/dist/lib/agentic-stream.js +294 -7
- package/dist/lib/auth-core-init.d.ts +2 -10
- package/dist/lib/auth-core-init.js +20 -67
- package/dist/lib/auth-failure.d.ts +33 -0
- package/dist/lib/auth-failure.js +65 -0
- package/dist/lib/commitments.d.ts +21 -1
- package/dist/lib/commitments.js +34 -0
- package/dist/lib/daemonBroker.d.ts +14 -0
- package/dist/lib/daemonBroker.js +64 -12
- package/dist/lib/delegated-cli.js +4 -1
- package/dist/lib/exec-runtime-binary.d.ts +3 -1
- package/dist/lib/exec-runtime-binary.js +4 -2
- package/dist/lib/first-party-harness-broker.js +4 -1
- package/dist/lib/harnesses.d.ts +10 -0
- package/dist/lib/live-runtime-binary.d.ts +40 -0
- package/dist/lib/live-runtime-binary.js +193 -0
- package/dist/lib/login.d.ts +23 -0
- package/dist/lib/login.js +44 -10
- package/dist/lib/message-intent.js +3 -1
- package/dist/lib/tasks.d.ts +20 -0
- package/dist/lib/tasks.js +54 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialEnvelopeBridge.d.ts +2 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/credentialEnvelopeBridge.js +26 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonToolApproval.d.ts +28 -4
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/daemonToolApproval.js +23 -5
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/deviceIdentityBridge.js +41 -3
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +25 -3
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/loopbackHttp.d.ts +32 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/loopbackHttp.js +268 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/machineId.d.ts +2 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/machineId.js +11 -10
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/machineUuid.d.ts +36 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/machineUuid.js +156 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.js +8 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/spawnEnv.d.ts +22 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/spawnEnv.js +61 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialEnvelopeBridge.d.ts +2 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/credentialEnvelopeBridge.js +25 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonToolApproval.d.ts +28 -4
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/daemonToolApproval.js +22 -4
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/deviceIdentityBridge.js +41 -3
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +3 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +10 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/loopbackHttp.d.ts +32 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/loopbackHttp.js +257 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/machineId.d.ts +2 -2
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/machineId.js +11 -10
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/machineUuid.d.ts +36 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/machineUuid.js +147 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.d.ts +8 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.js +8 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/spawnEnv.d.ts +22 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/spawnEnv.js +58 -1
- package/dist/node_modules/@skrr-ai/auth-core/package.json +21 -1
- package/dist/node_modules/@skrr-ai/data-provider/index.js +1928 -1924
- package/oclif.manifest.json +23832 -23688
- package/package.json +1 -1
|
@@ -123,7 +123,21 @@ function atomicWrite0600(target, value) {
|
|
|
123
123
|
* The event name passed in is the FULLY-QUALIFIED `cred_envelope.*` form
|
|
124
124
|
* because daemon-side telemetry consumers (`event-log.ts`, dashboards,
|
|
125
125
|
* spec assertions) key off the prefixed name. Do not strip the prefix.
|
|
126
|
+
*
|
|
127
|
+
* Identical failure warnings hit the logger only once per process.
|
|
128
|
+
* Telemetry still records every occurrence — the dedupe exists because a
|
|
129
|
+
* single unreadable envelope produced the same warning once per stored
|
|
130
|
+
* field (token, refresh token, expiry…), which read to users as three
|
|
131
|
+
* crashes rather than one stale credential (OSK-12074). The signature is
|
|
132
|
+
* event + kek identity + message, so a genuinely different failure mode
|
|
133
|
+
* still gets its own line.
|
|
126
134
|
*/
|
|
135
|
+
const warnedSignatures = new Set();
|
|
136
|
+
const MAX_WARNED_SIGNATURES = 64;
|
|
137
|
+
/** @internal Test seam — each spec owns its warn-dedupe horizon. */
|
|
138
|
+
export function __clearWarnDedupeForTest() {
|
|
139
|
+
warnedSignatures.clear();
|
|
140
|
+
}
|
|
127
141
|
function emit(eventName, success, metadata) {
|
|
128
142
|
emitAuthTelemetry({
|
|
129
143
|
timestamp: new Date().toISOString(),
|
|
@@ -132,7 +146,13 @@ function emit(eventName, success, metadata) {
|
|
|
132
146
|
metadata: { event: eventName, ...metadata },
|
|
133
147
|
});
|
|
134
148
|
if (!success) {
|
|
135
|
-
|
|
149
|
+
const signature = `${eventName}:${metadata.kekId ?? ''}:${metadata.kekKind ?? ''}:${metadata.message ?? ''}`;
|
|
150
|
+
if (!warnedSignatures.has(signature)) {
|
|
151
|
+
if (warnedSignatures.size >= MAX_WARNED_SIGNATURES)
|
|
152
|
+
warnedSignatures.clear();
|
|
153
|
+
warnedSignatures.add(signature);
|
|
154
|
+
getAuthLogger().warn(`[credEnvelope] ${eventName}`, metadata);
|
|
155
|
+
}
|
|
136
156
|
}
|
|
137
157
|
}
|
|
138
158
|
// ---------------------------------------------------------------------------
|
|
@@ -745,6 +765,10 @@ export function maybeDecryptOnRead(stored) {
|
|
|
745
765
|
kekId: _state.kekId,
|
|
746
766
|
kekKind: _state.kekKind,
|
|
747
767
|
message: err?.message ?? 'unknown',
|
|
768
|
+
// The crypto error alone reads as a crash; the actionable truth is
|
|
769
|
+
// that this stored credential is unreadable by THIS binary (usually
|
|
770
|
+
// a signing-identity or profile drift) and re-login rebuilds it.
|
|
771
|
+
hint: 'stored credential is unreadable on this machine — signing in again rebuilds it',
|
|
748
772
|
});
|
|
749
773
|
return { plaintext: null, needsMigration: false };
|
|
750
774
|
}
|
|
@@ -23,9 +23,14 @@
|
|
|
23
23
|
*
|
|
24
24
|
* What the daemon verifies is the binding, not the server's honesty: the
|
|
25
25
|
* request already arrives over the daemon's authenticated server channel, so
|
|
26
|
-
* the field IS the attestation
|
|
27
|
-
*
|
|
28
|
-
* one call cannot be replayed
|
|
26
|
+
* the field IS the attestation — it is unsigned, and `decidedBy` is a literal.
|
|
27
|
+
* What the binding buys is that the model — which authors `toolInput` —
|
|
28
|
+
* cannot mint an approval, and an approval for one call cannot be replayed
|
|
29
|
+
* onto another. The verifier also bounds the validity window itself (never
|
|
30
|
+
* trusting the issuer's `expiresAt` beyond `ATTESTED_TOOL_APPROVAL_TTL_MS`),
|
|
31
|
+
* and the daemon spends each approval once: a second delivery of the same
|
|
32
|
+
* attestation inside its window is refused as `replayed`. That ledger lives
|
|
33
|
+
* in daemon memory, so a daemon restart inside the (≤60s) window forgets it.
|
|
29
34
|
*/
|
|
30
35
|
/** Announced by a daemon that honours `attestedApproval` on daemon:tool:request. */
|
|
31
36
|
export declare const DAEMON_TOOL_ATTESTED_APPROVAL_CAPABILITY = "daemon_tool_attested_approval_v1";
|
|
@@ -89,12 +94,31 @@ export declare function mintAttestedToolApproval(args: {
|
|
|
89
94
|
now?: number;
|
|
90
95
|
ttlMs?: number;
|
|
91
96
|
}): AttestedToolApproval;
|
|
97
|
+
/**
|
|
98
|
+
* Why an attestation did not approve a call — logged by the daemon, never
|
|
99
|
+
* shown to the caller beyond "absent" vs "did not verify".
|
|
100
|
+
* - `absent` — no attestation arrived (the server did not ask anyone)
|
|
101
|
+
* - `malformed` — not the v1 shape
|
|
102
|
+
* - `expired` — past `expiresAt`, or issued implausibly far in the future
|
|
103
|
+
* - `window` — the issuer claimed a validity window longer than
|
|
104
|
+
* `ATTESTED_TOOL_APPROVAL_TTL_MS` (or an empty/negative one)
|
|
105
|
+
* - `binding` — minted for a different call (toolUseId, tool, or input)
|
|
106
|
+
* - `replayed` — this exact approval was already spent on this daemon
|
|
107
|
+
* (the ledger is the verifier's caller's, see the daemon's
|
|
108
|
+
* `permissions/attestation-ledger.ts`)
|
|
109
|
+
*/
|
|
110
|
+
export type AttestedToolApprovalRefusalReason = 'absent' | 'malformed' | 'binding' | 'expired' | 'window' | 'replayed';
|
|
92
111
|
export type AttestedToolApprovalVerdict = {
|
|
93
112
|
ok: true;
|
|
94
113
|
} | {
|
|
95
114
|
ok: false;
|
|
96
|
-
reason:
|
|
115
|
+
reason: AttestedToolApprovalRefusalReason;
|
|
97
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Clock skew tolerated on `issuedAt`: a server clock slightly ahead of the
|
|
119
|
+
* daemon's must not refuse a fresh approval.
|
|
120
|
+
*/
|
|
121
|
+
export declare const ATTESTED_TOOL_APPROVAL_CLOCK_SKEW_MS: number;
|
|
98
122
|
/**
|
|
99
123
|
* Daemon side: verify an attestation against the call it claims to approve.
|
|
100
124
|
* Untrusted wire input — every field is checked, and any mismatch is a plain
|
|
@@ -24,9 +24,14 @@ import { createHash } from 'node:crypto';
|
|
|
24
24
|
*
|
|
25
25
|
* What the daemon verifies is the binding, not the server's honesty: the
|
|
26
26
|
* request already arrives over the daemon's authenticated server channel, so
|
|
27
|
-
* the field IS the attestation
|
|
28
|
-
*
|
|
29
|
-
* one call cannot be replayed
|
|
27
|
+
* the field IS the attestation — it is unsigned, and `decidedBy` is a literal.
|
|
28
|
+
* What the binding buys is that the model — which authors `toolInput` —
|
|
29
|
+
* cannot mint an approval, and an approval for one call cannot be replayed
|
|
30
|
+
* onto another. The verifier also bounds the validity window itself (never
|
|
31
|
+
* trusting the issuer's `expiresAt` beyond `ATTESTED_TOOL_APPROVAL_TTL_MS`),
|
|
32
|
+
* and the daemon spends each approval once: a second delivery of the same
|
|
33
|
+
* attestation inside its window is refused as `replayed`. That ledger lives
|
|
34
|
+
* in daemon memory, so a daemon restart inside the (≤60s) window forgets it.
|
|
30
35
|
*/
|
|
31
36
|
/** Announced by a daemon that honours `attestedApproval` on daemon:tool:request. */
|
|
32
37
|
export const DAEMON_TOOL_ATTESTED_APPROVAL_CAPABILITY = 'daemon_tool_attested_approval_v1';
|
|
@@ -129,6 +134,11 @@ export function mintAttestedToolApproval(args) {
|
|
|
129
134
|
expiresAt: now + (args.ttlMs ?? ATTESTED_TOOL_APPROVAL_TTL_MS),
|
|
130
135
|
};
|
|
131
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Clock skew tolerated on `issuedAt`: a server clock slightly ahead of the
|
|
139
|
+
* daemon's must not refuse a fresh approval.
|
|
140
|
+
*/
|
|
141
|
+
export const ATTESTED_TOOL_APPROVAL_CLOCK_SKEW_MS = 30 * 1000;
|
|
132
142
|
/**
|
|
133
143
|
* Daemon side: verify an attestation against the call it claims to approve.
|
|
134
144
|
* Untrusted wire input — every field is checked, and any mismatch is a plain
|
|
@@ -152,9 +162,17 @@ export function verifyAttestedToolApproval(approval, call) {
|
|
|
152
162
|
return { ok: false, reason: 'malformed' };
|
|
153
163
|
}
|
|
154
164
|
const now = call.now ?? Date.now();
|
|
155
|
-
if (a.expiresAt <= now || a.issuedAt > now +
|
|
165
|
+
if (a.expiresAt <= now || a.issuedAt > now + ATTESTED_TOOL_APPROVAL_CLOCK_SKEW_MS) {
|
|
156
166
|
return { ok: false, reason: 'expired' };
|
|
157
167
|
}
|
|
168
|
+
// The TTL is the VERIFIER's bound, not the issuer's claim (OSK-12108): an
|
|
169
|
+
// attestation whose own window is longer than one approval may stay valid
|
|
170
|
+
// is refused whatever `expiresAt` says, so "answers one person about this
|
|
171
|
+
// call, moments ago" holds even against an issuer that set a year.
|
|
172
|
+
const window = a.expiresAt - a.issuedAt;
|
|
173
|
+
if (!(window > 0) || window > ATTESTED_TOOL_APPROVAL_TTL_MS) {
|
|
174
|
+
return { ok: false, reason: 'window' };
|
|
175
|
+
}
|
|
158
176
|
if (a.toolUseId !== call.toolUseId ||
|
|
159
177
|
a.toolName.toLowerCase() !== String(call.toolName).toLowerCase() ||
|
|
160
178
|
a.inputSha256 !== canonicalToolInputDigest(call.toolInput)) {
|
|
@@ -585,11 +585,49 @@ export async function enrollWithServer(opts) {
|
|
|
585
585
|
// Enrollment is the CLI's (JWT) job; the daemon holding an opaque
|
|
586
586
|
// token should not enroll. Guarded at the daemon call site, this is
|
|
587
587
|
// defense-in-depth for any other opaque caller.
|
|
588
|
-
// • 409
|
|
589
|
-
// for
|
|
588
|
+
// • 409 ALREADY_ENROLLED with OUR thumbprint — a concurrent binary won
|
|
589
|
+
// the enrollment race for this keypair; idempotent, nothing to do.
|
|
590
|
+
//
|
|
591
|
+
// A 409 is NOT benign when the row is pinned to a DIFFERENT key
|
|
592
|
+
// (OSK-12063). The server keeps one pin per (user, machine) row while
|
|
593
|
+
// every local profile has its own key, so a 409 can mean "every refresh
|
|
594
|
+
// this key signs will be refused with DEVICE_PROOF_THUMBPRINT_MISMATCH".
|
|
595
|
+
// The server names the pinned thumbprint (`enrolledThumbprint`) so the
|
|
596
|
+
// two cases can be told apart. An older server that omits it keeps the
|
|
597
|
+
// old reading, because there is nothing to compare. A 409
|
|
598
|
+
// ENROLLMENT_DUPLICATE_KEY — this key is pinned on another active row —
|
|
599
|
+
// is never benign either.
|
|
600
|
+
let conflictCode = null;
|
|
601
|
+
let enrolledThumbprint = null;
|
|
602
|
+
if (response.status === 409) {
|
|
603
|
+
try {
|
|
604
|
+
const parsed = JSON.parse(responseText);
|
|
605
|
+
conflictCode = typeof parsed.code === 'string' ? parsed.code : null;
|
|
606
|
+
enrolledThumbprint =
|
|
607
|
+
typeof parsed.enrolledThumbprint === 'string' ? parsed.enrolledThumbprint : null;
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
/* non-JSON 409 — treat as the legacy benign race */
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const pinnedToOtherKey = response.status === 409 &&
|
|
614
|
+
enrolledThumbprint !== null &&
|
|
615
|
+
enrolledThumbprint !== keypair.thumbprint;
|
|
616
|
+
const keyPinnedElsewhere = response.status === 409 && conflictCode === 'ENROLLMENT_DUPLICATE_KEY';
|
|
590
617
|
const isBenignRejection = (response.status === 404 && responseText.includes('DAEMON_NOT_FOUND')) ||
|
|
591
618
|
(response.status === 403 && responseText.includes('OPAQUE_AUTH_REFUSED')) ||
|
|
592
|
-
response.status === 409;
|
|
619
|
+
(response.status === 409 && !pinnedToOtherKey && !keyPinnedElsewhere);
|
|
620
|
+
if (pinnedToOtherKey) {
|
|
621
|
+
emit('enrollment_key_mismatch', false, {
|
|
622
|
+
profile,
|
|
623
|
+
thumbprint: keypair.thumbprint,
|
|
624
|
+
enrolledThumbprint,
|
|
625
|
+
serverUrl,
|
|
626
|
+
message: 'this machine is registered with a different device key than this profile signs ' +
|
|
627
|
+
'with; its refreshes will be refused. An interactive daemon login (skrrd login) ' +
|
|
628
|
+
're-registers this key.',
|
|
629
|
+
}, { logLevel: 'warn' });
|
|
630
|
+
}
|
|
593
631
|
if (response.status === 404 && responseText.includes('DAEMON_NOT_FOUND')) {
|
|
594
632
|
try {
|
|
595
633
|
atomicWrite0600(backoffPath, JSON.stringify({
|
|
@@ -29,11 +29,13 @@ export { __setKekStrategyForTest, getKekStrategy, InMemoryKek, UnavailableKek, K
|
|
|
29
29
|
export { buildProof as buildDeviceProof, generateDeviceKeyPair, jwkThumbprint, normalizeHtu, publicJwkFromX, tokenHash, verifyProof as verifyDeviceProof, type DeviceKeyPair, type DeviceProofClaims, type DeviceProofHeader, type Ed25519PrivateJwk, type Ed25519PublicJwk, type VerifyFailureReason as DeviceProofVerifyFailureReason, type VerifyFailure as DeviceProofVerifyFailure, type VerifyOptions as DeviceProofVerifyOptions, type VerifySuccess as DeviceProofVerifySuccess, } from './deviceKey.js';
|
|
30
30
|
export { initCredEnvelope, resetCredEnvelope, shutdownCredEnvelope, isCredEnvelopeActive, hasCredEnvelopePathConflict, describeCredEnvelopeState, maybeEncryptForWrite, maybeDecryptOnRead, __wrappedDekFilePathForTest, __setStateForTest as __setCredEnvelopeStateForTest, __getStateForTest as __getCredEnvelopeStateForTest, __resetShutdownGuardForTest, type ReadTransformResult, } from './credentialEnvelopeBridge.js';
|
|
31
31
|
export { initDeviceIdentity, resetDeviceIdentity, signServerRequest, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState, __publicKeyPathForTest, __privateKeyPathForTest, __enrollmentMarkerPathForTest, __enrollmentBackoffPathForTest, __setStateForTest as __setDeviceIdentityStateForTest, __getStateForTest as __getDeviceIdentityStateForTest, type EnrollmentResult, } from './deviceIdentityBridge.js';
|
|
32
|
+
export { getMachineUuid, hostedRuntimeIdOverride, HOSTED_RUNTIME_MACHINE_SOURCES, __resetMachineUuidCacheForTest, } from './machineUuid.js';
|
|
32
33
|
export { ensureMachineDaemonId, legacyDaemonUuids, __resetCachedDaemonIdForTest, } from './machineId.js';
|
|
33
34
|
export { PAIR_AAD_PREFIX, PAIR_AAD_MAX_LEN, PAIR_BUNDLE_MAX_BASE64_LEN, PAIR_NONCE_LEN, PAIR_PUBKEY_LEN, PAIR_SECRET_LEN, PairBundleError, assemblePairBundleBase64, base64ToUint8Array as pairBase64ToUint8Array, base64UrlToUint8Array as pairBase64UrlToUint8Array, buildPairAad, buildPairUrl, generatePairKeyPair, openPairBundleBase64, parsePairBundle, parsePairPlaintext, parsePairUrl, uint8ArrayToBase64 as pairUint8ArrayToBase64, uint8ArrayToBase64Url as pairUint8ArrayToBase64Url, type AssembleBundleOptions as PairAssembleBundleOptions, type OpenBundleOptions as PairOpenBundleOptions, type PairBundle, type PairBundleErrorCode, type PairKeyPair, type PairPlaintextV1, type PairUrlFields, } from './daemonPair.js';
|
|
34
35
|
export { HARNESS_TIERS, getHarnessTier, credentialPolicyForTier, tierPermitsConfiguredAutoMode, type HarnessTrustTier, type CredentialDeliveryPolicy, type CredentialMode, } from './harnessTrust.js';
|
|
35
36
|
export { HARNESSES_LOADING_CLAUDE_SKILLS_LAYOUT, claudeSkillsLayoutEvidence, harnessLoadsClaudeSkillsLayout, } from './harnessSkillLayout.js';
|
|
36
|
-
export { sanitizeSpawnEnv, SENSITIVE_ENV_VARS, SENSITIVE_ENV_PREFIXES, SENSITIVE_ENV_SUFFIXES, SENSITIVE_ENV_NAME_TOKENS, SENSITIVE_ENV_PREFIX_EXCEPTIONS, } from './spawnEnv.js';
|
|
37
|
+
export { sanitizeSpawnEnv, SENSITIVE_ENV_VARS, SENSITIVE_ENV_PREFIXES, SENSITIVE_ENV_SUFFIXES, SENSITIVE_ENV_NAME_TOKENS, SENSITIVE_ENV_PREFIX_EXCEPTIONS, LOOPBACK_NO_PROXY_HOSTS, envHasProxy, withLoopbackNoProxy, } from './spawnEnv.js';
|
|
38
|
+
export { loopbackFetch, assertLoopbackHttpUrl, isLoopbackHostname, isLoopbackAddress, LoopbackTargetRefusedError, LOOPBACK_DEFAULT_MAX_BODY_BYTES, type LoopbackFetch, type LoopbackFetchInit, } from './loopbackHttp.js';
|
|
37
39
|
export { CONFIG_DIR_NAME, LEGACY_CONFIG_DIR_NAMES, NATIVE_ID_PREFIX, LEGACY_NATIVE_ID_PREFIXES, DEFAULT_BINARY_NAME, } from './localIdentity.js';
|
|
38
40
|
export { findLegacyLocalState, describeLegacyState, type LegacyStateFinding, type LegacyStateReport, } from './legacyStatePreflight.js';
|
|
39
41
|
export * from './firstPartyHarness.js';
|
|
@@ -118,7 +118,12 @@ export {
|
|
|
118
118
|
initDeviceIdentity, resetDeviceIdentity, signServerRequest, enrollWithServer, clearEnrollmentMarker, isDeviceIdentityActive, getDevicePublicKey, describeDeviceIdentityState,
|
|
119
119
|
// Test seams — file path resolvers + state setters for spec files.
|
|
120
120
|
__publicKeyPathForTest, __privateKeyPathForTest, __enrollmentMarkerPathForTest, __enrollmentBackoffPathForTest, __setStateForTest as __setDeviceIdentityStateForTest, __getStateForTest as __getDeviceIdentityStateForTest, } from './deviceIdentityBridge.js';
|
|
121
|
+
// Hardware machine identity sent as `machineUuid` (IOPlatformUUID /
|
|
122
|
+
// machine-id / MachineGuid). ONE implementation for daemon and CLI —
|
|
123
|
+
// OSK-12063. Also exposed dependency-free as `@skrr-ai/auth-core/machine-uuid`.
|
|
124
|
+
export { getMachineUuid, hostedRuntimeIdOverride, HOSTED_RUNTIME_MACHINE_SOURCES, __resetMachineUuidCacheForTest, } from './machineUuid.js';
|
|
121
125
|
// Stable per-machine UUIDv7 identity persisted at <configDir>/daemon.id.
|
|
126
|
+
// NOT a `machineUuid` — see machineUuid.ts.
|
|
122
127
|
export { ensureMachineDaemonId, legacyDaemonUuids, __resetCachedDaemonIdForTest, } from './machineId.js';
|
|
123
128
|
// Tier 1 #2 — daemon QR pairing primitives. Pure crypto + AAD framing,
|
|
124
129
|
// shared between the daemon CLI orchestrator (`daemon/src/pair.ts`) and
|
|
@@ -140,7 +145,11 @@ export { HARNESSES_LOADING_CLAUDE_SKILLS_LAYOUT, claudeSkillsLayoutEvidence, har
|
|
|
140
145
|
// spawns the SAME engine and did not). `daemon/src/env-sanitize.ts` re-exports
|
|
141
146
|
// these so its own importers are unchanged, and keeps `filterCustomEnv` — that
|
|
142
147
|
// governs SERVER-PROVIDED env, which no other process is handed.
|
|
143
|
-
export { sanitizeSpawnEnv, SENSITIVE_ENV_VARS, SENSITIVE_ENV_PREFIXES, SENSITIVE_ENV_SUFFIXES, SENSITIVE_ENV_NAME_TOKENS, SENSITIVE_ENV_PREFIX_EXCEPTIONS, } from './spawnEnv.js';
|
|
148
|
+
export { sanitizeSpawnEnv, SENSITIVE_ENV_VARS, SENSITIVE_ENV_PREFIXES, SENSITIVE_ENV_SUFFIXES, SENSITIVE_ENV_NAME_TOKENS, SENSITIVE_ENV_PREFIX_EXCEPTIONS, LOOPBACK_NO_PROXY_HOSTS, envHasProxy, withLoopbackNoProxy, } from './spawnEnv.js';
|
|
149
|
+
// OSK-12134 — the one proxy-free client for loopback HTTP. Bun's fetch (and
|
|
150
|
+
// Node's under NODE_USE_ENV_PROXY) sends 127.0.0.1 requests to HTTP_PROXY,
|
|
151
|
+
// credentials and all; every loopback caller goes through this instead.
|
|
152
|
+
export { loopbackFetch, assertLoopbackHttpUrl, isLoopbackHostname, isLoopbackAddress, LoopbackTargetRefusedError, LOOPBACK_DEFAULT_MAX_BODY_BYTES, } from './loopbackHttp.js';
|
|
144
153
|
/* Local-machine identity — the names this product leaves on a disk. Exported so
|
|
145
154
|
the CLI, daemon and Desktop share one definition instead of 47 literals. */
|
|
146
155
|
export { CONFIG_DIR_NAME, LEGACY_CONFIG_DIR_NAMES, NATIVE_ID_PREFIX, LEGACY_NATIVE_ID_PREFIXES, DEFAULT_BINARY_NAME, } from './localIdentity.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Upper bound on a buffered response body. Loopback control-plane bodies are small. */
|
|
2
|
+
export declare const LOOPBACK_DEFAULT_MAX_BODY_BYTES: number;
|
|
3
|
+
/** Thrown (synchronously surfaced as a rejection) for a URL that is not loopback HTTP. */
|
|
4
|
+
export declare class LoopbackTargetRefusedError extends Error {
|
|
5
|
+
readonly code = "LOOPBACK_TARGET_REFUSED";
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/** True for an IP literal in 127.0.0.0/8, `::1`, or an IPv4-mapped 127/8 address. */
|
|
9
|
+
export declare function isLoopbackAddress(address: string): boolean;
|
|
10
|
+
/** True for a host name or address this client accepts as "this machine". */
|
|
11
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Parse and validate a loopback HTTP URL. Throws {@link LoopbackTargetRefusedError}
|
|
14
|
+
* for anything that is not `http:` to a loopback host.
|
|
15
|
+
*/
|
|
16
|
+
export declare function assertLoopbackHttpUrl(input: string | URL): URL;
|
|
17
|
+
/**
|
|
18
|
+
* `RequestInit`, so a `fetch` call site can switch to {@link loopbackFetch}
|
|
19
|
+
* unchanged. Only `method`, `headers`, `signal` and a string/bytes `body` are
|
|
20
|
+
* honoured; a stream, Blob or FormData body is rejected rather than guessed at.
|
|
21
|
+
*/
|
|
22
|
+
export interface LoopbackFetchInit extends RequestInit {
|
|
23
|
+
/** Cap on the buffered response body; exceeding it rejects. */
|
|
24
|
+
maxBodyBytes?: number;
|
|
25
|
+
}
|
|
26
|
+
/** A `fetch`-shaped signature, for callers that keep a `fetchImpl` seam. */
|
|
27
|
+
export type LoopbackFetch = (input: string | URL, init?: LoopbackFetchInit) => Promise<Response>;
|
|
28
|
+
/**
|
|
29
|
+
* `fetch` for a loopback URL, over `node:http`, never through a proxy.
|
|
30
|
+
* Refuses (rejects with {@link LoopbackTargetRefusedError}) any other target.
|
|
31
|
+
*/
|
|
32
|
+
export declare const loopbackFetch: LoopbackFetch;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OSK-12134 — the ONE HTTP client for talking to a process on this machine.
|
|
3
|
+
*
|
|
4
|
+
* ── Why this is not `fetch` ────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* The compiled daemon runs on Bun, and Bun's `fetch` routes EVERY URL through
|
|
7
|
+
* `HTTP_PROXY` / `HTTPS_PROXY` unless `NO_PROXY` names it — a `127.0.0.1`
|
|
8
|
+
* target included. Node's `fetch` does the same once `NODE_USE_ENV_PROXY=1` is
|
|
9
|
+
* set (Node 22.21+/24). On a laptop with a local proxy exported in the shell
|
|
10
|
+
* (Clash, Surge, a corporate agent, …) every loopback call the daemon, a
|
|
11
|
+
* wrapper, or the CLI made with `fetch` was delivered to that proxy instead —
|
|
12
|
+
* WITH its credential: the daemon's local secret, the CLI-handoff descriptor
|
|
13
|
+
* secret, the wrapper fan-out bearer, the browser bridge token, the extension
|
|
14
|
+
* relay token. OSK-12087 found this on the `/health` probe and moved that one
|
|
15
|
+
* caller to `node:http`; this module is that fix made the only way to do it.
|
|
16
|
+
*
|
|
17
|
+
* `node:http` never consults proxy environment variables, on Node or on Bun, so
|
|
18
|
+
* a request made through it cannot be routed off the machine by environment.
|
|
19
|
+
*
|
|
20
|
+
* ── What it refuses ────────────────────────────────────────────────────────
|
|
21
|
+
*
|
|
22
|
+
* Only `http:` URLs whose host is a loopback name or address are accepted
|
|
23
|
+
* (`127.0.0.0/8`, `::1`, `localhost`). Anything else throws BEFORE a socket is
|
|
24
|
+
* opened: a caller that builds its URL from a descriptor or an environment
|
|
25
|
+
* variable must not be turned into an SSRF primitive by a hostile value, and a
|
|
26
|
+
* credential that is only meant for this machine must not be sent anywhere
|
|
27
|
+
* else. `localhost` is resolved through a lookup that rejects any non-loopback
|
|
28
|
+
* answer, so a rewritten hosts file cannot redirect it either.
|
|
29
|
+
*
|
|
30
|
+
* ── Shape ──────────────────────────────────────────────────────────────────
|
|
31
|
+
*
|
|
32
|
+
* `loopbackFetch` is a drop-in for the subset of `fetch` these callers use —
|
|
33
|
+
* method, headers, a string/bytes body, an `AbortSignal` — and returns a real
|
|
34
|
+
* `Response`, so existing callers (and their `fetchImpl` test seams) change one
|
|
35
|
+
* identifier. Transport failures reject with `TypeError('fetch failed')` whose
|
|
36
|
+
* `cause` carries the socket error (`ECONNREFUSED`, …), and aborts reject with
|
|
37
|
+
* the signal's reason, exactly as `fetch` does, so existing error handling keeps
|
|
38
|
+
* working. The response body is buffered (bounded by `maxBodyBytes`); nothing
|
|
39
|
+
* on loopback streams through this client.
|
|
40
|
+
*/
|
|
41
|
+
import dns from 'node:dns';
|
|
42
|
+
import http from 'node:http';
|
|
43
|
+
import net from 'node:net';
|
|
44
|
+
/** Loopback host names this client will connect to, besides 127/8 and ::1 literals. */
|
|
45
|
+
const LOOPBACK_NAMES = new Set(['localhost']);
|
|
46
|
+
/** Upper bound on a buffered response body. Loopback control-plane bodies are small. */
|
|
47
|
+
export const LOOPBACK_DEFAULT_MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
48
|
+
/** Statuses a `Response` must be constructed with a null body for. */
|
|
49
|
+
const NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
|
|
50
|
+
/** Thrown (synchronously surfaced as a rejection) for a URL that is not loopback HTTP. */
|
|
51
|
+
export class LoopbackTargetRefusedError extends Error {
|
|
52
|
+
code = 'LOOPBACK_TARGET_REFUSED';
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = 'LoopbackTargetRefusedError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function stripBrackets(hostname) {
|
|
59
|
+
return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
60
|
+
}
|
|
61
|
+
/** True for an IP literal in 127.0.0.0/8, `::1`, or an IPv4-mapped 127/8 address. */
|
|
62
|
+
export function isLoopbackAddress(address) {
|
|
63
|
+
const value = stripBrackets(address.trim().toLowerCase());
|
|
64
|
+
if (net.isIPv4(value))
|
|
65
|
+
return value.split('.')[0] === '127';
|
|
66
|
+
if (net.isIPv6(value)) {
|
|
67
|
+
if (value === '::1' || value === '0:0:0:0:0:0:0:1')
|
|
68
|
+
return true;
|
|
69
|
+
// IPv4-mapped (::ffff:127.0.0.1, which WHATWG URL normalizes to ::ffff:7f00:1).
|
|
70
|
+
if (value.startsWith('::ffff:')) {
|
|
71
|
+
const rest = value.slice('::ffff:'.length);
|
|
72
|
+
if (net.isIPv4(rest))
|
|
73
|
+
return isLoopbackAddress(rest);
|
|
74
|
+
const high = /^([0-9a-f]{1,4}):[0-9a-f]{1,4}$/.exec(rest);
|
|
75
|
+
return high ? parseInt(high[1], 16) >> 8 === 127 : false;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
/** True for a host name or address this client accepts as "this machine". */
|
|
82
|
+
export function isLoopbackHostname(hostname) {
|
|
83
|
+
const value = stripBrackets(hostname.trim().toLowerCase());
|
|
84
|
+
return LOOPBACK_NAMES.has(value) || isLoopbackAddress(value);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parse and validate a loopback HTTP URL. Throws {@link LoopbackTargetRefusedError}
|
|
88
|
+
* for anything that is not `http:` to a loopback host.
|
|
89
|
+
*/
|
|
90
|
+
export function assertLoopbackHttpUrl(input) {
|
|
91
|
+
let url;
|
|
92
|
+
try {
|
|
93
|
+
url = new URL(String(input));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new LoopbackTargetRefusedError('Loopback request refused: not a valid URL.');
|
|
97
|
+
}
|
|
98
|
+
if (url.protocol !== 'http:') {
|
|
99
|
+
throw new LoopbackTargetRefusedError(`Loopback request refused: only http: is allowed on loopback (got ${url.protocol}).`);
|
|
100
|
+
}
|
|
101
|
+
if (!isLoopbackHostname(url.hostname)) {
|
|
102
|
+
throw new LoopbackTargetRefusedError(`Loopback request refused: ${url.hostname} is not a loopback host.`);
|
|
103
|
+
}
|
|
104
|
+
if (url.username || url.password) {
|
|
105
|
+
throw new LoopbackTargetRefusedError('Loopback request refused: URL must not carry userinfo.');
|
|
106
|
+
}
|
|
107
|
+
return url;
|
|
108
|
+
}
|
|
109
|
+
/** A `dns.lookup` that only ever answers with a loopback address. */
|
|
110
|
+
const loopbackOnlyLookup = (hostname, options, callback) => {
|
|
111
|
+
dns.lookup(hostname, { ...options, all: true }, (err, addresses) => {
|
|
112
|
+
if (err) {
|
|
113
|
+
callback(err, '', 0);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const list = (Array.isArray(addresses) ? addresses : []);
|
|
117
|
+
const loopback = list.filter((entry) => isLoopbackAddress(entry.address));
|
|
118
|
+
if (loopback.length === 0) {
|
|
119
|
+
const refused = Object.assign(new Error(`${hostname} did not resolve to a loopback address`), { code: 'LOOPBACK_TARGET_REFUSED' });
|
|
120
|
+
callback(refused, '', 0);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (options?.all) {
|
|
124
|
+
callback(null, loopback);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
callback(null, loopback[0].address, loopback[0].family);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
function abortReason(signal) {
|
|
131
|
+
return signal.reason !== undefined
|
|
132
|
+
? signal.reason
|
|
133
|
+
: new DOMException('This operation was aborted', 'AbortError');
|
|
134
|
+
}
|
|
135
|
+
function fetchFailed(cause) {
|
|
136
|
+
return new TypeError('fetch failed', { cause });
|
|
137
|
+
}
|
|
138
|
+
function toBodyBuffer(body) {
|
|
139
|
+
if (body === undefined || body === null)
|
|
140
|
+
return null;
|
|
141
|
+
if (typeof body === 'string')
|
|
142
|
+
return Buffer.from(body, 'utf8');
|
|
143
|
+
if (body instanceof ArrayBuffer)
|
|
144
|
+
return Buffer.from(body);
|
|
145
|
+
if (ArrayBuffer.isView(body))
|
|
146
|
+
return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
147
|
+
throw new TypeError('loopbackFetch supports only string or byte bodies');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* `fetch` for a loopback URL, over `node:http`, never through a proxy.
|
|
151
|
+
* Refuses (rejects with {@link LoopbackTargetRefusedError}) any other target.
|
|
152
|
+
*/
|
|
153
|
+
export const loopbackFetch = (input, init = {}) => {
|
|
154
|
+
let url;
|
|
155
|
+
let payload;
|
|
156
|
+
try {
|
|
157
|
+
url = assertLoopbackHttpUrl(input);
|
|
158
|
+
payload = toBodyBuffer(init.body);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
return Promise.reject(err);
|
|
162
|
+
}
|
|
163
|
+
const signal = init.signal ?? undefined;
|
|
164
|
+
if (signal?.aborted)
|
|
165
|
+
return Promise.reject(abortReason(signal));
|
|
166
|
+
const maxBodyBytes = init.maxBodyBytes ?? LOOPBACK_DEFAULT_MAX_BODY_BYTES;
|
|
167
|
+
const method = (init.method ?? 'GET').toUpperCase();
|
|
168
|
+
const headers = {};
|
|
169
|
+
new Headers(init.headers ?? undefined).forEach((value, name) => {
|
|
170
|
+
headers[name] = value;
|
|
171
|
+
});
|
|
172
|
+
if (payload && headers['content-length'] === undefined) {
|
|
173
|
+
headers['content-length'] = String(payload.length);
|
|
174
|
+
}
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
let settled = false;
|
|
177
|
+
let req;
|
|
178
|
+
const onAbort = () => {
|
|
179
|
+
if (settled)
|
|
180
|
+
return;
|
|
181
|
+
settled = true;
|
|
182
|
+
req?.destroy();
|
|
183
|
+
reject(abortReason(signal));
|
|
184
|
+
};
|
|
185
|
+
const finish = (fn) => {
|
|
186
|
+
if (settled)
|
|
187
|
+
return;
|
|
188
|
+
settled = true;
|
|
189
|
+
signal?.removeEventListener('abort', onAbort);
|
|
190
|
+
fn();
|
|
191
|
+
};
|
|
192
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
193
|
+
try {
|
|
194
|
+
req = http.request({
|
|
195
|
+
protocol: 'http:',
|
|
196
|
+
host: stripBrackets(url.hostname),
|
|
197
|
+
port: url.port ? Number(url.port) : 80,
|
|
198
|
+
path: `${url.pathname}${url.search}`,
|
|
199
|
+
method,
|
|
200
|
+
headers,
|
|
201
|
+
// No pooled agent: a short-lived command must be able to exit as soon
|
|
202
|
+
// as it has its answer, and no socket outlives its request.
|
|
203
|
+
agent: false,
|
|
204
|
+
lookup: loopbackOnlyLookup,
|
|
205
|
+
}, (res) => {
|
|
206
|
+
const chunks = [];
|
|
207
|
+
let size = 0;
|
|
208
|
+
res.on('data', (chunk) => {
|
|
209
|
+
size += chunk.length;
|
|
210
|
+
if (size > maxBodyBytes) {
|
|
211
|
+
res.destroy();
|
|
212
|
+
finish(() => reject(fetchFailed(new Error(`response larger than ${maxBodyBytes} bytes`))));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
chunks.push(chunk);
|
|
216
|
+
});
|
|
217
|
+
res.on('error', (err) => finish(() => reject(fetchFailed(err))));
|
|
218
|
+
res.on('aborted', () => finish(() => reject(fetchFailed(new Error('response aborted')))));
|
|
219
|
+
res.on('end', () => {
|
|
220
|
+
finish(() => {
|
|
221
|
+
const status = res.statusCode ?? 0;
|
|
222
|
+
const responseHeaders = new Headers();
|
|
223
|
+
for (const [name, value] of Object.entries(res.headers)) {
|
|
224
|
+
if (value === undefined)
|
|
225
|
+
continue;
|
|
226
|
+
if (Array.isArray(value)) {
|
|
227
|
+
for (const v of value)
|
|
228
|
+
responseHeaders.append(name, v);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
responseHeaders.set(name, String(value));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const body = NULL_BODY_STATUSES.has(status) ? null : Buffer.concat(chunks);
|
|
235
|
+
try {
|
|
236
|
+
resolve(new Response(body, {
|
|
237
|
+
status,
|
|
238
|
+
statusText: res.statusMessage ?? '',
|
|
239
|
+
headers: responseHeaders,
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
reject(fetchFailed(err));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
req.on('error', (err) => finish(() => reject(fetchFailed(err))));
|
|
249
|
+
if (payload)
|
|
250
|
+
req.write(payload);
|
|
251
|
+
req.end();
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
finish(() => reject(fetchFailed(err)));
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* with a real UUIDv7 downstream.
|
|
11
11
|
*
|
|
12
12
|
* The caller may pass `machineUuidFallback` to override the default
|
|
13
|
-
* hostname+platform fingerprint with a richer detector (e.g.
|
|
14
|
-
*
|
|
13
|
+
* hostname+platform fingerprint with a richer detector (e.g.
|
|
14
|
+
* `getMachineUuid()` from `machineUuid.ts`).
|
|
15
15
|
*/
|
|
16
16
|
export declare function ensureMachineDaemonId(machineUuidFallback?: () => string): string;
|
|
17
17
|
/**
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
* directory survives), and a user whose machineUuid changes can
|
|
16
16
|
* still be re-anchored via the legacy-id list.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* This id is NOT the `machineUuid` the server keys Daemon rows on. That
|
|
19
|
+
* is the hardware id from `getMachineUuid()` (`machineUuid.ts`), and the
|
|
20
|
+
* two must never be substituted for each other on the wire: OSK-12063
|
|
21
|
+
* was the CLI sending this id as `machineUuid` on device-key enrollment,
|
|
22
|
+
* which matched no Daemon row and 404'd forever. The fallback used when
|
|
23
|
+
* this file cannot be persisted is supplied by the consumer via the
|
|
24
|
+
* `machineUuidFallback` parameter (the daemon passes `getMachineUuid`).
|
|
23
25
|
*/
|
|
24
26
|
import crypto from 'node:crypto';
|
|
25
27
|
import fs from 'node:fs';
|
|
@@ -100,9 +102,8 @@ function writeDaemonIdFile(target, id) {
|
|
|
100
102
|
* SHA-256 of `os.hostname()` + `os.platform()` — better than just
|
|
101
103
|
* hostname (includes platform) but worse than a true hardware UUID.
|
|
102
104
|
*
|
|
103
|
-
* The daemon overrides this with
|
|
104
|
-
* (`
|
|
105
|
-
* no native deps for OS UUIDs and so accepts this default.
|
|
105
|
+
* The daemon overrides this with the hardware detector
|
|
106
|
+
* (`getMachineUuid()`, `machineUuid.ts`).
|
|
106
107
|
*/
|
|
107
108
|
function defaultMachineUuidFallback() {
|
|
108
109
|
const host = os.hostname() || 'unknown-host';
|
|
@@ -121,8 +122,8 @@ function defaultMachineUuidFallback() {
|
|
|
121
122
|
* with a real UUIDv7 downstream.
|
|
122
123
|
*
|
|
123
124
|
* The caller may pass `machineUuidFallback` to override the default
|
|
124
|
-
* hostname+platform fingerprint with a richer detector (e.g.
|
|
125
|
-
*
|
|
125
|
+
* hostname+platform fingerprint with a richer detector (e.g.
|
|
126
|
+
* `getMachineUuid()` from `machineUuid.ts`).
|
|
126
127
|
*/
|
|
127
128
|
export function ensureMachineDaemonId(machineUuidFallback) {
|
|
128
129
|
if (cachedStableDaemonId !== null)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon sources whose identity is ISSUED by the control plane rather than
|
|
3
|
+
* derived from the host: the provisioner mints the daemon id and machine uuid
|
|
4
|
+
* before the daemon exists, and every binary on the runtime must use exactly
|
|
5
|
+
* those values.
|
|
6
|
+
*
|
|
7
|
+
* `dedicated-runtime` is here because the server's generation fence parses the
|
|
8
|
+
* lease generation out of the machine uuid (`dedicated-runtime:<lease>:<gen>`).
|
|
9
|
+
* A guest that fell back to `/etc/machine-id` would register under a uuid the
|
|
10
|
+
* fence cannot read, and every dispatch to it would be refused.
|
|
11
|
+
*/
|
|
12
|
+
export declare const HOSTED_RUNTIME_MACHINE_SOURCES: ReadonlySet<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The control-plane-issued value of `name` (e.g. `OVERSKY_MACHINE_UUID`), or
|
|
15
|
+
* null when this process is not on a hosted runtime or the value is absent /
|
|
16
|
+
* malformed. Only honoured under a hosted `OVERSKY_DAEMON_SOURCE`, so a stray
|
|
17
|
+
* variable on a laptop cannot rename the machine.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hostedRuntimeIdOverride(name: string, env?: NodeJS.ProcessEnv): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* Return a stable, machine-scoped UUID. Cached for the process lifetime.
|
|
22
|
+
*
|
|
23
|
+
* Callers should treat this as opaque: the format differs per platform
|
|
24
|
+
* (macOS IOPlatformUUID, Linux systemd machine-id, Windows MachineGuid).
|
|
25
|
+
* The guarantee is only: same machine -> same value across reboots, and the
|
|
26
|
+
* same value from every binary that calls this function.
|
|
27
|
+
*
|
|
28
|
+
* On a hosted runtime the control-plane-issued `OVERSKY_MACHINE_UUID` wins.
|
|
29
|
+
*
|
|
30
|
+
* Falls back to a deterministic hostname+username hash if the platform
|
|
31
|
+
* probe fails. This preserves server-side record continuity even on
|
|
32
|
+
* locked-down machines that refuse ioreg / registry access.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getMachineUuid(): string;
|
|
35
|
+
/** @internal test seam — forget the cached value so the next call re-probes. */
|
|
36
|
+
export declare function __resetMachineUuidCacheForTest(): void;
|