@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.56
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/dist/ui/views.d.ts +3 -1
- package/dist/ui/views.js +2 -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
|
@@ -22,9 +22,11 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
22
22
|
import { ownerFactsOf, ownerModeOf } from "../local-devices/owner-report.js";
|
|
23
23
|
import { deviceFeaturesOf } from "../local-devices/policy-summary.js";
|
|
24
24
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
25
|
+
import { canonicalHostCeiling, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
|
|
26
|
+
import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
|
|
25
27
|
import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
|
|
26
28
|
import { assertAuthorityHeld } from "./permission-authority-lock.js";
|
|
27
|
-
import { permissionAvailabilityFor } from "./permission-availability.js";
|
|
29
|
+
import { permissionAvailabilityFor, } from "./permission-availability.js";
|
|
28
30
|
import { readCurrentReport, readRuntimeReport, sameRuntimeIdentity, } from "./permission-runtime-reports.js";
|
|
29
31
|
import { providerForDevice, SandboxProviders } from "./providers.js";
|
|
30
32
|
import { homeOf } from "./review/rules.js";
|
|
@@ -53,9 +55,13 @@ let PermissionFacts = class PermissionFacts {
|
|
|
53
55
|
this.providers = providers;
|
|
54
56
|
this.devices = devices;
|
|
55
57
|
}
|
|
56
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Current policy, the device sandbox and persisted owner roots; access is checked by the caller.
|
|
60
|
+
* `sandbox` is the device sandbox under the device's current runtime report (the provider layer
|
|
61
|
+
* assumed before one is recorded), the same under every permission profile.
|
|
62
|
+
*/
|
|
57
63
|
async readDevice(orgId, deviceId) {
|
|
58
|
-
const [policy, machine] = await Promise.all([
|
|
64
|
+
const [policy, machine, availability] = await Promise.all([
|
|
59
65
|
this.devicePolicy({ orgId, deviceId }),
|
|
60
66
|
this.db
|
|
61
67
|
.selectFrom("device_machines")
|
|
@@ -64,24 +70,134 @@ let PermissionFacts = class PermissionFacts {
|
|
|
64
70
|
.where("org_id", "=", orgId)
|
|
65
71
|
.where("revoked_at", "is", null)
|
|
66
72
|
.executeTakeFirst(),
|
|
73
|
+
this.availability(orgId, deviceId),
|
|
67
74
|
]);
|
|
68
75
|
const facts = machine ? ownerFactsOf(machine) : null;
|
|
76
|
+
const owner = facts === null || facts.state === "missing"
|
|
77
|
+
? null
|
|
78
|
+
: {
|
|
79
|
+
state: facts.state,
|
|
80
|
+
outsideSandbox: facts.outsideSandbox,
|
|
81
|
+
restrictedProjectReach: facts.restrictedProjectReach,
|
|
82
|
+
network: facts.network,
|
|
83
|
+
allowedDomains: facts.allowedDomains,
|
|
84
|
+
};
|
|
85
|
+
const sandbox = await this.deviceSandboxFacts(orgId, deviceId, availability);
|
|
69
86
|
return {
|
|
70
87
|
policy,
|
|
71
|
-
// the owner's authenticated facts (B2)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
fullAccess: facts.fullAccess,
|
|
78
|
-
restrictedProjectReach: facts.restrictedProjectReach,
|
|
79
|
-
allowedDomains: facts.restrictedAllowedDomains,
|
|
80
|
-
},
|
|
88
|
+
// the owner's authenticated facts (B2); null when the machine reported nothing readable
|
|
89
|
+
owner,
|
|
90
|
+
sandbox: sandbox.box,
|
|
91
|
+
hostCeiling: sandbox.hostCeiling,
|
|
92
|
+
hostRefusal: sandbox.refusal,
|
|
93
|
+
reach: sandbox.reach,
|
|
81
94
|
roots: machine?.roots ?? null,
|
|
82
95
|
home: machine?.home ?? null,
|
|
83
96
|
};
|
|
84
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* The effective device sandbox (approval-only profiles design, "Settings model"): the platform,
|
|
100
|
+
* org, device and provider layers read live and combined by {@link effectiveDeviceSandbox}. A
|
|
101
|
+
* local device's layer is its owner's authenticated report (missing or blocked: fail closed,
|
|
102
|
+
* nothing outside and the allowlist); a cloud device's is its stored network choice.
|
|
103
|
+
*/
|
|
104
|
+
async deviceSandbox(orgId, deviceId, availability) {
|
|
105
|
+
return (await this.deviceSandboxFacts(orgId, deviceId, availability)).box;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* {@link deviceSandbox} with the layers a per-call host grant is checked against: its ceiling
|
|
109
|
+
* ({@link hostGrantCeiling}), why a host is unavailable ({@link hostGrantRefusal}) and the
|
|
110
|
+
* crossing ceilings a Full access consent covers ({@link ConsentReach}).
|
|
111
|
+
*/
|
|
112
|
+
async deviceSandboxFacts(orgId, deviceId, availability,
|
|
113
|
+
/** A cloud device's network as it would be stored (a change checked before it is written). */
|
|
114
|
+
pendingCloud) {
|
|
115
|
+
const [settings, org, row] = await Promise.all([
|
|
116
|
+
readDeviceSandboxSettings(this.db.db, this.config),
|
|
117
|
+
readOrgSettings(this.db.db, orgId),
|
|
118
|
+
this.db
|
|
119
|
+
.selectFrom("devices as e")
|
|
120
|
+
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
121
|
+
.select(["e.source", "e.network_mode", "e.network_hosts", "m.owner_report"])
|
|
122
|
+
.where("e.id", "=", deviceId)
|
|
123
|
+
.where("e.org_id", "=", orgId)
|
|
124
|
+
.executeTakeFirst(),
|
|
125
|
+
]);
|
|
126
|
+
const location = row?.source === "local" ? "local" : "cloud";
|
|
127
|
+
const limits = this.config.get().sandbox.limits;
|
|
128
|
+
let device;
|
|
129
|
+
let owner = null;
|
|
130
|
+
if (location === "local") {
|
|
131
|
+
const facts = ownerFactsOf(row ?? {});
|
|
132
|
+
owner = { network: facts.network, allowedDomains: facts.allowedDomains };
|
|
133
|
+
device = {
|
|
134
|
+
location,
|
|
135
|
+
outsideSandbox: facts.outsideSandbox,
|
|
136
|
+
network: facts.network,
|
|
137
|
+
allowedDomains: facts.allowedDomains,
|
|
138
|
+
restrictedProjectReach: facts.restrictedProjectReach,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
else
|
|
142
|
+
device = { location, ...(pendingCloud ?? cloudOwnNetwork(row)) };
|
|
143
|
+
const current = availability ?? (await this.availability(orgId, deviceId));
|
|
144
|
+
const report = current.state === "supported" ? current.report : null;
|
|
145
|
+
const platform = {
|
|
146
|
+
settings,
|
|
147
|
+
allowHosts: limits.allowHosts,
|
|
148
|
+
orgHosts: limits.orgHosts,
|
|
149
|
+
egress: limits.egress,
|
|
150
|
+
};
|
|
151
|
+
const orgLayer = {
|
|
152
|
+
...(org.outsideSandbox !== undefined && { outsideSandbox: org.outsideSandbox }),
|
|
153
|
+
...(org.deviceNetwork !== undefined && { deviceNetwork: org.deviceNetwork }),
|
|
154
|
+
};
|
|
155
|
+
const box = effectiveDeviceSandbox(platform, orgLayer, device, providerLayerOf(report, location));
|
|
156
|
+
const hostCeiling = hostGrantCeiling(box, platform, orgLayer, owner);
|
|
157
|
+
return {
|
|
158
|
+
box,
|
|
159
|
+
hostCeiling,
|
|
160
|
+
/** The org's effective hosts: what a device's own host list may narrow, never add to. */
|
|
161
|
+
orgHosts: orgHostsOf(platform, orgLayer),
|
|
162
|
+
refusal: (host) => hostGrantRefusal(host, box, platform, orgLayer, owner),
|
|
163
|
+
reach: {
|
|
164
|
+
outsideSandbox: box.outsideSandbox,
|
|
165
|
+
networkCeiling: box.networkCeiling,
|
|
166
|
+
networkMode: box.networkMode,
|
|
167
|
+
restrictedProjectReach: box.restrictedProjectReach,
|
|
168
|
+
hostCeiling: canonicalHostCeiling(hostCeiling),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The per-call host ceiling of an org, with no device (`hostGrantCeiling` under the platform and
|
|
174
|
+
* org layers alone): what a standing grant that may reach any of the org's devices (a scheduled
|
|
175
|
+
* task's network grant, a network approval) is checked against. A device's own layers only
|
|
176
|
+
* narrow it further.
|
|
177
|
+
*/
|
|
178
|
+
async orgHostGrantCeiling(orgId) {
|
|
179
|
+
const [settings, org] = await Promise.all([
|
|
180
|
+
readDeviceSandboxSettings(this.db.db, this.config),
|
|
181
|
+
readOrgSettings(this.db.db, orgId),
|
|
182
|
+
]);
|
|
183
|
+
const limits = this.config.get().sandbox.limits;
|
|
184
|
+
const platform = {
|
|
185
|
+
settings,
|
|
186
|
+
allowHosts: limits.allowHosts,
|
|
187
|
+
orgHosts: limits.orgHosts,
|
|
188
|
+
egress: limits.egress,
|
|
189
|
+
};
|
|
190
|
+
const orgLayer = {
|
|
191
|
+
...(org.outsideSandbox !== undefined && { outsideSandbox: org.outsideSandbox }),
|
|
192
|
+
...(org.deviceNetwork !== undefined && { deviceNetwork: org.deviceNetwork }),
|
|
193
|
+
};
|
|
194
|
+
const box = effectiveDeviceSandbox(platform, orgLayer, { location: "cloud", networkMode: null, networkHosts: [] }, {
|
|
195
|
+
boundary: "operation",
|
|
196
|
+
network: { openPublic: true, allowlist: true, perOperationHosts: true },
|
|
197
|
+
outsideSandbox: false,
|
|
198
|
+
});
|
|
199
|
+
return hostGrantCeiling(box, platform, orgLayer, null);
|
|
200
|
+
}
|
|
85
201
|
/** Stored binding only; projectScope supplies the live owner and deletion checks. */
|
|
86
202
|
async readProject(orgId, deviceId, name) {
|
|
87
203
|
return ((await this.db
|
|
@@ -93,15 +209,33 @@ let PermissionFacts = class PermissionFacts {
|
|
|
93
209
|
.where("p.name", "=", name)
|
|
94
210
|
.executeTakeFirst()) ?? null);
|
|
95
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* The device's lifecycle policy: the kernel-internal mode tier (`auto` / `sandbox`, recorded with
|
|
214
|
+
* a cloud instance's applied limits and deciding the working root's reach) and the network a
|
|
215
|
+
* cloud instance is created with. A cloud device's network is its device sandbox network
|
|
216
|
+
* ({@link deviceSandbox}); the B1 snapshot's `outer_network` is no longer read: migrations 0165
|
|
217
|
+
* and 0167 and the snapshot writer copy an allowlist snapshot into the device's own network
|
|
218
|
+
* choice (`network_mode`, `network_hosts`).
|
|
219
|
+
*/
|
|
96
220
|
async devicePolicy(device) {
|
|
97
221
|
const [deployment, settings, chosen] = await Promise.all([
|
|
98
222
|
readDeploymentDevicePolicy(this.db.db, this.config),
|
|
99
223
|
readOrgSettings(this.db.db, device.orgId),
|
|
100
224
|
device.deviceId === undefined
|
|
101
|
-
? { mode: null,
|
|
225
|
+
? { mode: null, source: null }
|
|
102
226
|
: this.deviceChosenMode(device.orgId, device.deviceId),
|
|
103
227
|
]);
|
|
104
|
-
|
|
228
|
+
const policy = effectiveDevicePolicy(deployment, settings, chosen.mode);
|
|
229
|
+
if (chosen.source !== "cloud" || device.deviceId === undefined)
|
|
230
|
+
return policy;
|
|
231
|
+
// a cloud instance's outer network is its sandbox network (its provider enforces it, read
|
|
232
|
+
// under the provider layer assumed before a report); a local device's commands carry its
|
|
233
|
+
// sandbox network in their limits (`SandboxService.deviceLimits`)
|
|
234
|
+
const box = await this.deviceSandbox(device.orgId, device.deviceId, {
|
|
235
|
+
state: "unprobed",
|
|
236
|
+
reason: "lifecycle",
|
|
237
|
+
});
|
|
238
|
+
return { ...policy, network: networkOfSandbox(box) };
|
|
105
239
|
}
|
|
106
240
|
/**
|
|
107
241
|
* Refuses admission on a cloud device whose B1 snapshot found applied limits it could not
|
|
@@ -136,34 +270,52 @@ let PermissionFacts = class PermissionFacts {
|
|
|
136
270
|
throw new ApiError("device.owner_report_stale", "This device's machine reported an owner ceiling older than the one it reported before (its owner report sequence was lost or reset); run capybara-device login again on that machine to reset it");
|
|
137
271
|
}
|
|
138
272
|
/**
|
|
139
|
-
* The mode a device chose: a local device's derived one (`
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
142
|
-
* org.
|
|
273
|
+
* The mode tier a device chose: a local device's derived one (`ownerModeOf`: `auto` only when
|
|
274
|
+
* its owner allows running outside the sandbox); a cloud device's narrower of its old switch and
|
|
275
|
+
* its B1 owner snapshot (`cloudChosenMode`), or null for a cloud device that follows the
|
|
276
|
+
* platform and the org. The tier is kernel-internal (instance limits, reach): a cloud device
|
|
277
|
+
* never runs outside its sandbox.
|
|
143
278
|
*/
|
|
144
279
|
async deviceChosenMode(orgId, deviceId) {
|
|
145
280
|
const row = await this.db
|
|
146
281
|
.selectFrom("devices as e")
|
|
147
282
|
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
148
|
-
.select([
|
|
149
|
-
"e.source",
|
|
150
|
-
"e.mode",
|
|
151
|
-
"e.owner_full_access",
|
|
152
|
-
"e.outer_network",
|
|
153
|
-
"m.features",
|
|
154
|
-
"m.local_policy",
|
|
155
|
-
"m.owner_report",
|
|
156
|
-
])
|
|
283
|
+
.select(["e.source", "e.mode", "e.owner_full_access", "m.owner_report"])
|
|
157
284
|
.where("e.id", "=", deviceId)
|
|
158
285
|
.where("e.org_id", "=", orgId)
|
|
159
286
|
.where("e.deleted_at", "is", null)
|
|
160
287
|
.executeTakeFirst();
|
|
161
288
|
if (row === undefined)
|
|
162
|
-
return { mode: null,
|
|
289
|
+
return { mode: null, source: null };
|
|
163
290
|
if (row.source === "local")
|
|
164
|
-
return { mode: ownerModeOf(row),
|
|
165
|
-
|
|
166
|
-
|
|
291
|
+
return { mode: ownerModeOf(row), source: "local" };
|
|
292
|
+
return { mode: cloudChosenMode(row), source: "cloud" };
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The device's current permission availability: the provider's capability shape, then the
|
|
296
|
+
* runtime report recorded for its current identity. No probe or provider call.
|
|
297
|
+
*/
|
|
298
|
+
async availability(orgId, deviceId) {
|
|
299
|
+
const device = await this.db
|
|
300
|
+
.selectFrom("devices")
|
|
301
|
+
.select(["provider", "source"])
|
|
302
|
+
.where("id", "=", deviceId)
|
|
303
|
+
.where("org_id", "=", orgId)
|
|
304
|
+
.executeTakeFirst();
|
|
305
|
+
const provider = device ? providerForDevice(this.providers, device.provider) : undefined;
|
|
306
|
+
let availability = permissionAvailabilityFor(provider?.impl);
|
|
307
|
+
if (availability.state === "unprobed" && provider) {
|
|
308
|
+
const machine = provider.plugin === "@local"
|
|
309
|
+
? await this.db
|
|
310
|
+
.selectFrom("device_machines")
|
|
311
|
+
.select("program_version")
|
|
312
|
+
.where("device_id", "=", deviceId)
|
|
313
|
+
.where("revoked_at", "is", null)
|
|
314
|
+
.executeTakeFirst()
|
|
315
|
+
: undefined;
|
|
316
|
+
availability = await readRuntimeReport(this.db.db, deviceId, provider.plugin, machine?.program_version ?? provider.version);
|
|
317
|
+
}
|
|
318
|
+
return availability;
|
|
167
319
|
}
|
|
168
320
|
async readWorkingFacts({ orgId, rootConversationId, holderConversationId: conversationId, deviceId, }) {
|
|
169
321
|
const [applied, recorded, recordedRoot, machine, project] = await Promise.all([
|
|
@@ -278,9 +430,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
278
430
|
reach: allowedMode === "auto" && owner.restrictedProjectReach === "os-user"
|
|
279
431
|
? "os-user"
|
|
280
432
|
: "workspace",
|
|
281
|
-
//
|
|
282
|
-
// (its wire reads unsandboxed); an authenticated report bounds browsing by scope instead
|
|
283
|
-
widerThanAllowed: owner.state !== "report" && allowedMode === "sandbox" && ownerModeOf(row) === "auto",
|
|
433
|
+
// an authenticated report bounds browsing by scope: never wider than the device allows
|
|
284
434
|
workspace: row.machine_workspace ?? DEFAULT_SANDBOX_ROOTS.workspace,
|
|
285
435
|
home: row.home,
|
|
286
436
|
supported: deviceFeaturesOf(row.features).includes("projects"),
|
|
@@ -293,7 +443,6 @@ let PermissionFacts = class PermissionFacts {
|
|
|
293
443
|
mode,
|
|
294
444
|
// cloud projects stay within their provisioned files
|
|
295
445
|
reach: "workspace",
|
|
296
|
-
widerThanAllowed: false,
|
|
297
446
|
workspace: handle === null ? DEFAULT_SANDBOX_ROOTS.workspace : rootsOf(handle).workspace,
|
|
298
447
|
home: null,
|
|
299
448
|
supported: typeof impl?.list === "function" && typeof impl.scan === "function",
|
|
@@ -325,26 +474,14 @@ let PermissionFacts = class PermissionFacts {
|
|
|
325
474
|
return row !== undefined;
|
|
326
475
|
}
|
|
327
476
|
async scope(orgId, deviceId, projectPath, project) {
|
|
328
|
-
const {
|
|
329
|
-
const
|
|
477
|
+
const { roots: ownerRoots, sandbox, policy } = await this.readDevice(orgId, deviceId);
|
|
478
|
+
const source = (await this.db
|
|
330
479
|
.selectFrom("devices")
|
|
331
|
-
.select(
|
|
480
|
+
.select("source")
|
|
332
481
|
.where("id", "=", deviceId)
|
|
333
482
|
.where("org_id", "=", orgId)
|
|
334
|
-
.executeTakeFirst();
|
|
335
|
-
const
|
|
336
|
-
let availability = permissionAvailabilityFor(provider?.impl);
|
|
337
|
-
if (availability.state === "unprobed" && provider) {
|
|
338
|
-
const machine = provider.plugin === "@local"
|
|
339
|
-
? await this.db
|
|
340
|
-
.selectFrom("device_machines")
|
|
341
|
-
.select("program_version")
|
|
342
|
-
.where("device_id", "=", deviceId)
|
|
343
|
-
.where("revoked_at", "is", null)
|
|
344
|
-
.executeTakeFirst()
|
|
345
|
-
: undefined;
|
|
346
|
-
availability = await readRuntimeReport(this.db.db, deviceId, provider.plugin, machine?.program_version ?? provider.version);
|
|
347
|
-
}
|
|
483
|
+
.executeTakeFirst())?.source;
|
|
484
|
+
const availability = await this.availability(orgId, deviceId);
|
|
348
485
|
// A ceiling restored to the same values is still a new authorization decision. Reads do
|
|
349
486
|
// not initialize epoch rows; absent rows denote the pre-change revision zero.
|
|
350
487
|
const epochRows = await this.db
|
|
@@ -365,31 +502,42 @@ let PermissionFacts = class PermissionFacts {
|
|
|
365
502
|
.select("handle")
|
|
366
503
|
.where("device_id", "=", deviceId)
|
|
367
504
|
.executeTakeFirst();
|
|
368
|
-
|
|
505
|
+
// the consent fingerprint: the device, the project binding and the crossing ceilings Full
|
|
506
|
+
// access auto-approves within (approval-only profiles design, "Consent fingerprint"), from
|
|
507
|
+
// the settings layers under the provider layer assumed before a report: a runtime report
|
|
508
|
+
// arriving or changing only narrows what the consent covers, so it never resets it
|
|
509
|
+
const consentReach = (await this.deviceSandboxFacts(orgId, deviceId, { state: "unprobed", reason: "consent" })).reach;
|
|
510
|
+
// what a consent is bound to besides the reach: the device, the project binding and the
|
|
511
|
+
// epochs a widening writer bumps (a ceiling restored to the same values still resets)
|
|
512
|
+
const consentIdentity = permissionScopeHash({
|
|
369
513
|
authority,
|
|
370
514
|
deviceId,
|
|
371
515
|
projectPath,
|
|
372
516
|
workingRoot: projectPath ??
|
|
373
517
|
ownerRoots?.workspace ??
|
|
374
518
|
rootsOf(instanceRoots?.handle ?? { id: deviceId }).workspace,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
519
|
+
});
|
|
520
|
+
const scopeRevision = permissionScopeHash({
|
|
521
|
+
identity: consentIdentity,
|
|
522
|
+
orgHosts: this.config.get().sandbox.limits.orgHosts,
|
|
523
|
+
sandbox: consentReach,
|
|
380
524
|
});
|
|
381
525
|
return {
|
|
382
526
|
deviceId,
|
|
383
527
|
project,
|
|
384
528
|
scopeRevision,
|
|
529
|
+
consentIdentity,
|
|
530
|
+
consentReach,
|
|
385
531
|
availability,
|
|
386
|
-
|
|
532
|
+
sandbox,
|
|
533
|
+
outsideSandboxCeiling: sandbox.outsideSandbox,
|
|
387
534
|
// B2: broad restricted reach (directories outside the working root) is the owner's reach
|
|
388
|
-
// within the platform and org
|
|
389
|
-
// device keeps its previous rule (its
|
|
390
|
-
broadProjectReach:
|
|
391
|
-
|
|
392
|
-
|
|
535
|
+
// within the platform and org ceilings; a cloud instance's whole filesystem is its sandbox,
|
|
536
|
+
// and an operation-boundary cloud device keeps its previous rule (its mode tier)
|
|
537
|
+
broadProjectReach: sandbox.boundary === "instance" ||
|
|
538
|
+
(source === "local"
|
|
539
|
+
? sandbox.restrictedProjectReach === "os-user"
|
|
540
|
+
: policy.mode === "auto" && policy.allowedMode === "auto"),
|
|
393
541
|
};
|
|
394
542
|
}
|
|
395
543
|
async preview(orgId, accountId, deviceId, project) {
|
|
@@ -427,10 +575,9 @@ let PermissionFacts = class PermissionFacts {
|
|
|
427
575
|
}
|
|
428
576
|
const consent = row.permission_consent;
|
|
429
577
|
const profile = row.permission_profile === "full-access" &&
|
|
430
|
-
(!preview
|
|
578
|
+
(!preview ||
|
|
431
579
|
preview.availability.state === "unsupported" ||
|
|
432
|
-
consent
|
|
433
|
-
consent?.scopeRevision !== preview.scopeRevision)
|
|
580
|
+
!consentHolds(consent, row.device_id, preview))
|
|
434
581
|
? "approve-for-me"
|
|
435
582
|
: row.permission_profile;
|
|
436
583
|
return {
|
|
@@ -440,14 +587,17 @@ let PermissionFacts = class PermissionFacts {
|
|
|
440
587
|
revision: row.permission_revision,
|
|
441
588
|
rootConversationId: row.id,
|
|
442
589
|
deviceId: row.device_id,
|
|
443
|
-
consentScope: profile === "full-access"
|
|
590
|
+
consentScope: profile === "full-access" && consent
|
|
591
|
+
? { deviceId: consent.deviceId, scopeRevision: consent.scopeRevision }
|
|
592
|
+
: null,
|
|
444
593
|
scopeRevision: preview?.scopeRevision ?? null,
|
|
445
594
|
availability: preview?.availability ?? {
|
|
446
595
|
state: "unsupported",
|
|
447
596
|
reason: unavailableReason,
|
|
448
597
|
},
|
|
449
|
-
|
|
598
|
+
outsideSandboxCeiling: preview?.outsideSandboxCeiling ?? false,
|
|
450
599
|
broadProjectReach: preview?.broadProjectReach ?? false,
|
|
600
|
+
sandbox: preview?.sandbox ?? null,
|
|
451
601
|
startingWorkNotice: notice,
|
|
452
602
|
},
|
|
453
603
|
};
|
|
@@ -633,3 +783,41 @@ export function hostsWithinOuter(hosts, outer) {
|
|
|
633
783
|
return [];
|
|
634
784
|
return hosts.filter((host) => outer.hosts.some((pattern) => coversHost(pattern, host)));
|
|
635
785
|
}
|
|
786
|
+
/**
|
|
787
|
+
* The network a device sandbox gives a cloud instance's outer boundary: the open public internet,
|
|
788
|
+
* or its allowlist (empty under the kill switch, which closes it).
|
|
789
|
+
*/
|
|
790
|
+
export function networkOfSandbox(box) {
|
|
791
|
+
if (box.networkMode === "open")
|
|
792
|
+
return { kind: "open-public", hosts: [] };
|
|
793
|
+
return { kind: "allowlist", hosts: box.networkMode === "allowlist" ? [...box.hosts] : [] };
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* A cloud device's own sandbox network: its stored choice (`network_mode`, `network_hosts`; null
|
|
797
|
+
* follows the org). A B1 snapshot is copied into it by migrations 0165 and 0167, the snapshot
|
|
798
|
+
* writer and every publication (`copyCloudSnapshotNetworks`), never read here.
|
|
799
|
+
*/
|
|
800
|
+
export function cloudOwnNetwork(row) {
|
|
801
|
+
const hosts = row?.network_hosts;
|
|
802
|
+
const mode = row?.network_mode;
|
|
803
|
+
if (mode === "open" || mode === "allowlist" || mode === "none")
|
|
804
|
+
return {
|
|
805
|
+
networkMode: mode,
|
|
806
|
+
networkHosts: Array.isArray(hosts) && hosts.every((h) => typeof h === "string") ? hosts : [],
|
|
807
|
+
};
|
|
808
|
+
return { networkMode: null, networkHosts: [] };
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Whether a stored consent still covers the device's current crossing ceilings: the same device,
|
|
812
|
+
* and either the exact scope it confirmed or the same identity with every ceiling within what it
|
|
813
|
+
* covered (a narrowing never drops Full access to Approve for me).
|
|
814
|
+
*/
|
|
815
|
+
export function consentHolds(consent, deviceId, preview) {
|
|
816
|
+
if (consent === null || consent.deviceId !== deviceId)
|
|
817
|
+
return false;
|
|
818
|
+
if (consent.scopeRevision === preview.scopeRevision)
|
|
819
|
+
return true;
|
|
820
|
+
return (consent.identity === preview.consentIdentity &&
|
|
821
|
+
consent.reach !== undefined &&
|
|
822
|
+
reachWithin(preview.consentReach, consent.reach));
|
|
823
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SandboxHandle, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -30,9 +30,10 @@ export declare function cloudRuntimeIdentity(input: {
|
|
|
30
30
|
applied: AppliedLimits;
|
|
31
31
|
}): PermissionRuntimeIdentity;
|
|
32
32
|
/**
|
|
33
|
-
* A
|
|
34
|
-
*
|
|
35
|
-
* nothing beyond the contract's fields is kept)
|
|
33
|
+
* A permission support report strictly parsed (`parseSandboxPermissionSupport`, version 2), or null
|
|
34
|
+
* when it is not one: a cloud provider's answer (an in-process extension is trusted, but its answer
|
|
35
|
+
* is stored and read back later, so nothing beyond the contract's fields is kept) and a stored
|
|
36
|
+
* report read back (one recorded before version 2 is no report).
|
|
36
37
|
*/
|
|
37
38
|
export declare function cloudSupportOf(value: unknown): SandboxPermissionSupport | null;
|
|
38
39
|
/**
|
|
@@ -8,6 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
+
import { instanceSupported, parseSandboxPermissionSupport, } from "@capybara-hq/plugin-sdk";
|
|
11
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
14
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -74,32 +75,18 @@ export function cloudRuntimeIdentity(input) {
|
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
|
-
* A
|
|
78
|
-
*
|
|
79
|
-
* nothing beyond the contract's fields is kept)
|
|
78
|
+
* A permission support report strictly parsed (`parseSandboxPermissionSupport`, version 2), or null
|
|
79
|
+
* when it is not one: a cloud provider's answer (an in-process extension is trusted, but its answer
|
|
80
|
+
* is stored and read back later, so nothing beyond the contract's fields is kept) and a stored
|
|
81
|
+
* report read back (one recorded before version 2 is no report).
|
|
80
82
|
*/
|
|
81
83
|
export function cloudSupportOf(value) {
|
|
82
|
-
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return null;
|
|
87
|
-
const r = o.restricted;
|
|
88
|
-
if (r !== null && (typeof r !== "object" || r === undefined))
|
|
89
|
-
return null;
|
|
90
|
-
if (r && !["filesystem", "network", "native", "concurrentScopes"].every((k) => r[k] === true))
|
|
84
|
+
try {
|
|
85
|
+
return parseSandboxPermissionSupport(value);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
91
88
|
return null;
|
|
92
|
-
|
|
93
|
-
version: 1,
|
|
94
|
-
restricted: r
|
|
95
|
-
? { filesystem: true, network: true, native: true, concurrentScopes: true }
|
|
96
|
-
: null,
|
|
97
|
-
fullAccess: o.fullAccess,
|
|
98
|
-
background: o.background,
|
|
99
|
-
...(typeof o.unavailableReason === "string" && {
|
|
100
|
-
unavailableReason: o.unavailableReason.slice(0, 1000),
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
89
|
+
}
|
|
103
90
|
}
|
|
104
91
|
/**
|
|
105
92
|
* The cloud identity the instance row proves now, or null when it proves none: no live instance
|
|
@@ -127,11 +114,11 @@ function currentCloudIdentity(instance, provider, version) {
|
|
|
127
114
|
* Full reads as unsupported there whatever the provider reports; restricted support stands.
|
|
128
115
|
*/
|
|
129
116
|
export function cloudEnforceable(report, instanceLimits) {
|
|
130
|
-
if (!report.
|
|
117
|
+
if (!report.outsideSandbox || readInstanceLimits(instanceLimits).applied?.mode === "auto")
|
|
131
118
|
return report;
|
|
132
119
|
return {
|
|
133
120
|
...report,
|
|
134
|
-
|
|
121
|
+
outsideSandbox: false,
|
|
135
122
|
unavailableReason: "This cloud instance enforces its outer network only inside the OS sandbox, so it cannot run Full access",
|
|
136
123
|
};
|
|
137
124
|
}
|
|
@@ -200,10 +187,13 @@ export async function readCurrentReport(db, deviceId, provider, version) {
|
|
|
200
187
|
row.instance_generation !== String(instance.created_at.getTime()) ||
|
|
201
188
|
row.identity_hash !== permissionScopeHash(instance.permission_runtime_identity))
|
|
202
189
|
return unprobed;
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
190
|
+
const stored = cloudSupportOf(row.report);
|
|
191
|
+
if (stored === null)
|
|
192
|
+
return unprobed;
|
|
193
|
+
const report = device?.source === "cloud" ? cloudEnforceable(stored, instance.instance_limits) : stored;
|
|
194
|
+
// an instance-boundary provider is a supported device whose scope is the whole instance,
|
|
195
|
+
// unless its report names why it is unavailable (a stale image, a digest mismatch)
|
|
196
|
+
if (!report.restricted && !instanceSupported(report) && !report.outsideSandbox)
|
|
207
197
|
return {
|
|
208
198
|
availability: {
|
|
209
199
|
state: "unsupported",
|
|
@@ -55,6 +55,14 @@ export interface ReviewClassifierInput {
|
|
|
55
55
|
personMessages: string;
|
|
56
56
|
/** The call's data tag ({@link newReviewTag}). */
|
|
57
57
|
tag: string;
|
|
58
|
+
/**
|
|
59
|
+
* Why a call of a Full access conversation is reviewed at all: a sub-agent asked for the
|
|
60
|
+
* escalation, or the escalation carries a credential consent. Absent otherwise.
|
|
61
|
+
*/
|
|
62
|
+
fullAccessReview?: {
|
|
63
|
+
subAgent?: true;
|
|
64
|
+
credential?: true;
|
|
65
|
+
};
|
|
58
66
|
}
|
|
59
67
|
/**
|
|
60
68
|
* The user message of the classifier call: the facts, the untrusted command or path, the rule
|
|
@@ -88,6 +88,16 @@ export function classifierMessage(input) {
|
|
|
88
88
|
`</${input.tag}>`,
|
|
89
89
|
]
|
|
90
90
|
: []),
|
|
91
|
+
...(input.fullAccessReview?.subAgent
|
|
92
|
+
? [
|
|
93
|
+
"Review context: a sub-agent requested this escalation; its task text was written by an agent, not the person. The person chose Full access for this conversation, but a sub-agent's escalation is always reviewed. Apply the same standard as for any escalation.",
|
|
94
|
+
]
|
|
95
|
+
: []),
|
|
96
|
+
...(input.fullAccessReview?.credential
|
|
97
|
+
? [
|
|
98
|
+
"Review context: this escalation also reads, prints or links credentials (see the rule findings). The person chose Full access for this conversation, but an escalation that touches credentials is always reviewed. Apply the same standard as for any escalation.",
|
|
99
|
+
]
|
|
100
|
+
: []),
|
|
91
101
|
"Rule findings:",
|
|
92
102
|
rules,
|
|
93
103
|
"The person's recent messages, oldest first (what they asked for):",
|