@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +3 -3
- package/dist/admin/admin.schemas.d.ts +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +11 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +304 -4
- package/dist/conversations/events.js +279 -29
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/db/kernel-schema.d.ts +238 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +31 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +129 -0
- package/dist/sandbox/review/review.service.d.ts +4 -1
- package/dist/sandbox/review/review.service.js +19 -5
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtins/builtin-tools.d.ts +16 -2
- package/dist/tools/builtins/builtin-tools.js +38 -10
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +2 -2
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +300 -19
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +12 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -15,18 +15,22 @@ import { ExtensionDisplayNames } from "../extensions/display-name.js";
|
|
|
15
15
|
import { audit } from "../identity/audit.js";
|
|
16
16
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
17
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
18
|
-
import { assertNotSharedAdmission, TransactionHost } from "../infra/database/transaction-host.js";
|
|
18
|
+
import { assertNotSharedAdmission, TransactionHost, withOrderedLocks, } from "../infra/database/transaction-host.js";
|
|
19
19
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
20
20
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
21
21
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
22
22
|
import { DevicePolicyService } from "../local-devices/device-policy.service.js";
|
|
23
23
|
import { deviceLeaseKey } from "../local-devices/keys.js";
|
|
24
24
|
import { MachinesService } from "../local-devices/machines.js";
|
|
25
|
-
import {
|
|
25
|
+
import { ownerFactsOf, ownerModeOf } from "../local-devices/owner-report.js";
|
|
26
|
+
import { deviceFeaturesOf, localPolicyOf } from "../local-devices/policy-summary.js";
|
|
26
27
|
import { readOrgSettings } from "../orgs/settings.service.js";
|
|
27
28
|
import { oweDeviceDestroy, SandboxJobs } from "../sandbox/jobs.js";
|
|
28
|
-
import { deviceNetwork, effectiveDevicePolicy, readDeploymentDevicePolicy, } from "../sandbox/modes.js";
|
|
29
|
-
import {
|
|
29
|
+
import { cloudChosenMode, deviceNetwork, effectiveDevicePolicy, intersectNetworks, projectReachOf, readDeploymentDevicePolicy, } from "../sandbox/modes.js";
|
|
30
|
+
import { permissionAvailabilityFor } from "../sandbox/permission-availability.js";
|
|
31
|
+
import { needsFullCeiling, PermissionCeilingWrites, requiresFullExecution, } from "../sandbox/permission-ceiling-writes.js";
|
|
32
|
+
import { readRuntimeReport } from "../sandbox/permission-runtime-reports.js";
|
|
33
|
+
import { isInternalProvider, LOCAL_PROVIDER, providerForDevice, SandboxProviders, } from "../sandbox/providers.js";
|
|
30
34
|
import { deviceNotFound, SandboxService } from "../sandbox/sandbox.service.js";
|
|
31
35
|
import { DeviceAccess, demotedProvider, deviceProvider, deviceUnavailable, inUseForDefault, } from "./access.js";
|
|
32
36
|
/** How many recent mode and policy changes a device view lists. */
|
|
@@ -56,11 +60,12 @@ let DevicesService = class DevicesService {
|
|
|
56
60
|
locks;
|
|
57
61
|
machines;
|
|
58
62
|
policies;
|
|
63
|
+
ceilings;
|
|
59
64
|
constructor(db, txHost, config, providers, sandbox, sandboxJobs,
|
|
60
65
|
/** Owes a deleted device's destruction in the delete's transaction. */
|
|
61
66
|
outbox, access, displayNames,
|
|
62
67
|
/** Reads the device relay's lease (`online`). */
|
|
63
|
-
locks, machines, policies) {
|
|
68
|
+
locks, machines, policies, ceilings) {
|
|
64
69
|
this.db = db;
|
|
65
70
|
this.txHost = txHost;
|
|
66
71
|
this.config = config;
|
|
@@ -73,6 +78,7 @@ let DevicesService = class DevicesService {
|
|
|
73
78
|
this.locks = locks;
|
|
74
79
|
this.machines = machines;
|
|
75
80
|
this.policies = policies;
|
|
81
|
+
this.ceilings = ceilings;
|
|
76
82
|
}
|
|
77
83
|
/**
|
|
78
84
|
* The person's live devices in the org, the default first, then by creation. With a
|
|
@@ -261,6 +267,7 @@ let DevicesService = class DevicesService {
|
|
|
261
267
|
async updateIn(orgId, accountId, id, patch, actorTokenId) {
|
|
262
268
|
const before = await this.lockOwn(orgId, accountId, id);
|
|
263
269
|
if (patch.mode !== undefined) {
|
|
270
|
+
await this.ceilings.lock({ orgId, deviceId: id }, "device");
|
|
264
271
|
// A cloud device's owner narrows it to sandbox or clears the choice to follow the org (auto
|
|
265
272
|
// mode spec §4.3, hardening D2); a local device's mode lives on its machine.
|
|
266
273
|
if (before.source !== "cloud") {
|
|
@@ -275,7 +282,17 @@ let DevicesService = class DevicesService {
|
|
|
275
282
|
.set({ mode: patch.mode, updated_at: sql `now()` })
|
|
276
283
|
.where("id", "=", id)
|
|
277
284
|
.execute();
|
|
285
|
+
// B1: once snapshotted, the owner ceiling decides; sandbox narrows it, while clearing the
|
|
286
|
+
// old switch never widens it (only a deliberate owner widening does)
|
|
287
|
+
if (patch.mode === "sandbox")
|
|
288
|
+
await this.db
|
|
289
|
+
.updateTable("devices")
|
|
290
|
+
.set({ owner_full_access: false })
|
|
291
|
+
.where("id", "=", id)
|
|
292
|
+
.where("owner_full_access", "=", true)
|
|
293
|
+
.execute();
|
|
278
294
|
const to = (await this.sandbox.devicePolicy({ orgId, deviceId: id })).mode;
|
|
295
|
+
await this.ceilings.publishLocked({ orgId, deviceId: id }, "device", to === "sandbox" ? needsFullCeiling : false, true);
|
|
279
296
|
if (from !== to) {
|
|
280
297
|
await audit(this.db.db, {
|
|
281
298
|
actorAccountId: accountId,
|
|
@@ -288,10 +305,100 @@ let DevicesService = class DevicesService {
|
|
|
288
305
|
}
|
|
289
306
|
}
|
|
290
307
|
}
|
|
308
|
+
if (patch.ownerCeiling !== undefined)
|
|
309
|
+
await this.cloudOwnerCeilingLocked(orgId, accountId, id, before, patch, actorTokenId);
|
|
291
310
|
if (patch.name !== undefined) {
|
|
292
311
|
await this.renameLocked(orgId, accountId, id, before, patch.name, actorTokenId, undefined);
|
|
293
312
|
}
|
|
294
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* B2 cloud owner ceiling (`PATCH ownerCeiling: {fullAccess}`), under the device authority
|
|
316
|
+
* writer: a cloud device's explicit Full ceiling. Narrowing applies at once and revokes only Full
|
|
317
|
+
* work; widening needs the person's explicit confirmation in a web session, is refused while
|
|
318
|
+
* the platform or the org does not allow Full access, never touches the outer network, and
|
|
319
|
+
* resets Full consent (conversations need fresh consent). A local device's ceiling is its
|
|
320
|
+
* machine's (`device.mode_on_device`).
|
|
321
|
+
*/
|
|
322
|
+
async cloudOwnerCeilingLocked(orgId, accountId, id, before, patch, actorTokenId) {
|
|
323
|
+
const want = patch.ownerCeiling.fullAccess;
|
|
324
|
+
await this.ceilings.lock({ orgId, deviceId: id }, "device");
|
|
325
|
+
if (before.source !== "cloud")
|
|
326
|
+
throw new ApiError("device.mode_on_device", "This device's owner ceiling is kept on its connected machine: narrow it from the device page or run capybara-device ceiling set there.");
|
|
327
|
+
const row = await this.db
|
|
328
|
+
.selectFrom("devices")
|
|
329
|
+
.select(["owner_full_access", "mode", "provider", "outer_network"])
|
|
330
|
+
.where("id", "=", id)
|
|
331
|
+
.executeTakeFirstOrThrow();
|
|
332
|
+
// the explicit ceiling exists only once B1 snapshotted the device's old effective authority
|
|
333
|
+
// and its outer network (under the exclusive lifecycle lease, which a request cannot take
|
|
334
|
+
// inside its transaction): writing it first would pre-empt the snapshot and could leave the
|
|
335
|
+
// outer network open, so the PATCH is refused until then (the old sandbox switch narrows)
|
|
336
|
+
if (row.owner_full_access === null || row.outer_network === null)
|
|
337
|
+
throw new ApiError("device.permission_not_migrated", "This device's permissions have not been migrated yet; switch it to sandbox mode to narrow it, and set its Full access ceiling once the migration has run");
|
|
338
|
+
const current = cloudChosenMode(row) !== "sandbox";
|
|
339
|
+
if (want === current)
|
|
340
|
+
return;
|
|
341
|
+
if (want && !current) {
|
|
342
|
+
if (patch.confirmWidening !== true)
|
|
343
|
+
throw new ApiError("device.owner_ceiling_confirmation_required", "Widening a device's Full access ceiling needs explicit confirmation; conversations then need fresh Full consent");
|
|
344
|
+
const policy = await this.sandbox.devicePolicy({ orgId, deviceId: id });
|
|
345
|
+
if (policy.allowedMode !== "auto")
|
|
346
|
+
throw new ApiError("device.full_access_not_allowed", "The platform or the organization does not allow Full access, so this device's ceiling cannot be widened");
|
|
347
|
+
// M3: nor beyond what the provider can enforce (a report or a provider without Full)
|
|
348
|
+
const provider = providerForDevice(this.providers, row.provider);
|
|
349
|
+
let availability = permissionAvailabilityFor(provider?.impl);
|
|
350
|
+
if (availability.state === "unprobed" && provider)
|
|
351
|
+
availability = await readRuntimeReport(this.db.db, id, provider.plugin, provider.version);
|
|
352
|
+
if (availability.state === "unsupported" ||
|
|
353
|
+
(availability.state === "supported" && !availability.report.fullAccess))
|
|
354
|
+
throw new ApiError("device.full_access_not_allowed", "This device's sandbox provider cannot run Full access, so its ceiling cannot be widened");
|
|
355
|
+
}
|
|
356
|
+
await this.db
|
|
357
|
+
.updateTable("devices")
|
|
358
|
+
.set({
|
|
359
|
+
owner_full_access: want,
|
|
360
|
+
// the old sandbox switch no longer decides once the explicit ceiling is set
|
|
361
|
+
...(want && { mode: null }),
|
|
362
|
+
updated_at: sql `now()`,
|
|
363
|
+
})
|
|
364
|
+
.where("id", "=", id)
|
|
365
|
+
.execute();
|
|
366
|
+
if (want !== current) {
|
|
367
|
+
await this.ceilings.publishLocked({ orgId, deviceId: id }, "device", want ? false : requiresFullExecution, true);
|
|
368
|
+
await audit(this.db.db, {
|
|
369
|
+
actorAccountId: accountId,
|
|
370
|
+
...(actorTokenId !== undefined && { actorTokenId }),
|
|
371
|
+
orgId,
|
|
372
|
+
action: "device.owner_ceiling_changed",
|
|
373
|
+
target: id,
|
|
374
|
+
detail: {
|
|
375
|
+
from: { fullAccess: current },
|
|
376
|
+
to: { fullAccess: want },
|
|
377
|
+
by: accountId,
|
|
378
|
+
via: "web",
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* How far restricted work may root outside the device's workspace now (B2): a local machine's
|
|
385
|
+
* owner reach within a platform and org that allow the wider device ceiling; a cloud device
|
|
386
|
+
* keeps its previous rule (its effective mode). Never the owner's Full permission alone.
|
|
387
|
+
*/
|
|
388
|
+
async projectReach(orgId, deviceId) {
|
|
389
|
+
const row = await this.db
|
|
390
|
+
.selectFrom("devices as e")
|
|
391
|
+
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
392
|
+
.select(["e.source", "m.owner_report", "m.local_policy"])
|
|
393
|
+
.where("e.id", "=", deviceId)
|
|
394
|
+
.where("e.org_id", "=", orgId)
|
|
395
|
+
.where("e.deleted_at", "is", null)
|
|
396
|
+
.executeTakeFirst();
|
|
397
|
+
if (row === undefined)
|
|
398
|
+
return "workspace";
|
|
399
|
+
const policy = await this.sandbox.devicePolicy({ orgId, deviceId });
|
|
400
|
+
return projectReachOf(row.source, policy, row.source === "local" ? ownerFactsOf(row).restrictedProjectReach : null);
|
|
401
|
+
}
|
|
295
402
|
/**
|
|
296
403
|
* The mode a sandbox call in the device runs at now, for the model (`device_paths`, auto mode
|
|
297
404
|
* spec §4.2): the effective policy for the mode it runs at (a local machine's derived mode,
|
|
@@ -303,7 +410,15 @@ let DevicesService = class DevicesService {
|
|
|
303
410
|
const row = await this.db
|
|
304
411
|
.selectFrom("devices as e")
|
|
305
412
|
.leftJoin("device_machines as m", (j) => j.onRef("m.device_id", "=", "e.id").on("m.revoked_at", "is", null))
|
|
306
|
-
.select([
|
|
413
|
+
.select([
|
|
414
|
+
"e.source",
|
|
415
|
+
"e.mode",
|
|
416
|
+
"e.owner_full_access",
|
|
417
|
+
"e.outer_network",
|
|
418
|
+
"m.features",
|
|
419
|
+
"m.local_policy",
|
|
420
|
+
"m.owner_report",
|
|
421
|
+
])
|
|
307
422
|
.where("e.id", "=", deviceId)
|
|
308
423
|
.where("e.org_id", "=", orgId)
|
|
309
424
|
.where("e.deleted_at", "is", null)
|
|
@@ -314,9 +429,10 @@ let DevicesService = class DevicesService {
|
|
|
314
429
|
readDeploymentDevicePolicy(this.db.db, this.config),
|
|
315
430
|
readOrgSettings(this.db.db, orgId),
|
|
316
431
|
]);
|
|
317
|
-
// a local device's mode is derived fail-closed; a cloud device's switch
|
|
318
|
-
|
|
319
|
-
const
|
|
432
|
+
// a local device's mode is derived fail-closed; a cloud device's switch (or its B1 owner
|
|
433
|
+
// ceiling and outer network once snapshotted) only narrows it
|
|
434
|
+
const chosen = row.source === "local" ? ownerModeOf(row) : cloudChosenMode(row);
|
|
435
|
+
const policy = effectiveDevicePolicy(deployment, settings, chosen, row.source === "local" ? null : row.outer_network);
|
|
320
436
|
let mode = policy.mode;
|
|
321
437
|
let network = row.source === "local"
|
|
322
438
|
? { kind: "allowlist", hosts: [...policy.localAllowedDomains] }
|
|
@@ -369,9 +485,24 @@ let DevicesService = class DevicesService {
|
|
|
369
485
|
* sandbox tools then fail with `device.not_found`. A local device's machine is
|
|
370
486
|
* revoked in the same transaction; after the commit it is told `stop { reason: "deleted" }`
|
|
371
487
|
* (while connected) and its connection is closed.
|
|
488
|
+
*
|
|
489
|
+
* The membership, the device row and the device's permission authority lock are the
|
|
490
|
+
* transaction's ordered prelude (`withOrderedLocks`): inside a run's fence (the Platform tool's
|
|
491
|
+
* `devices.delete`) they follow the org row and precede the conversation rows.
|
|
372
492
|
*/
|
|
373
493
|
async remove(orgId, accountId, id, actorTokenId, auditDetail) {
|
|
494
|
+
await withOrderedLocks(() => this.lockRemovalSubject(orgId, accountId, id), () => this.removeIn(orgId, accountId, id, actorTokenId, auditDetail));
|
|
495
|
+
}
|
|
496
|
+
/** The prelude of {@link remove}: the membership, the device row, the device's write lock. */
|
|
497
|
+
async lockRemovalSubject(orgId, accountId, id) {
|
|
498
|
+
await this.lockOwn(orgId, accountId, id);
|
|
499
|
+
await this.ceilings.lock({ orgId, deviceId: id }, "device");
|
|
500
|
+
}
|
|
501
|
+
async removeIn(orgId, accountId, id, actorTokenId, auditDetail) {
|
|
502
|
+
// held since the prelude (the row and the lock are the same; naming them again re-checks)
|
|
374
503
|
const before = await this.lockOwn(orgId, accountId, id);
|
|
504
|
+
await this.ceilings.lock({ orgId, deviceId: id }, "device");
|
|
505
|
+
await this.ceilings.publishLocked({ orgId, deviceId: id }, "device", true, true);
|
|
375
506
|
await this.db
|
|
376
507
|
.updateTable("devices")
|
|
377
508
|
.set({ deleted_at: sql `now()`, updated_at: sql `now()` })
|
|
@@ -420,6 +551,7 @@ let DevicesService = class DevicesService {
|
|
|
420
551
|
...(change.add !== undefined && { add: change.add }),
|
|
421
552
|
...(change.remove !== undefined && { remove: change.remove }),
|
|
422
553
|
...(change.mode !== undefined && { mode: change.mode }),
|
|
554
|
+
...(change.ownerCeiling !== undefined && { ownerCeiling: narrowOnly(change.ownerCeiling) }),
|
|
423
555
|
},
|
|
424
556
|
source: { accountId: account.id, accountName: account.displayName, via: "web" },
|
|
425
557
|
});
|
|
@@ -718,6 +850,9 @@ let DevicesService = class DevicesService {
|
|
|
718
850
|
"e.provider",
|
|
719
851
|
"e.demoted_from_provider",
|
|
720
852
|
"e.mode",
|
|
853
|
+
"e.owner_full_access",
|
|
854
|
+
"e.outer_network",
|
|
855
|
+
"e.permission_reconcile_required",
|
|
721
856
|
"e.created_at",
|
|
722
857
|
"m.id as machine_id",
|
|
723
858
|
"m.name as machine_name",
|
|
@@ -728,6 +863,7 @@ let DevicesService = class DevicesService {
|
|
|
728
863
|
"m.session_isolation as machine_session_isolation",
|
|
729
864
|
"m.features as machine_features",
|
|
730
865
|
"m.local_policy as machine_local_policy",
|
|
866
|
+
"m.owner_report as machine_owner_report",
|
|
731
867
|
"i.provider as instance_provider",
|
|
732
868
|
"i.fs_status",
|
|
733
869
|
"i.handle",
|
|
@@ -774,9 +910,18 @@ let DevicesService = class DevicesService {
|
|
|
774
910
|
]);
|
|
775
911
|
const summaryOf = (r) => r.source === "local" ? localPolicyOf(r.machine_local_policy) : null;
|
|
776
912
|
/** The mode the device chose: its machine's report (local) or its switch (cloud: sandbox, or null to follow the org). */
|
|
777
|
-
const chosenOf = (r) => r.source === "local"
|
|
778
|
-
|
|
913
|
+
const chosenOf = (r) => r.source === "local"
|
|
914
|
+
? ownerModeOf({
|
|
915
|
+
features: r.machine_features,
|
|
916
|
+
local_policy: r.machine_local_policy,
|
|
917
|
+
owner_report: r.machine_owner_report,
|
|
918
|
+
})
|
|
919
|
+
: cloudChosenMode(r);
|
|
920
|
+
const policyOf = (r) => effectiveDevicePolicy(deployment, settings, chosenOf(r), r.source === "local" ? null : r.outer_network);
|
|
921
|
+
// the network each mode gives a cloud device, within its outer network once snapshotted
|
|
779
922
|
const sandboxNetwork = deviceNetwork(deployment, settings, "sandbox");
|
|
923
|
+
const fullNetwork = deviceNetwork(deployment, settings, "auto");
|
|
924
|
+
const within = (n, outer) => outer === null ? n : intersectNetworks(n, outer);
|
|
780
925
|
// each device's limits and its instance's pending change
|
|
781
926
|
const perDevice = new Map(await Promise.all(rows.map(async (r) => {
|
|
782
927
|
const policy = policyOf(r);
|
|
@@ -835,9 +980,13 @@ let DevicesService = class DevicesService {
|
|
|
835
980
|
pendingNextUse: perDevice.get(r.id)?.state.pendingNextUse ?? false,
|
|
836
981
|
pendingFilesReset: perDevice.get(r.id)?.state.pendingFilesReset ?? false,
|
|
837
982
|
recent: recent.get(r.id) ?? [],
|
|
838
|
-
sandboxNetwork,
|
|
983
|
+
sandboxNetwork: within(sandboxNetwork, r.outer_network),
|
|
984
|
+
fullNetwork: within(fullNetwork, r.outer_network),
|
|
985
|
+
outerNetwork: r.source === "local" ? null : r.outer_network,
|
|
839
986
|
}, this.config.get().sandbox.limits.egress === "none"),
|
|
840
987
|
// a local device's machine decides it; cloud devices have none in phase 2
|
|
988
|
+
ownerCeiling: ownerCeilingViewOf(r, online.get(r.id) ?? false),
|
|
989
|
+
reconcileRequired: r.source === "cloud" && r.permission_reconcile_required,
|
|
841
990
|
sessionIsolation: r.machine_session_isolation ?? false,
|
|
842
991
|
filesLost: r.fs_status === "lost",
|
|
843
992
|
instance: live
|
|
@@ -854,7 +1003,8 @@ let DevicesService = class DevicesService {
|
|
|
854
1003
|
/**
|
|
855
1004
|
* The last {@link RECENT_POLICY_CHANGES} mode and policy changes of each device in the org
|
|
856
1005
|
* (audit rows `device.policy_changed`, `device.policy_unknown`, `device.policy_failed`,
|
|
857
|
-
* `device.mode_changed`), newest first, with the deciding
|
|
1006
|
+
* `device.mode_changed`, `device.owner_ceiling_changed`), newest first, with the deciding
|
|
1007
|
+
* account's display name.
|
|
858
1008
|
*/
|
|
859
1009
|
async recentModeChanges(orgId, deviceIds) {
|
|
860
1010
|
const out = new Map();
|
|
@@ -958,9 +1108,12 @@ __decorate([
|
|
|
958
1108
|
__decorate([
|
|
959
1109
|
Transactional()
|
|
960
1110
|
], DevicesService.prototype, "updateIn", null);
|
|
1111
|
+
__decorate([
|
|
1112
|
+
Transactional({ propagation: "mandatory" })
|
|
1113
|
+
], DevicesService.prototype, "lockRemovalSubject", null);
|
|
961
1114
|
__decorate([
|
|
962
1115
|
Transactional()
|
|
963
|
-
], DevicesService.prototype, "
|
|
1116
|
+
], DevicesService.prototype, "removeIn", null);
|
|
964
1117
|
__decorate([
|
|
965
1118
|
Transactional()
|
|
966
1119
|
], DevicesService.prototype, "recordReset", null);
|
|
@@ -980,7 +1133,8 @@ DevicesService = __decorate([
|
|
|
980
1133
|
__param(8, Inject(ExtensionDisplayNames)),
|
|
981
1134
|
__param(9, Inject(LockService)),
|
|
982
1135
|
__param(10, Inject(MachinesService)),
|
|
983
|
-
__param(11, Inject(DevicePolicyService))
|
|
1136
|
+
__param(11, Inject(DevicePolicyService)),
|
|
1137
|
+
__param(12, Inject(PermissionCeilingWrites))
|
|
984
1138
|
], DevicesService);
|
|
985
1139
|
export { DevicesService };
|
|
986
1140
|
/**
|
|
@@ -997,18 +1151,42 @@ const limitsView = (l) => ({
|
|
|
997
1151
|
...l,
|
|
998
1152
|
network: { kind: l.network.kind, hosts: [...l.network.hosts] },
|
|
999
1153
|
});
|
|
1000
|
-
/** The audit actions a device's recent mode and
|
|
1154
|
+
/** The audit actions a device's recent mode, policy and ceiling changes list. */
|
|
1001
1155
|
const MODE_CHANGE_ACTIONS = [
|
|
1002
1156
|
"device.policy_changed",
|
|
1003
1157
|
"device.policy_unknown",
|
|
1004
1158
|
"device.policy_failed",
|
|
1005
1159
|
"device.mode_changed",
|
|
1160
|
+
"device.owner_ceiling_changed",
|
|
1006
1161
|
];
|
|
1007
1162
|
const modeOrNull = (v) => (v === "auto" || v === "sandbox" ? v : null);
|
|
1163
|
+
/** One side of an audited ceiling change; null when the row does not carry a readable one. */
|
|
1164
|
+
function ceilingFactsOf(v) {
|
|
1165
|
+
if (typeof v !== "object" || v === null)
|
|
1166
|
+
return null;
|
|
1167
|
+
const o = v;
|
|
1168
|
+
if (typeof o.fullAccess !== "boolean")
|
|
1169
|
+
return null;
|
|
1170
|
+
const reach = o.restrictedProjectReach;
|
|
1171
|
+
return {
|
|
1172
|
+
fullAccess: o.fullAccess,
|
|
1173
|
+
...((reach === "workspace" || reach === "os-user") && { restrictedProjectReach: reach }),
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1008
1176
|
/** One audit row of {@link MODE_CHANGE_ACTIONS} as a {@link DeviceModeChangeView}. */
|
|
1009
1177
|
function modeChangeOf(action, at, d, by) {
|
|
1010
1178
|
const hosts = (v) => Array.isArray(v) ? v.filter((h) => typeof h === "string") : [];
|
|
1011
|
-
const base = { at: at.toISOString(), add: [], remove: [], mode: null, by };
|
|
1179
|
+
const base = { at: at.toISOString(), add: [], remove: [], mode: null, ceiling: null, by };
|
|
1180
|
+
if (action === "device.owner_ceiling_changed") {
|
|
1181
|
+
const to = ceilingFactsOf(d.to);
|
|
1182
|
+
return {
|
|
1183
|
+
...base,
|
|
1184
|
+
kind: "ceiling",
|
|
1185
|
+
ceiling: to === null ? null : { from: ceilingFactsOf(d.from), to },
|
|
1186
|
+
via: d.via === "im" ? "im" : d.via === "device" ? "device" : "web",
|
|
1187
|
+
outcome: "applied",
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1012
1190
|
if (action === "device.mode_changed") {
|
|
1013
1191
|
const to = modeOrNull(d.to);
|
|
1014
1192
|
return {
|
|
@@ -1040,7 +1218,8 @@ function modeChangeOf(action, at, d, by) {
|
|
|
1040
1218
|
export function deviceModeViewOf(policy, settings, local, summary, extra,
|
|
1041
1219
|
/** The platform kill switch (`sandbox.limits.egress: none`): the network is the platform's. */
|
|
1042
1220
|
killSwitch = false) {
|
|
1043
|
-
const { sandboxNetwork, ...rest } = extra;
|
|
1221
|
+
const { sandboxNetwork, fullNetwork, outerNetwork, ...rest } = extra;
|
|
1222
|
+
const copy = (n) => local || n === null ? null : { kind: n.kind, hosts: [...n.hosts] };
|
|
1044
1223
|
const networkKind = local ? "allowlist" : policy.network.kind;
|
|
1045
1224
|
const org = settings.cloudNetwork;
|
|
1046
1225
|
// "org" only when the org supplied what is in effect: the kill switch always wins; auto mode
|
|
@@ -1069,7 +1248,7 @@ killSwitch = false) {
|
|
|
1069
1248
|
allowedMode: policy.allowedMode,
|
|
1070
1249
|
allowedBy: policy.allowedMode === "sandbox"
|
|
1071
1250
|
? null
|
|
1072
|
-
: settings.
|
|
1251
|
+
: settings.fullAccess === "allowed"
|
|
1073
1252
|
? "org"
|
|
1074
1253
|
: "platform",
|
|
1075
1254
|
network,
|
|
@@ -1079,7 +1258,60 @@ killSwitch = false) {
|
|
|
1079
1258
|
allowedDomains: [...(summary?.allowedDomains ?? [])],
|
|
1080
1259
|
}
|
|
1081
1260
|
: null,
|
|
1082
|
-
sandboxNetwork:
|
|
1261
|
+
sandboxNetwork: copy(sandboxNetwork),
|
|
1262
|
+
fullNetwork: copy(fullNetwork),
|
|
1263
|
+
outerNetwork: copy(outerNetwork),
|
|
1083
1264
|
...rest,
|
|
1084
1265
|
};
|
|
1085
1266
|
}
|
|
1267
|
+
/** The read-only owner ceiling view of a listed device row (B2). */
|
|
1268
|
+
function ownerCeilingViewOf(r, online) {
|
|
1269
|
+
if (r.source === "cloud")
|
|
1270
|
+
return r.owner_full_access === null
|
|
1271
|
+
? null
|
|
1272
|
+
: {
|
|
1273
|
+
state: "cloud",
|
|
1274
|
+
revision: null,
|
|
1275
|
+
sequence: null,
|
|
1276
|
+
fullAccess: r.owner_full_access,
|
|
1277
|
+
effectiveFullAccess: cloudChosenMode(r) !== "sandbox",
|
|
1278
|
+
restrictedProjectReach: "workspace",
|
|
1279
|
+
restrictedAllowedDomains: [],
|
|
1280
|
+
observedAt: null,
|
|
1281
|
+
stale: false,
|
|
1282
|
+
};
|
|
1283
|
+
if (r.machine_id === null)
|
|
1284
|
+
return null;
|
|
1285
|
+
const f = ownerFactsOf({
|
|
1286
|
+
owner_report: r.machine_owner_report,
|
|
1287
|
+
local_policy: r.machine_local_policy,
|
|
1288
|
+
});
|
|
1289
|
+
return {
|
|
1290
|
+
state: f.state,
|
|
1291
|
+
revision: f.revision,
|
|
1292
|
+
sequence: f.sequence,
|
|
1293
|
+
fullAccess: f.fullAccess,
|
|
1294
|
+
// the mode admission derives (an old program without a report included), fail closed
|
|
1295
|
+
effectiveFullAccess: ownerModeOf({
|
|
1296
|
+
features: r.machine_features,
|
|
1297
|
+
local_policy: r.machine_local_policy,
|
|
1298
|
+
owner_report: r.machine_owner_report,
|
|
1299
|
+
}) === "auto",
|
|
1300
|
+
restrictedProjectReach: f.restrictedProjectReach,
|
|
1301
|
+
restrictedAllowedDomains: f.restrictedAllowedDomains,
|
|
1302
|
+
observedAt: f.observedAt,
|
|
1303
|
+
stale: !online || f.state !== "report",
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
/** The owner ceiling narrowing the web may send (B2): anything wider is refused, never sent. */
|
|
1307
|
+
function narrowOnly(c) {
|
|
1308
|
+
if ((c.fullAccess !== undefined && c.fullAccess !== false) ||
|
|
1309
|
+
(c.restrictedProjectReach !== undefined && c.restrictedProjectReach !== "workspace"))
|
|
1310
|
+
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");
|
|
1311
|
+
return {
|
|
1312
|
+
...(c.fullAccess === false && { fullAccess: false }),
|
|
1313
|
+
...(c.restrictedProjectReach === "workspace" && {
|
|
1314
|
+
restrictedProjectReach: "workspace",
|
|
1315
|
+
}),
|
|
1316
|
+
};
|
|
1317
|
+
}
|
package/dist/devices/dto.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export declare const DeviceParams: z.ZodObject<{
|
|
|
17
17
|
export declare const DevicePatchBody: z.ZodObject<{
|
|
18
18
|
name: z.ZodOptional<z.ZodString>;
|
|
19
19
|
mode: z.ZodOptional<z.ZodNullable<z.ZodLiteral<"sandbox">>>;
|
|
20
|
+
ownerCeiling: z.ZodOptional<z.ZodObject<{
|
|
21
|
+
fullAccess: z.ZodBoolean;
|
|
22
|
+
}, z.core.$strict>>;
|
|
23
|
+
confirmWidening: z.ZodOptional<z.ZodLiteral<true>>;
|
|
20
24
|
}, z.core.$strict>;
|
|
21
25
|
/**
|
|
22
26
|
* `POST /devices/:id/policy` (network ask-to-allow spec §7; auto mode spec §4.1): the device
|
|
@@ -28,6 +32,10 @@ export declare const DevicePolicyBody: z.ZodObject<{
|
|
|
28
32
|
add: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
29
33
|
remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
30
34
|
mode: z.ZodOptional<z.ZodLiteral<"sandbox">>;
|
|
35
|
+
ownerCeiling: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
fullAccess: z.ZodOptional<z.ZodLiteral<false>>;
|
|
37
|
+
restrictedProjectReach: z.ZodOptional<z.ZodLiteral<"workspace">>;
|
|
38
|
+
}, z.core.$strict>>;
|
|
31
39
|
}, z.core.$strict>;
|
|
32
40
|
/**
|
|
33
41
|
* A project's name (project root §4.1, `isDeviceProjectName`): 1-64 UTF-16 code units, not `.` or
|
|
@@ -56,6 +64,10 @@ export declare class DeviceCreateBodyDto extends DeviceCreateBodyDto_base {
|
|
|
56
64
|
declare const DevicePatchBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
|
|
57
65
|
name: z.ZodOptional<z.ZodString>;
|
|
58
66
|
mode: z.ZodOptional<z.ZodNullable<z.ZodLiteral<"sandbox">>>;
|
|
67
|
+
ownerCeiling: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
fullAccess: z.ZodBoolean;
|
|
69
|
+
}, z.core.$strict>>;
|
|
70
|
+
confirmWidening: z.ZodOptional<z.ZodLiteral<true>>;
|
|
59
71
|
}, z.core.$strict>>;
|
|
60
72
|
export declare class DevicePatchBodyDto extends DevicePatchBodyDto_base {
|
|
61
73
|
}
|
|
@@ -68,6 +80,10 @@ declare const DevicePolicyBodyDto_base: import("../infra/validation/create-zod-d
|
|
|
68
80
|
add: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
69
81
|
remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
82
|
mode: z.ZodOptional<z.ZodLiteral<"sandbox">>;
|
|
83
|
+
ownerCeiling: z.ZodOptional<z.ZodObject<{
|
|
84
|
+
fullAccess: z.ZodOptional<z.ZodLiteral<false>>;
|
|
85
|
+
restrictedProjectReach: z.ZodOptional<z.ZodLiteral<"workspace">>;
|
|
86
|
+
}, z.core.$strict>>;
|
|
71
87
|
}, z.core.$strict>>;
|
|
72
88
|
export declare class DevicePolicyBodyDto extends DevicePolicyBodyDto_base {
|
|
73
89
|
}
|
package/dist/devices/dto.js
CHANGED
|
@@ -14,10 +14,22 @@ export const DeviceParams = z.object({ id: z.string().min(1).max(100) });
|
|
|
14
14
|
* `device.mode_requires_session`, and the Platform operation (`devices.rename`) omits it.
|
|
15
15
|
*/
|
|
16
16
|
export const DevicePatchBody = z
|
|
17
|
-
.object({
|
|
17
|
+
.object({
|
|
18
|
+
name: DeviceName.optional(),
|
|
19
|
+
mode: z.literal("sandbox").nullable().optional(),
|
|
20
|
+
/**
|
|
21
|
+
* B2: a cloud device's explicit Full ceiling. `false` narrows; `true` widens and needs
|
|
22
|
+
* `confirmWidening: true` (a person in a web session only); it never opens the outer network.
|
|
23
|
+
*/
|
|
24
|
+
ownerCeiling: z.object({ fullAccess: z.boolean() }).strict().optional(),
|
|
25
|
+
confirmWidening: z.literal(true).optional(),
|
|
26
|
+
})
|
|
18
27
|
.strict()
|
|
19
|
-
.refine((b) => b.name !== undefined || b.mode !== undefined, {
|
|
20
|
-
message: "Give at least one of name or
|
|
28
|
+
.refine((b) => b.name !== undefined || b.mode !== undefined || b.ownerCeiling !== undefined, {
|
|
29
|
+
message: "Give at least one of name, mode or ownerCeiling",
|
|
30
|
+
})
|
|
31
|
+
.refine((b) => b.mode === undefined || b.ownerCeiling === undefined, {
|
|
32
|
+
message: "Give either mode or ownerCeiling, not both",
|
|
21
33
|
});
|
|
22
34
|
/** One host of a device's network allowlist (`validateAllowHost`: lowercase, `*.` allowed). */
|
|
23
35
|
const PolicyHost = z
|
|
@@ -44,11 +56,27 @@ export const DevicePolicyBody = z
|
|
|
44
56
|
add: z.array(AddHost).min(1).max(20).optional(),
|
|
45
57
|
remove: z.array(PolicyHost).min(1).max(100).optional(),
|
|
46
58
|
mode: z.literal("sandbox").optional(),
|
|
59
|
+
/**
|
|
60
|
+
* B2: narrow the machine's owner ceiling. Only `fullAccess: false` and `workspace` reach are
|
|
61
|
+
* accepted: the web never widens it (the owner does, on the machine, with `capybara-device
|
|
62
|
+
* ceiling set`).
|
|
63
|
+
*/
|
|
64
|
+
ownerCeiling: z
|
|
65
|
+
.object({
|
|
66
|
+
fullAccess: z.literal(false).optional(),
|
|
67
|
+
restrictedProjectReach: z.literal("workspace").optional(),
|
|
68
|
+
})
|
|
69
|
+
.strict()
|
|
70
|
+
.refine((c) => c.fullAccess !== undefined || c.restrictedProjectReach !== undefined, {
|
|
71
|
+
message: "Give fullAccess: false or restrictedProjectReach: workspace",
|
|
72
|
+
})
|
|
73
|
+
.optional(),
|
|
47
74
|
})
|
|
48
75
|
.strict()
|
|
49
|
-
.refine((b) => b.add !== undefined ||
|
|
50
|
-
|
|
51
|
-
|
|
76
|
+
.refine((b) => b.add !== undefined ||
|
|
77
|
+
b.remove !== undefined ||
|
|
78
|
+
b.mode !== undefined ||
|
|
79
|
+
b.ownerCeiling !== undefined, { message: "Give at least one of add, remove, mode or ownerCeiling" });
|
|
52
80
|
/**
|
|
53
81
|
* A project's name (project root §4.1, `isDeviceProjectName`): 1-64 UTF-16 code units, not `.` or
|
|
54
82
|
* `..`, no `/`, no control characters, no leading or trailing whitespace; unique on its device.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
/** The device is missing, deleted, or not in the caller's org (404; ids cannot be probed). */
|
|
3
|
+
export declare const deviceNotFound: () => ApiError;
|
|
4
|
+
/**
|
|
5
|
+
* The device offers no projects (project root §4.1): a local machine whose `capybara-device`
|
|
6
|
+
* does not announce `projects`, or a cloud provider without `list` / `scan`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const projectsUnsupported: (local: boolean) => ApiError;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
/** The device is missing, deleted, or not in the caller's org (404; ids cannot be probed). */
|
|
3
|
+
export const deviceNotFound = () => new ApiError("device.not_found", "This device does not exist or was deleted.");
|
|
4
|
+
/**
|
|
5
|
+
* The device offers no projects (project root §4.1): a local machine whose `capybara-device`
|
|
6
|
+
* does not announce `projects`, or a cloud provider without `list` / `scan`.
|
|
7
|
+
*/
|
|
8
|
+
export const projectsUnsupported = (local) => new ApiError("device.projects_unsupported", local
|
|
9
|
+
? "This device's capybara-device does not support projects; update capybara-device on that machine and reconnect it."
|
|
10
|
+
: "This device's sandbox provider does not support projects; its conversations work without one.");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
import type { SandboxMode } from "../sandbox/modes.js";
|
|
3
|
+
/** What a project's scope is read from: the device's mode now and the bases it gives. */
|
|
4
|
+
export interface DeviceProjectScope {
|
|
5
|
+
source: "cloud" | "local";
|
|
6
|
+
mode: SandboxMode;
|
|
7
|
+
/**
|
|
8
|
+
* How far restricted reads reach (B2): `os-user` only on a local machine whose owner chose it,
|
|
9
|
+
* within a platform and org that allow the wider device ceiling; else the workspace.
|
|
10
|
+
*/
|
|
11
|
+
reach: "workspace" | "os-user";
|
|
12
|
+
/** The workspace root as last known (a machine's hello, a cloud instance's handle). */
|
|
13
|
+
workspace: string;
|
|
14
|
+
/** The owner's home a local machine reported; null when unknown (and for a cloud device). */
|
|
15
|
+
home: string | null;
|
|
16
|
+
supported: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A machine whose own policy is auto mode while the organization allows only sandbox mode: exec
|
|
19
|
+
* refuses it (`device.auto_mode_not_allowed`), and the kernel reads nothing on it unasked.
|
|
20
|
+
*/
|
|
21
|
+
widerThanAllowed: boolean;
|
|
22
|
+
}
|
|
23
|
+
type Scope = DeviceProjectScope;
|
|
24
|
+
/**
|
|
25
|
+
* The protocol 2 read mode for list/scan on the device (`limits.mode`): the reach, encoded (B2: a
|
|
26
|
+
* restricted OS-user read is never a Full grant; the v3 browse scope carries roots instead).
|
|
27
|
+
*/
|
|
28
|
+
export declare const readModeOf: (s: Pick<Scope, "source" | "reach" | "mode">) => SandboxMode;
|
|
29
|
+
/** The base a relative path is resolved against in the scope's mode (project root §4.2). */
|
|
30
|
+
export declare const baseOf: (s: Scope, workspace?: string) => string | null;
|
|
31
|
+
/**
|
|
32
|
+
* `path` lies inside what the scope's mode may read (sandbox mode and cloud: the workspace, as the
|
|
33
|
+
* held instance reports it when given).
|
|
34
|
+
*/
|
|
35
|
+
export declare const withinMode: (s: Scope, path: string, workspace?: string) => boolean;
|
|
36
|
+
export declare const nameInvalid: (name: string) => ApiError;
|
|
37
|
+
export declare const nameTaken: (name: string) => ApiError;
|
|
38
|
+
export declare const projectNotFound: (name: string) => ApiError;
|
|
39
|
+
export declare const outsideMode: (path: string, mode: SandboxMode) => ApiError;
|
|
40
|
+
export declare const tooBroad: (path: string) => ApiError;
|
|
41
|
+
export declare const homeUnknown: () => ApiError;
|
|
42
|
+
/** A device-supplied or person-supplied string inside a message, bounded. */
|
|
43
|
+
export declare function clipped(s: string, max?: number): string;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
/** Only the owner's home bounds nothing: OS-user reach on a machine reads what its owner can. */
|
|
3
|
+
const homeBased = (s) => s.source === "local" && s.reach === "os-user";
|
|
4
|
+
/**
|
|
5
|
+
* The protocol 2 read mode for list/scan on the device (`limits.mode`): the reach, encoded (B2: a
|
|
6
|
+
* restricted OS-user read is never a Full grant; the v3 browse scope carries roots instead).
|
|
7
|
+
*/
|
|
8
|
+
export const readModeOf = (s) => s.source === "local" ? (s.reach === "os-user" ? "auto" : "sandbox") : s.mode;
|
|
9
|
+
/** The base a relative path is resolved against in the scope's mode (project root §4.2). */
|
|
10
|
+
export const baseOf = (s, workspace = s.workspace) => homeBased(s) ? s.home : workspace;
|
|
11
|
+
/**
|
|
12
|
+
* `path` lies inside what the scope's mode may read (sandbox mode and cloud: the workspace, as the
|
|
13
|
+
* held instance reports it when given).
|
|
14
|
+
*/
|
|
15
|
+
export const withinMode = (s, path, workspace = s.workspace) => homeBased(s) || path === workspace || path.startsWith(workspace === "/" ? "/" : `${workspace}/`);
|
|
16
|
+
export const nameInvalid = (name) => new ApiError("device.project_name_invalid", `"${clipped(name)}" is not a valid project name: use 1-64 characters, not . or .., without / or control characters, and without leading or trailing spaces`);
|
|
17
|
+
export const nameTaken = (name) => new ApiError("device.project_name_taken", `This device already has a project named "${clipped(name)}"; pick another name`);
|
|
18
|
+
export const projectNotFound = (name) => new ApiError("device.project_not_found", `This device has no project named "${clipped(name)}"`);
|
|
19
|
+
export const outsideMode = (path, mode) => new ApiError("device.project_outside_mode", mode === "sandbox"
|
|
20
|
+
? `${clipped(path)} is outside the device's workspace, the only directory it can read in sandbox mode`
|
|
21
|
+
: `${clipped(path)} is outside the device's workspace, the only directory a cloud device can read`);
|
|
22
|
+
export const tooBroad = (path) => new ApiError("device.project_path_too_broad", `${clipped(path)} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
|
|
23
|
+
export const homeUnknown = () => new ApiError("device.project_home_unknown", "In auto mode a project's path is relative to the owner's home directory, which this device has not reported; update capybara-device on that machine and reconnect it");
|
|
24
|
+
/** A device-supplied or person-supplied string inside a message, bounded. */
|
|
25
|
+
export function clipped(s, max = 200) {
|
|
26
|
+
return s.length <= max ? s : `${s.slice(0, max)}…`;
|
|
27
|
+
}
|