@capybara-hq/kernel 0.1.0-rc.68 → 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/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/marketplaces.service.d.ts +1 -1
- 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/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- 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
|
@@ -14,20 +14,19 @@ import { sql } from "kysely";
|
|
|
14
14
|
import { permissionCodePointCompare } from "../conversations/events.js";
|
|
15
15
|
import { DeviceAccess } from "../devices/access.js";
|
|
16
16
|
import { deviceNotFound, projectsUnsupported } from "../devices/errors.js";
|
|
17
|
-
import {
|
|
17
|
+
import { projectNotFound, tooBroad } from "../devices/project-rules.js";
|
|
18
18
|
import { aboveHome } from "../devices/working-root.js";
|
|
19
19
|
import { ApiError } from "../errors.js";
|
|
20
20
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
21
21
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
22
|
-
import { ownerFactsOf, ownerModeOf } from "../local-devices/owner-report.js";
|
|
23
|
-
import { deviceFeaturesOf } from "../local-devices/policy-summary.js";
|
|
24
22
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
23
|
+
import { storedReport, storedSupport } from "./device-reports.js";
|
|
25
24
|
import { canonicalHostCeiling, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
|
|
26
25
|
import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
|
|
27
26
|
import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
|
|
28
27
|
import { assertAuthorityHeld } from "./permission-authority-lock.js";
|
|
29
28
|
import { deviceWorkAvailability, permissionAvailabilityFor, } from "./permission-availability.js";
|
|
30
|
-
import { readCurrentReport
|
|
29
|
+
import { readCurrentReport } from "./permission-runtime-reports.js";
|
|
31
30
|
import { DeviceProviders } from "./providers.js";
|
|
32
31
|
import { homeOf } from "./review/rules.js";
|
|
33
32
|
export const permissionScopeHash = (value) => createHash("sha256").update(canonical(value)).digest("hex");
|
|
@@ -56,50 +55,32 @@ let PermissionFacts = class PermissionFacts {
|
|
|
56
55
|
this.devices = devices;
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
|
-
* Current policy
|
|
60
|
-
*
|
|
61
|
-
* assumed before one is recorded), the same under every permission
|
|
58
|
+
* Current policy and the device sandbox; access is checked by the caller. `sandbox` is the device
|
|
59
|
+
* sandbox under the device's current runtime report (else the support stored with its report,
|
|
60
|
+
* else the provider layer assumed before one is recorded), the same under every permission
|
|
61
|
+
* profile.
|
|
62
62
|
*/
|
|
63
63
|
async readDevice(orgId, deviceId) {
|
|
64
|
-
const [policy,
|
|
64
|
+
const [policy, availability] = await Promise.all([
|
|
65
65
|
this.devicePolicy({ orgId, deviceId }),
|
|
66
|
-
this.db
|
|
67
|
-
.selectFrom("device_machines")
|
|
68
|
-
.select(["local_policy", "owner_report", "roots", "home"])
|
|
69
|
-
.where("device_id", "=", deviceId)
|
|
70
|
-
.where("org_id", "=", orgId)
|
|
71
|
-
.where("revoked_at", "is", null)
|
|
72
|
-
.executeTakeFirst(),
|
|
73
66
|
this.availability(orgId, deviceId),
|
|
74
67
|
]);
|
|
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
68
|
const sandbox = await this.deviceSandboxFacts(orgId, deviceId, availability);
|
|
86
69
|
return {
|
|
87
70
|
policy,
|
|
88
|
-
// the owner's authenticated facts (B2); null when the machine reported nothing readable
|
|
89
|
-
owner,
|
|
90
71
|
sandbox: sandbox.box,
|
|
91
72
|
hostCeiling: sandbox.hostCeiling,
|
|
92
73
|
hostRefusal: sandbox.refusal,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
home: machine?.home ?? null,
|
|
74
|
+
/** The provider's description of the device (its stored report, English), or null. */
|
|
75
|
+
description: sandbox.description,
|
|
96
76
|
};
|
|
97
77
|
}
|
|
98
78
|
/**
|
|
99
79
|
* 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}
|
|
101
|
-
*
|
|
102
|
-
*
|
|
80
|
+
* org, device and provider layers read live and combined by {@link effectiveDeviceSandbox}, one
|
|
81
|
+
* path for every provider. The device layer is its stored network choice; the provider layer
|
|
82
|
+
* its current runtime report, else the support stored with its device report (device-provider
|
|
83
|
+
* spec §6.7), else the layer assumed before any ({@link providerLayerOf}).
|
|
103
84
|
*/
|
|
104
85
|
async deviceSandbox(orgId, deviceId, availability) {
|
|
105
86
|
return (await this.deviceSandboxFacts(orgId, deviceId, availability)).box;
|
|
@@ -110,38 +91,35 @@ let PermissionFacts = class PermissionFacts {
|
|
|
110
91
|
* crossing ceilings a Full access consent covers ({@link ConsentReach}).
|
|
111
92
|
*/
|
|
112
93
|
async deviceSandboxFacts(orgId, deviceId, availability,
|
|
113
|
-
/**
|
|
114
|
-
|
|
94
|
+
/** The device's network as it would be stored (a change checked before it is written). */
|
|
95
|
+
pending,
|
|
96
|
+
/**
|
|
97
|
+
* Which provider layer: `ceilings` (the support chain, {@link providerLayerOf}; the consent
|
|
98
|
+
* reach reads it too) or `lifecycle` (no support: the network an instance is created with is
|
|
99
|
+
* the device's own choice within the ceilings, never a support read after an earlier
|
|
100
|
+
* instance, so a support arriving never makes the next use recreate the instance; the
|
|
101
|
+
* provider enforces what it can).
|
|
102
|
+
*/
|
|
103
|
+
layer = "ceilings") {
|
|
115
104
|
const [settings, org, row] = await Promise.all([
|
|
116
105
|
readDeviceSandboxSettings(this.db.db, this.config),
|
|
117
106
|
readOrgSettings(this.db.db, orgId),
|
|
118
107
|
this.db
|
|
119
|
-
.selectFrom("devices
|
|
120
|
-
.
|
|
121
|
-
.
|
|
122
|
-
.where("
|
|
123
|
-
.where("e.org_id", "=", orgId)
|
|
108
|
+
.selectFrom("devices")
|
|
109
|
+
.select(["network_mode", "network_hosts", "report"])
|
|
110
|
+
.where("id", "=", deviceId)
|
|
111
|
+
.where("org_id", "=", orgId)
|
|
124
112
|
.executeTakeFirst(),
|
|
125
113
|
]);
|
|
126
|
-
const location = row?.source === "local" ? "local" : "cloud";
|
|
127
114
|
const limits = this.config.get().sandbox.limits;
|
|
128
|
-
|
|
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)) };
|
|
115
|
+
const device = pending ?? ownNetwork(row);
|
|
143
116
|
const current = availability ?? (await this.availability(orgId, deviceId));
|
|
144
|
-
|
|
117
|
+
// the provider's support: its current runtime report, else the one stored with its report
|
|
118
|
+
const support = layer === "lifecycle"
|
|
119
|
+
? null
|
|
120
|
+
: current.state === "supported"
|
|
121
|
+
? current.report
|
|
122
|
+
: storedSupport(row?.report);
|
|
145
123
|
const platform = {
|
|
146
124
|
settings,
|
|
147
125
|
allowHosts: limits.allowHosts,
|
|
@@ -152,19 +130,21 @@ let PermissionFacts = class PermissionFacts {
|
|
|
152
130
|
...(org.outsideSandbox !== undefined && { outsideSandbox: org.outsideSandbox }),
|
|
153
131
|
...(org.deviceNetwork !== undefined && { deviceNetwork: org.deviceNetwork }),
|
|
154
132
|
};
|
|
155
|
-
const box = effectiveDeviceSandbox(platform, orgLayer, device, providerLayerOf(
|
|
156
|
-
const hostCeiling = hostGrantCeiling(box, platform, orgLayer
|
|
133
|
+
const box = effectiveDeviceSandbox(platform, orgLayer, device, providerLayerOf(support));
|
|
134
|
+
const hostCeiling = hostGrantCeiling(box, platform, orgLayer);
|
|
157
135
|
return {
|
|
158
136
|
box,
|
|
159
137
|
hostCeiling,
|
|
160
138
|
/** The org's effective hosts: what a device's own host list may narrow, never add to. */
|
|
161
139
|
orgHosts: orgHostsOf(platform, orgLayer),
|
|
162
|
-
refusal: (host) => hostGrantRefusal(host, box, platform, orgLayer
|
|
140
|
+
refusal: (host) => hostGrantRefusal(host, box, platform, orgLayer),
|
|
141
|
+
description: storedReport(row?.report)?.description.en ?? null,
|
|
142
|
+
/** Its provider enforces a sandbox allowlist (its support): a blocked host may be asked about. */
|
|
143
|
+
allowlist: support !== null && support.unavailableReason === undefined && support.network.allowlist,
|
|
163
144
|
reach: {
|
|
164
145
|
outsideSandbox: box.outsideSandbox,
|
|
165
146
|
networkCeiling: box.networkCeiling,
|
|
166
147
|
networkMode: box.networkMode,
|
|
167
|
-
restrictedProjectReach: box.restrictedProjectReach,
|
|
168
148
|
hostCeiling: canonicalHostCeiling(hostCeiling),
|
|
169
149
|
},
|
|
170
150
|
};
|
|
@@ -191,12 +171,12 @@ let PermissionFacts = class PermissionFacts {
|
|
|
191
171
|
...(org.outsideSandbox !== undefined && { outsideSandbox: org.outsideSandbox }),
|
|
192
172
|
...(org.deviceNetwork !== undefined && { deviceNetwork: org.deviceNetwork }),
|
|
193
173
|
};
|
|
194
|
-
const box = effectiveDeviceSandbox(platform, orgLayer, {
|
|
174
|
+
const box = effectiveDeviceSandbox(platform, orgLayer, { networkMode: null, networkHosts: [] }, {
|
|
195
175
|
boundary: "operation",
|
|
196
176
|
network: { openPublic: true, allowlist: true, perOperationHosts: true },
|
|
197
177
|
outsideSandbox: false,
|
|
198
178
|
});
|
|
199
|
-
return hostGrantCeiling(box, platform, orgLayer
|
|
179
|
+
return hostGrantCeiling(box, platform, orgLayer);
|
|
200
180
|
}
|
|
201
181
|
/** Stored binding only; projectScope supplies the live owner and deletion checks. */
|
|
202
182
|
async readProject(orgId, deviceId, name) {
|
|
@@ -211,30 +191,25 @@ let PermissionFacts = class PermissionFacts {
|
|
|
211
191
|
}
|
|
212
192
|
/**
|
|
213
193
|
* The device's lifecycle policy: the kernel-internal mode tier (`auto` / `sandbox`, recorded with
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* choice (`network_mode`, `network_hosts`).
|
|
194
|
+
* an instance's applied limits) and the network an instance is created with: its device sandbox
|
|
195
|
+
* network ({@link deviceSandbox}), the same for every provider. The B1 snapshot's
|
|
196
|
+
* `outer_network` is no longer read: migrations 0165 and 0167 and the snapshot writer copy an
|
|
197
|
+
* allowlist snapshot into the device's own network choice (`network_mode`, `network_hosts`).
|
|
219
198
|
*/
|
|
220
199
|
async devicePolicy(device) {
|
|
221
200
|
const [deployment, settings, chosen] = await Promise.all([
|
|
222
201
|
readDeploymentDevicePolicy(this.db.db, this.config),
|
|
223
202
|
readOrgSettings(this.db.db, device.orgId),
|
|
224
203
|
device.deviceId === undefined
|
|
225
|
-
? {
|
|
226
|
-
: this.
|
|
204
|
+
? { found: false, mode: null }
|
|
205
|
+
: this.chosenMode(device.orgId, device.deviceId),
|
|
227
206
|
]);
|
|
228
207
|
const policy = effectiveDevicePolicy(deployment, settings, chosen.mode);
|
|
229
|
-
if (chosen.
|
|
208
|
+
if (!chosen.found || device.deviceId === undefined)
|
|
230
209
|
return policy;
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
const box = await this.deviceSandbox(device.orgId, device.deviceId, {
|
|
235
|
-
state: "unprobed",
|
|
236
|
-
reason: "lifecycle",
|
|
237
|
-
});
|
|
210
|
+
// an instance's outer network is its sandbox network (its provider enforces it), from the
|
|
211
|
+
// device's own choice within the ceilings: the same before and after a support is known
|
|
212
|
+
const box = (await this.deviceSandboxFacts(device.orgId, device.deviceId, { state: "unprobed", reason: "lifecycle" }, undefined, "lifecycle")).box;
|
|
238
213
|
return { ...policy, network: networkOfSandbox(box) };
|
|
239
214
|
}
|
|
240
215
|
/**
|
|
@@ -254,66 +229,39 @@ let PermissionFacts = class PermissionFacts {
|
|
|
254
229
|
throw new ApiError("device.permission_reconcile_required", "This device's sandbox limits must be established again before it runs anything; reset the device's files to apply them");
|
|
255
230
|
}
|
|
256
231
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
232
|
+
* The mode tier a device chose: the narrower of its old switch and its B1 owner snapshot
|
|
233
|
+
* (`cloudChosenMode`), or null for a device that follows the platform and the org; `found`:
|
|
234
|
+
* a live device of the org. The tier is kernel-internal (instance limits); whether a call may
|
|
235
|
+
* run outside the sandbox is the device sandbox's.
|
|
260
236
|
*/
|
|
261
|
-
async
|
|
237
|
+
async chosenMode(orgId, deviceId) {
|
|
262
238
|
const row = await this.db
|
|
263
|
-
.selectFrom("
|
|
264
|
-
.select(["
|
|
265
|
-
.where("
|
|
239
|
+
.selectFrom("devices")
|
|
240
|
+
.select(["mode", "owner_full_access"])
|
|
241
|
+
.where("id", "=", deviceId)
|
|
266
242
|
.where("org_id", "=", orgId)
|
|
267
|
-
.where("
|
|
268
|
-
.executeTakeFirst();
|
|
269
|
-
if (row && ownerFactsOf(row).state === "blocked")
|
|
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");
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
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.
|
|
278
|
-
*/
|
|
279
|
-
async deviceChosenMode(orgId, deviceId) {
|
|
280
|
-
const row = await this.db
|
|
281
|
-
.selectFrom("devices as e")
|
|
282
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
283
|
-
.select(["e.source", "e.mode", "e.owner_full_access", "m.owner_report"])
|
|
284
|
-
.where("e.id", "=", deviceId)
|
|
285
|
-
.where("e.org_id", "=", orgId)
|
|
286
|
-
.where("e.deleted_at", "is", null)
|
|
243
|
+
.where("deleted_at", "is", null)
|
|
287
244
|
.executeTakeFirst();
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return { mode: ownerModeOf(row), source: "local" };
|
|
292
|
-
return { mode: cloudChosenMode(row), source: "cloud" };
|
|
245
|
+
return row === undefined
|
|
246
|
+
? { found: false, mode: null }
|
|
247
|
+
: { found: true, mode: cloudChosenMode(row) };
|
|
293
248
|
}
|
|
294
249
|
/**
|
|
295
250
|
* The device's current permission availability: the provider's capability shape, then the
|
|
296
|
-
* runtime report recorded for its current identity
|
|
251
|
+
* runtime report recorded for its current identity under the provider's version, the same for
|
|
252
|
+
* every provider. No probe or provider call.
|
|
297
253
|
*/
|
|
298
254
|
async availability(orgId, deviceId) {
|
|
299
255
|
const device = await this.db
|
|
300
256
|
.selectFrom("devices")
|
|
301
|
-
.select(
|
|
257
|
+
.select("provider")
|
|
302
258
|
.where("id", "=", deviceId)
|
|
303
259
|
.where("org_id", "=", orgId)
|
|
304
260
|
.executeTakeFirst();
|
|
305
261
|
const provider = device ? this.providers.forDevice(device.provider) : undefined;
|
|
306
262
|
let availability = permissionAvailabilityFor(provider);
|
|
307
263
|
if (availability.state === "unprobed" && provider) {
|
|
308
|
-
|
|
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);
|
|
264
|
+
availability = (await readCurrentReport(this.db.db, deviceId, provider.plugin, provider.version)).availability;
|
|
317
265
|
// a recorded runtime report that cannot enforce the sandbox is the runtime's cause
|
|
318
266
|
if (availability.state === "unsupported")
|
|
319
267
|
availability = { ...availability, cause: { kind: "runtime" } };
|
|
@@ -321,23 +269,18 @@ let PermissionFacts = class PermissionFacts {
|
|
|
321
269
|
return availability;
|
|
322
270
|
}
|
|
323
271
|
async readWorkingFacts({ orgId, rootConversationId, holderConversationId: conversationId, deviceId, }) {
|
|
324
|
-
const [applied, recorded, recordedRoot,
|
|
272
|
+
const [applied, recorded, recordedRoot, reported, project] = await Promise.all([
|
|
325
273
|
this.readAppliedEnvironment({ orgId, deviceId }),
|
|
326
274
|
this.recordedWorkspace(conversationId),
|
|
327
275
|
conversationId === rootConversationId ? null : this.recordedWorkspace(rootConversationId),
|
|
328
|
-
this.
|
|
276
|
+
this.reportedHome(orgId, deviceId),
|
|
329
277
|
this.workingProject(orgId, rootConversationId),
|
|
330
278
|
]);
|
|
331
|
-
// the held instance's committed
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
const workspace = applied?.roots.workspace ??
|
|
335
|
-
|
|
336
|
-
recordedRoot ??
|
|
337
|
-
machine?.workspace ??
|
|
338
|
-
DEFAULT_SANDBOX_ROOTS.workspace;
|
|
339
|
-
// never from a project root: the machine's home, else the device workspace's home prefix
|
|
340
|
-
const reported = machine?.home;
|
|
279
|
+
// the held instance's committed roots first: a recorded `device_paths` may be stale (an
|
|
280
|
+
// earlier instance's), and the managed writer records the device paths from these roots; the
|
|
281
|
+
// records only stand in while no instance is committed
|
|
282
|
+
const workspace = applied?.roots.workspace ?? recorded ?? recordedRoot ?? DEFAULT_SANDBOX_ROOTS.workspace;
|
|
283
|
+
// never from a project root: the provider's reported home, else the workspace's home prefix
|
|
341
284
|
const home = reported?.startsWith("/") ? reported : homeOf(workspace);
|
|
342
285
|
return { workspace, home, project };
|
|
343
286
|
}
|
|
@@ -389,34 +332,28 @@ let PermissionFacts = class PermissionFacts {
|
|
|
389
332
|
.executeTakeFirst();
|
|
390
333
|
return row?.workspace ?? null;
|
|
391
334
|
}
|
|
392
|
-
/**
|
|
393
|
-
|
|
394
|
-
* (cloud: no machine).
|
|
395
|
-
*/
|
|
396
|
-
async machineRoots(deviceId) {
|
|
335
|
+
/** The owner's home the device's provider last reported (`devices.report`), or null. */
|
|
336
|
+
async reportedHome(orgId, deviceId) {
|
|
397
337
|
const row = await this.db
|
|
398
|
-
.selectFrom("
|
|
399
|
-
.select(
|
|
400
|
-
.where("
|
|
401
|
-
.where("
|
|
338
|
+
.selectFrom("devices")
|
|
339
|
+
.select("report")
|
|
340
|
+
.where("id", "=", deviceId)
|
|
341
|
+
.where("org_id", "=", orgId)
|
|
402
342
|
.executeTakeFirst();
|
|
403
|
-
return row
|
|
343
|
+
return storedReport(row?.report)?.home ?? null;
|
|
404
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* The owner's live device's project scope: whether its provider offers projects (it has
|
|
347
|
+
* `list`), the home its provider last reported (the base the picker starts from; null: none,
|
|
348
|
+
* the workspace) and the workspace as last known (the instance's handle). What a project path
|
|
349
|
+
* may be is the provider's rule (device-provider spec §6.1): it refuses one it will not serve,
|
|
350
|
+
* so the kernel narrows no path below a reported home.
|
|
351
|
+
*/
|
|
405
352
|
async projectScope(orgId, accountId, deviceId) {
|
|
406
353
|
const row = await this.db
|
|
407
354
|
.selectFrom("devices as e")
|
|
408
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
409
355
|
.leftJoin("device_instances as i", "i.device_id", "e.id")
|
|
410
|
-
.select([
|
|
411
|
-
"e.source",
|
|
412
|
-
"e.provider",
|
|
413
|
-
"m.features",
|
|
414
|
-
"m.local_policy",
|
|
415
|
-
"m.owner_report",
|
|
416
|
-
"m.home",
|
|
417
|
-
sql `m.roots->>'workspace'`.as("machine_workspace"),
|
|
418
|
-
"i.handle",
|
|
419
|
-
])
|
|
356
|
+
.select(["e.provider", "e.report", "i.handle"])
|
|
420
357
|
.where("e.id", "=", deviceId)
|
|
421
358
|
.where("e.org_id", "=", orgId)
|
|
422
359
|
.where("e.owner_kind", "=", "personal")
|
|
@@ -425,47 +362,24 @@ let PermissionFacts = class PermissionFacts {
|
|
|
425
362
|
.executeTakeFirst();
|
|
426
363
|
if (row === undefined)
|
|
427
364
|
throw deviceNotFound();
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
// still has, on purpose (projects are offered for what the device will read; no effect today)
|
|
431
|
-
const { mode, allowedMode } = await this.devicePolicy({ orgId, deviceId });
|
|
432
|
-
if (row.source === "local") {
|
|
433
|
-
const owner = ownerFactsOf(row);
|
|
434
|
-
return {
|
|
435
|
-
source: "local",
|
|
436
|
-
mode,
|
|
437
|
-
// B2: restricted reach follows the owner's reach, independent of its Full permission, and
|
|
438
|
-
// only within a platform and org that allow the wider device ceiling
|
|
439
|
-
reach: allowedMode === "auto" && owner.restrictedProjectReach === "os-user"
|
|
440
|
-
? "os-user"
|
|
441
|
-
: "workspace",
|
|
442
|
-
// an authenticated report bounds browsing by scope: never wider than the device allows
|
|
443
|
-
workspace: row.machine_workspace ?? DEFAULT_SANDBOX_ROOTS.workspace,
|
|
444
|
-
home: row.home,
|
|
445
|
-
supported: deviceFeaturesOf(row.features).includes("projects"),
|
|
446
|
-
};
|
|
447
|
-
}
|
|
365
|
+
const { mode } = await this.devicePolicy({ orgId, deviceId });
|
|
366
|
+
const home = storedReport(row.report)?.home ?? null;
|
|
448
367
|
const impl = this.providers.forDevice(row.provider)?.impl;
|
|
449
368
|
const handle = row.handle;
|
|
450
369
|
return {
|
|
451
|
-
source: "cloud",
|
|
452
370
|
mode,
|
|
453
|
-
// cloud projects stay within their provisioned files
|
|
454
|
-
reach: "workspace",
|
|
455
371
|
workspace: handle === null ? DEFAULT_SANDBOX_ROOTS.workspace : rootsOf(handle).workspace,
|
|
456
|
-
home
|
|
457
|
-
supported: typeof impl?.list === "function"
|
|
372
|
+
home,
|
|
373
|
+
supported: typeof impl?.list === "function",
|
|
458
374
|
};
|
|
459
375
|
}
|
|
460
376
|
async resolveProjectForBinding(orgId, deviceId, accountId, name) {
|
|
461
377
|
const scope = await this.projectScope(orgId, accountId, deviceId);
|
|
462
378
|
if (!scope.supported)
|
|
463
|
-
throw projectsUnsupported(
|
|
379
|
+
throw projectsUnsupported();
|
|
464
380
|
const row = await this.readProject(orgId, deviceId, name);
|
|
465
381
|
if (row === null)
|
|
466
382
|
throw projectNotFound(name);
|
|
467
|
-
if (!withinMode(scope, row.path))
|
|
468
|
-
throw outsideMode(row.path, scope.mode);
|
|
469
383
|
// a home reported after the project was added can put it above the home: the working root
|
|
470
384
|
// would fall back for it, so it is not bound (the add rule, project root §4.3)
|
|
471
385
|
if (aboveHome(row.path, scope.home))
|
|
@@ -483,13 +397,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
483
397
|
return row !== undefined;
|
|
484
398
|
}
|
|
485
399
|
async scope(orgId, deviceId, projectPath, project) {
|
|
486
|
-
const {
|
|
487
|
-
const source = (await this.db
|
|
488
|
-
.selectFrom("devices")
|
|
489
|
-
.select("source")
|
|
490
|
-
.where("id", "=", deviceId)
|
|
491
|
-
.where("org_id", "=", orgId)
|
|
492
|
-
.executeTakeFirst())?.source;
|
|
400
|
+
const { sandbox } = await this.readDevice(orgId, deviceId);
|
|
493
401
|
const availability = await this.availability(orgId, deviceId);
|
|
494
402
|
// A ceiling restored to the same values is still a new authorization decision. Reads do
|
|
495
403
|
// not initialize epoch rows; absent rows denote the pre-change revision zero.
|
|
@@ -506,26 +414,16 @@ let PermissionFacts = class PermissionFacts {
|
|
|
506
414
|
for (const row of epochRows)
|
|
507
415
|
if (row.kind === "platform" || row.kind === "org" || row.kind === "device")
|
|
508
416
|
authority[row.kind] = row.full_revision;
|
|
509
|
-
const instanceRoots = await this.db
|
|
510
|
-
.selectFrom("device_instances")
|
|
511
|
-
.select("handle")
|
|
512
|
-
.where("device_id", "=", deviceId)
|
|
513
|
-
.executeTakeFirst();
|
|
514
417
|
// the consent fingerprint: the device, the project binding and the crossing ceilings Full
|
|
515
|
-
// access auto-approves within (approval-only profiles design, "Consent fingerprint"),
|
|
516
|
-
//
|
|
517
|
-
//
|
|
518
|
-
|
|
418
|
+
// access auto-approves within (approval-only profiles design, "Consent fingerprint"), read
|
|
419
|
+
// from exactly the layer the ceilings read (the current runtime support, else the stored one,
|
|
420
|
+
// else no crossing): a support that allows a crossing the consent did not cover outgrows it,
|
|
421
|
+
// so Full access never auto-approves past what the person confirmed
|
|
422
|
+
const consentReach = (await this.deviceSandboxFacts(orgId, deviceId, availability)).reach;
|
|
519
423
|
// what a consent is bound to besides the reach: the device, the project binding and the
|
|
520
|
-
// epochs a widening writer bumps (a ceiling restored to the same values still resets
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
deviceId,
|
|
524
|
-
projectPath,
|
|
525
|
-
workingRoot: projectPath ??
|
|
526
|
-
ownerRoots?.workspace ??
|
|
527
|
-
rootsOf(instanceRoots?.handle ?? { id: deviceId }).workspace,
|
|
528
|
-
});
|
|
424
|
+
// epochs a widening writer bumps (a ceiling restored to the same values still resets; an
|
|
425
|
+
// instance committed on other roots than the device's previous one bumps the device epoch)
|
|
426
|
+
const consentIdentity = permissionScopeHash({ authority, deviceId, projectPath });
|
|
529
427
|
const scopeRevision = permissionScopeHash({
|
|
530
428
|
identity: consentIdentity,
|
|
531
429
|
orgHosts: this.config.get().sandbox.limits.orgHosts,
|
|
@@ -538,21 +436,16 @@ let PermissionFacts = class PermissionFacts {
|
|
|
538
436
|
consentIdentity,
|
|
539
437
|
consentReach,
|
|
540
438
|
availability,
|
|
541
|
-
location: source === "local" ? "local" : "cloud",
|
|
542
439
|
sandbox,
|
|
543
440
|
outsideSandboxCeiling: sandbox.outsideSandbox,
|
|
544
|
-
// B2: broad restricted reach (directories outside the working root) is the owner's reach
|
|
545
|
-
// within the platform and org ceilings; a cloud instance's whole filesystem is its sandbox,
|
|
546
|
-
// and an operation-boundary cloud device keeps its previous rule (its mode tier)
|
|
547
|
-
broadProjectReach: sandbox.boundary === "instance" ||
|
|
548
|
-
(source === "local"
|
|
549
|
-
? sandbox.restrictedProjectReach === "os-user"
|
|
550
|
-
: policy.mode === "auto" && policy.allowedMode === "auto"),
|
|
551
441
|
};
|
|
552
442
|
}
|
|
553
443
|
/**
|
|
554
444
|
* The preview people see before choosing a profile: availability is the device-work verdict
|
|
555
|
-
* ({@link deviceWorkAvailability}). Kernel callers only use it as a check.
|
|
445
|
+
* ({@link deviceWorkAvailability}). Kernel callers only use it as a check. `consentReach` is the
|
|
446
|
+
* reach an Auto consent confirmed against this `scopeRevision` records (the same layer as the
|
|
447
|
+
* crossing ceilings, whatever the runtime's state): the confirmation names exactly what it
|
|
448
|
+
* covers, never a guess from the runtime availability.
|
|
556
449
|
*/
|
|
557
450
|
async preview(orgId, accountId, deviceId, project) {
|
|
558
451
|
await this.devices.usable(orgId, accountId, deviceId);
|
|
@@ -560,7 +453,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
560
453
|
? null
|
|
561
454
|
: await this.resolveProjectForBinding(orgId, deviceId, accountId, project);
|
|
562
455
|
const scope = await this.scope(orgId, deviceId, binding?.path ?? null, project ?? null);
|
|
563
|
-
return { ...scope, availability: deviceWorkAvailability(scope.availability
|
|
456
|
+
return { ...scope, availability: deviceWorkAvailability(scope.availability) };
|
|
564
457
|
}
|
|
565
458
|
async view(orgId, accountId, row) {
|
|
566
459
|
return (await this.viewWithAccess(orgId, accountId, row)).view;
|
|
@@ -571,10 +464,8 @@ let PermissionFacts = class PermissionFacts {
|
|
|
571
464
|
* its sandbox reads `unsupported` with the runtime cause. Kernel readers use {@link view}.
|
|
572
465
|
*/
|
|
573
466
|
async peopleView(orgId, accountId, row) {
|
|
574
|
-
const { view,
|
|
575
|
-
return
|
|
576
|
-
? view
|
|
577
|
-
: { ...view, availability: deviceWorkAvailability(view.availability, location) };
|
|
467
|
+
const { view, previewed } = await this.viewWithAccess(orgId, accountId, row);
|
|
468
|
+
return previewed ? { ...view, availability: deviceWorkAvailability(view.availability) } : view;
|
|
578
469
|
}
|
|
579
470
|
/**
|
|
580
471
|
* {@link view} plus how the actor reached the root's device: none selected, usable, refused for
|
|
@@ -610,7 +501,8 @@ let PermissionFacts = class PermissionFacts {
|
|
|
610
501
|
: row.permission_profile;
|
|
611
502
|
return {
|
|
612
503
|
access,
|
|
613
|
-
|
|
504
|
+
/** Whether the device's scope was read (a usable device): its availability is a verdict. */
|
|
505
|
+
previewed: preview !== null,
|
|
614
506
|
view: {
|
|
615
507
|
profile,
|
|
616
508
|
revision: row.permission_revision,
|
|
@@ -626,21 +518,27 @@ let PermissionFacts = class PermissionFacts {
|
|
|
626
518
|
cause: { kind: "runtime" },
|
|
627
519
|
},
|
|
628
520
|
outsideSandboxCeiling: preview?.outsideSandboxCeiling ?? false,
|
|
629
|
-
|
|
521
|
+
/** What an Auto consent confirmed now records (the confirmation names exactly this). */
|
|
522
|
+
consentReach: preview?.consentReach ?? null,
|
|
630
523
|
sandbox: preview?.sandbox ?? null,
|
|
631
524
|
startingWorkNotice: notice,
|
|
632
525
|
},
|
|
633
526
|
};
|
|
634
527
|
}
|
|
635
528
|
/**
|
|
636
|
-
* The installed environment of the device's current instance (B1 adapter
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* ones
|
|
642
|
-
*
|
|
643
|
-
*
|
|
529
|
+
* The installed environment of the device's current instance (B1 adapter), read under the
|
|
530
|
+
* caller's device authority lock: its provider's current runtime report recorded with the
|
|
531
|
+
* kernel-built identity ({@link readCurrentReport}, which binds the device's report revision),
|
|
532
|
+
* the same for every provider. Null whenever it cannot be proved: no live instance (none,
|
|
533
|
+
* creating, destroyed), an instance of another provider than the device's, roots differing from
|
|
534
|
+
* the committed ones, missing or stale evidence, desired limits waiting for a file reset
|
|
535
|
+
* (`unapplied`) and applied limits more permissive than the effective desired ones in any
|
|
536
|
+
* dimension (network kind, a host the desired allowlist does not cover; spec §124): a pending
|
|
537
|
+
* desired change is never projected as installed. Applied limits narrower than desired stand;
|
|
538
|
+
* the next use's lifecycle lease applies any change before admitting an operation, and its new
|
|
539
|
+
* limits change the identity, so that use records the evidence again. Never desired policy,
|
|
540
|
+
* never a provider call, probe, resume or provisioning; a suspended instance is read as
|
|
541
|
+
* recorded.
|
|
644
542
|
*/
|
|
645
543
|
async readAppliedEnvironmentLocked(input) {
|
|
646
544
|
assertAuthorityHeld("device", input.deviceId);
|
|
@@ -657,7 +555,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
657
555
|
async readAppliedEnvironment(input) {
|
|
658
556
|
const device = await this.db
|
|
659
557
|
.selectFrom("devices")
|
|
660
|
-
.select(
|
|
558
|
+
.select("provider")
|
|
661
559
|
.where("id", "=", input.deviceId)
|
|
662
560
|
.where("org_id", "=", input.orgId)
|
|
663
561
|
.where("deleted_at", "is", null)
|
|
@@ -683,7 +581,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
683
581
|
!instance.permission_roots ||
|
|
684
582
|
!instance.permission_runtime_identity ||
|
|
685
583
|
(instance.status !== "running" && instance.status !== "suspended") ||
|
|
686
|
-
|
|
584
|
+
device.provider !== instance.provider)
|
|
687
585
|
return null;
|
|
688
586
|
const roots = rootsOf(instance.handle);
|
|
689
587
|
const committed = instance.permission_roots;
|
|
@@ -691,88 +589,36 @@ let PermissionFacts = class PermissionFacts {
|
|
|
691
589
|
committed.skills !== roots.skills ||
|
|
692
590
|
committed.tmp !== roots.tmp)
|
|
693
591
|
return null;
|
|
694
|
-
|
|
695
|
-
return this.cloudAppliedLocked(input, {
|
|
696
|
-
...instance,
|
|
697
|
-
provider: instance.provider,
|
|
698
|
-
handle: instance.handle,
|
|
699
|
-
});
|
|
700
|
-
const instanceGeneration = String(instance.created_at.getTime());
|
|
701
|
-
const [binding, machine] = await Promise.all([
|
|
702
|
-
this.db
|
|
703
|
-
.selectFrom("device_instance_bindings")
|
|
704
|
-
.select(["binding_id", "provider", "status", "machine_id", "runtime_identity"])
|
|
705
|
-
.where("device_id", "=", input.deviceId)
|
|
706
|
-
.where("instance_generation", "=", instanceGeneration)
|
|
707
|
-
.executeTakeFirst(),
|
|
708
|
-
this.db
|
|
709
|
-
.selectFrom("device_machines")
|
|
710
|
-
.select("id")
|
|
711
|
-
.where("device_id", "=", input.deviceId)
|
|
712
|
-
.where("org_id", "=", input.orgId)
|
|
713
|
-
.where("revoked_at", "is", null)
|
|
714
|
-
.executeTakeFirst(),
|
|
715
|
-
]);
|
|
716
|
-
if (binding?.status !== "installed" ||
|
|
717
|
-
binding.provider !== instance.provider ||
|
|
718
|
-
!binding.runtime_identity ||
|
|
719
|
-
!machine ||
|
|
720
|
-
binding.machine_id !== machine.id ||
|
|
721
|
-
!sameRuntimeIdentity(binding.runtime_identity, instance.permission_runtime_identity))
|
|
722
|
-
return null;
|
|
723
|
-
return {
|
|
724
|
-
location: "local",
|
|
725
|
-
provider: instance.provider,
|
|
726
|
-
instanceId: instance.handle.id,
|
|
727
|
-
instanceGeneration,
|
|
728
|
-
bindingId: binding.binding_id,
|
|
729
|
-
roots: { workspace: roots.workspace, skills: roots.skills, tmp: roots.tmp },
|
|
730
|
-
// a local device's outer boundary is its host environment; restricted rules are the
|
|
731
|
-
// operation's own network field, never an outer network-off
|
|
732
|
-
outerNetwork: { kind: "host-environment" },
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* A cloud instance's installed environment (B-15, Q1 option A): its current runtime report
|
|
737
|
-
* recorded with the kernel-built cloud identity (provider plugin and version, handle,
|
|
738
|
-
* generation, applied limits; `readCurrentReport`), named by that report's identity hash in
|
|
739
|
-
* place of a binding id. Null while the evidence is missing or stale, while desired limits wait
|
|
740
|
-
* for a file reset (`unapplied`) and while the applied limits are more permissive than the
|
|
741
|
-
* effective desired ones in any dimension (mode, network kind, a host the desired allowlist
|
|
742
|
-
* does not cover; spec §124): a pending desired change is never projected as installed. Applied
|
|
743
|
-
* limits narrower than desired stand (the outer boundary is the applied network, and restricted
|
|
744
|
-
* hosts are cut to it); the next use's lifecycle lease applies any change before admitting an
|
|
745
|
-
* operation, and its new limits change the identity, so that use records the evidence again.
|
|
746
|
-
*/
|
|
747
|
-
async cloudAppliedLocked(input, instance) {
|
|
748
|
-
const device = await this.db
|
|
749
|
-
.selectFrom("devices")
|
|
750
|
-
.select("provider")
|
|
751
|
-
.where("id", "=", input.deviceId)
|
|
752
|
-
.executeTakeFirst();
|
|
753
|
-
const entry = this.providers.forDevice(device?.provider ?? null);
|
|
592
|
+
const entry = this.providers.forDevice(device.provider);
|
|
754
593
|
if (!entry || entry.plugin !== instance.provider)
|
|
755
594
|
return null;
|
|
756
595
|
const evidence = await readCurrentReport(this.db.db, input.deviceId, entry.plugin, entry.version);
|
|
757
|
-
if (evidence.identityHash === null)
|
|
596
|
+
if (evidence.identityHash === null || evidence.support === null)
|
|
758
597
|
return null;
|
|
759
598
|
const limits = readInstanceLimits(instance.instance_limits);
|
|
760
599
|
if (limits.applied === null || limits.unapplied !== null)
|
|
761
600
|
return null;
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
|
|
601
|
+
// an operation-boundary runtime holds its outer boundary per operation in its host
|
|
602
|
+
// environment (the operation's own network field restricts it); an instance-boundary one's
|
|
603
|
+
// outer boundary is its applied instance network
|
|
604
|
+
const boundary = evidence.support.boundary;
|
|
605
|
+
// an instance's applied limits more permissive than the effective desired ones (spec §124)
|
|
606
|
+
// are not the installed authority: unproved until the next use's lifecycle lease applies the
|
|
607
|
+
// narrowing (an operation-boundary runtime's operations carry their own network)
|
|
608
|
+
if (boundary === "instance" &&
|
|
609
|
+
appliedWider(limits.applied, appliedOf(await this.devicePolicy(input))))
|
|
765
610
|
return null;
|
|
766
|
-
const outerNetwork =
|
|
611
|
+
const outerNetwork = boundary === "operation"
|
|
612
|
+
? { kind: "host-environment" }
|
|
613
|
+
: instanceOuterNetwork(limits.applied.network);
|
|
767
614
|
if (outerNetwork === null)
|
|
768
615
|
return null;
|
|
769
|
-
const roots = rootsOf(instance.handle);
|
|
770
616
|
return {
|
|
771
|
-
|
|
617
|
+
revision: evidence.identityHash,
|
|
618
|
+
boundary,
|
|
772
619
|
provider: instance.provider,
|
|
773
620
|
instanceId: instance.handle.id,
|
|
774
621
|
instanceGeneration: String(instance.created_at.getTime()),
|
|
775
|
-
bindingId: evidence.identityHash,
|
|
776
622
|
roots: { workspace: roots.workspace, skills: roots.skills, tmp: roots.tmp },
|
|
777
623
|
outerNetwork,
|
|
778
624
|
};
|
|
@@ -787,11 +633,11 @@ PermissionFacts = __decorate([
|
|
|
787
633
|
], PermissionFacts);
|
|
788
634
|
export { PermissionFacts };
|
|
789
635
|
/**
|
|
790
|
-
* The outer boundary
|
|
791
|
-
* allowlist (empty: network disabled). Null when the allowlist cannot be stated as
|
|
792
|
-
* context hosts (a host that is not a normalized authority host, or more than the cap).
|
|
636
|
+
* The outer boundary an instance-boundary instance's applied network proves: public addresses, or
|
|
637
|
+
* its exact allowlist (empty: network disabled). Null when the allowlist cannot be stated as
|
|
638
|
+
* recorded context hosts (a host that is not a normalized authority host, or more than the cap).
|
|
793
639
|
*/
|
|
794
|
-
export function
|
|
640
|
+
export function instanceOuterNetwork(network) {
|
|
795
641
|
if (network.kind === "open-public")
|
|
796
642
|
return { kind: "open-public" };
|
|
797
643
|
const hosts = [...new Set(network.hosts)].sort(permissionCodePointCompare);
|
|
@@ -802,9 +648,9 @@ export function cloudOuterNetwork(network) {
|
|
|
802
648
|
return { kind: "allowlist", hosts };
|
|
803
649
|
}
|
|
804
650
|
/**
|
|
805
|
-
* Restricted hosts within
|
|
806
|
-
*
|
|
807
|
-
*
|
|
651
|
+
* Restricted hosts within an instance's applied outer boundary (narrowing only): a host the outer
|
|
652
|
+
* allowlist does not cover cannot be reached, so neither admission nor the recorded context names
|
|
653
|
+
* it. An operation-boundary runtime's host environment keeps every host.
|
|
808
654
|
*/
|
|
809
655
|
export function hostsWithinOuter(hosts, outer) {
|
|
810
656
|
if (!outer || outer.kind === "host-environment" || outer.kind === "open-public")
|
|
@@ -814,8 +660,8 @@ export function hostsWithinOuter(hosts, outer) {
|
|
|
814
660
|
return hosts.filter((host) => outer.hosts.some((pattern) => coversHost(pattern, host)));
|
|
815
661
|
}
|
|
816
662
|
/**
|
|
817
|
-
* The network a device sandbox gives
|
|
818
|
-
*
|
|
663
|
+
* The network a device sandbox gives an instance's outer boundary: the open public internet, or
|
|
664
|
+
* its allowlist (empty under the kill switch, which closes it).
|
|
819
665
|
*/
|
|
820
666
|
export function networkOfSandbox(box) {
|
|
821
667
|
if (box.networkMode === "open")
|
|
@@ -823,11 +669,11 @@ export function networkOfSandbox(box) {
|
|
|
823
669
|
return { kind: "allowlist", hosts: box.networkMode === "allowlist" ? [...box.hosts] : [] };
|
|
824
670
|
}
|
|
825
671
|
/**
|
|
826
|
-
* A
|
|
827
|
-
* follows the org). A B1 snapshot is copied into it by migrations 0165 and
|
|
828
|
-
* writer and every publication (`copyCloudSnapshotNetworks`), never read here.
|
|
672
|
+
* A device's own sandbox network, whatever its provider: its stored choice (`network_mode`,
|
|
673
|
+
* `network_hosts`; null follows the org). A B1 snapshot is copied into it by migrations 0165 and
|
|
674
|
+
* 0167, the snapshot writer and every publication (`copyCloudSnapshotNetworks`), never read here.
|
|
829
675
|
*/
|
|
830
|
-
export function
|
|
676
|
+
export function ownNetwork(row) {
|
|
831
677
|
const hosts = row?.network_hosts;
|
|
832
678
|
const mode = row?.network_mode;
|
|
833
679
|
if (mode === "open" || mode === "allowlist" || mode === "none")
|