@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
|
@@ -10,6 +10,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { DialInHandlers } from "../dial-in/handlers.js";
|
|
14
|
+
import { DialInMachines } from "../dial-in/machines.js";
|
|
15
|
+
import { DialInRelay } from "../dial-in/relay.js";
|
|
13
16
|
import { ApiError } from "../errors.js";
|
|
14
17
|
import { ExtensionDisplayNames } from "../extensions/display-name.js";
|
|
15
18
|
import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
|
|
@@ -18,20 +21,14 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
18
21
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
22
|
import { assertNotSharedAdmission, TransactionHost, withOrderedLocks, } from "../infra/database/transaction-host.js";
|
|
20
23
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
|
-
import { LockService } from "../infra/lock/lock.service.js";
|
|
22
24
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
23
|
-
import { DevicePolicyService } from "../local-devices/device-policy.service.js";
|
|
24
|
-
import { deviceLeaseKey } from "../local-devices/keys.js";
|
|
25
|
-
import { MachinesService } from "../local-devices/machines.js";
|
|
26
|
-
import { ownerFactsOf } from "../local-devices/owner-report.js";
|
|
27
|
-
import { deviceFeaturesOf, localPolicyOf } from "../local-devices/policy-summary.js";
|
|
28
25
|
import { DeviceReports } from "../sandbox/device-reports.js";
|
|
29
26
|
import { hostGrantable } from "../sandbox/device-sandbox.js";
|
|
30
27
|
import { oweDeviceDestroy, SandboxJobs } from "../sandbox/jobs.js";
|
|
31
|
-
import { coversHost
|
|
28
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
32
29
|
import { hostsNarrowed, needsOpenNetwork, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
30
|
+
import { ownNetwork, PermissionFacts } from "../sandbox/permission-facts.js";
|
|
31
|
+
import { DeviceProviders, servesDialIn } from "../sandbox/providers.js";
|
|
35
32
|
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
36
33
|
import { DeviceAccess } from "./access.js";
|
|
37
34
|
import { DeviceProviderSelection } from "./device-provider-selection.js";
|
|
@@ -55,12 +52,14 @@ const providerNotOn = (provider, on) => {
|
|
|
55
52
|
const message = `Device provider ${provider} is not on in this organization; choose one of: ${providerChoices(on)}`;
|
|
56
53
|
return new ApiError("validation_failed", message, [{ path: "provider", message }]);
|
|
57
54
|
};
|
|
55
|
+
/** A device sign-in names a provider that is no dial-in provider on in the org (403). */
|
|
56
|
+
export const dialInProviderUnavailable = (provider) => new ApiError("device.provider_unavailable", `Device provider ${provider} cannot take a machine in this organization; choose one of the providers listed on the sign-in page`);
|
|
58
57
|
const nameTaken = () => new ApiError("device.name_taken", "You already have a device with this name");
|
|
59
58
|
/**
|
|
60
|
-
* Personal devices (spec 2026-11-07-environments-design §4.2 items 7, 12, 13; §6; §9)
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* person's devices in an org, visible and usable only by their owner (anyone else gets
|
|
59
|
+
* Personal devices (spec 2026-11-07-environments-design §4.2 items 7, 12, 13; §6; §9), each
|
|
60
|
+
* bound for life to the device provider it was created on (device-provider spec §6.1) and handled
|
|
61
|
+
* the same way whatever that provider is (a dial-in provider's device is signed in from its
|
|
62
|
+
* machine); a person's devices in an org, visible and usable only by their owner (anyone else gets
|
|
64
63
|
* `device.not_found`). Deleting one soft-deletes it and owes the destruction of its instance and
|
|
65
64
|
* files (a `sandbox-destroy-for` job) in the same transaction.
|
|
66
65
|
*/
|
|
@@ -73,20 +72,25 @@ let DevicesService = class DevicesService {
|
|
|
73
72
|
sandboxJobs;
|
|
74
73
|
outbox;
|
|
75
74
|
access;
|
|
76
|
-
|
|
75
|
+
relay;
|
|
76
|
+
providers;
|
|
77
77
|
machines;
|
|
78
|
-
policies;
|
|
79
78
|
ceilings;
|
|
80
79
|
facts;
|
|
81
80
|
displayNames;
|
|
82
81
|
reports;
|
|
82
|
+
dialIn;
|
|
83
83
|
constructor(db, txHost, config, selection, sandbox, sandboxJobs,
|
|
84
84
|
/** Owes a deleted device's destruction in the delete's transaction. */
|
|
85
85
|
outbox, access,
|
|
86
|
-
/**
|
|
87
|
-
|
|
86
|
+
/** Whether a dial-in device's machine is connected now. */
|
|
87
|
+
relay,
|
|
88
|
+
/** Each device's provider (whether it serves its devices over the dial-in channel). */
|
|
89
|
+
providers, machines, ceilings, facts, displayNames,
|
|
88
90
|
/** Each device's stored provider report (read only; never asks the provider). */
|
|
89
|
-
reports
|
|
91
|
+
reports,
|
|
92
|
+
/** The dial-in providers on in an org (a device signed in from a machine). */
|
|
93
|
+
dialIn) {
|
|
90
94
|
this.db = db;
|
|
91
95
|
this.txHost = txHost;
|
|
92
96
|
this.config = config;
|
|
@@ -95,13 +99,14 @@ let DevicesService = class DevicesService {
|
|
|
95
99
|
this.sandboxJobs = sandboxJobs;
|
|
96
100
|
this.outbox = outbox;
|
|
97
101
|
this.access = access;
|
|
98
|
-
this.
|
|
102
|
+
this.relay = relay;
|
|
103
|
+
this.providers = providers;
|
|
99
104
|
this.machines = machines;
|
|
100
|
-
this.policies = policies;
|
|
101
105
|
this.ceilings = ceilings;
|
|
102
106
|
this.facts = facts;
|
|
103
107
|
this.displayNames = displayNames;
|
|
104
108
|
this.reports = reports;
|
|
109
|
+
this.dialIn = dialIn;
|
|
105
110
|
}
|
|
106
111
|
/**
|
|
107
112
|
* The person's live devices in the org, the default first, then by creation, with the device
|
|
@@ -148,7 +153,7 @@ let DevicesService = class DevicesService {
|
|
|
148
153
|
return view;
|
|
149
154
|
}
|
|
150
155
|
/**
|
|
151
|
-
* A new personal
|
|
156
|
+
* A new personal device, ready at once (its instance and files are made on first use),
|
|
152
157
|
* bound for life to `input.provider` or, without one, the org's default provider: a provider not
|
|
153
158
|
* on in the org (unknown, not loaded, off, kernel-internal) → `validation_failed` at `provider`;
|
|
154
159
|
* none named and no default serving the org → `device.provider_required`. A live name of the
|
|
@@ -162,7 +167,7 @@ let DevicesService = class DevicesService {
|
|
|
162
167
|
return this.get(orgId, accountId, id);
|
|
163
168
|
}
|
|
164
169
|
/**
|
|
165
|
-
* The provider a new
|
|
170
|
+
* The provider a new device of `orgId` is bound to: `named` when it serves the org now
|
|
166
171
|
* (one of {@link DeviceProviderSelection.onInOrg}), else the org's default
|
|
167
172
|
* ({@link DeviceProviderSelection.defaultFor}) when none is named; never another one.
|
|
168
173
|
*/
|
|
@@ -179,18 +184,21 @@ let DevicesService = class DevicesService {
|
|
|
179
184
|
return fallback.plugin;
|
|
180
185
|
}
|
|
181
186
|
async insert(orgId, accountId, name, provider, actorTokenId, auditDetail) {
|
|
182
|
-
return this.insertNamed(orgId, accountId, name,
|
|
187
|
+
return this.insertNamed(orgId, accountId, name, provider, actorTokenId, auditDetail ?? {});
|
|
183
188
|
}
|
|
184
189
|
/**
|
|
185
|
-
* A new personal
|
|
186
|
-
*
|
|
190
|
+
* A new personal device for a machine being signed in (the device sign-in; the machine row is
|
|
191
|
+
* the caller's), bound for life to the dial-in provider `provider`: one that serves the org now
|
|
192
|
+
* and declares `permissions.dialIn` ({@link DialInHandlers.onInOrg}), else
|
|
193
|
+
* `device.provider_unavailable`. Joins the caller's transaction (the device authorization's).
|
|
187
194
|
* Counted against `devices.maxPersonal` (`device.limit_reached`); a live name of the
|
|
188
|
-
* person's → `device.name_taken`.
|
|
195
|
+
* person's → `device.name_taken`.
|
|
189
196
|
*/
|
|
190
|
-
async
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
197
|
+
async createDialIn(orgId, accountId, provider, name) {
|
|
198
|
+
if (!(await this.dialIn.onInOrg(orgId)).some((p) => p.plugin === provider)) {
|
|
199
|
+
throw dialInProviderUnavailable(provider);
|
|
200
|
+
}
|
|
201
|
+
const id = await this.insertNamed(orgId, accountId, name, provider, undefined, {});
|
|
194
202
|
return { id };
|
|
195
203
|
}
|
|
196
204
|
/**
|
|
@@ -198,7 +206,7 @@ let DevicesService = class DevicesService {
|
|
|
198
206
|
* and name checks, and audits `device.created` (with its provider). Runs in the caller's
|
|
199
207
|
* transaction.
|
|
200
208
|
*/
|
|
201
|
-
async insertNamed(orgId, accountId, name,
|
|
209
|
+
async insertNamed(orgId, accountId, name, provider, actorTokenId, auditDetail) {
|
|
202
210
|
await this.lockMember(orgId, accountId);
|
|
203
211
|
const { n } = await this.db
|
|
204
212
|
.selectFrom("devices")
|
|
@@ -223,7 +231,6 @@ let DevicesService = class DevicesService {
|
|
|
223
231
|
owner_kind: "personal",
|
|
224
232
|
owner_account_id: accountId,
|
|
225
233
|
name,
|
|
226
|
-
source,
|
|
227
234
|
provider,
|
|
228
235
|
})
|
|
229
236
|
.execute();
|
|
@@ -277,11 +284,12 @@ let DevicesService = class DevicesService {
|
|
|
277
284
|
return Number(n);
|
|
278
285
|
}
|
|
279
286
|
/**
|
|
280
|
-
* The refusals {@link resetFiles} would raise (not found, its provider not
|
|
281
|
-
*
|
|
287
|
+
* The refusals {@link resetFiles} would raise (not found, its provider not on, a provider that
|
|
288
|
+
* offers no reset), read only.
|
|
282
289
|
*/
|
|
283
290
|
async checkReset(orgId, accountId, id) {
|
|
284
|
-
|
|
291
|
+
await this.access.usable(orgId, accountId, id);
|
|
292
|
+
refuseDeviceReset(await this.reports.read(orgId, id));
|
|
285
293
|
}
|
|
286
294
|
/** The refusals {@link rename} would raise, read without locks (see {@link checkCreate}). */
|
|
287
295
|
async checkRename(orgId, accountId, id, name) {
|
|
@@ -304,13 +312,12 @@ let DevicesService = class DevicesService {
|
|
|
304
312
|
await this.renameLocked(orgId, accountId, id, before, name, actorTokenId, auditDetail);
|
|
305
313
|
}
|
|
306
314
|
/**
|
|
307
|
-
* `PATCH /devices/:id`: renames one of the person's live devices ({@link rename}) and sets
|
|
308
|
-
*
|
|
309
|
-
* takes the membership, the device row and the device's permission write lock as
|
|
310
|
-
* prelude (`withOrderedLocks`): inside a run's fence (`devices.set-network`) they
|
|
311
|
-
* row and precede the conversation rows.
|
|
312
|
-
*
|
|
313
|
-
* only narrow, stored and effective.
|
|
315
|
+
* `PATCH /devices/:id`: renames one of the person's live devices ({@link rename}) and sets its
|
|
316
|
+
* sandbox network ({@link networkLocked}), in one transaction, the same for every provider. A
|
|
317
|
+
* network change takes the membership, the device row and the device's permission write lock as
|
|
318
|
+
* the ordered prelude (`withOrderedLocks`): inside a run's fence (`devices.set-network`) they
|
|
319
|
+
* follow the org row and precede the conversation rows. `narrowOnly` (an API token, the Platform
|
|
320
|
+
* tool): the network may only narrow, stored and effective.
|
|
314
321
|
*/
|
|
315
322
|
async update(orgId, accountId, id, patch, actorTokenId, opts = {}) {
|
|
316
323
|
if (patch.network !== undefined)
|
|
@@ -328,21 +335,21 @@ let DevicesService = class DevicesService {
|
|
|
328
335
|
// held since the prelude for a network change (naming them again re-checks)
|
|
329
336
|
const before = await this.lockOwn(orgId, accountId, id);
|
|
330
337
|
if (patch.network !== undefined)
|
|
331
|
-
await this.networkLocked(orgId, accountId, id,
|
|
338
|
+
await this.networkLocked(orgId, accountId, id, patch.network, actorTokenId, opts);
|
|
332
339
|
if (patch.name !== undefined) {
|
|
333
340
|
await this.renameLocked(orgId, accountId, id, before, patch.name, actorTokenId, opts.auditDetail);
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
/**
|
|
337
|
-
* Checks a
|
|
338
|
-
*
|
|
344
|
+
* Checks a network change without writing anything and without locks (the Platform tool's
|
|
345
|
+
* precheck): the device is the person's live device, and the change stays within
|
|
339
346
|
* the ceilings and, with `narrowOnly`, only narrows. Throws what {@link update} would; the
|
|
340
347
|
* write re-checks under its locks.
|
|
341
348
|
*/
|
|
342
349
|
async checkNetwork(orgId, accountId, id, network, narrowOnly) {
|
|
343
350
|
const row = await this.db
|
|
344
351
|
.selectFrom("devices")
|
|
345
|
-
.select(["
|
|
352
|
+
.select(["id"])
|
|
346
353
|
.where("id", "=", id)
|
|
347
354
|
.where("org_id", "=", orgId)
|
|
348
355
|
.where("owner_kind", "=", "personal")
|
|
@@ -351,25 +358,22 @@ let DevicesService = class DevicesService {
|
|
|
351
358
|
.executeTakeFirst();
|
|
352
359
|
if (!row)
|
|
353
360
|
throw deviceNotFound();
|
|
354
|
-
await this.planNetwork(orgId, id,
|
|
361
|
+
await this.planNetwork(orgId, id, network, narrowOnly);
|
|
355
362
|
}
|
|
356
363
|
/**
|
|
357
|
-
* Decides a
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* (`device.network_not_allowed`)
|
|
362
|
-
* the effective network (`device.network_not_allowed`). Null when nothing changes.
|
|
364
|
+
* Decides a network change (read only): the stored setting before and after, the effective
|
|
365
|
+
* device sandbox before and after (computed in memory from the patched setting), and whether it
|
|
366
|
+
* widens. Refuses, without writing: the open network above the ceilings or a host outside the
|
|
367
|
+
* org's list (`device.network_not_allowed`), and with `narrowOnly` a widening of the stored
|
|
368
|
+
* setting or of the effective network (`device.network_not_allowed`). Null when nothing changes.
|
|
363
369
|
*/
|
|
364
|
-
async planNetwork(orgId, id,
|
|
365
|
-
if (before.source !== "cloud")
|
|
366
|
-
throw new ApiError("device.ceiling_on_machine", "This device's sandbox network is kept on its connected machine: narrow it from the device page, or widen it on that machine with capybara-device ceiling set --network open or capybara-device policy add allowedDomains <host>.");
|
|
370
|
+
async planNetwork(orgId, id, want, narrowOnly) {
|
|
367
371
|
const row = await this.db
|
|
368
372
|
.selectFrom("devices")
|
|
369
373
|
.select(["network_mode", "network_hosts"])
|
|
370
374
|
.where("id", "=", id)
|
|
371
375
|
.executeTakeFirstOrThrow();
|
|
372
|
-
const own =
|
|
376
|
+
const own = ownNetwork(row);
|
|
373
377
|
const from = { mode: own.networkMode, hosts: [...own.networkHosts] };
|
|
374
378
|
const to = {
|
|
375
379
|
mode: want.mode,
|
|
@@ -398,7 +402,7 @@ let DevicesService = class DevicesService {
|
|
|
398
402
|
return { from, to, next, widened };
|
|
399
403
|
}
|
|
400
404
|
/**
|
|
401
|
-
* A
|
|
405
|
+
* A device's sandbox network (approval-only profiles design, "Settings model"), under the
|
|
402
406
|
* device authority writer held since the prelude: its owner chooses `open`, `allowlist` (its
|
|
403
407
|
* org's hosts, narrowed by its own list: a device list never adds a host; an empty one follows
|
|
404
408
|
* the org's hosts), `none` (closed) or null (follow the org), in both directions within the
|
|
@@ -408,9 +412,9 @@ let DevicesService = class DevicesService {
|
|
|
408
412
|
* Full consent; a widening resets Full consent with a `permission_profile_changed` event.
|
|
409
413
|
* Audited `device.network_changed` (`via`: `web`, `token` for an API token, or the agent's).
|
|
410
414
|
*/
|
|
411
|
-
async networkLocked(orgId, accountId, id,
|
|
415
|
+
async networkLocked(orgId, accountId, id, want, actorTokenId, opts) {
|
|
412
416
|
await this.ceilings.lock({ orgId, deviceId: id }, "device");
|
|
413
|
-
const plan = await this.planNetwork(orgId, id,
|
|
417
|
+
const plan = await this.planNetwork(orgId, id, want, opts.narrowOnly === true);
|
|
414
418
|
if (plan === null)
|
|
415
419
|
return;
|
|
416
420
|
const { from, to, next, widened } = plan;
|
|
@@ -439,36 +443,17 @@ let DevicesService = class DevicesService {
|
|
|
439
443
|
},
|
|
440
444
|
});
|
|
441
445
|
}
|
|
442
|
-
/**
|
|
443
|
-
* How far restricted work may root outside the device's workspace now (B2): a local machine's
|
|
444
|
-
* owner reach within a platform and org that allow the wider device ceiling; a cloud device
|
|
445
|
-
* keeps its previous rule (its effective mode). Never the owner's Full permission alone.
|
|
446
|
-
*/
|
|
447
|
-
async projectReach(orgId, deviceId) {
|
|
448
|
-
const row = await this.db
|
|
449
|
-
.selectFrom("devices as e")
|
|
450
|
-
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
451
|
-
.select(["e.source", "m.owner_report", "m.local_policy"])
|
|
452
|
-
.where("e.id", "=", deviceId)
|
|
453
|
-
.where("e.org_id", "=", orgId)
|
|
454
|
-
.where("e.deleted_at", "is", null)
|
|
455
|
-
.executeTakeFirst();
|
|
456
|
-
if (row === undefined)
|
|
457
|
-
return "workspace";
|
|
458
|
-
const policy = await this.sandbox.devicePolicy({ orgId, deviceId });
|
|
459
|
-
return projectReachOf(row.source, policy, row.source === "local" ? ownerFactsOf(row).restrictedProjectReach : null);
|
|
460
|
-
}
|
|
461
446
|
/**
|
|
462
447
|
* The level a sandbox call in the device runs at now, for the model (legacy `device_paths`, auto
|
|
463
|
-
* mode spec §4.2): the kernel-internal tier (`SandboxMode
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* device is not a live device of the org.
|
|
448
|
+
* mode spec §4.2), the same for every provider: the kernel-internal tier (`SandboxMode`) with
|
|
449
|
+
* its device sandbox network, a pending file-reset state (the tier and network its instance
|
|
450
|
+
* still runs with), and whether its provider runs each operation on its host machine (an
|
|
451
|
+
* operation boundary). Null when the device is not a live device of the org.
|
|
467
452
|
*/
|
|
468
453
|
async modeLevel(orgId, deviceId) {
|
|
469
454
|
const row = await this.db
|
|
470
455
|
.selectFrom("devices")
|
|
471
|
-
.select(["
|
|
456
|
+
.select(["id"])
|
|
472
457
|
.where("id", "=", deviceId)
|
|
473
458
|
.where("org_id", "=", orgId)
|
|
474
459
|
.where("deleted_at", "is", null)
|
|
@@ -477,20 +462,21 @@ let DevicesService = class DevicesService {
|
|
|
477
462
|
return null;
|
|
478
463
|
const policy = await this.sandbox.devicePolicy({ orgId, deviceId });
|
|
479
464
|
let mode = policy.mode;
|
|
480
|
-
let network =
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
// limits: tell the model the widest, never a narrower network than it may reach
|
|
488
|
-
mode = state.applied === null ? "auto" : state.applied.mode;
|
|
489
|
-
network =
|
|
490
|
-
state.applied === null ? { kind: "open-public", hosts: [] } : state.applied.network;
|
|
491
|
-
}
|
|
465
|
+
let network = policy.network;
|
|
466
|
+
const state = await this.sandbox.limitsState({ orgId, deviceId }, { policy });
|
|
467
|
+
if (state.pendingFilesReset) {
|
|
468
|
+
// an unknown record (an instance made before auto mode) may be wider than the effective
|
|
469
|
+
// limits: tell the model the widest, never a narrower network than it may reach
|
|
470
|
+
mode = state.applied === null ? "auto" : state.applied.mode;
|
|
471
|
+
network = state.applied === null ? { kind: "open-public", hosts: [] } : state.applied.network;
|
|
492
472
|
}
|
|
493
|
-
|
|
473
|
+
const box = await this.facts.deviceSandbox(orgId, deviceId);
|
|
474
|
+
return {
|
|
475
|
+
mode,
|
|
476
|
+
allowedMode: policy.allowedMode,
|
|
477
|
+
network,
|
|
478
|
+
local: box.boundary === "operation",
|
|
479
|
+
};
|
|
494
480
|
}
|
|
495
481
|
/** Renames the device locked by {@link lockOwn} (`before`); see {@link rename}. */
|
|
496
482
|
async renameLocked(orgId, accountId, id, before, name, actorTokenId, auditDetail) {
|
|
@@ -525,7 +511,7 @@ let DevicesService = class DevicesService {
|
|
|
525
511
|
* Deletes one of the person's live devices: soft delete, its IM default row cleared, and a
|
|
526
512
|
* `sandbox-destroy-for` job owed in the same transaction (`device-destroy-<deviceId>`; the
|
|
527
513
|
* worker waits for running commands, then destroys the instance and the files). Conversations bound to it keep pointing at it; their
|
|
528
|
-
* sandbox tools then fail with `device.not_found`. A
|
|
514
|
+
* sandbox tools then fail with `device.not_found`. A dial-in device's machine is
|
|
529
515
|
* revoked in the same transaction; after the commit it is told `stop { reason: "deleted" }`
|
|
530
516
|
* (while connected) and its connection is closed.
|
|
531
517
|
*
|
|
@@ -569,50 +555,19 @@ let DevicesService = class DevicesService {
|
|
|
569
555
|
await oweDeviceDestroy(this.outbox, id, orgId);
|
|
570
556
|
}
|
|
571
557
|
/**
|
|
572
|
-
* Disconnects the machine of one of the person's own
|
|
573
|
-
* again); see {@link
|
|
558
|
+
* Disconnects the machine of one of the person's own dial-in devices (it must sign in
|
|
559
|
+
* again); see {@link DialInMachines.revoke}.
|
|
574
560
|
*/
|
|
575
561
|
async revokeMachine(orgId, accountId, id, actorTokenId) {
|
|
576
562
|
await this.machines.revoke(orgId, accountId, id, actorTokenId);
|
|
577
563
|
}
|
|
578
|
-
/**
|
|
579
|
-
* The owner narrows one of their own local devices' sandbox from the web (approval-only
|
|
580
|
-
* profiles design, "Settings model"): sent to the machine with the `policy` op, which is the
|
|
581
|
-
* authority and answers with the policy as written. Anyone but the owner gets
|
|
582
|
-
* `device.not_found`. The owner may remove hosts from the machine's allowlist and narrow its
|
|
583
|
-
* owner ceiling (no running outside the sandbox, the allowlist network, the workspace reach);
|
|
584
|
-
* widening happens on the machine only. The machine offline → `device.offline`; a cloud device
|
|
585
|
-
* or a program without the `policyOpId` feature → `device.policy_unsupported`; the machine's
|
|
586
|
-
* refusal → `device.policy_refused` with its message. Callers are human sessions only (no
|
|
587
|
-
* personal access token, no service token, no Platform op).
|
|
588
|
-
*/
|
|
589
|
-
async changePolicy(orgId, account, id, change) {
|
|
590
|
-
await this.access.usable(orgId, account.id, id);
|
|
591
|
-
const out = await this.policies.apply({
|
|
592
|
-
orgId,
|
|
593
|
-
deviceId: id,
|
|
594
|
-
change: {
|
|
595
|
-
...(change.remove !== undefined && { remove: change.remove }),
|
|
596
|
-
...(change.ownerCeiling !== undefined && { ownerCeiling: narrowOnly(change.ownerCeiling) }),
|
|
597
|
-
},
|
|
598
|
-
source: { accountId: account.id, accountName: account.displayName, via: "web" },
|
|
599
|
-
});
|
|
600
|
-
if (out.applied)
|
|
601
|
-
return out.policy;
|
|
602
|
-
if (out.reason === "offline")
|
|
603
|
-
throw new ApiError("device.offline", out.message);
|
|
604
|
-
if (out.reason === "unsupported") {
|
|
605
|
-
throw new ApiError("device.policy_unsupported", out.message);
|
|
606
|
-
}
|
|
607
|
-
throw new ApiError("device.policy_refused", out.message);
|
|
608
|
-
}
|
|
609
564
|
/**
|
|
610
565
|
* Starts one of the person's devices over with empty files (after
|
|
611
566
|
* `device.files_lost`): records the request (audit), then, after the commit, enqueues the
|
|
612
567
|
* `sandbox-reset-files` job (deterministic id per device), whose worker waits for running
|
|
613
568
|
* commands and destroys any instance and the file system; the next use creates new ones. Its
|
|
614
|
-
* provider must be
|
|
615
|
-
*
|
|
569
|
+
* provider must be on (`device.unavailable`) and offer a reset (its report's `reset`, else
|
|
570
|
+
* `device.files_on_device`). An enqueue failure is thrown
|
|
616
571
|
* (the request can be repeated: the reset is idempotent).
|
|
617
572
|
*/
|
|
618
573
|
async resetFiles(orgId, accountId, id, actorTokenId, auditDetail) {
|
|
@@ -621,7 +576,8 @@ let DevicesService = class DevicesService {
|
|
|
621
576
|
}
|
|
622
577
|
/** The check and audit row of {@link resetFiles}, committed before the job is enqueued. */
|
|
623
578
|
async recordReset(orgId, accountId, id, actorTokenId, auditDetail) {
|
|
624
|
-
|
|
579
|
+
await this.access.usable(orgId, accountId, id);
|
|
580
|
+
refuseDeviceReset(await this.reports.read(orgId, id));
|
|
625
581
|
await audit(this.db.db, {
|
|
626
582
|
actorAccountId: accountId,
|
|
627
583
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -667,7 +623,6 @@ let DevicesService = class DevicesService {
|
|
|
667
623
|
owner_account_id: accountId,
|
|
668
624
|
name: null,
|
|
669
625
|
is_default: true,
|
|
670
|
-
source: "cloud",
|
|
671
626
|
provider,
|
|
672
627
|
})
|
|
673
628
|
.onConflict((oc) => oc
|
|
@@ -751,7 +706,6 @@ let DevicesService = class DevicesService {
|
|
|
751
706
|
"e.id",
|
|
752
707
|
"e.name",
|
|
753
708
|
"e.is_default",
|
|
754
|
-
"e.source",
|
|
755
709
|
"e.provider",
|
|
756
710
|
"e.network_mode",
|
|
757
711
|
"e.network_hosts",
|
|
@@ -760,13 +714,8 @@ let DevicesService = class DevicesService {
|
|
|
760
714
|
"m.id as machine_id",
|
|
761
715
|
"m.name as machine_name",
|
|
762
716
|
"m.os as machine_os",
|
|
763
|
-
"m.mode as machine_mode",
|
|
764
717
|
"m.program_version as machine_program_version",
|
|
765
718
|
"m.last_seen_at as machine_last_seen_at",
|
|
766
|
-
"m.session_isolation as machine_session_isolation",
|
|
767
|
-
"m.features as machine_features",
|
|
768
|
-
"m.local_policy as machine_local_policy",
|
|
769
|
-
"m.owner_report as machine_owner_report",
|
|
770
719
|
"i.provider as instance_provider",
|
|
771
720
|
"i.fs_status",
|
|
772
721
|
"i.handle",
|
|
@@ -785,76 +734,58 @@ let DevicesService = class DevicesService {
|
|
|
785
734
|
if (rows.length === 0)
|
|
786
735
|
return [];
|
|
787
736
|
const recent = await this.recentChanges(orgId, rows.map((r) => r.id));
|
|
788
|
-
// whether each provider serves the org now
|
|
789
|
-
// request; a kernel-internal provider (`@local`) is on while registered (`isOnInOrg`)
|
|
737
|
+
// whether each provider serves the org now, evaluated once per provider and request
|
|
790
738
|
const providerNames = [...new Set(rows.flatMap((r) => (r.provider ? [r.provider] : [])))];
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
: new Set();
|
|
794
|
-
const on = new Map(await Promise.all(providerNames.map(async (p) => [
|
|
795
|
-
p,
|
|
796
|
-
isInternalProvider(p) ? await this.selection.isOnInOrg(orgId, p) : served.has(p),
|
|
797
|
-
])));
|
|
798
|
-
// each device's sandbox, limits and its instance's pending change
|
|
739
|
+
const on = new Map(await Promise.all(providerNames.map(async (p) => [p, await this.selection.isOnInOrg(orgId, p)])));
|
|
740
|
+
// each device's sandbox, limits, its instance's pending change and its stored report
|
|
799
741
|
const perDevice = new Map(await Promise.all(rows.map(async (r) => {
|
|
800
742
|
const policy = await this.sandbox.devicePolicy({ orgId, deviceId: r.id });
|
|
801
743
|
const [limits, state, facts, report] = await Promise.all([
|
|
802
|
-
this.sandbox.deviceLimits({ orgId, deviceId: r.id }, { policy
|
|
803
|
-
r.
|
|
804
|
-
? this.sandbox.limitsState({ orgId, deviceId: r.id }, { policy })
|
|
805
|
-
: { pendingNextUse: false, pendingFilesReset: false },
|
|
744
|
+
this.sandbox.deviceLimits({ orgId, deviceId: r.id }, { policy }),
|
|
745
|
+
this.sandbox.limitsState({ orgId, deviceId: r.id }, { policy }),
|
|
806
746
|
this.facts.deviceSandboxFacts(orgId, r.id),
|
|
807
747
|
this.reports.read(orgId, r.id),
|
|
808
748
|
]);
|
|
809
749
|
return [r.id, { limits, state, box: facts.box, report }];
|
|
810
750
|
})));
|
|
811
|
-
// a
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
.map(async (r) => [r.id, (await this.locks.holderOf(deviceLeaseKey(r.id))) !== null])));
|
|
751
|
+
// a dial-in device is online while a replica holds its machine's connection
|
|
752
|
+
const dialIn = new Set(rows.filter((r) => this.isDialIn(r.provider)).map((r) => r.id));
|
|
753
|
+
const online = new Map(await Promise.all([...dialIn].map(async (deviceId) => [deviceId, await this.relay.online(deviceId)])));
|
|
815
754
|
return rows.map((r) => {
|
|
816
755
|
const provider = r.provider;
|
|
817
756
|
const live = (r.status === "running" || r.status === "suspended") && r.last_used_at;
|
|
757
|
+
const device = perDevice.get(r.id);
|
|
818
758
|
return {
|
|
819
759
|
id: r.id,
|
|
820
760
|
name: r.name,
|
|
821
761
|
isDefault: r.is_default,
|
|
822
762
|
ownerKind: "personal",
|
|
823
|
-
source: r.source,
|
|
824
763
|
provider,
|
|
764
|
+
dialIn: dialIn.has(r.id),
|
|
825
765
|
// an instance row of another provider (never written by this kernel) is refused on use
|
|
826
766
|
available: provider !== null &&
|
|
827
767
|
(on.get(provider) ?? false) &&
|
|
828
768
|
(r.instance_provider === null || r.instance_provider === provider),
|
|
829
|
-
report:
|
|
830
|
-
online: r.
|
|
831
|
-
machine:
|
|
769
|
+
report: device?.report ?? null,
|
|
770
|
+
online: dialIn.has(r.id) ? (online.get(r.id) ?? false) : null,
|
|
771
|
+
machine: dialIn.has(r.id) &&
|
|
772
|
+
r.machine_id !== null &&
|
|
773
|
+
r.machine_name !== null &&
|
|
774
|
+
r.machine_os !== null
|
|
832
775
|
? {
|
|
833
776
|
id: r.machine_id,
|
|
834
777
|
name: r.machine_name,
|
|
835
778
|
os: r.machine_os,
|
|
836
|
-
mode: r.machine_mode,
|
|
837
779
|
programVersion: r.machine_program_version,
|
|
838
780
|
lastSeenAt: r.machine_last_seen_at?.toISOString() ?? null,
|
|
839
781
|
}
|
|
840
782
|
: null,
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
policy: localPolicyOf(r.machine_local_policy),
|
|
845
|
-
}
|
|
846
|
-
: null,
|
|
847
|
-
sandbox: sandboxViewOf(perDevice.get(r.id)?.box, r.source === "local"
|
|
848
|
-
? ownerFactsOf({ owner_report: r.machine_owner_report })
|
|
849
|
-
: cloudOwnNetwork(r), {
|
|
850
|
-
pendingNextUse: perDevice.get(r.id)?.state.pendingNextUse ?? false,
|
|
851
|
-
pendingFilesReset: perDevice.get(r.id)?.state.pendingFilesReset ?? false,
|
|
783
|
+
sandbox: sandboxViewOf(device?.box, ownNetwork(r), {
|
|
784
|
+
pendingNextUse: device?.state.pendingNextUse ?? false,
|
|
785
|
+
pendingFilesReset: device?.state.pendingFilesReset ?? false,
|
|
852
786
|
recent: recent.get(r.id) ?? [],
|
|
853
787
|
}),
|
|
854
|
-
|
|
855
|
-
ownerCeiling: ownerCeilingViewOf(r, online.get(r.id) ?? false),
|
|
856
|
-
reconcileRequired: r.source === "cloud" && r.permission_reconcile_required,
|
|
857
|
-
sessionIsolation: r.machine_session_isolation ?? false,
|
|
788
|
+
reconcileRequired: r.permission_reconcile_required,
|
|
858
789
|
filesLost: r.fs_status === "lost",
|
|
859
790
|
instance: live
|
|
860
791
|
? {
|
|
@@ -862,11 +793,16 @@ let DevicesService = class DevicesService {
|
|
|
862
793
|
lastUsedAt: r.last_used_at.toISOString(),
|
|
863
794
|
}
|
|
864
795
|
: null,
|
|
865
|
-
limits: limitsView(
|
|
796
|
+
limits: limitsView(device?.limits),
|
|
866
797
|
createdAt: r.created_at.toISOString(),
|
|
867
798
|
};
|
|
868
799
|
});
|
|
869
800
|
}
|
|
801
|
+
/** Whether `provider` (a device's `devices.provider`) serves its devices over dial-in. */
|
|
802
|
+
isDialIn(provider) {
|
|
803
|
+
const p = this.providers.forDevice(provider);
|
|
804
|
+
return p !== undefined && servesDialIn(p);
|
|
805
|
+
}
|
|
870
806
|
/**
|
|
871
807
|
* The last {@link RECENT_POLICY_CHANGES} setting changes of each device in the org (audit rows
|
|
872
808
|
* {@link SETTING_CHANGE_ACTIONS}), newest first, with the deciding account's display name.
|
|
@@ -950,7 +886,7 @@ let DevicesService = class DevicesService {
|
|
|
950
886
|
await this.lockMember(orgId, accountId);
|
|
951
887
|
const row = await this.db
|
|
952
888
|
.selectFrom("devices")
|
|
953
|
-
.select(["name", "is_default"
|
|
889
|
+
.select(["name", "is_default"])
|
|
954
890
|
.where("id", "=", id)
|
|
955
891
|
.where("org_id", "=", orgId)
|
|
956
892
|
.where("owner_kind", "=", "personal")
|
|
@@ -980,7 +916,7 @@ __decorate([
|
|
|
980
916
|
], DevicesService.prototype, "insert", null);
|
|
981
917
|
__decorate([
|
|
982
918
|
Transactional()
|
|
983
|
-
], DevicesService.prototype, "
|
|
919
|
+
], DevicesService.prototype, "createDialIn", null);
|
|
984
920
|
__decorate([
|
|
985
921
|
Transactional()
|
|
986
922
|
], DevicesService.prototype, "renameIn", null);
|
|
@@ -1012,22 +948,25 @@ DevicesService = __decorate([
|
|
|
1012
948
|
__param(5, Inject(SandboxJobs)),
|
|
1013
949
|
__param(6, Inject(OutboxService)),
|
|
1014
950
|
__param(7, Inject(DeviceAccess)),
|
|
1015
|
-
__param(8, Inject(
|
|
1016
|
-
__param(9, Inject(
|
|
1017
|
-
__param(10, Inject(
|
|
951
|
+
__param(8, Inject(DialInRelay)),
|
|
952
|
+
__param(9, Inject(DeviceProviders)),
|
|
953
|
+
__param(10, Inject(DialInMachines)),
|
|
1018
954
|
__param(11, Inject(PermissionCeilingWrites)),
|
|
1019
955
|
__param(12, Inject(PermissionFacts)),
|
|
1020
956
|
__param(13, Inject(ExtensionDisplayNames)),
|
|
1021
|
-
__param(14, Inject(DeviceReports))
|
|
957
|
+
__param(14, Inject(DeviceReports)),
|
|
958
|
+
__param(15, Inject(DialInHandlers))
|
|
1022
959
|
], DevicesService);
|
|
1023
960
|
export { DevicesService };
|
|
1024
961
|
/**
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
962
|
+
* A device whose provider last reported no file reset (`report.reset` false, device-provider spec
|
|
963
|
+
* §6.1): its files are kept where the provider keeps them and the platform never wipes them
|
|
964
|
+
* (`device.files_on_device`, with the provider's own description). A device with no stored report
|
|
965
|
+
* yet is not refused: its provider's reset decides.
|
|
1027
966
|
*/
|
|
1028
|
-
function refuseDeviceReset(
|
|
1029
|
-
if (
|
|
1030
|
-
throw new ApiError("device.files_on_device",
|
|
967
|
+
function refuseDeviceReset(report) {
|
|
968
|
+
if (report !== null && !report.reset) {
|
|
969
|
+
throw new ApiError("device.files_on_device", `This device's provider does not reset its files from here (${report.description.en}).`);
|
|
1031
970
|
}
|
|
1032
971
|
}
|
|
1033
972
|
/** A copy of `l` for a view (its lists not shared; the kernel-internal tier left out). */
|
|
@@ -1164,52 +1103,18 @@ function settingChangeOf(action, at, d, by) {
|
|
|
1164
1103
|
};
|
|
1165
1104
|
}
|
|
1166
1105
|
/**
|
|
1167
|
-
* The sandbox view of one device: its effective {@link DeviceSandbox} with its own network
|
|
1168
|
-
* (`own
|
|
1169
|
-
* change with the recent changes.
|
|
1106
|
+
* The sandbox view of one device: its effective {@link DeviceSandbox} with its own stored network
|
|
1107
|
+
* setting (`own`) and the instance's pending change with the recent changes.
|
|
1170
1108
|
*/
|
|
1171
1109
|
export function sandboxViewOf(box, own, extra) {
|
|
1172
|
-
const local = "state" in own;
|
|
1173
1110
|
return {
|
|
1174
1111
|
network: box.networkMode,
|
|
1175
1112
|
networkCeiling: box.networkCeiling,
|
|
1176
1113
|
hosts: [...box.hosts],
|
|
1177
|
-
ownNetwork:
|
|
1178
|
-
allowedDomains:
|
|
1114
|
+
ownNetwork: own.networkMode,
|
|
1115
|
+
allowedDomains: [...own.networkHosts],
|
|
1179
1116
|
outsideSandbox: box.outsideSandbox,
|
|
1180
|
-
restrictedProjectReach: box.restrictedProjectReach,
|
|
1181
1117
|
layer: { ...box.layer },
|
|
1182
1118
|
...extra,
|
|
1183
1119
|
};
|
|
1184
1120
|
}
|
|
1185
|
-
/** The read-only owner ceiling view of a listed local device row. */
|
|
1186
|
-
function ownerCeilingViewOf(r, online) {
|
|
1187
|
-
if (r.source === "cloud" || r.machine_id === null)
|
|
1188
|
-
return null;
|
|
1189
|
-
const f = ownerFactsOf({ owner_report: r.machine_owner_report });
|
|
1190
|
-
return {
|
|
1191
|
-
state: f.state,
|
|
1192
|
-
revision: f.revision,
|
|
1193
|
-
sequence: f.sequence,
|
|
1194
|
-
outsideSandbox: f.outsideSandbox,
|
|
1195
|
-
network: f.network,
|
|
1196
|
-
allowedDomains: [...f.allowedDomains],
|
|
1197
|
-
restrictedProjectReach: f.restrictedProjectReach,
|
|
1198
|
-
observedAt: f.observedAt,
|
|
1199
|
-
stale: !online || f.state !== "report",
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
/** The owner ceiling narrowing the web may send: anything wider is refused, never sent. */
|
|
1203
|
-
function narrowOnly(c) {
|
|
1204
|
-
if ((c.outsideSandbox !== undefined && c.outsideSandbox !== false) ||
|
|
1205
|
-
(c.network !== undefined && c.network !== "allowlist") ||
|
|
1206
|
-
(c.restrictedProjectReach !== undefined && c.restrictedProjectReach !== "workspace"))
|
|
1207
|
-
throw new ApiError("validation_failed", "The device page can only narrow a machine's owner ceiling; widen it on the machine with capybara-device ceiling set");
|
|
1208
|
-
return {
|
|
1209
|
-
...(c.outsideSandbox === false && { outsideSandbox: false }),
|
|
1210
|
-
...(c.network === "allowlist" && { network: "allowlist" }),
|
|
1211
|
-
...(c.restrictedProjectReach === "workspace" && {
|
|
1212
|
-
restrictedProjectReach: "workspace",
|
|
1213
|
-
}),
|
|
1214
|
-
};
|
|
1215
|
-
}
|