@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69
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/bootstrap.json +9 -1
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/credential-key.d.ts +10 -0
- package/dist/catalog/credential-key.js +28 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -19
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/connectors.controller.d.ts +2 -0
- package/dist/tools/connectors.schemas.d.ts +2 -0
- package/dist/tools/credentials.d.ts +2 -0
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/oauth/authorization-params.d.ts +7 -0
- package/dist/tools/oauth/authorization-params.js +19 -0
- package/dist/tools/oauth/flow.js +7 -0
- package/dist/tools/oauth/tokens.js +2 -1
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
package/dist/sandbox/modes.js
CHANGED
|
@@ -44,17 +44,6 @@ export async function readDeploymentDevicePolicy(db, config) {
|
|
|
44
44
|
const settings = await readDeviceSandboxSettings(db, config);
|
|
45
45
|
return { fullAccess: settings.outsideSandbox, limits: config.get().sandbox.limits };
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
* How far restricted work may root outside the workspace now (B2), the one rule the command
|
|
49
|
-
* review (`DevicesService.projectReach`) and admission's working root both read: a local device
|
|
50
|
-
* follows its owner's reported reach within a device ceiling that allows auto; a cloud device
|
|
51
|
-
* reaches beyond its workspace only in auto mode.
|
|
52
|
-
*/
|
|
53
|
-
export function projectReachOf(source, policy, ownerReach) {
|
|
54
|
-
if (source !== "local")
|
|
55
|
-
return policy.mode === "auto" ? "os-user" : "workspace";
|
|
56
|
-
return policy.allowedMode === "auto" && ownerReach === "os-user" ? "os-user" : "workspace";
|
|
57
|
-
}
|
|
58
47
|
/** The mode the platform and the org allow: `auto` only when neither turns it off. */
|
|
59
48
|
export function allowedDeviceMode(platform, org) {
|
|
60
49
|
return platform === "allowed" && org !== "off" ? "auto" : "sandbox";
|
|
@@ -81,9 +70,8 @@ export function deviceNetwork(deployment, org, mode) {
|
|
|
81
70
|
return { kind: "allowlist", hosts: orgAllowedDomains(deployment, org) };
|
|
82
71
|
}
|
|
83
72
|
/**
|
|
84
|
-
* The effective device policy. `deviceMode` is the device's owner ceiling (
|
|
85
|
-
*
|
|
86
|
-
* org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
73
|
+
* The effective device policy. `deviceMode` is the device's owner ceiling (its B1 snapshot or
|
|
74
|
+
* narrowing switch; null = follow the platform and the org). A stored mode the platform or org forbids is cut, never honoured; the network follows the
|
|
87
75
|
* resulting mode.
|
|
88
76
|
*/
|
|
89
77
|
export function effectiveDevicePolicy(deployment, org, deviceMode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SandboxLimits } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { DeviceExecGrants } from "@capybara-hq/plugin-sdk/device-protocol";
|
|
2
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import { type SandboxMode } from "../sandbox/modes.js";
|
|
4
4
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
5
5
|
export declare const MAX_GRANT_HOSTS = 100;
|
|
6
6
|
/** What a run tree's network asks add up to (network ask-to-allow spec §6.8). */
|
|
@@ -62,27 +62,8 @@ export declare class NetworkGrants {
|
|
|
62
62
|
* approves domains for their own devices only). Exact valid hosts only.
|
|
63
63
|
*/
|
|
64
64
|
private taskGrants;
|
|
65
|
-
/**
|
|
66
|
-
* The mode a local device's connected machine runs, read fresh at each exec: null when no machine
|
|
67
|
-
* is connected, else {@link localModeOf} (a program without the `mode` feature is `sandbox`
|
|
68
|
-
* unless its legacy summary said it ran unsandboxed, i.e. `auto`).
|
|
69
|
-
*/
|
|
70
|
-
reportedMode(deviceId: string): Promise<SandboxMode | null>;
|
|
71
65
|
/** The runs of the tree whose budget run is `root`. */
|
|
72
66
|
private treeOf;
|
|
73
67
|
}
|
|
74
68
|
/** Whether the org's sandbox-mode network lets a command reach `host`. */
|
|
75
69
|
export declare function orgAllows(host: string, limits: Pick<SandboxLimits, "network">): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* The kernel's own layer for a device's report (auto mode spec §4.2): it trusts the device's word
|
|
78
|
-
* that a host was refused, never its word that the org allows it. A host the device calls `device`
|
|
79
|
-
* that the org's sandbox network (`limits`, read for this exec) does not allow becomes `org`; one
|
|
80
|
-
* that is no valid host name becomes `address`. Other layers are kept.
|
|
81
|
-
*/
|
|
82
|
-
export declare function relayer(blocked: NetworkBlockedHost[], limits: Pick<SandboxLimits, "network">): NetworkBlockedHost[];
|
|
83
|
-
/**
|
|
84
|
-
* `grants` cut to the hosts the org's sandbox network (`limits`, read for this exec) admits, or
|
|
85
|
-
* undefined when none is left. The device intersects them with the limits too; the kernel does it
|
|
86
|
-
* first so a grant never reaches a device beyond what the org allows.
|
|
87
|
-
*/
|
|
88
|
-
export declare function grantsWithin(grants: DeviceExecGrants | undefined, limits: Pick<SandboxLimits, "network">): DeviceExecGrants | undefined;
|
|
@@ -7,14 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { validateAllowHost
|
|
10
|
+
import { validateAllowHost } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
14
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
15
|
-
import { coversHost } from "../sandbox/modes.js";
|
|
16
15
|
import { taskGrantsRunOf } from "../schedules/unattended.js";
|
|
17
|
-
import {
|
|
16
|
+
import { coversHost } from "./modes.js";
|
|
18
17
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
19
18
|
export const MAX_GRANT_HOSTS = 100;
|
|
20
19
|
/** The key prefix of a scheduled task's network grant (`schedules/grant-rules.ts`). */
|
|
@@ -197,22 +196,6 @@ let NetworkGrants = class NetworkGrants {
|
|
|
197
196
|
return undefined;
|
|
198
197
|
return { hosts, source: { kind: "task", id: task.taskId, accountId: task.accountId } };
|
|
199
198
|
}
|
|
200
|
-
/**
|
|
201
|
-
* The mode a local device's connected machine runs, read fresh at each exec: null when no machine
|
|
202
|
-
* is connected, else {@link localModeOf} (a program without the `mode` feature is `sandbox`
|
|
203
|
-
* unless its legacy summary said it ran unsandboxed, i.e. `auto`).
|
|
204
|
-
*/
|
|
205
|
-
async reportedMode(deviceId) {
|
|
206
|
-
const row = await this.db
|
|
207
|
-
.selectFrom("device_machines")
|
|
208
|
-
.select(["local_policy", "features", "owner_report"])
|
|
209
|
-
.where("device_id", "=", deviceId)
|
|
210
|
-
.where("revoked_at", "is", null)
|
|
211
|
-
.executeTakeFirst();
|
|
212
|
-
if (row === undefined)
|
|
213
|
-
return null;
|
|
214
|
-
return ownerModeOf(row);
|
|
215
|
-
}
|
|
216
199
|
/** The runs of the tree whose budget run is `root`. */
|
|
217
200
|
treeOf(root) {
|
|
218
201
|
return this.db
|
|
@@ -226,7 +209,7 @@ NetworkGrants = __decorate([
|
|
|
226
209
|
__param(0, Inject(KernelDb))
|
|
227
210
|
], NetworkGrants);
|
|
228
211
|
export { NetworkGrants };
|
|
229
|
-
const
|
|
212
|
+
const normalizeHost = (host) => {
|
|
230
213
|
const h = host.toLowerCase();
|
|
231
214
|
return h.endsWith(".") ? h.slice(0, -1) : h;
|
|
232
215
|
};
|
|
@@ -234,34 +217,6 @@ const normalize = (host) => {
|
|
|
234
217
|
export function orgAllows(host, limits) {
|
|
235
218
|
if (limits.network.kind === "open-public")
|
|
236
219
|
return true;
|
|
237
|
-
const h =
|
|
220
|
+
const h = normalizeHost(host);
|
|
238
221
|
return limits.network.hosts.some((p) => coversHost(p.toLowerCase(), h));
|
|
239
222
|
}
|
|
240
|
-
/**
|
|
241
|
-
* The kernel's own layer for a device's report (auto mode spec §4.2): it trusts the device's word
|
|
242
|
-
* that a host was refused, never its word that the org allows it. A host the device calls `device`
|
|
243
|
-
* that the org's sandbox network (`limits`, read for this exec) does not allow becomes `org`; one
|
|
244
|
-
* that is no valid host name becomes `address`. Other layers are kept.
|
|
245
|
-
*/
|
|
246
|
-
export function relayer(blocked, limits) {
|
|
247
|
-
return blocked.map((b) => {
|
|
248
|
-
if (b.layer !== "device")
|
|
249
|
-
return b;
|
|
250
|
-
const h = normalize(b.host);
|
|
251
|
-
if (validateAllowHost(h).length > 0 || h.startsWith("*.")) {
|
|
252
|
-
return { ...b, layer: "address" };
|
|
253
|
-
}
|
|
254
|
-
return orgAllows(b.host, limits) ? b : { ...b, layer: "org" };
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* `grants` cut to the hosts the org's sandbox network (`limits`, read for this exec) admits, or
|
|
259
|
-
* undefined when none is left. The device intersects them with the limits too; the kernel does it
|
|
260
|
-
* first so a grant never reaches a device beyond what the org allows.
|
|
261
|
-
*/
|
|
262
|
-
export function grantsWithin(grants, limits) {
|
|
263
|
-
if (grants === undefined)
|
|
264
|
-
return undefined;
|
|
265
|
-
const hosts = grants.hosts.filter((h) => orgAllows(h, limits));
|
|
266
|
-
return hosts.length === 0 ? undefined : { ...grants, hosts };
|
|
267
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SandboxBrowseScope, type SandboxOperationScope, SandboxScopeDeniedError } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { DeviceExecGrants } from "@capybara-hq/plugin-sdk/device-protocol";
|
|
2
3
|
/**
|
|
3
4
|
* A call that asked to run outside the sandbox (`sandbox: "escalated"`) whose escalation grant no
|
|
4
5
|
* longer matches at admission: the device, its outside-sandbox setting or the permission scope
|
|
@@ -3,15 +3,15 @@ import { type PermissionContextV2 } from "../conversations/events.js";
|
|
|
3
3
|
import { PermissionProfileStore } from "../conversations/permission-profile-store.js";
|
|
4
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
5
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
6
|
-
import { NetworkGrants } from "../local-devices/network-grants.js";
|
|
7
6
|
import type { DeviceSandbox } from "./device-sandbox.js";
|
|
8
7
|
import { type KernelReadInvocation, type KernelReadMethod } from "./kernel-read.js";
|
|
8
|
+
import { NetworkGrants } from "./network-grants.js";
|
|
9
9
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
10
10
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
11
11
|
import { PermissionCallGrants } from "./permission-call-grants.js";
|
|
12
12
|
import type { PermissionCallRef, PermissionReviewSnapshot } from "./permission-call-types.js";
|
|
13
13
|
import { PermissionConfigPublication } from "./permission-config-publication.js";
|
|
14
|
-
import type {
|
|
14
|
+
import type { AppliedOuterNetwork } from "./permission-context-types.js";
|
|
15
15
|
import { type PermissionContextSubject } from "./permission-context-types.js";
|
|
16
16
|
import { PermissionFacts } from "./permission-facts.js";
|
|
17
17
|
import type { SandboxUseContext } from "./use-context.js";
|
|
@@ -44,7 +44,7 @@ export interface PermissionScopeFacts {
|
|
|
44
44
|
escalated?: boolean;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* The sandbox network of a call: the device sandbox's mode within
|
|
47
|
+
* The sandbox network of a call: the device sandbox's mode within an instance's applied outer
|
|
48
48
|
* boundary (an open network never sits inside an allowlisted or disabled one); `allowlist` takes
|
|
49
49
|
* the call's hosts, and an allowlist without hosts is `none` at the scope.
|
|
50
50
|
*/
|
|
@@ -57,14 +57,6 @@ export declare function sandboxNetworkOf(box: Pick<DeviceSandbox, "networkMode">
|
|
|
57
57
|
* is the provider's rule.
|
|
58
58
|
*/
|
|
59
59
|
export declare function intersectPermissionScope(f: PermissionScopeFacts): SandboxOperationScope;
|
|
60
|
-
/** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
|
|
61
|
-
/**
|
|
62
|
-
* The read roots of a restricted profile: the working root, plus the held instance's
|
|
63
|
-
* kernel-staged skills root (its committed roots), read-only, so a staged skill's scripts run
|
|
64
|
-
* (`sh /skills/<name>@<digest>/…`). Never writable; nothing else is added. Sorted by code point,
|
|
65
|
-
* as the recorded context requires.
|
|
66
|
-
*/
|
|
67
|
-
export declare function restrictedReadRoots(workingRoot: string, applied: Pick<AppliedEnvironment, "roots"> | null | undefined): string[];
|
|
68
60
|
export declare class SandboxOperationAuthority {
|
|
69
61
|
private readonly callGrants;
|
|
70
62
|
private readonly publication;
|
|
@@ -115,13 +107,6 @@ export declare class SandboxOperationAuthority {
|
|
|
115
107
|
* check that its run is still `queued`).
|
|
116
108
|
*/
|
|
117
109
|
resolveKernelRead(ctx: SandboxUseContext, read: Pick<KernelReadInvocation, "purpose" | "root">, method: KernelReadMethod, path: string, signal: AbortSignal): Promise<SandboxOperationScope>;
|
|
118
|
-
/**
|
|
119
|
-
* Whether the device's runtime is isolated from its host's files (a kernel read may then go
|
|
120
|
-
* under the conversation's Full access on a Full-only runtime): a cloud device, or a local
|
|
121
|
-
* machine whose authenticated connection recorded its Docker mode (`device_machines.mode`,
|
|
122
|
-
* written at hello; a mode change resets the device's files).
|
|
123
|
-
*/
|
|
124
|
-
private isolatedRuntime;
|
|
125
110
|
private scopeOf;
|
|
126
111
|
private snapshot;
|
|
127
112
|
/**
|
|
@@ -143,8 +128,9 @@ export declare class SandboxOperationAuthority {
|
|
|
143
128
|
* (`devices/working-root.ts` `workingRootOf`, permission activation L2): the bound project's
|
|
144
129
|
* root when the root conversation's latest `project_root` snapshot is usable and names that
|
|
145
130
|
* root, else the recorded or reported workspace. A bound project before its first snapshot, an
|
|
146
|
-
* unavailable one
|
|
147
|
-
*
|
|
131
|
+
* unavailable one and one above the owner's home all work in the workspace (where a project
|
|
132
|
+
* may lie is its provider's rule, checked when it was added), so a call the review judged
|
|
133
|
+
* against the workspace is
|
|
148
134
|
* not stale at admission. Narrowing only: no root other than the binding's or the workspace is
|
|
149
135
|
* ever named. `projectUsable` (a kernel read of the bound project) takes the binding as its
|
|
150
136
|
* snapshot. `projectRoot` is the bound project path when it is the working root, else null.
|
|
@@ -18,10 +18,10 @@ import { ApiError } from "../errors.js";
|
|
|
18
18
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
19
|
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
20
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
|
-
import { NetworkGrants } from "../local-devices/network-grants.js";
|
|
22
21
|
import { hostGrantable } from "./device-sandbox.js";
|
|
23
22
|
import { KernelReadUnsupported, kernelReadRoot, kernelReadRoute, } from "./kernel-read.js";
|
|
24
|
-
import { coversHost
|
|
23
|
+
import { coversHost } from "./modes.js";
|
|
24
|
+
import { NetworkGrants } from "./network-grants.js";
|
|
25
25
|
import { EscalationGrantMissingError, isExecutionMethod, parseStartingExecutionGrants, } from "./operation-authority-types.js";
|
|
26
26
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
27
27
|
import { assertAuthorityHeld, PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
@@ -37,10 +37,12 @@ const RUNTIME_CAUSE = { kind: "runtime" };
|
|
|
37
37
|
* The one verdict over a device's runtime report and its applied environment (B1, B-16): the
|
|
38
38
|
* recorded permission context withholds its scope exactly when this returns a verdict, and
|
|
39
39
|
* admission refuses with the same reason, so the model is never told it can do what admission
|
|
40
|
-
* refuses, nor the reverse (
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* refuses, nor the reverse (the same for every provider, B-15; device-provider spec §6.7).
|
|
41
|
+
* Unknown applied facts precede a positive capability report (the applied environment is proved
|
|
42
|
+
* by that same current report, its boundary included); a working root that is not the installed
|
|
43
|
+
* workspace (no project) is never installed scope. The sandbox is the same under every profile
|
|
44
|
+
* (support v2): a runtime that enforces per-operation scopes, or an instance-boundary provider
|
|
45
|
+
* whose instance is the sandbox.
|
|
44
46
|
*/
|
|
45
47
|
function withheldScope(input) {
|
|
46
48
|
const { availability, applied } = input;
|
|
@@ -53,10 +55,9 @@ function withheldScope(input) {
|
|
|
53
55
|
cause: availability.cause ?? RUNTIME_CAUSE,
|
|
54
56
|
};
|
|
55
57
|
if (applied === null ||
|
|
56
|
-
applied.location !== input.location ||
|
|
57
58
|
(input.projectPath === null && input.workingRoot !== applied.roots.workspace))
|
|
58
59
|
return { state: "unprobed", reason: UNPROVED_ENVIRONMENT };
|
|
59
|
-
const verdict = runtimeReportVerdict(availability.report
|
|
60
|
+
const verdict = runtimeReportVerdict(availability.report);
|
|
60
61
|
return verdict === null ? null : { state: "unsupported", reason: verdict, cause: RUNTIME_CAUSE };
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
@@ -65,7 +66,7 @@ function withheldScope(input) {
|
|
|
65
66
|
*/
|
|
66
67
|
const KERNEL_READ_PROFILE = "request-approval";
|
|
67
68
|
/**
|
|
68
|
-
* The sandbox network of a call: the device sandbox's mode within
|
|
69
|
+
* The sandbox network of a call: the device sandbox's mode within an instance's applied outer
|
|
69
70
|
* boundary (an open network never sits inside an allowlisted or disabled one); `allowlist` takes
|
|
70
71
|
* the call's hosts, and an allowlist without hosts is `none` at the scope.
|
|
71
72
|
*/
|
|
@@ -122,20 +123,6 @@ export function intersectPermissionScope(f) {
|
|
|
122
123
|
: { kind: "none" },
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
|
-
/** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
|
|
126
|
-
/**
|
|
127
|
-
* The read roots of a restricted profile: the working root, plus the held instance's
|
|
128
|
-
* kernel-staged skills root (its committed roots), read-only, so a staged skill's scripts run
|
|
129
|
-
* (`sh /skills/<name>@<digest>/…`). Never writable; nothing else is added. Sorted by code point,
|
|
130
|
-
* as the recorded context requires.
|
|
131
|
-
*/
|
|
132
|
-
export function restrictedReadRoots(workingRoot, applied) {
|
|
133
|
-
const skills = applied?.roots.skills;
|
|
134
|
-
const roots = skills?.startsWith("/") && !withinDirectory(skills, workingRoot)
|
|
135
|
-
? [workingRoot, skills]
|
|
136
|
-
: [workingRoot];
|
|
137
|
-
return [...new Set(roots)].sort(permissionCodePointCompare);
|
|
138
|
-
}
|
|
139
126
|
let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
140
127
|
callGrants;
|
|
141
128
|
publication;
|
|
@@ -163,7 +150,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
163
150
|
await this.locks.acquire({ orgId: ctx.orgId, deviceId: ctx.deviceId }, { kind: "admit" });
|
|
164
151
|
await this.publication.assertCurrent();
|
|
165
152
|
await this.facts.assertCloudReconciled(ctx.orgId, ctx.deviceId);
|
|
166
|
-
await this.facts.assertOwnerReportUsable(ctx.orgId, ctx.deviceId);
|
|
167
153
|
if (!(await this.isActiveMember(ctx.orgId, ctx.accountId)))
|
|
168
154
|
throw new ApiError("device.not_found", "Device not found");
|
|
169
155
|
await this.facts.preview(ctx.orgId, ctx.accountId, ctx.deviceId);
|
|
@@ -178,7 +164,9 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
178
164
|
accountId: ctx.accountId,
|
|
179
165
|
admitBeforeMs: Date.now() + 30000,
|
|
180
166
|
ceilingRevision: permissionScopeHash(vector),
|
|
181
|
-
|
|
167
|
+
// the base the picker starts from: the provider's reported home, else the workspace (what
|
|
168
|
+
// the device answers within it is the provider's rule)
|
|
169
|
+
readRoots: [scope.home ?? scope.workspace],
|
|
182
170
|
tag: operationId,
|
|
183
171
|
});
|
|
184
172
|
}
|
|
@@ -294,15 +282,13 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
294
282
|
.find((refusal) => refusal !== null);
|
|
295
283
|
if (runtime)
|
|
296
284
|
throw new ApiError("forbidden", runtime);
|
|
297
|
-
if ((
|
|
298
|
-
(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
: f.policy.network.kind !== "open-public" &&
|
|
302
|
-
!f.policy.network.hosts.some((pattern) => coversHost(pattern, host))))
|
|
285
|
+
if (grant.expansion.hosts.some((host) => f.hostCeiling
|
|
286
|
+
? !hostGrantable(f.hostCeiling, host)
|
|
287
|
+
: f.policy.network.kind !== "open-public" &&
|
|
288
|
+
!f.policy.network.hosts.some((pattern) => coversHost(pattern, host))))
|
|
303
289
|
throw new ApiError("forbidden", "Permission expansion exceeds the current ceiling");
|
|
304
290
|
}
|
|
305
|
-
// an accepted host addition the applied
|
|
291
|
+
// an accepted host addition the applied instance outer boundary does not cover cannot be
|
|
306
292
|
// reached: cut like the base hosts, so admission never names more than the context (B-15);
|
|
307
293
|
// an open sandbox network needs none, and an instance-boundary device takes none per call
|
|
308
294
|
const expansionHosts = f.network === "allowlist" && f.boundary !== "instance"
|
|
@@ -310,8 +296,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
310
296
|
: [];
|
|
311
297
|
const scope = this.scopeOf(ctx, operation, {
|
|
312
298
|
...f,
|
|
313
|
-
// an accepted read-directory expansion stays in the review facts and the grant row but
|
|
314
|
-
// reaches no provider: a scope carries no read roots (the provider's read rule decides)
|
|
315
299
|
baseWriteDirectories: [
|
|
316
300
|
...f.baseWriteDirectories,
|
|
317
301
|
...(grant?.expansion.writeDirectories ?? []),
|
|
@@ -375,14 +359,14 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
375
359
|
route = kernelReadRoute({
|
|
376
360
|
restricted: availability.report.restricted !== null || instanceSupported(availability.report),
|
|
377
361
|
fullAccess: availability.report.outsideSandbox,
|
|
378
|
-
isolated
|
|
362
|
+
// an instance-boundary runtime is isolated from its host's files
|
|
363
|
+
isolated: availability.report.boundary === "instance",
|
|
379
364
|
});
|
|
380
365
|
if (route === "refused")
|
|
381
366
|
throw new KernelReadUnsupported();
|
|
382
367
|
}
|
|
383
368
|
const profile = this.scopeOf(ctx, method, f);
|
|
384
|
-
if (profile.filesystem.kind === "scoped" &&
|
|
385
|
-
!f.baseReadDirectories.some((r) => covering === r || covering.startsWith(r === "/" ? "/" : `${r}/`)))
|
|
369
|
+
if (profile.filesystem.kind === "scoped" && !withinDirectory(covering, f.workingRoot))
|
|
386
370
|
throw new ApiError("forbidden", "The kernel read is outside the conversation's profile");
|
|
387
371
|
// a restricted read-only scope whenever the runtime enforces it, whatever the conversation's
|
|
388
372
|
// profile: a runtime keyed on Full access may follow a symlinked AGENTS.md or SKILL.md out of
|
|
@@ -403,22 +387,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
403
387
|
network: { kind: "none" },
|
|
404
388
|
});
|
|
405
389
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Whether the device's runtime is isolated from its host's files (a kernel read may then go
|
|
408
|
-
* under the conversation's Full access on a Full-only runtime): a cloud device, or a local
|
|
409
|
-
* machine whose authenticated connection recorded its Docker mode (`device_machines.mode`,
|
|
410
|
-
* written at hello; a mode change resets the device's files).
|
|
411
|
-
*/
|
|
412
|
-
async isolatedRuntime(orgId, deviceId) {
|
|
413
|
-
const row = await this.db
|
|
414
|
-
.selectFrom("devices as d")
|
|
415
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "d.id").on("m.revoked_at", "is", null))
|
|
416
|
-
.select(["d.source", "m.mode"])
|
|
417
|
-
.where("d.id", "=", deviceId)
|
|
418
|
-
.where("d.org_id", "=", orgId)
|
|
419
|
-
.executeTakeFirst();
|
|
420
|
-
return row !== undefined && (row.source !== "local" || row.mode === "docker");
|
|
421
|
-
}
|
|
422
390
|
scopeOf(ctx, operation, f, escalated = false) {
|
|
423
391
|
if (!["exec", "readFile", "writeFile", "stat", "list", "scan", "backgroundStart"].includes(operation))
|
|
424
392
|
throw new ApiError("forbidden", "Unknown sandbox operation");
|
|
@@ -475,7 +443,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
475
443
|
throw new ApiError("forbidden", "This run's actor is no longer authorized");
|
|
476
444
|
await this.publication.assertCurrent();
|
|
477
445
|
await this.facts.assertCloudReconciled(ctx.orgId, ctx.deviceId);
|
|
478
|
-
await this.facts.assertOwnerReportUsable(ctx.orgId, ctx.deviceId);
|
|
479
446
|
const root = await this.profiles.readOwnedRoot(ctx.orgId, ctx.holderConversationId, ctx.actor.accountId);
|
|
480
447
|
const view = await this.facts.view(ctx.orgId, ctx.actor.accountId, root);
|
|
481
448
|
if (view.deviceId !== ctx.deviceId)
|
|
@@ -492,13 +459,13 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
492
459
|
runId: ctx.actor.runId,
|
|
493
460
|
...opts,
|
|
494
461
|
});
|
|
495
|
-
const { policy,
|
|
462
|
+
const { policy, workingRoot, projectRoot, grant, sandbox } = base;
|
|
496
463
|
const applied = await this.facts.readAppliedEnvironmentLocked({
|
|
497
464
|
orgId: ctx.orgId,
|
|
498
465
|
deviceId: ctx.deviceId,
|
|
499
466
|
});
|
|
500
|
-
// admission's hosts, as the recorded context names them: within
|
|
501
|
-
//
|
|
467
|
+
// admission's hosts, as the recorded context names them: within an instance's applied outer
|
|
468
|
+
// boundary
|
|
502
469
|
const allowedHosts = hostsWithinOuter(base.allowedHosts, applied?.outerNetwork);
|
|
503
470
|
const grantHosts = hostsWithinOuter(base.grantHosts, applied?.outerNetwork);
|
|
504
471
|
captureGrant?.(grant
|
|
@@ -508,18 +475,17 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
508
475
|
}
|
|
509
476
|
: undefined);
|
|
510
477
|
const effectiveProfile = unattended ? "request-approval" : view.profile;
|
|
511
|
-
// one verdict for
|
|
512
|
-
//
|
|
513
|
-
//
|
|
478
|
+
// one verdict for every provider (B-16, B-15): a device without an instance yet is refused
|
|
479
|
+
// here, but provisioning is not an admitted operation: the lifecycle lease creates the
|
|
480
|
+
// instance and records its evidence before the first operation is admitted
|
|
514
481
|
const withheld = withheldScope({
|
|
515
482
|
availability: view.availability,
|
|
516
|
-
location: device.source === "local" ? "local" : "cloud",
|
|
517
483
|
workingRoot,
|
|
518
484
|
projectPath: projectRoot,
|
|
519
485
|
applied,
|
|
520
486
|
});
|
|
521
487
|
// whether this call could run outside the sandbox (per-call escalation): the device's
|
|
522
|
-
// outside-sandbox ceiling, which already holds the provider's support for it
|
|
488
|
+
// outside-sandbox ceiling, which already holds the provider's support for it now
|
|
523
489
|
const escalationRefusal = unattended
|
|
524
490
|
? ESCALATION_UNATTENDED_WHY
|
|
525
491
|
: withheld
|
|
@@ -527,8 +493,8 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
527
493
|
: !view.outsideSandboxCeiling
|
|
528
494
|
? escalationCeilingWhy({
|
|
529
495
|
layer: sandbox.layer.outsideSandbox,
|
|
530
|
-
location: device.source === "local" ? "local" : "cloud",
|
|
531
496
|
boundary: sandbox.boundary,
|
|
497
|
+
description: base.description,
|
|
532
498
|
})
|
|
533
499
|
: null;
|
|
534
500
|
const vector = await this.epochs.readLocked(subject);
|
|
@@ -549,13 +515,11 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
549
515
|
authorityRevision: permissionScopeHash({ scopeRevision: view.scopeRevision, vector }),
|
|
550
516
|
workingRoot,
|
|
551
517
|
projectRoot,
|
|
552
|
-
baseReadDirectories: restrictedReadRoots(workingRoot, applied),
|
|
553
518
|
baseWriteDirectories: [workingRoot],
|
|
554
519
|
baseHosts: allowedHosts,
|
|
555
520
|
network: sandboxNetworkOf(sandbox, applied?.outerNetwork),
|
|
556
521
|
boundary: sandbox.boundary,
|
|
557
522
|
outsideSandboxCeiling: view.outsideSandboxCeiling,
|
|
558
|
-
broadProjectReach: view.broadProjectReach,
|
|
559
523
|
// the view keeps Full access only while its consent covers the device's ceilings
|
|
560
524
|
fullConsent: view.profile === "full-access",
|
|
561
525
|
unattended,
|
|
@@ -604,17 +568,8 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
604
568
|
*/
|
|
605
569
|
async baseScopeLocked(input) {
|
|
606
570
|
const { orgId, deviceId } = input;
|
|
607
|
-
const { policy,
|
|
608
|
-
const
|
|
609
|
-
.selectFrom("devices")
|
|
610
|
-
.select("source")
|
|
611
|
-
.where("id", "=", deviceId)
|
|
612
|
-
.executeTakeFirstOrThrow();
|
|
613
|
-
const { workingRoot, projectRoot } = await this.workingRootOf({
|
|
614
|
-
...input,
|
|
615
|
-
reach: projectReachOf(device.source, policy, owner?.restrictedProjectReach),
|
|
616
|
-
mode: policy.mode,
|
|
617
|
-
});
|
|
571
|
+
const { policy, sandbox, hostCeiling, hostRefusal, description } = await this.facts.readDevice(orgId, deviceId);
|
|
572
|
+
const { workingRoot, projectRoot } = await this.workingRootOf(input);
|
|
618
573
|
const grant = input.runId
|
|
619
574
|
? await this.grants.forExec({ orgId, deviceId, runId: input.runId })
|
|
620
575
|
: undefined;
|
|
@@ -625,7 +580,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
625
580
|
const allowedHosts = sandbox.networkMode !== "allowlist" ? [] : [...new Set([...sandbox.hosts, ...grantHosts])];
|
|
626
581
|
return {
|
|
627
582
|
policy,
|
|
628
|
-
|
|
583
|
+
description,
|
|
629
584
|
workingRoot,
|
|
630
585
|
projectRoot,
|
|
631
586
|
grant,
|
|
@@ -641,8 +596,9 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
641
596
|
* (`devices/working-root.ts` `workingRootOf`, permission activation L2): the bound project's
|
|
642
597
|
* root when the root conversation's latest `project_root` snapshot is usable and names that
|
|
643
598
|
* root, else the recorded or reported workspace. A bound project before its first snapshot, an
|
|
644
|
-
* unavailable one
|
|
645
|
-
*
|
|
599
|
+
* unavailable one and one above the owner's home all work in the workspace (where a project
|
|
600
|
+
* may lie is its provider's rule, checked when it was added), so a call the review judged
|
|
601
|
+
* against the workspace is
|
|
646
602
|
* not stale at admission. Narrowing only: no root other than the binding's or the workspace is
|
|
647
603
|
* ever named. `projectUsable` (a kernel read of the bound project) takes the binding as its
|
|
648
604
|
* snapshot. `projectRoot` is the bound project path when it is the working root, else null.
|
|
@@ -672,8 +628,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
672
628
|
? { root: bound, unavailable: false }
|
|
673
629
|
: null;
|
|
674
630
|
const workingRoot = reviewWorkingRootOf(usable, {
|
|
675
|
-
mode: input.mode,
|
|
676
|
-
reach: input.reach,
|
|
677
631
|
workspace: working.workspace,
|
|
678
632
|
home: working.home,
|
|
679
633
|
});
|
|
@@ -688,19 +642,11 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
688
642
|
*/
|
|
689
643
|
async workingRootFor(input) {
|
|
690
644
|
const root = await this.profiles.readRoot(input.orgId, input.conversationId);
|
|
691
|
-
const { policy, owner } = await this.facts.readDevice(input.orgId, input.deviceId);
|
|
692
|
-
const device = await this.db
|
|
693
|
-
.selectFrom("devices")
|
|
694
|
-
.select("source")
|
|
695
|
-
.where("id", "=", input.deviceId)
|
|
696
|
-
.executeTakeFirstOrThrow();
|
|
697
645
|
return (await this.workingRootOf({
|
|
698
646
|
orgId: input.orgId,
|
|
699
647
|
deviceId: input.deviceId,
|
|
700
648
|
root,
|
|
701
649
|
holderConversationId: input.conversationId,
|
|
702
|
-
reach: projectReachOf(device.source, policy, owner?.restrictedProjectReach),
|
|
703
|
-
mode: policy.mode,
|
|
704
650
|
})).workingRoot;
|
|
705
651
|
}
|
|
706
652
|
/**
|
|
@@ -849,7 +795,6 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
849
795
|
// states admission refuses before any operation: the device is not verified for new work
|
|
850
796
|
try {
|
|
851
797
|
await this.facts.assertCloudReconciled(input.orgId, deviceId);
|
|
852
|
-
await this.facts.assertOwnerReportUsable(input.orgId, deviceId);
|
|
853
798
|
}
|
|
854
799
|
catch (error) {
|
|
855
800
|
if (!(error instanceof ApiError))
|
|
@@ -876,13 +821,11 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
876
821
|
orgId: input.orgId,
|
|
877
822
|
deviceId,
|
|
878
823
|
});
|
|
879
|
-
|
|
880
|
-
// the hosts admission uses: within a cloud instance's applied outer boundary (B-15)
|
|
824
|
+
// the hosts admission uses: within an instance's applied outer boundary (B-15)
|
|
881
825
|
const allowedHosts = hostsWithinOuter(base.allowedHosts, applied?.outerNetwork);
|
|
882
826
|
// the verdict admission refuses with (B-16)
|
|
883
827
|
const withheld = withheldScope({
|
|
884
828
|
availability,
|
|
885
|
-
location,
|
|
886
829
|
workingRoot: base.workingRoot,
|
|
887
830
|
projectPath: base.projectRoot,
|
|
888
831
|
applied,
|
|
@@ -902,33 +845,29 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
902
845
|
: hosts.length
|
|
903
846
|
? { kind: "allowlist", hosts }
|
|
904
847
|
: { kind: "none" };
|
|
905
|
-
const directories = box.boundary === "instance"
|
|
906
|
-
? instanceRoots(base.workingRoot)
|
|
907
|
-
: restrictedReadRoots(base.workingRoot, applied);
|
|
908
848
|
return parse({
|
|
909
849
|
...known,
|
|
910
850
|
availability: { state: "supported" },
|
|
911
851
|
scope: {
|
|
912
|
-
|
|
852
|
+
boundary: box.boundary,
|
|
913
853
|
workingRoot: base.workingRoot,
|
|
914
854
|
filesystem: {
|
|
915
855
|
kind: "scoped",
|
|
916
|
-
|
|
917
|
-
writeDirectories: box.boundary === "instance" ? directories : [base.workingRoot],
|
|
856
|
+
writeDirectories: box.boundary === "instance" ? instanceRoots(base.workingRoot) : [base.workingRoot],
|
|
918
857
|
},
|
|
919
858
|
network,
|
|
920
859
|
outerNetwork: applied.outerNetwork,
|
|
921
860
|
},
|
|
922
861
|
sandbox: {
|
|
923
862
|
boundary: box.boundary,
|
|
924
|
-
location,
|
|
925
863
|
workingRoot: base.workingRoot,
|
|
926
864
|
network: { kind: network.kind, hostsCount: hosts.length },
|
|
927
|
-
//
|
|
928
|
-
outsideSandbox:
|
|
865
|
+
// an instance boundary has no outside: its instance is the outermost boundary
|
|
866
|
+
outsideSandbox: box.boundary === "operation" && box.outsideSandbox,
|
|
929
867
|
outerNetwork: applied.outerNetwork,
|
|
930
|
-
//
|
|
931
|
-
|
|
868
|
+
// a host is granted per call only where each operation carries its own network (an
|
|
869
|
+
// operation boundary whose provider reports `perOperationHosts`)
|
|
870
|
+
perCallHosts: box.perCallHosts,
|
|
932
871
|
},
|
|
933
872
|
});
|
|
934
873
|
}
|
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
8
|
import { PermissionProfileStoreModule } from "../conversations/permission-profile-store.module.js";
|
|
9
|
-
import { NetworkGrantsModule } from "
|
|
9
|
+
import { NetworkGrantsModule } from "./network-grants.module.js";
|
|
10
10
|
import { SandboxOperationAuthority } from "./operation-authority.js";
|
|
11
11
|
import { PermissionAuthorityModule } from "./permission-authority.module.js";
|
|
12
12
|
import { PermissionCallGrantsModule } from "./permission-call-grants.module.js";
|
|
@@ -242,7 +242,10 @@ export declare class SandboxOperationIntents {
|
|
|
242
242
|
/**
|
|
243
243
|
* A disconnected or still-pending revoke remains owed; every retry is a new deterministic
|
|
244
244
|
* persisted attempt, backing off (30 s doubling, at most an hour) so an obligation that only
|
|
245
|
-
* retirement can resolve (a lost or replaced instance) never spins.
|
|
245
|
+
* retirement can resolve (a lost or replaced instance) never spins. Retries stop once the
|
|
246
|
+
* device or its org is deleted: nothing can reach its instance any more, the revoke stays
|
|
247
|
+
* unacknowledged (no cleanup is claimed) and the retirement settles it from the device's
|
|
248
|
+
* recorded destruction, if any.
|
|
246
249
|
*/
|
|
247
250
|
deferRevocation(id: string): Promise<void>;
|
|
248
251
|
acknowledgeRevocation(id: string): Promise<void>;
|