@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.55
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/admin/admin.schemas.d.ts +11 -1
- package/dist/catalog/catalog.module.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +5 -5
- package/dist/catalog/requests.service.js +9 -9
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +25 -16
- package/dist/channels/phrases.d.ts +15 -4
- package/dist/channels/phrases.js +15 -1
- package/dist/config/load.d.ts +26 -7
- package/dist/config/load.js +60 -9
- package/dist/config/permission-migration.d.ts +17 -9
- package/dist/config/permission-migration.js +60 -9
- package/dist/config/schema.d.ts +11 -1
- package/dist/config/schema.js +37 -11
- package/dist/conversations/events.d.ts +247 -5
- package/dist/conversations/events.js +127 -16
- package/dist/conversations/permission-profiles.controller.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.js +11 -4
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/devices/device-projects.service.d.ts +1 -1
- package/dist/devices/device-projects.service.js +6 -6
- package/dist/devices/devices.controller.d.ts +10 -8
- package/dist/devices/devices.controller.js +14 -18
- package/dist/devices/devices.schemas.d.ts +5 -5
- package/dist/devices/devices.schemas.js +5 -5
- package/dist/devices/devices.service.d.ts +188 -175
- package/dist/devices/devices.service.js +284 -292
- package/dist/devices/dto.d.ts +43 -23
- package/dist/devices/dto.js +45 -49
- package/dist/devices/project-rules.d.ts +0 -10
- package/dist/devices/project-rules.js +0 -5
- package/dist/errors.d.ts +24 -19
- package/dist/errors.js +24 -19
- package/dist/evals/reconstruct.d.ts +12 -3
- package/dist/evals/reconstruct.js +10 -6
- package/dist/evals/recorded-permission-context.d.ts +6 -4
- package/dist/evals/recorded-permission-context.js +15 -9
- package/dist/evals/run-replay.d.ts +6 -1
- package/dist/evals/run-replay.js +7 -2
- package/dist/evals/worker.js +3 -1
- package/dist/identity/settings.d.ts +45 -18
- package/dist/identity/settings.js +151 -51
- package/dist/infra/config/kernel-config.service.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +17 -5
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -4
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +18 -9
- package/dist/local-devices/device-policy.service.js +21 -61
- package/dist/local-devices/device-routes.d.ts +3 -1
- package/dist/local-devices/device-routes.js +15 -4
- package/dist/local-devices/instance-bindings.js +5 -2
- package/dist/local-devices/local-device-gateway.d.ts +2 -2
- package/dist/local-devices/local-device-gateway.js +3 -3
- package/dist/local-devices/local-device-provider.d.ts +4 -4
- package/dist/local-devices/local-device-provider.js +23 -9
- package/dist/local-devices/local-devices.module.d.ts +1 -1
- package/dist/local-devices/local-devices.module.js +1 -1
- package/dist/local-devices/machines.d.ts +40 -16
- package/dist/local-devices/machines.js +89 -61
- package/dist/local-devices/owner-report.d.ts +16 -14
- package/dist/local-devices/owner-report.js +24 -30
- package/dist/local-devices/owner-reports.js +26 -8
- package/dist/local-devices/policy-summary.d.ts +25 -44
- package/dist/local-devices/policy-summary.js +26 -71
- package/dist/local-devices/relay.d.ts +6 -6
- package/dist/local-devices/relay.js +10 -8
- package/dist/net/public-address.d.ts +1 -1
- package/dist/net/public-address.js +5 -2
- package/dist/orgs/device-network-setting.d.ts +82 -0
- package/dist/orgs/device-network-setting.js +142 -0
- package/dist/orgs/settings.service.d.ts +103 -66
- package/dist/orgs/settings.service.js +201 -137
- package/dist/overrides.d.ts +5 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.js +20 -11
- package/dist/platform/ops/devices.ops.js +70 -5
- package/dist/platform/ops/org-settings.ops.js +10 -6
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/runtime/context/permission-profile.d.ts +17 -8
- package/dist/runtime/context/permission-profile.js +126 -45
- package/dist/runtime/permission-context.service.d.ts +1 -1
- package/dist/runtime/permission-context.service.js +5 -3
- package/dist/runtime/project/knowledge.d.ts +5 -4
- package/dist/runtime/project/knowledge.js +2 -1
- package/dist/runtime/project/knowledge.service.js +16 -13
- package/dist/sandbox/cloud-permission-snapshot.js +22 -3
- package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
- package/dist/sandbox/device-sandbox-settings.js +470 -0
- package/dist/sandbox/device-sandbox.d.ts +187 -0
- package/dist/sandbox/device-sandbox.js +236 -0
- package/dist/sandbox/held-operations.js +15 -7
- package/dist/sandbox/modes.d.ts +49 -24
- package/dist/sandbox/modes.js +27 -19
- package/dist/sandbox/operation-authority-types.d.ts +6 -5
- package/dist/sandbox/operation-authority-types.js +7 -8
- package/dist/sandbox/operation-authority.d.ts +23 -9
- package/dist/sandbox/operation-authority.js +179 -97
- package/dist/sandbox/permission-auto-grants.d.ts +42 -0
- package/dist/sandbox/permission-auto-grants.js +145 -0
- package/dist/sandbox/permission-call-grants.d.ts +12 -4
- package/dist/sandbox/permission-call-grants.js +84 -35
- package/dist/sandbox/permission-call-grants.module.js +10 -3
- package/dist/sandbox/permission-call-types.d.ts +39 -5
- package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
- package/dist/sandbox/permission-ceiling-writes.js +38 -4
- package/dist/sandbox/permission-config-publication.d.ts +44 -2
- package/dist/sandbox/permission-config-publication.js +230 -59
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-facts.d.ts +144 -15
- package/dist/sandbox/permission-facts.js +258 -70
- package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
- package/dist/sandbox/permission-runtime-reports.js +19 -29
- package/dist/sandbox/review/classifier.d.ts +8 -0
- package/dist/sandbox/review/classifier.js +10 -0
- package/dist/sandbox/review/permission-candidate.d.ts +69 -5
- package/dist/sandbox/review/permission-candidate.js +153 -30
- package/dist/sandbox/review/review.service.d.ts +19 -3
- package/dist/sandbox/review/review.service.js +59 -11
- package/dist/sandbox/review/rules.js +23 -3
- package/dist/sandbox/sandbox.service.d.ts +29 -11
- package/dist/sandbox/sandbox.service.js +51 -26
- package/dist/skills/invoke.js +3 -2
- package/dist/tools/approvals.service.d.ts +26 -116
- package/dist/tools/approvals.service.js +42 -346
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +80 -28
- package/dist/tools/builtins/sandbox/common.d.ts +39 -14
- package/dist/tools/builtins/sandbox/common.js +47 -24
- package/dist/tools/builtins/sandbox/deliver.js +7 -4
- package/dist/tools/builtins/skill-load.d.ts +2 -2
- package/dist/tools/builtins/skill-load.js +4 -3
- package/dist/tools/device-op-resolver.d.ts +4 -10
- package/dist/tools/device-op-resolver.js +8 -19
- package/dist/tools/network-asks.d.ts +52 -15
- package/dist/tools/network-asks.js +55 -25
- package/dist/tools/pipeline.d.ts +26 -14
- package/dist/tools/pipeline.js +144 -61
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/tools.module.js +1 -1
- package/package.json +4 -4
- package/src/migrations/0165_device_network_columns.sql +50 -0
- package/src/migrations/0166_permission_grant_full_access.sql +17 -0
- package/src/migrations/0167_device_network_backfill.sql +32 -0
- package/src/migrations/0168_binding_installed_connection.sql +6 -0
- package/dist/orgs/cloud-network-setting.d.ts +0 -33
- package/dist/orgs/cloud-network-setting.js +0 -47
- package/dist/sandbox/platform-full-access.d.ts +0 -110
- package/dist/sandbox/platform-full-access.js +0 -198
|
@@ -53,8 +53,9 @@ const NOT_RECEIVED_MESSAGE = "The device's machine never received the policy cha
|
|
|
53
53
|
const OWNER_CEILING_UNSUPPORTED_MESSAGE = "The device's capybara-device program cannot narrow its owner ceiling from the platform. Update capybara-device on the machine, or run capybara-device ceiling set there.";
|
|
54
54
|
const errMsg = (e) => (e instanceof Error ? e.message : String(e));
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Narrows a local device's policy on its machine (approval-only profiles design, "Settings model":
|
|
57
|
+
* hosts removed, the network to the allowlist, no running outside the sandbox, the workspace
|
|
58
|
+
* reach): the kernel→device `policy`
|
|
58
59
|
* op over the {@link LocalDeviceRelay}. The machine is the authority: it refuses what its owner
|
|
59
60
|
* forbids, validates every host and answers with the policy as written, which the kernel then
|
|
60
61
|
* keeps on the active machine's row (§5.4).
|
|
@@ -123,7 +124,7 @@ let DevicePolicyService = class DevicePolicyService {
|
|
|
123
124
|
throw new Error("DevicePolicyService.begin() must not run inside a transaction: the intent is recorded " +
|
|
124
125
|
"first, the policy op sent, then the outcome recorded in a transaction.");
|
|
125
126
|
}
|
|
126
|
-
assertHosts(input.change
|
|
127
|
+
assertHosts(input.change);
|
|
127
128
|
const device = await this.db
|
|
128
129
|
.selectFrom("devices as e")
|
|
129
130
|
.innerJoin("orgs as o", "o.id", "e.org_id")
|
|
@@ -157,14 +158,14 @@ let DevicePolicyService = class DevicePolicyService {
|
|
|
157
158
|
throw e;
|
|
158
159
|
return { outcome: offline() };
|
|
159
160
|
}
|
|
160
|
-
const change =
|
|
161
|
+
const change = wireChange(input.change);
|
|
161
162
|
// B2: an owner-ceiling narrowing needs a program that reports authenticated owner facts over
|
|
162
|
-
// a staged connection
|
|
163
|
+
// a staged connection
|
|
163
164
|
if (change.ownerCeiling !== undefined) {
|
|
164
165
|
const row = connection
|
|
165
166
|
? await this.db
|
|
166
167
|
.selectFrom("device_machines")
|
|
167
|
-
.select(["owner_report"
|
|
168
|
+
.select(["owner_report"])
|
|
168
169
|
.where("id", "=", machine.id)
|
|
169
170
|
.executeTakeFirst()
|
|
170
171
|
: undefined;
|
|
@@ -402,8 +403,6 @@ let DevicePolicyService = class DevicePolicyService {
|
|
|
402
403
|
}
|
|
403
404
|
const live = row.revoked_at === null;
|
|
404
405
|
const policy = result.outcome === "applied" ? result.policy : undefined;
|
|
405
|
-
const modeBefore = localPolicyOf(row.local_policy)?.mode ?? null;
|
|
406
|
-
const modeNow = policy !== undefined && live && policy.mode !== modeBefore ? policy.mode : undefined;
|
|
407
406
|
await this.db
|
|
408
407
|
.updateTable("device_machines")
|
|
409
408
|
.set({
|
|
@@ -417,22 +416,15 @@ let DevicePolicyService = class DevicePolicyService {
|
|
|
417
416
|
policy !== undefined &&
|
|
418
417
|
live &&
|
|
419
418
|
JSON.stringify(policy) !== JSON.stringify(localPolicyOf(row.local_policy)))
|
|
420
|
-
await this.ceilings.publishLocked({ orgId: row.org_id, deviceId: row.device_id }, "device", (scope, intent) => ownerPolicyRevokes(policy, scope, intent.method, intent.granted_hosts),
|
|
419
|
+
await this.ceilings.publishLocked({ orgId: row.org_id, deviceId: row.device_id }, "device", (scope, intent) => ownerPolicyRevokes(policy, scope, intent.method, intent.granted_hosts), false);
|
|
421
420
|
if (result.outcome === "applied") {
|
|
422
|
-
if (op.
|
|
421
|
+
if (op.remove.length > 0) {
|
|
423
422
|
await auditOp("device.policy_changed", {
|
|
424
423
|
...(op.status === "unknown" && { late: true }),
|
|
425
424
|
});
|
|
426
425
|
}
|
|
427
|
-
//
|
|
428
|
-
// (`device.owner_ceiling_changed`)
|
|
429
|
-
if (modeNow !== undefined && !v3Report) {
|
|
430
|
-
await auditOp("device.mode_changed", {
|
|
431
|
-
from: modeBefore,
|
|
432
|
-
to: modeNow,
|
|
433
|
-
...(op.status === "unknown" && { late: true }),
|
|
434
|
-
});
|
|
435
|
-
}
|
|
426
|
+
// the owner ceiling's change is the owner report's, audited once by its writer
|
|
427
|
+
// (`device.owner_ceiling_changed`)
|
|
436
428
|
const stored = policy ?? (await this.machines.activeFor(row.device_id))?.localPolicy;
|
|
437
429
|
return stored
|
|
438
430
|
? { applied: true, policy: stored }
|
|
@@ -503,15 +495,9 @@ let DevicePolicyService = class DevicePolicyService {
|
|
|
503
495
|
const { change, source } = input;
|
|
504
496
|
const op = {
|
|
505
497
|
id: input.opId,
|
|
506
|
-
add: change.add ?? [],
|
|
507
498
|
remove: change.remove ?? [],
|
|
508
|
-
...(change.mode !== undefined && { mode: change.mode }),
|
|
509
499
|
...(change.ownerCeiling !== undefined && { ownerCeiling: change.ownerCeiling }),
|
|
510
|
-
source: {
|
|
511
|
-
accountId: source.accountId,
|
|
512
|
-
via: source.via,
|
|
513
|
-
approvalId: source.approvalId ?? null,
|
|
514
|
-
},
|
|
500
|
+
source: { accountId: source.accountId, via: source.via },
|
|
515
501
|
...(input.actorTokenId !== undefined && { actorTokenId: input.actorTokenId }),
|
|
516
502
|
status: "sent",
|
|
517
503
|
sentAt: now,
|
|
@@ -576,22 +562,13 @@ DevicePolicyService = __decorate([
|
|
|
576
562
|
], DevicePolicyService);
|
|
577
563
|
export { DevicePolicyService };
|
|
578
564
|
/**
|
|
579
|
-
* A change as
|
|
580
|
-
*
|
|
581
|
-
* it stands for; the protocol 3 machine keeps its owner ceiling, not a daily mode. Never wider:
|
|
582
|
-
* only `false` / `workspace` can come out of it (the frame parser refuses anything else).
|
|
565
|
+
* A change as the machine takes it (protocol 4): the hosts to remove and the owner-ceiling
|
|
566
|
+
* narrowing. Never wider: only narrowings come out of it (the frame parser refuses anything else).
|
|
583
567
|
*/
|
|
584
|
-
function
|
|
585
|
-
if (change.mode !== "sandbox")
|
|
586
|
-
return change;
|
|
587
|
-
const { mode: _narrowed, ...rest } = change;
|
|
568
|
+
function wireChange(change) {
|
|
588
569
|
return {
|
|
589
|
-
...
|
|
590
|
-
ownerCeiling:
|
|
591
|
-
...change.ownerCeiling,
|
|
592
|
-
fullAccess: false,
|
|
593
|
-
restrictedProjectReach: "workspace",
|
|
594
|
-
},
|
|
570
|
+
...(change.remove !== undefined && { remove: change.remove }),
|
|
571
|
+
...(change.ownerCeiling !== undefined && { ownerCeiling: change.ownerCeiling }),
|
|
595
572
|
};
|
|
596
573
|
}
|
|
597
574
|
const offline = () => ({
|
|
@@ -604,17 +581,9 @@ const unsupported = () => ({
|
|
|
604
581
|
reason: "unsupported",
|
|
605
582
|
message: UNSUPPORTED_MESSAGE,
|
|
606
583
|
});
|
|
607
|
-
/** The audit detail of an op's change and source (every `device.policy_*`
|
|
584
|
+
/** The audit detail of an op's change and source (every `device.policy_*` row). */
|
|
608
585
|
function changeDetail(op) {
|
|
609
|
-
return {
|
|
610
|
-
opId: op.id,
|
|
611
|
-
add: op.add,
|
|
612
|
-
remove: op.remove,
|
|
613
|
-
...(op.mode !== undefined && { mode: op.mode }),
|
|
614
|
-
by: op.source.accountId,
|
|
615
|
-
via: op.source.via,
|
|
616
|
-
approvalId: op.source.approvalId,
|
|
617
|
-
};
|
|
586
|
+
return { opId: op.id, remove: op.remove, by: op.source.accountId, via: op.source.via };
|
|
618
587
|
}
|
|
619
588
|
/** The machine's pending ops with the fields `patch` merged into the op `opId`. */
|
|
620
589
|
const withOp = (opId, patch) => sql `(
|
|
@@ -626,18 +595,9 @@ const withoutOp = (opId) => sql `(
|
|
|
626
595
|
SELECT coalesce(jsonb_agg(e), '[]'::jsonb) FROM jsonb_array_elements(pending_policy_ops) e
|
|
627
596
|
WHERE e->>'id' <> ${opId}
|
|
628
597
|
)`;
|
|
629
|
-
/**
|
|
630
|
-
|
|
631
|
-
* wildcard); the owner's own change on the device page (no approval) may add a wildcard (spec §7);
|
|
632
|
-
* `remove` takes any valid entry (narrowing, a wildcard too).
|
|
633
|
-
*/
|
|
634
|
-
function assertHosts(change, fromApproval) {
|
|
598
|
+
/** Hosts the platform may send: `remove` takes any valid entry (narrowing, a wildcard too). */
|
|
599
|
+
function assertHosts(change) {
|
|
635
600
|
const bad = (h) => typeof h !== "string" || validateAllowHost(h).length > 0;
|
|
636
|
-
for (const h of change.add ?? []) {
|
|
637
|
-
if (bad(h) || (fromApproval && h.startsWith("*."))) {
|
|
638
|
-
throw new Error(`not an exact host to add to a device policy: ${JSON.stringify(h)}`);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
601
|
for (const h of change.remove ?? []) {
|
|
642
602
|
if (bad(h))
|
|
643
603
|
throw new Error(`not a host to remove from a device policy: ${JSON.stringify(h)}`);
|
|
@@ -26,7 +26,9 @@ export declare function isWebSocketUpgrade(req: FastifyRequest): boolean;
|
|
|
26
26
|
* `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
|
|
27
27
|
* CSRF check applies; the route checks the machine credential itself, before the upgrade (401
|
|
28
28
|
* `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
|
|
29
|
-
* {@link DEVICE_PROTOCOL_VERSION} (
|
|
29
|
+
* {@link DEVICE_PROTOCOL_VERSION} (4) is served; an older program (protocol 3 among them) must
|
|
30
|
+
* update. A newer program reads the kernel's protocol in the message and asks for the deployment
|
|
31
|
+
* to be upgraded instead.
|
|
30
32
|
* Must be called before Nest `app.init()`, on the root instance.
|
|
31
33
|
*
|
|
32
34
|
* `@fastify/websocket` sends every upgrade request of the server through the Fastify router; the
|
|
@@ -37,7 +37,9 @@ function bearer(req) {
|
|
|
37
37
|
* `@fastify/websocket`: a raw Fastify route outside Nest, so neither the API's `AuthGuard` nor its
|
|
38
38
|
* CSRF check applies; the route checks the machine credential itself, before the upgrade (401
|
|
39
39
|
* `device.credential_invalid`), then the protocol header (426 `device.program_outdated`): only
|
|
40
|
-
* {@link DEVICE_PROTOCOL_VERSION} (
|
|
40
|
+
* {@link DEVICE_PROTOCOL_VERSION} (4) is served; an older program (protocol 3 among them) must
|
|
41
|
+
* update. A newer program reads the kernel's protocol in the message and asks for the deployment
|
|
42
|
+
* to be upgraded instead.
|
|
41
43
|
* Must be called before Nest `app.init()`, on the root instance.
|
|
42
44
|
*
|
|
43
45
|
* `@fastify/websocket` sends every upgrade request of the server through the Fastify router; the
|
|
@@ -71,11 +73,20 @@ export async function registerDeviceConnectRoute(fastify, opts) {
|
|
|
71
73
|
.code(401)
|
|
72
74
|
.send(errorBody("device.credential_invalid", "The machine credential is unknown or revoked. Run capybara-device logout, then capybara-device login."));
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
const spoken = req.headers[DEVICE_PROTOCOL_HEADER];
|
|
77
|
+
if (spoken !== String(DEVICE_PROTOCOL_VERSION)) {
|
|
78
|
+
// the program's own protocol, named only when it is a plain number (header input)
|
|
79
|
+
const number = typeof spoken === "string" && /^[0-9]{1,3}$/.test(spoken) ? Number(spoken) : null;
|
|
80
|
+
const theirs = number !== null
|
|
81
|
+
? `this capybara-device protocol ${number}`
|
|
82
|
+
: "this capybara-device an older protocol";
|
|
83
|
+
// a newer program than this deployment: the deployment is the one to upgrade
|
|
84
|
+
const fix = number !== null && number > DEVICE_PROTOCOL_VERSION
|
|
85
|
+
? "This deployment is older than the program; ask the platform's super admin to upgrade Capybara, or install the capybara-device release that matches this deployment."
|
|
86
|
+
: "Update capybara-device on the machine (npm install -g @capybara-hq/device@next), then start it again.";
|
|
75
87
|
return reply
|
|
76
88
|
.code(426)
|
|
77
|
-
.send(errorBody("device.program_outdated", `This kernel speaks device protocol ${DEVICE_PROTOCOL_VERSION}. `
|
|
78
|
-
"Update capybara-device."));
|
|
89
|
+
.send(errorBody("device.program_outdated", `This kernel speaks device protocol ${DEVICE_PROTOCOL_VERSION}, ${theirs}. ${fix}`));
|
|
79
90
|
}
|
|
80
91
|
credentials.set(req, cred);
|
|
81
92
|
},
|
|
@@ -114,9 +114,11 @@ let LocalInstanceBindings = class LocalInstanceBindings {
|
|
|
114
114
|
if (availability.state === "supported")
|
|
115
115
|
return availability.report;
|
|
116
116
|
return {
|
|
117
|
-
version:
|
|
117
|
+
version: 2,
|
|
118
|
+
boundary: "operation",
|
|
118
119
|
restricted: null,
|
|
119
|
-
|
|
120
|
+
network: { openPublic: false, allowlist: false, perOperationHosts: false },
|
|
121
|
+
outsideSandbox: false,
|
|
120
122
|
background: false,
|
|
121
123
|
unavailableReason: availability.state === "unsupported"
|
|
122
124
|
? availability.reason
|
|
@@ -277,6 +279,7 @@ let LocalInstanceBindings = class LocalInstanceBindings {
|
|
|
277
279
|
machine_id: machineId,
|
|
278
280
|
runtime_identity: JSON.stringify(identity),
|
|
279
281
|
installed_at: sql `now()`,
|
|
282
|
+
installed_connection_id: connectionId,
|
|
280
283
|
})
|
|
281
284
|
.where("device_id", "=", deviceId)
|
|
282
285
|
.where("instance_generation", "=", request.instanceGeneration)
|
|
@@ -131,8 +131,8 @@ export declare class LocalDeviceGateway {
|
|
|
131
131
|
/** Who a `Bearer` machine credential stands for, or null (checked before the upgrade). */
|
|
132
132
|
authenticate(credential: string): Promise<MachineIdentity | null>;
|
|
133
133
|
/**
|
|
134
|
-
* Serves one upgraded socket of a machine until it closes (protocol
|
|
135
|
-
* other header with 426, and a hello that is not protocol
|
|
134
|
+
* Serves one upgraded socket of a machine until it closes (protocol 4 only: the route refused any
|
|
135
|
+
* other header with 426, and a hello that is not protocol 4 closes 4400). The credential is
|
|
136
136
|
* checked again here, with the socket paused, so a credential revoked since the upgrade check
|
|
137
137
|
* never gets a connection.
|
|
138
138
|
*/
|
|
@@ -178,7 +178,7 @@ class DeviceConnection {
|
|
|
178
178
|
async onFrame(text) {
|
|
179
179
|
let frame;
|
|
180
180
|
try {
|
|
181
|
-
// protocol
|
|
181
|
+
// protocol 4 only: an older hello (or any frame that is not protocol 4, such as a hello
|
|
182
182
|
// whose protocol differs from the upgrade header's) fails the strict parse and closes 4400
|
|
183
183
|
frame = parseDeviceFrame(text, "device", this.effectiveCap ?? this.gw.maxFrameBytes());
|
|
184
184
|
if (this.effectiveCap !== undefined && this.gw.maxFrameBytes() < this.effectiveCap)
|
|
@@ -634,8 +634,8 @@ let LocalDeviceGateway = class LocalDeviceGateway {
|
|
|
634
634
|
return this.machines.authenticate(credential);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
|
-
* Serves one upgraded socket of a machine until it closes (protocol
|
|
638
|
-
* other header with 426, and a hello that is not protocol
|
|
637
|
+
* Serves one upgraded socket of a machine until it closes (protocol 4 only: the route refused any
|
|
638
|
+
* other header with 426, and a hello that is not protocol 4 closes 4400). The credential is
|
|
639
639
|
* checked again here, with the socket paused, so a credential revoked since the upgrade check
|
|
640
640
|
* never gets a connection.
|
|
641
641
|
*/
|
|
@@ -18,7 +18,7 @@ export declare const FRAME_ENVELOPE_BYTES: number;
|
|
|
18
18
|
export { projectsUnsupported } from "../devices/errors.js";
|
|
19
19
|
/** The most raw bytes whose base64 plus {@link FRAME_ENVELOPE_BYTES} fit in `maxFrameBytes`. */
|
|
20
20
|
export declare const maxReadBytes: (maxFrameBytes: number) => number;
|
|
21
|
-
/** What the staged provider sends through: the relay's protocol
|
|
21
|
+
/** What the staged provider sends through: the relay's protocol 4 call and the attested support. */
|
|
22
22
|
export interface StagedDeviceTransport {
|
|
23
23
|
call(deviceId: string, op: DeviceOperation, args: Record<string, unknown>, opts: {
|
|
24
24
|
deadlineMs: number;
|
|
@@ -60,12 +60,12 @@ export declare class LocalDeviceProvider implements SandboxProvider {
|
|
|
60
60
|
private readonly callGrants?;
|
|
61
61
|
readonly concurrentExec: true;
|
|
62
62
|
readonly sessionIsolation = false;
|
|
63
|
-
constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits">, config: Pick<KernelConfigService, "get">, callGrants?: PermissionCallGrants | undefined);
|
|
63
|
+
constructor(relay: LocalDeviceRelay, targets: Pick<DeviceTargets, "orgOf" | "machineRoots">, sandbox: Pick<SandboxService, "devicePolicy" | "deviceLimits" | "hostGrantCeiling">, config: Pick<KernelConfigService, "get">, callGrants?: PermissionCallGrants | undefined);
|
|
64
64
|
/**
|
|
65
|
-
* The `@local` provider as the staged (protocol
|
|
65
|
+
* The `@local` provider as the staged (protocol 4) registration hands it out
|
|
66
66
|
* (`LocalDevicesModule`): the protocol 2 lifecycle methods that send no frame (file system,
|
|
67
67
|
* resume, suspend, destroy), the v3 operation adapter ({@link stagedOperations}), `create` as a
|
|
68
|
-
* protocol
|
|
68
|
+
* protocol 4 request, no raw protocol 2 call and no broad kill. Dormant until the protocol gate
|
|
69
69
|
* selects it.
|
|
70
70
|
*
|
|
71
71
|
* The raw methods (`exec`, `readFile`, `writeFile`, `stat`, `list`, `scan`) refuse before
|
|
@@ -10,9 +10,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { parseDeviceFrame, parseOperationResult, parseSandboxBrowseScope, parseSandboxOperationScope, parseSandboxPreparationScope, SandboxPermissionUnsupportedError, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
12
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
13
|
+
import { hostGrantable } from "../sandbox/device-sandbox.js";
|
|
14
|
+
import { providerLimits } from "../sandbox/modes.js";
|
|
13
15
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
14
16
|
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
15
|
-
import {
|
|
17
|
+
import { relayer } from "./network-grants.js";
|
|
16
18
|
import { deviceOffline, LocalDeviceRelay } from "./relay.js";
|
|
17
19
|
import { DeviceTargets, sameRoots } from "./targets.js";
|
|
18
20
|
/** Extra time the machine gets beyond a command's own timeout (spawn, output, the trip back). */
|
|
@@ -34,7 +36,7 @@ const NAME_PREFIX = "cap-device-";
|
|
|
34
36
|
* an admitted operation scope; there is no raw fallback).
|
|
35
37
|
*/
|
|
36
38
|
const refuseRaw = (method) => async (..._args) => {
|
|
37
|
-
throw new SandboxPermissionUnsupportedError(`${method} without an operation scope is not available on a protocol
|
|
39
|
+
throw new SandboxPermissionUnsupportedError(`${method} without an operation scope is not available on a protocol 4 device; run it through an admitted operation scope`);
|
|
38
40
|
};
|
|
39
41
|
/** The device id of a `cap-device-<deviceId>` name; undefined for any other name. */
|
|
40
42
|
export const deviceIdOfName = (name) => name.startsWith(NAME_PREFIX) && name.length > NAME_PREFIX.length
|
|
@@ -68,10 +70,10 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
68
70
|
this.callGrants = callGrants;
|
|
69
71
|
}
|
|
70
72
|
/**
|
|
71
|
-
* The `@local` provider as the staged (protocol
|
|
73
|
+
* The `@local` provider as the staged (protocol 4) registration hands it out
|
|
72
74
|
* (`LocalDevicesModule`): the protocol 2 lifecycle methods that send no frame (file system,
|
|
73
75
|
* resume, suspend, destroy), the v3 operation adapter ({@link stagedOperations}), `create` as a
|
|
74
|
-
* protocol
|
|
76
|
+
* protocol 4 request, no raw protocol 2 call and no broad kill. Dormant until the protocol gate
|
|
75
77
|
* selects it.
|
|
76
78
|
*
|
|
77
79
|
* The raw methods (`exec`, `readFile`, `writeFile`, `stat`, `list`, `scan`) refuse before
|
|
@@ -135,10 +137,22 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
135
137
|
if (!this.callGrants)
|
|
136
138
|
throw new Error("Admitted execution authority is unavailable; check the device operation configuration");
|
|
137
139
|
const original = await this.callGrants.forExecution(scope.operationId, deviceId, method, scope, input);
|
|
138
|
-
|
|
140
|
+
// explicit hosts are checked against the per-call host ceiling (the org's hard allowlist
|
|
141
|
+
// ceiling and exclusions, the owner's list), never against the sandbox's own allowlist
|
|
142
|
+
const ceiling = await this.sandbox.hostGrantCeiling({ orgId, deviceId });
|
|
143
|
+
const ceilingNetwork = ceiling.kind === "any"
|
|
144
|
+
? { kind: "open-public", hosts: [] }
|
|
145
|
+
: { kind: "allowlist", hosts: [...ceiling.hosts] };
|
|
146
|
+
const kept = original?.hosts.filter((host) => hostGrantable(ceiling, host)) ?? [];
|
|
147
|
+
const grants = original && kept.length ? { ...original, hosts: kept } : undefined;
|
|
139
148
|
if (original?.hosts.some((host) => !grants?.hosts.includes(host)))
|
|
140
149
|
throw new Error("Current organization limits refuse the admitted explicit hosts; review the operation again");
|
|
141
|
-
|
|
150
|
+
// the wire carries resources and the device sandbox network only: the mode tier is
|
|
151
|
+
// kernel-internal
|
|
152
|
+
return {
|
|
153
|
+
wire: { limits: providerLimits(limits), ...(grants === undefined ? {} : { grants }) },
|
|
154
|
+
ceiling: { network: ceilingNetwork },
|
|
155
|
+
};
|
|
142
156
|
};
|
|
143
157
|
const background = {
|
|
144
158
|
start: async (h, input, args) => {
|
|
@@ -147,7 +161,7 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
147
161
|
const { signal, instanceGeneration: _generation, ...rest } = args;
|
|
148
162
|
const authority = await execArgs(h.id, scope, "backgroundStart", rest);
|
|
149
163
|
signal.throwIfAborted();
|
|
150
|
-
return parseOperationResult("backgroundStart", await transport.call(h.id, "backgroundStart", { scope, ...rest, ...authority }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal }));
|
|
164
|
+
return parseOperationResult("backgroundStart", await transport.call(h.id, "backgroundStart", { scope, ...rest, ...authority.wire }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal }));
|
|
151
165
|
},
|
|
152
166
|
status: async (h, ref, signal) => parseOperationResult("backgroundStatus", await transport.call(h.id, "backgroundStatus", { ref }, { deadlineMs: OP_DEADLINE_MS, signal })),
|
|
153
167
|
readOutput: async (h, ref, opts) => {
|
|
@@ -198,14 +212,14 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
198
212
|
const authority = await execArgs(h.id, scope, "exec", rest);
|
|
199
213
|
const combined = AbortSignal.any([signal, callSignal]);
|
|
200
214
|
combined.throwIfAborted();
|
|
201
|
-
const result = parseOperationResult("exec", await transport.call(h.id, "exec", { scope, ...rest, ...authority }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal: combined }));
|
|
215
|
+
const result = parseOperationResult("exec", await transport.call(h.id, "exec", { scope, ...rest, ...authority.wire }, { deadlineMs: args.timeoutMs + EXEC_DEADLINE_MARGIN_MS, signal: combined }));
|
|
202
216
|
// the kernel's own layer for the machine's report, as on protocol 2: a host the org
|
|
203
217
|
// does not allow is `org` (only an admin can lift it), never a question to the owner
|
|
204
218
|
if (result.network?.blocked === undefined)
|
|
205
219
|
return result;
|
|
206
220
|
return {
|
|
207
221
|
...result,
|
|
208
|
-
network: { blocked: relayer(result.network.blocked, authority.
|
|
222
|
+
network: { blocked: relayer(result.network.blocked, authority.ceiling) },
|
|
209
223
|
};
|
|
210
224
|
},
|
|
211
225
|
};
|
|
@@ -20,7 +20,7 @@ export declare class LocalDevicesModule implements OnModuleInit {
|
|
|
20
20
|
onModuleInit(): void;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* The `@local` registration: the protocol
|
|
23
|
+
* The `@local` registration: the protocol 4 provider ({@link LocalDeviceProvider.staged}: scoped
|
|
24
24
|
* operations, no broad kill) with its instance binder, which binds every committed generation
|
|
25
25
|
* before shared use (B-8).
|
|
26
26
|
*/
|
|
@@ -82,7 +82,7 @@ LocalDevicesModule = __decorate([
|
|
|
82
82
|
], LocalDevicesModule);
|
|
83
83
|
export { LocalDevicesModule };
|
|
84
84
|
/**
|
|
85
|
-
* The `@local` registration: the protocol
|
|
85
|
+
* The `@local` registration: the protocol 4 provider ({@link LocalDeviceProvider.staged}: scoped
|
|
86
86
|
* operations, no broad kill) with its instance binder, which binds every committed generation
|
|
87
87
|
* before shared use (B-8).
|
|
88
88
|
*/
|
|
@@ -94,14 +94,14 @@ export declare class MachinesService {
|
|
|
94
94
|
* never said hello has no known roots: nothing to compare. The reported features (known ones
|
|
95
95
|
* only) and local policy summary (null when absent or malformed) replace the stored ones, so a
|
|
96
96
|
* program downgraded to one without them is no longer sent what it cannot do. The summary is the
|
|
97
|
-
* device's
|
|
98
|
-
*
|
|
97
|
+
* device's sandbox allowlist; a change of what the owner sets, made on the machine while it was
|
|
98
|
+
* away, is audited `device.policy_changed` (the owner ceiling's, `device.owner_ceiling_changed`)
|
|
99
99
|
* ({@link reportedPolicy}). The outcomes of its recent policy ops (`recentOps`) backfill the
|
|
100
100
|
* platform's ops still pending on the row ({@link backfillOps}). The owner's home directory
|
|
101
101
|
* (`home`) replaces the stored one too (null when the hello has none).
|
|
102
102
|
*/
|
|
103
|
-
recordHello(machineId: string, hello: LegacyDeviceHello,
|
|
104
|
-
/** A
|
|
103
|
+
recordHello(machineId: string, hello: LegacyDeviceHello,
|
|
104
|
+
/** A protocol 4 hello's authenticated owner report (B2): it, not the summary, decides publication. */
|
|
105
105
|
owner?: {
|
|
106
106
|
report: DeviceOwnerCeiling;
|
|
107
107
|
connectionId: string | null;
|
|
@@ -118,26 +118,50 @@ export declare class MachinesService {
|
|
|
118
118
|
* transaction, with the machine's row locked; an op already reported is not owed again.
|
|
119
119
|
*/
|
|
120
120
|
private backfillOps;
|
|
121
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* A protocol 4 hello on an authenticated connection: validated as a frame, then recorded like
|
|
123
|
+
* {@link recordHello} with its owner report and the connection it arrived on.
|
|
124
|
+
*/
|
|
122
125
|
recordHelloV3(machineId: string, hello: DeviceHello, connectionId?: string | null): Promise<void>;
|
|
123
126
|
/**
|
|
124
127
|
* The runtime identity a v3 hello may attest (B4): only a bound hello re-reporting exactly the
|
|
125
128
|
* identity of the current instance generation's installed binding. An unbound hello, another
|
|
126
129
|
* generation or a binding still awaiting the device attests nothing (unprobed; it never finishes
|
|
127
|
-
* an installation, which only the bindInstance answer does).
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
+
* an installation, which only the bindInstance answer does).
|
|
131
|
+
*
|
|
132
|
+
* The machine the current generation was installed for no longer attesting it means its program
|
|
133
|
+
* can never serve that generation again: a restarted program whose verified runtime differs from
|
|
134
|
+
* the one its stored binding attested (every capybara-device upgrade changes the runtime bytes)
|
|
135
|
+
* starts unbound, and the device refuses to rebind a generation under a changed runtime. The
|
|
136
|
+
* instance is then replaced ({@link replaceUnattestedLocked}), so the next use creates and binds
|
|
137
|
+
* a new generation under the new evidence instead of staying unprobed until a new login.
|
|
138
|
+
*
|
|
139
|
+
* A connection answers bindInstance before its own hello is recorded (the hello is recorded
|
|
140
|
+
* after `ready`), so a binding installed on the hello's own connection is newer than the hello:
|
|
141
|
+
* it is left as it is (`installed-here`), never replaced by the evidence the hello predates.
|
|
130
142
|
*/
|
|
131
143
|
private boundIdentityLocked;
|
|
144
|
+
/**
|
|
145
|
+
* Replaces a local instance whose installed binding its machine no longer attests (under the
|
|
146
|
+
* device authority writer): the row forgets its instance (status `none`, no handle) and its
|
|
147
|
+
* fence moves on, so a lifecycle holder of the old instance fails its next write; the device's
|
|
148
|
+
* admission epoch advances, revoking every admitted or started operation of the old generation.
|
|
149
|
+
* The files stay (the same machine and directory): the next use creates a new instance on them,
|
|
150
|
+
* which the kernel binds under the program's new runtime evidence. Full consent is left to that
|
|
151
|
+
* install, which resets it when the proven environment fingerprint changed: a fingerprint a
|
|
152
|
+
* hello merely names proves nothing, and nothing is admitted before the install records a
|
|
153
|
+
* report, so resetting here too would reset twice.
|
|
154
|
+
*/
|
|
155
|
+
private replaceUnattestedLocked;
|
|
132
156
|
/**
|
|
133
157
|
* Stores the local policy summary a connected program pushed after its hello (a `policy` frame:
|
|
134
|
-
* its policy file changed on the machine: its
|
|
135
|
-
*
|
|
136
|
-
*
|
|
158
|
+
* its policy file changed on the machine: its sandbox allowlist), read and audited as the hello's
|
|
159
|
+
* ({@link recordHello}). A change the owner made on the machine is audited
|
|
160
|
+
* `device.policy_changed`. The next sandbox call then records a
|
|
137
161
|
* new `device_paths` event when the facts the model is told changed. A revoked machine is left
|
|
138
162
|
* alone.
|
|
139
163
|
*/
|
|
140
|
-
recordPolicy(machineId: string, summary: DeviceLocalPolicySummary | undefined
|
|
164
|
+
recordPolicy(machineId: string, summary: DeviceLocalPolicySummary | undefined): Promise<void>;
|
|
141
165
|
/**
|
|
142
166
|
* A staged (v3) `policy` frame (B2): the summary is kept for the device page like protocol 2's,
|
|
143
167
|
* while the authenticated owner report alone decides what changed ({@link OwnerReports}).
|
|
@@ -148,10 +172,10 @@ export declare class MachinesService {
|
|
|
148
172
|
* null. When both the stored and the reported summary are readable and what the owner sets
|
|
149
173
|
* changed ({@link localPolicyDiff}) by no `policy` op the platform sent ({@link opExplains}: its
|
|
150
174
|
* answer may come after the machine's own report), the owner changed it on the machine
|
|
151
|
-
* (`capybara-device
|
|
152
|
-
* `device.policy_changed
|
|
153
|
-
*
|
|
154
|
-
* (the op's answer is). A summary reported again is no change. Runs in the caller's transaction,
|
|
175
|
+
* (`capybara-device policy add|remove allowedDomains ...`): the host changes are audited
|
|
176
|
+
* `device.policy_changed`, `via: "device"`, so the device page lists them beside the platform's
|
|
177
|
+
* changes (an owner ceiling change is the owner report writer's, `device.owner_ceiling_changed`);
|
|
178
|
+
* one an op explains is not audited here (the op's answer is). A summary reported again is no change. Runs in the caller's transaction,
|
|
155
179
|
* with the machine's row locked.
|
|
156
180
|
*/
|
|
157
181
|
private reportedPolicy;
|