@capybara-hq/kernel 0.1.0-rc.41 → 0.1.0-rc.43
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 +4 -1
- package/dist/config/schema.js +41 -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 +307 -4
- package/dist/conversations/events.js +286 -32
- 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/ctx/create-ctx.d.ts +12 -5
- package/dist/ctx/create-ctx.js +21 -5
- package/dist/db/kernel-schema.d.ts +248 -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/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +10 -6
- 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 +35 -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/models/image-usable.d.ts +22 -0
- package/dist/models/image-usable.js +29 -0
- package/dist/models/images.d.ts +125 -0
- package/dist/models/images.js +440 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +16 -5
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +28 -3
- package/dist/models/purposes.js +40 -13
- 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/models.ops.js +10 -0
- 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/hook-calls.d.ts +11 -1
- package/dist/runtime/hook-calls.js +24 -1
- 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/providers.d.ts +9 -5
- package/dist/runtime/providers.js +22 -3
- 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/runtime/usage-report.d.ts +10 -6
- package/dist/runtime/usage-report.js +31 -11
- 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 +145 -0
- package/dist/sandbox/review/review.service.d.ts +5 -2
- package/dist/sandbox/review/review.service.js +60 -15
- 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/builtin-names.d.ts +3 -1
- package/dist/tools/builtin-names.js +5 -1
- package/dist/tools/builtins/artifacts.d.ts +43 -0
- package/dist/tools/builtins/artifacts.js +67 -0
- package/dist/tools/builtins/builtin-tools.d.ts +20 -2
- package/dist/tools/builtins/builtin-tools.js +61 -10
- package/dist/tools/builtins/image/generate.d.ts +59 -0
- package/dist/tools/builtins/image/generate.js +535 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- 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 +9 -51
- 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 +315 -26
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +15 -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/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -8,6 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { randomBytes } from "node:crypto";
|
|
11
|
+
import { parseDeviceFrameV3, } from "@capybara-hq/plugin-sdk";
|
|
11
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
13
|
import { sql } from "kysely";
|
|
13
14
|
import { audit } from "../identity/audit.js";
|
|
@@ -19,11 +20,15 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
19
20
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
20
21
|
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
21
22
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
23
|
+
import { LegacyRetirementStore } from "../sandbox/legacy-retirement.js";
|
|
24
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
25
|
+
import { PermissionRuntimeReports, sameRuntimeIdentity, } from "../sandbox/permission-runtime-reports.js";
|
|
22
26
|
import { LOCAL_PROVIDER } from "../sandbox/providers.js";
|
|
23
27
|
import { deviceNotFound } from "../sandbox/sandbox.service.js";
|
|
24
28
|
import { deviceRevokedTopic } from "./keys.js";
|
|
29
|
+
import { OwnerReports } from "./owner-reports.js";
|
|
25
30
|
import { DEVICE_OP_RESOLVE_JOB, deviceOpReportedJobId } from "./policy-op-jobs.js";
|
|
26
|
-
import { deviceFeaturesOf, legacyPolicyOf, localPolicyDiff, localPolicyOf, opExplains, opVisibleIn, pendingPolicyOpsOf, } from "./policy-summary.js";
|
|
31
|
+
import { deviceFeaturesOf, legacyPolicyOf, localPolicyDiff, localPolicyOf, opExplains, opVisibleIn, ownerPolicyRevokes, pendingPolicyOpsOf, } from "./policy-summary.js";
|
|
27
32
|
import { LocalDeviceRelay } from "./relay.js";
|
|
28
33
|
/** The machine credential's prefix (`cap_dev_` plus 32 random bytes, base64url). */
|
|
29
34
|
export const MACHINE_CREDENTIAL_PREFIX = "cap_dev_";
|
|
@@ -40,6 +45,15 @@ const STOP_DEADLINE_MS = 30_000;
|
|
|
40
45
|
* its connection (fire-and-forget, ruling R14) and `device.revoked.<deviceId>` published with
|
|
41
46
|
* `{ machineId }`, so the holder closes that machine's connection.
|
|
42
47
|
*/
|
|
48
|
+
/** Roots in a fixed key order (null when absent), whatever order jsonb stored them in. */
|
|
49
|
+
const canonicalRoots = (roots) => {
|
|
50
|
+
if (!roots || typeof roots !== "object")
|
|
51
|
+
return "null";
|
|
52
|
+
const r = roots;
|
|
53
|
+
return JSON.stringify(Object.keys(r)
|
|
54
|
+
.sort()
|
|
55
|
+
.map((k) => [k, r[k]]));
|
|
56
|
+
};
|
|
43
57
|
let MachinesService = class MachinesService {
|
|
44
58
|
db;
|
|
45
59
|
txHost;
|
|
@@ -47,13 +61,23 @@ let MachinesService = class MachinesService {
|
|
|
47
61
|
bus;
|
|
48
62
|
outbox;
|
|
49
63
|
log;
|
|
50
|
-
|
|
64
|
+
ceilings;
|
|
65
|
+
reports;
|
|
66
|
+
owners;
|
|
67
|
+
retirement;
|
|
68
|
+
constructor(db, txHost, relay, bus, outbox, log, ceilings, reports, owners,
|
|
69
|
+
/** The host's boot identity: restart evidence for local legacy obligations (8.5). */
|
|
70
|
+
retirement) {
|
|
51
71
|
this.db = db;
|
|
52
72
|
this.txHost = txHost;
|
|
53
73
|
this.relay = relay;
|
|
54
74
|
this.bus = bus;
|
|
55
75
|
this.outbox = outbox;
|
|
56
76
|
this.log = log;
|
|
77
|
+
this.ceilings = ceilings;
|
|
78
|
+
this.reports = reports;
|
|
79
|
+
this.owners = owners;
|
|
80
|
+
this.retirement = retirement;
|
|
57
81
|
}
|
|
58
82
|
/**
|
|
59
83
|
* A new machine for the device and its credential (returned once). Revokes the
|
|
@@ -169,7 +193,18 @@ let MachinesService = class MachinesService {
|
|
|
169
193
|
* platform's ops still pending on the row ({@link backfillOps}). The owner's home directory
|
|
170
194
|
* (`home`) replaces the stored one too (null when the hello has none).
|
|
171
195
|
*/
|
|
172
|
-
async recordHello(machineId, hello, rawPolicy = hello.policy
|
|
196
|
+
async recordHello(machineId, hello, rawPolicy = hello.policy,
|
|
197
|
+
/** A v3 hello's authenticated owner report (B2): it, not the summary, decides publication. */
|
|
198
|
+
owner) {
|
|
199
|
+
const subject = await this.db
|
|
200
|
+
.selectFrom("device_machines")
|
|
201
|
+
.select(["org_id", "device_id"])
|
|
202
|
+
.where("id", "=", machineId)
|
|
203
|
+
.where("revoked_at", "is", null)
|
|
204
|
+
.executeTakeFirst();
|
|
205
|
+
if (!subject)
|
|
206
|
+
return;
|
|
207
|
+
await this.ceilings.lock({ orgId: subject.org_id, deviceId: subject.device_id }, "device");
|
|
173
208
|
const self = await this.db
|
|
174
209
|
.selectFrom("device_machines")
|
|
175
210
|
.select([
|
|
@@ -186,6 +221,8 @@ let MachinesService = class MachinesService {
|
|
|
186
221
|
])
|
|
187
222
|
.where("id", "=", machineId)
|
|
188
223
|
.where("revoked_at", "is", null)
|
|
224
|
+
.where("org_id", "=", subject.org_id)
|
|
225
|
+
.where("device_id", "=", subject.device_id)
|
|
189
226
|
.forUpdate()
|
|
190
227
|
.executeTakeFirst();
|
|
191
228
|
if (self === undefined)
|
|
@@ -213,7 +250,20 @@ let MachinesService = class MachinesService {
|
|
|
213
250
|
.execute();
|
|
214
251
|
}
|
|
215
252
|
}
|
|
216
|
-
const policy = await this.reportedPolicy(machineId, self, hello.policy, rawPolicy);
|
|
253
|
+
const policy = await this.reportedPolicy(machineId, self, hello.policy, rawPolicy, owner !== undefined);
|
|
254
|
+
// jsonb returns keys in its own order: compare roots canonically, or every reconnect would
|
|
255
|
+
// look like a changed reach and reset Full consent (B4 consent stability)
|
|
256
|
+
const rootsChanged = canonicalRoots(self.roots) !== canonicalRoots(hello.roots);
|
|
257
|
+
if (owner !== undefined)
|
|
258
|
+
await this.owners.recordLocked(machineId, owner.report, {
|
|
259
|
+
connectionId: owner.connectionId,
|
|
260
|
+
via: "hello",
|
|
261
|
+
rootsChanged,
|
|
262
|
+
});
|
|
263
|
+
else if (rootsChanged ||
|
|
264
|
+
JSON.stringify(localPolicyOf(self.local_policy)) !== JSON.stringify(policy))
|
|
265
|
+
await this.ceilings.publishLocked({ orgId: self.org_id, deviceId: self.device_id }, "device", (scope, row) => rootsChanged ||
|
|
266
|
+
ownerPolicyRevokes(localPolicyOf(policy), scope, row.method, row.granted_hosts), localPolicyOf(self.local_policy)?.mode !== localPolicyOf(policy)?.mode || rootsChanged);
|
|
217
267
|
await this.db
|
|
218
268
|
.updateTable("device_machines")
|
|
219
269
|
.set({
|
|
@@ -235,6 +285,13 @@ let MachinesService = class MachinesService {
|
|
|
235
285
|
if (hello.recentOps !== undefined) {
|
|
236
286
|
await this.backfillOps(machineId, self, hello.recentOps, localPolicyOf(hello.policy));
|
|
237
287
|
}
|
|
288
|
+
// only an authenticated, claimed connection's hello reaches here (the machine row locked):
|
|
289
|
+
// its boot identity is the evidence a restart ended the old processes
|
|
290
|
+
if (hello.bootId !== undefined)
|
|
291
|
+
await this.retirement.recordBoot(machineId, hello.bootId);
|
|
292
|
+
// a hello without one (a downgraded program) leaves no stale boot as evidence (M2)
|
|
293
|
+
else
|
|
294
|
+
await this.retirement.clearBoot(machineId);
|
|
238
295
|
}
|
|
239
296
|
/**
|
|
240
297
|
* Hello backfill (transactional outbox spec §7): a pending op of the platform's whose outcome
|
|
@@ -288,6 +345,63 @@ let MachinesService = class MachinesService {
|
|
|
288
345
|
});
|
|
289
346
|
}
|
|
290
347
|
}
|
|
348
|
+
/** Dormant authenticated hello adapter; the active gateway still accepts only protocol 2. */
|
|
349
|
+
async recordHelloV3(machineId, hello, connectionId = null) {
|
|
350
|
+
const parsed = parseDeviceFrameV3(JSON.stringify(hello), "device");
|
|
351
|
+
if (parsed.type !== "hello")
|
|
352
|
+
throw new Error("Expected a validated operation hello");
|
|
353
|
+
await this.recordHello(machineId, parsed, parsed.policy, {
|
|
354
|
+
report: parsed.ownerCeiling,
|
|
355
|
+
connectionId,
|
|
356
|
+
});
|
|
357
|
+
const machine = await this.db
|
|
358
|
+
.selectFrom("device_machines")
|
|
359
|
+
.select(["org_id", "device_id"])
|
|
360
|
+
.where("id", "=", machineId)
|
|
361
|
+
.where("revoked_at", "is", null)
|
|
362
|
+
.executeTakeFirst();
|
|
363
|
+
if (!machine)
|
|
364
|
+
return;
|
|
365
|
+
const subject = { orgId: machine.org_id, deviceId: machine.device_id };
|
|
366
|
+
await this.ceilings.lock(subject, "device");
|
|
367
|
+
await this.reports.record(machine.device_id, LOCAL_PROVIDER, parsed.programVersion, await this.boundIdentityLocked(subject, parsed), parsed.permissionSupport);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* The runtime identity a v3 hello may attest (B4): only a bound hello re-reporting exactly the
|
|
371
|
+
* identity of the current instance generation's installed binding. An unbound hello, another
|
|
372
|
+
* generation or a binding still awaiting the device attests nothing (unprobed; it never finishes
|
|
373
|
+
* an installation, which only the bindInstance answer does). A changed identity under the same
|
|
374
|
+
* binding (helper, interpreter or environment bytes) invalidates the report and advances the
|
|
375
|
+
* device's admission epoch; a changed environment fingerprint also resets Full consent.
|
|
376
|
+
*/
|
|
377
|
+
async boundIdentityLocked(subject, hello) {
|
|
378
|
+
const reported = hello.runtimeIdentity;
|
|
379
|
+
if (hello.instanceGeneration === null || !reported)
|
|
380
|
+
return undefined;
|
|
381
|
+
const instance = await this.db
|
|
382
|
+
.selectFrom("device_instances")
|
|
383
|
+
.select(["provider", "created_at", "permission_runtime_identity"])
|
|
384
|
+
.where("device_id", "=", subject.deviceId)
|
|
385
|
+
.executeTakeFirst();
|
|
386
|
+
if (!instance ||
|
|
387
|
+
instance.provider !== LOCAL_PROVIDER ||
|
|
388
|
+
String(instance.created_at.getTime()) !== reported.instanceGeneration)
|
|
389
|
+
return undefined;
|
|
390
|
+
const binding = await this.db
|
|
391
|
+
.selectFrom("device_instance_bindings")
|
|
392
|
+
.select(["status", "runtime_identity"])
|
|
393
|
+
.where("device_id", "=", subject.deviceId)
|
|
394
|
+
.where("instance_generation", "=", reported.instanceGeneration)
|
|
395
|
+
.executeTakeFirst();
|
|
396
|
+
if (binding?.status !== "installed" || !binding.runtime_identity)
|
|
397
|
+
return undefined;
|
|
398
|
+
if (sameRuntimeIdentity(binding.runtime_identity, reported))
|
|
399
|
+
return reported;
|
|
400
|
+
const previous = instance.permission_runtime_identity;
|
|
401
|
+
if (previous)
|
|
402
|
+
await this.ceilings.publishLocked(subject, "device", true, previous.imageFingerprint !== reported.imageFingerprint);
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
291
405
|
/**
|
|
292
406
|
* Stores the local policy summary a connected program pushed after its hello (a `policy` frame:
|
|
293
407
|
* its policy file changed on the machine: its mode or its sandbox-mode allowlist), read and
|
|
@@ -297,22 +411,64 @@ let MachinesService = class MachinesService {
|
|
|
297
411
|
* alone.
|
|
298
412
|
*/
|
|
299
413
|
async recordPolicy(machineId, summary, rawPolicy = summary) {
|
|
414
|
+
const subject = await this.db
|
|
415
|
+
.selectFrom("device_machines")
|
|
416
|
+
.select(["org_id", "device_id"])
|
|
417
|
+
.where("id", "=", machineId)
|
|
418
|
+
.where("revoked_at", "is", null)
|
|
419
|
+
.executeTakeFirst();
|
|
420
|
+
if (!subject)
|
|
421
|
+
return;
|
|
422
|
+
await this.ceilings.lock({ orgId: subject.org_id, deviceId: subject.device_id }, "device");
|
|
300
423
|
const self = await this.db
|
|
301
424
|
.selectFrom("device_machines")
|
|
302
425
|
.select(["device_id", "org_id", "account_id", "local_policy", "pending_policy_ops"])
|
|
303
426
|
.where("id", "=", machineId)
|
|
304
427
|
.where("revoked_at", "is", null)
|
|
428
|
+
.where("org_id", "=", subject.org_id)
|
|
429
|
+
.where("device_id", "=", subject.device_id)
|
|
305
430
|
.forUpdate()
|
|
306
431
|
.executeTakeFirst();
|
|
307
432
|
if (self === undefined)
|
|
308
433
|
return;
|
|
309
434
|
const policy = await this.reportedPolicy(machineId, self, summary, rawPolicy);
|
|
435
|
+
if (JSON.stringify(localPolicyOf(self.local_policy)) !== JSON.stringify(policy))
|
|
436
|
+
await this.ceilings.publishLocked({ orgId: self.org_id, deviceId: self.device_id }, "device", (scope, row) => ownerPolicyRevokes(localPolicyOf(policy), scope, row.method, row.granted_hosts), localPolicyOf(self.local_policy)?.mode !== localPolicyOf(policy)?.mode);
|
|
437
|
+
await this.db
|
|
438
|
+
.updateTable("device_machines")
|
|
439
|
+
.set({ local_policy: jsonOrNull(policy), last_seen_at: sql `now()` })
|
|
440
|
+
.where("id", "=", machineId)
|
|
441
|
+
.where("revoked_at", "is", null)
|
|
442
|
+
.execute();
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* A staged (v3) `policy` frame (B2): the summary is kept for the device page like protocol 2's,
|
|
446
|
+
* while the authenticated owner report alone decides what changed ({@link OwnerReports}).
|
|
447
|
+
*/
|
|
448
|
+
async recordPolicyV3(machineId, frame, connectionId = null) {
|
|
449
|
+
const parsed = parseDeviceFrameV3(JSON.stringify(frame), "device");
|
|
450
|
+
if (parsed.type !== "policy")
|
|
451
|
+
throw new Error("Expected a validated policy frame");
|
|
452
|
+
const subject = await this.db
|
|
453
|
+
.selectFrom("device_machines")
|
|
454
|
+
.select(["org_id", "device_id", "account_id", "local_policy", "pending_policy_ops"])
|
|
455
|
+
.where("id", "=", machineId)
|
|
456
|
+
.where("revoked_at", "is", null)
|
|
457
|
+
.executeTakeFirst();
|
|
458
|
+
if (!subject)
|
|
459
|
+
return;
|
|
460
|
+
await this.ceilings.lock({ orgId: subject.org_id, deviceId: subject.device_id }, "device");
|
|
461
|
+
const policy = await this.reportedPolicy(machineId, { ...subject, device_id: subject.device_id }, parsed.policy, parsed.policy, true);
|
|
310
462
|
await this.db
|
|
311
463
|
.updateTable("device_machines")
|
|
312
464
|
.set({ local_policy: jsonOrNull(policy), last_seen_at: sql `now()` })
|
|
313
465
|
.where("id", "=", machineId)
|
|
314
466
|
.where("revoked_at", "is", null)
|
|
315
467
|
.execute();
|
|
468
|
+
await this.owners.recordLocked(machineId, parsed.ownerCeiling, {
|
|
469
|
+
connectionId,
|
|
470
|
+
via: "policy",
|
|
471
|
+
});
|
|
316
472
|
}
|
|
317
473
|
/**
|
|
318
474
|
* The summary to store for one a program reported (hello or `policy` frame): the parsed one, else
|
|
@@ -325,7 +481,13 @@ let MachinesService = class MachinesService {
|
|
|
325
481
|
* (the op's answer is). A summary reported again is no change. Runs in the caller's transaction,
|
|
326
482
|
* with the machine's row locked.
|
|
327
483
|
*/
|
|
328
|
-
async reportedPolicy(machineId, self, reported, rawPolicy
|
|
484
|
+
async reportedPolicy(machineId, self, reported, rawPolicy,
|
|
485
|
+
/**
|
|
486
|
+
* A staged (v3) report: the authenticated owner report carries the Full change and is audited
|
|
487
|
+
* once, `device.owner_ceiling_changed` ({@link OwnerReports}); the summary's derived mode is
|
|
488
|
+
* not audited a second time as `device.mode_changed`.
|
|
489
|
+
*/
|
|
490
|
+
ownerReported = false) {
|
|
329
491
|
const summary = localPolicyOf(reported);
|
|
330
492
|
const prev = localPolicyOf(self.local_policy);
|
|
331
493
|
const diff = summary !== null && prev !== null ? localPolicyDiff(prev, summary) : null;
|
|
@@ -353,7 +515,7 @@ let MachinesService = class MachinesService {
|
|
|
353
515
|
},
|
|
354
516
|
});
|
|
355
517
|
}
|
|
356
|
-
if (diff.mode !== undefined) {
|
|
518
|
+
if (diff.mode !== undefined && !ownerReported) {
|
|
357
519
|
await audit(this.db.db, {
|
|
358
520
|
...base,
|
|
359
521
|
action: "device.mode_changed",
|
|
@@ -425,6 +587,13 @@ let MachinesService = class MachinesService {
|
|
|
425
587
|
* {@link revoke} and the device's deletion (`deleted`).
|
|
426
588
|
*/
|
|
427
589
|
async revokeActive(deviceId, reason) {
|
|
590
|
+
const device = await this.db
|
|
591
|
+
.selectFrom("devices")
|
|
592
|
+
.select("org_id")
|
|
593
|
+
.where("id", "=", deviceId)
|
|
594
|
+
.executeTakeFirstOrThrow();
|
|
595
|
+
await this.ceilings.lock({ orgId: device.org_id, deviceId }, "device");
|
|
596
|
+
await this.ceilings.publishLocked({ orgId: device.org_id, deviceId }, "device", true, true);
|
|
428
597
|
const row = await this.db
|
|
429
598
|
.updateTable("device_machines")
|
|
430
599
|
.set({ revoked_at: sql `now()` })
|
|
@@ -443,6 +612,15 @@ let MachinesService = class MachinesService {
|
|
|
443
612
|
* same post-commit disconnect as a replacement (no stop frame). True when it was active.
|
|
444
613
|
*/
|
|
445
614
|
async revokeMachine(machineId) {
|
|
615
|
+
const machine = await this.db
|
|
616
|
+
.selectFrom("device_machines")
|
|
617
|
+
.select(["org_id", "device_id"])
|
|
618
|
+
.where("id", "=", machineId)
|
|
619
|
+
.executeTakeFirst();
|
|
620
|
+
if (!machine)
|
|
621
|
+
return false;
|
|
622
|
+
await this.ceilings.lock({ orgId: machine.org_id, deviceId: machine.device_id }, "device");
|
|
623
|
+
await this.ceilings.publishLocked({ orgId: machine.org_id, deviceId: machine.device_id }, "device", true, true);
|
|
446
624
|
const row = await this.db
|
|
447
625
|
.updateTable("device_machines")
|
|
448
626
|
.set({ revoked_at: sql `now()` })
|
|
@@ -500,7 +678,8 @@ let MachinesService = class MachinesService {
|
|
|
500
678
|
async disconnect(deviceId, machineId, reason) {
|
|
501
679
|
try {
|
|
502
680
|
if (reason !== null && (await this.relay.holderLive(deviceId))) {
|
|
503
|
-
|
|
681
|
+
// fenced to this machine: on a staged connection it goes out as a protocol 3 `stop`
|
|
682
|
+
await this.relay.send(deviceId, "stop", { reason }, STOP_DEADLINE_MS, machineId);
|
|
504
683
|
}
|
|
505
684
|
}
|
|
506
685
|
catch (err) {
|
|
@@ -520,12 +699,24 @@ __decorate([
|
|
|
520
699
|
__decorate([
|
|
521
700
|
Transactional()
|
|
522
701
|
], MachinesService.prototype, "recordHello", null);
|
|
702
|
+
__decorate([
|
|
703
|
+
Transactional()
|
|
704
|
+
], MachinesService.prototype, "recordHelloV3", null);
|
|
523
705
|
__decorate([
|
|
524
706
|
Transactional()
|
|
525
707
|
], MachinesService.prototype, "recordPolicy", null);
|
|
708
|
+
__decorate([
|
|
709
|
+
Transactional()
|
|
710
|
+
], MachinesService.prototype, "recordPolicyV3", null);
|
|
526
711
|
__decorate([
|
|
527
712
|
Transactional()
|
|
528
713
|
], MachinesService.prototype, "revoke", null);
|
|
714
|
+
__decorate([
|
|
715
|
+
Transactional()
|
|
716
|
+
], MachinesService.prototype, "revokeActive", null);
|
|
717
|
+
__decorate([
|
|
718
|
+
Transactional()
|
|
719
|
+
], MachinesService.prototype, "revokeMachine", null);
|
|
529
720
|
MachinesService = __decorate([
|
|
530
721
|
Injectable(),
|
|
531
722
|
__param(0, Inject(KernelDb)),
|
|
@@ -533,7 +724,11 @@ MachinesService = __decorate([
|
|
|
533
724
|
__param(2, Inject(LocalDeviceRelay)),
|
|
534
725
|
__param(3, Inject(KERNEL_BUS)),
|
|
535
726
|
__param(4, Inject(OutboxService)),
|
|
536
|
-
__param(5, Inject(KERNEL_LOGGER))
|
|
727
|
+
__param(5, Inject(KERNEL_LOGGER)),
|
|
728
|
+
__param(6, Inject(PermissionCeilingWrites)),
|
|
729
|
+
__param(7, Inject(PermissionRuntimeReports)),
|
|
730
|
+
__param(8, Inject(OwnerReports)),
|
|
731
|
+
__param(9, Inject(LegacyRetirementStore))
|
|
537
732
|
], MachinesService);
|
|
538
733
|
export { MachinesService };
|
|
539
734
|
const jsonOrNull = (v) => (v === null ? null : JSON.stringify(v));
|
|
@@ -14,7 +14,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
14
14
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
15
15
|
import { coversHost } from "../sandbox/modes.js";
|
|
16
16
|
import { taskGrantsRunOf } from "../schedules/unattended.js";
|
|
17
|
-
import {
|
|
17
|
+
import { ownerModeOf } from "./owner-report.js";
|
|
18
18
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
19
19
|
export const MAX_GRANT_HOSTS = 100;
|
|
20
20
|
/** The key prefix of a scheduled task's network grant (`schedules/grant-rules.ts`). */
|
|
@@ -205,13 +205,13 @@ let NetworkGrants = class NetworkGrants {
|
|
|
205
205
|
async reportedMode(deviceId) {
|
|
206
206
|
const row = await this.db
|
|
207
207
|
.selectFrom("device_machines")
|
|
208
|
-
.select(["local_policy", "features"])
|
|
208
|
+
.select(["local_policy", "features", "owner_report"])
|
|
209
209
|
.where("device_id", "=", deviceId)
|
|
210
210
|
.where("revoked_at", "is", null)
|
|
211
211
|
.executeTakeFirst();
|
|
212
212
|
if (row === undefined)
|
|
213
213
|
return null;
|
|
214
|
-
return
|
|
214
|
+
return ownerModeOf(row);
|
|
215
215
|
}
|
|
216
216
|
/** The runs of the tree whose budget run is `root`. */
|
|
217
217
|
treeOf(root) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from "@nestjs/common";
|
|
8
|
+
import { NetworkGrants } from "./network-grants.js";
|
|
9
|
+
let NetworkGrantsModule = class NetworkGrantsModule {
|
|
10
|
+
};
|
|
11
|
+
NetworkGrantsModule = __decorate([
|
|
12
|
+
Module({ imports: [], providers: [NetworkGrants], exports: [NetworkGrants] })
|
|
13
|
+
], NetworkGrantsModule);
|
|
14
|
+
export { NetworkGrantsModule };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type DeviceOwnerCeilingV3, type SandboxBrowseScope, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/** How far restricted (non-Full) operations and project browsing may reach on a machine. */
|
|
3
|
+
export type RestrictedProjectReach = "workspace" | "os-user";
|
|
4
|
+
/** Which message carried a report (audit and diagnostics only). */
|
|
5
|
+
export type OwnerReportVia = "hello" | "policy" | "policy-result" | "bind";
|
|
6
|
+
/**
|
|
7
|
+
* The authenticated owner report kept on a machine row (`device_machines.owner_report`, B2): the
|
|
8
|
+
* strict report, the connection and time it arrived, and a block set by an out-of-order report.
|
|
9
|
+
*/
|
|
10
|
+
export interface StoredOwnerReport {
|
|
11
|
+
report: DeviceOwnerCeilingV3;
|
|
12
|
+
connectionId: string | null;
|
|
13
|
+
observedAt: string;
|
|
14
|
+
via: OwnerReportVia;
|
|
15
|
+
/** A later report arrived stale or conflicting: no new authority until a valid current one. */
|
|
16
|
+
blocked?: {
|
|
17
|
+
reason: "stale" | "conflict";
|
|
18
|
+
sequence: number;
|
|
19
|
+
at: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** The stored report in `v`, or null (absent or malformed: never trusted). */
|
|
23
|
+
export declare function storedOwnerReportOf(v: unknown): StoredOwnerReport | null;
|
|
24
|
+
/**
|
|
25
|
+
* What a newly arrived report means against the stored one: a higher sequence is recorded; the
|
|
26
|
+
* same sequence, revision and bytes is idempotent; a lower sequence is stale; the same sequence
|
|
27
|
+
* with other bytes is a protocol conflict.
|
|
28
|
+
*/
|
|
29
|
+
export declare function decideOwnerReport(stored: StoredOwnerReport | null, incoming: DeviceOwnerCeilingV3): "record" | "same" | "stale" | "conflict";
|
|
30
|
+
/**
|
|
31
|
+
* The owner facts the kernel decides with (B2), never inferred wider than reported:
|
|
32
|
+
* - `report`: an authenticated version-2 report (Full and reach independent);
|
|
33
|
+
* - `blocked`: a stale or conflicting report arrived: fail closed, admission refused;
|
|
34
|
+
* - `legacy`: only a protocol 2 summary (the active wire until activation): its `mode` translates
|
|
35
|
+
* exactly (auto: Full + OS-user reach; sandbox: neither);
|
|
36
|
+
* - `missing`: nothing readable: fail closed.
|
|
37
|
+
*/
|
|
38
|
+
export interface OwnerFacts {
|
|
39
|
+
state: "report" | "blocked" | "legacy" | "missing";
|
|
40
|
+
fullAccess: boolean;
|
|
41
|
+
restrictedProjectReach: RestrictedProjectReach;
|
|
42
|
+
restrictedAllowedDomains: string[];
|
|
43
|
+
revision: string | null;
|
|
44
|
+
sequence: number | null;
|
|
45
|
+
observedAt: string | null;
|
|
46
|
+
}
|
|
47
|
+
/** The facts of a stored report alone (a successful record). */
|
|
48
|
+
export declare function ownerFactsOfReport(stored: StoredOwnerReport): OwnerFacts;
|
|
49
|
+
/** A machine row's owner facts: its authenticated report, else its protocol 2 summary. */
|
|
50
|
+
export declare function ownerFactsOf(row: {
|
|
51
|
+
owner_report?: unknown;
|
|
52
|
+
local_policy?: unknown;
|
|
53
|
+
}): OwnerFacts;
|
|
54
|
+
/**
|
|
55
|
+
* The owner writer's selector (B2): what an owner-ceiling change takes from a running admission.
|
|
56
|
+
* Full work loses only to Full being removed; broad browsing (`/`) and restricted roots outside
|
|
57
|
+
* the machine's own roots lose only to the reach narrowing to the workspace; a restricted
|
|
58
|
+
* execution loses a host only when no independent grant keeps it. A restricted-only change never
|
|
59
|
+
* touches Full work, and a Full-only change never touches restricted work.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ownerReportRevokes(next: OwnerFacts, scope: SandboxOperationScope | SandboxBrowseScope, method: string, grantedHosts: readonly string[], machineRoots: readonly string[]): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* A restricted operation scope reaching outside the machine's own roots (a selected project beyond
|
|
64
|
+
* the workspace): what narrowing the reach to the workspace takes away (B2). The owner writer and
|
|
65
|
+
* the platform/org Full-off writers share it.
|
|
66
|
+
*/
|
|
67
|
+
export declare function outsideMachineRoots(scope: SandboxOperationScope | SandboxBrowseScope, machineRoots: readonly string[] | undefined): boolean;
|
|
68
|
+
/** The machine's reported roots as a list (workspace, tmp, skills ...), or none. */
|
|
69
|
+
export declare function machineRootList(roots: unknown): string[];
|
|
70
|
+
/**
|
|
71
|
+
* The protocol-2 mode encoding of a machine's owner Full permission (the kernel's internal
|
|
72
|
+
* lifecycle ceiling encoding; never re-encodes reach): its authenticated report when there is one
|
|
73
|
+
* (a blocked report fails closed), else the protocol 2 derivation ({@link localModeOf}).
|
|
74
|
+
*/
|
|
75
|
+
export declare function ownerModeOf(row: {
|
|
76
|
+
features: unknown;
|
|
77
|
+
local_policy: unknown;
|
|
78
|
+
owner_report?: unknown;
|
|
79
|
+
}): "auto" | "sandbox";
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { parseOwnerCeilingReportV3, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
3
|
+
import { isExecutionMethod } from "../sandbox/operation-authority-types.js";
|
|
4
|
+
import { localModeOf, localPolicyOf } from "./policy-summary.js";
|
|
5
|
+
/** The stored report in `v`, or null (absent or malformed: never trusted). */
|
|
6
|
+
export function storedOwnerReportOf(v) {
|
|
7
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
8
|
+
return null;
|
|
9
|
+
const o = v;
|
|
10
|
+
let report;
|
|
11
|
+
try {
|
|
12
|
+
report = parseOwnerCeilingReportV3(o.report);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (typeof o.observedAt !== "string")
|
|
18
|
+
return null;
|
|
19
|
+
if (o.connectionId !== null && typeof o.connectionId !== "string")
|
|
20
|
+
return null;
|
|
21
|
+
if (!["hello", "policy", "policy-result", "bind"].includes(String(o.via)))
|
|
22
|
+
return null;
|
|
23
|
+
const b = o.blocked;
|
|
24
|
+
return {
|
|
25
|
+
report,
|
|
26
|
+
connectionId: o.connectionId,
|
|
27
|
+
observedAt: o.observedAt,
|
|
28
|
+
via: o.via,
|
|
29
|
+
...(b &&
|
|
30
|
+
(b.reason === "stale" || b.reason === "conflict") &&
|
|
31
|
+
typeof b.sequence === "number" &&
|
|
32
|
+
typeof b.at === "string" && {
|
|
33
|
+
blocked: { reason: b.reason, sequence: b.sequence, at: b.at },
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a newly arrived report means against the stored one: a higher sequence is recorded; the
|
|
39
|
+
* same sequence, revision and bytes is idempotent; a lower sequence is stale; the same sequence
|
|
40
|
+
* with other bytes is a protocol conflict.
|
|
41
|
+
*/
|
|
42
|
+
export function decideOwnerReport(stored, incoming) {
|
|
43
|
+
if (stored === null)
|
|
44
|
+
return "record";
|
|
45
|
+
const prev = stored.report;
|
|
46
|
+
if (incoming.sequence > prev.sequence)
|
|
47
|
+
return "record";
|
|
48
|
+
if (incoming.sequence < prev.sequence)
|
|
49
|
+
return "stale";
|
|
50
|
+
return JSON.stringify(canonicalReport(incoming)) === JSON.stringify(canonicalReport(prev))
|
|
51
|
+
? "same"
|
|
52
|
+
: "conflict";
|
|
53
|
+
}
|
|
54
|
+
const canonicalReport = (r) => ({
|
|
55
|
+
version: r.version,
|
|
56
|
+
revision: r.revision,
|
|
57
|
+
sequence: r.sequence,
|
|
58
|
+
fullAccess: r.fullAccess,
|
|
59
|
+
restrictedProjectReach: r.restrictedProjectReach,
|
|
60
|
+
restrictedAllowedDomains: [...r.restrictedAllowedDomains],
|
|
61
|
+
});
|
|
62
|
+
const FAIL_CLOSED = {
|
|
63
|
+
fullAccess: false,
|
|
64
|
+
restrictedProjectReach: "workspace",
|
|
65
|
+
restrictedAllowedDomains: [],
|
|
66
|
+
};
|
|
67
|
+
/** The facts of a stored report alone (a successful record). */
|
|
68
|
+
export function ownerFactsOfReport(stored) {
|
|
69
|
+
if (stored.blocked)
|
|
70
|
+
return {
|
|
71
|
+
state: "blocked",
|
|
72
|
+
...FAIL_CLOSED,
|
|
73
|
+
revision: stored.report.revision,
|
|
74
|
+
sequence: stored.report.sequence,
|
|
75
|
+
observedAt: stored.observedAt,
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
state: "report",
|
|
79
|
+
fullAccess: stored.report.fullAccess,
|
|
80
|
+
restrictedProjectReach: stored.report.restrictedProjectReach,
|
|
81
|
+
restrictedAllowedDomains: [...stored.report.restrictedAllowedDomains],
|
|
82
|
+
revision: stored.report.revision,
|
|
83
|
+
sequence: stored.report.sequence,
|
|
84
|
+
observedAt: stored.observedAt,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** A machine row's owner facts: its authenticated report, else its protocol 2 summary. */
|
|
88
|
+
export function ownerFactsOf(row) {
|
|
89
|
+
const stored = storedOwnerReportOf(row.owner_report);
|
|
90
|
+
if (stored !== null)
|
|
91
|
+
return ownerFactsOfReport(stored);
|
|
92
|
+
const summary = localPolicyOf(row.local_policy);
|
|
93
|
+
if (summary === null)
|
|
94
|
+
return { state: "missing", ...FAIL_CLOSED, revision: null, sequence: null, observedAt: null };
|
|
95
|
+
return {
|
|
96
|
+
state: "legacy",
|
|
97
|
+
fullAccess: summary.mode === "auto",
|
|
98
|
+
restrictedProjectReach: summary.mode === "auto" ? "os-user" : "workspace",
|
|
99
|
+
restrictedAllowedDomains: [...summary.allowedDomains],
|
|
100
|
+
revision: null,
|
|
101
|
+
sequence: null,
|
|
102
|
+
observedAt: null,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** True when `path` lies in one of `roots` (absolute, normalized). */
|
|
106
|
+
const within = (path, root) => root === "/" || path === root || path.startsWith(`${root}/`);
|
|
107
|
+
/**
|
|
108
|
+
* The owner writer's selector (B2): what an owner-ceiling change takes from a running admission.
|
|
109
|
+
* Full work loses only to Full being removed; broad browsing (`/`) and restricted roots outside
|
|
110
|
+
* the machine's own roots lose only to the reach narrowing to the workspace; a restricted
|
|
111
|
+
* execution loses a host only when no independent grant keeps it. A restricted-only change never
|
|
112
|
+
* touches Full work, and a Full-only change never touches restricted work.
|
|
113
|
+
*/
|
|
114
|
+
export function ownerReportRevokes(next, scope, method, grantedHosts, machineRoots) {
|
|
115
|
+
if (next.state === "blocked" || next.state === "missing")
|
|
116
|
+
return true;
|
|
117
|
+
const inMachine = (root) => machineRoots.some((r) => within(root, r));
|
|
118
|
+
if (!("profile" in scope))
|
|
119
|
+
return (next.restrictedProjectReach === "workspace" && scope.readRoots.some((r) => !inMachine(r)));
|
|
120
|
+
if (scope.profile === "full-access")
|
|
121
|
+
return !next.fullAccess;
|
|
122
|
+
if (next.restrictedProjectReach === "workspace" && outsideMachineRoots(scope, machineRoots))
|
|
123
|
+
return true;
|
|
124
|
+
if (!isExecutionMethod(method) || scope.network.kind !== "allowlist")
|
|
125
|
+
return false;
|
|
126
|
+
return scope.network.hosts.some((host) => !next.restrictedAllowedDomains.some((pattern) => coversHost(pattern, host)) &&
|
|
127
|
+
!grantedHosts.includes(host));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A restricted operation scope reaching outside the machine's own roots (a selected project beyond
|
|
131
|
+
* the workspace): what narrowing the reach to the workspace takes away (B2). The owner writer and
|
|
132
|
+
* the platform/org Full-off writers share it.
|
|
133
|
+
*/
|
|
134
|
+
export function outsideMachineRoots(scope, machineRoots) {
|
|
135
|
+
if (machineRoots === undefined || !("profile" in scope) || scope.filesystem.kind !== "scoped")
|
|
136
|
+
return false;
|
|
137
|
+
return [...scope.filesystem.readRoots, ...scope.filesystem.writeRoots].some((r) => !machineRoots.some((m) => within(r, m)));
|
|
138
|
+
}
|
|
139
|
+
/** The machine's reported roots as a list (workspace, tmp, skills ...), or none. */
|
|
140
|
+
export function machineRootList(roots) {
|
|
141
|
+
if (typeof roots !== "object" || roots === null)
|
|
142
|
+
return [];
|
|
143
|
+
return Object.values(roots).filter((r) => typeof r === "string" && r.startsWith("/"));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The protocol-2 mode encoding of a machine's owner Full permission (the kernel's internal
|
|
147
|
+
* lifecycle ceiling encoding; never re-encodes reach): its authenticated report when there is one
|
|
148
|
+
* (a blocked report fails closed), else the protocol 2 derivation ({@link localModeOf}).
|
|
149
|
+
*/
|
|
150
|
+
export function ownerModeOf(row) {
|
|
151
|
+
const stored = storedOwnerReportOf(row.owner_report);
|
|
152
|
+
if (stored === null)
|
|
153
|
+
return localModeOf(row.features, row.local_policy);
|
|
154
|
+
return ownerFactsOfReport(stored).fullAccess ? "auto" : "sandbox";
|
|
155
|
+
}
|