@capybara-hq/kernel 0.1.0-rc.68 → 0.1.0-rc.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.module.js +2 -0
- package/dist/admin/health.service.d.ts +11 -4
- package/dist/admin/health.service.js +33 -17
- package/dist/background/poll.job.js +2 -2
- package/dist/background/tasks.service.d.ts +5 -5
- package/dist/background/tasks.service.js +9 -8
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.js +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +9 -9
- package/dist/conversations/conversations.controller.d.ts +8 -3
- package/dist/conversations/conversations.controller.js +8 -3
- package/dist/conversations/conversations.service.d.ts +33 -15
- package/dist/conversations/conversations.service.js +60 -10
- package/dist/conversations/events.d.ts +21 -41
- package/dist/conversations/events.js +57 -31
- package/dist/conversations/permission-profiles.controller.d.ts +6 -4
- package/dist/conversations/permission-profiles.service.d.ts +6 -4
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +77 -6
- package/dist/ctx/device-provider-check.d.ts +6 -2
- package/dist/ctx/device-provider-check.js +17 -2
- package/dist/db/kernel-schema.d.ts +10 -48
- package/dist/devices/access.d.ts +3 -4
- package/dist/devices/access.js +3 -4
- package/dist/devices/conversation-devices.d.ts +1 -3
- package/dist/devices/conversation-devices.js +2 -7
- package/dist/devices/device-projects.service.js +24 -29
- package/dist/devices/device-provider-selection.d.ts +5 -6
- package/dist/devices/device-provider-selection.js +8 -9
- package/dist/devices/devices.controller.d.ts +8 -21
- package/dist/devices/devices.controller.js +9 -34
- package/dist/devices/devices.module.js +6 -4
- package/dist/devices/devices.schemas.d.ts +1 -5
- package/dist/devices/devices.schemas.js +1 -5
- package/dist/devices/devices.service.d.ts +84 -147
- package/dist/devices/devices.service.js +134 -229
- package/dist/devices/dto.d.ts +5 -32
- package/dist/devices/dto.js +5 -37
- package/dist/devices/errors.d.ts +6 -5
- package/dist/devices/errors.js +7 -8
- package/dist/devices/project-rules.d.ts +9 -11
- package/dist/devices/project-rules.js +7 -7
- package/dist/devices/working-root.d.ts +3 -6
- package/dist/devices/working-root.js +3 -8
- package/dist/dial-in/access.d.ts +23 -0
- package/dist/dial-in/access.js +64 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +214 -0
- package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
- package/dist/dial-in/handlers.d.ts +47 -0
- package/dist/dial-in/handlers.js +84 -0
- package/dist/dial-in/machines.d.ts +155 -0
- package/dist/dial-in/machines.js +383 -0
- package/dist/dial-in/relay.d.ts +135 -0
- package/dist/dial-in/relay.js +444 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
- package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
- package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
- package/dist/{local-devices → dial-in}/targets.js +3 -48
- package/dist/errors.d.ts +8 -27
- package/dist/errors.js +8 -27
- package/dist/extensions/bootstrap.d.ts +5 -0
- package/dist/extensions/bootstrap.js +10 -1
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +6 -0
- package/dist/extensions/host.js +12 -2
- package/dist/extensions/permission-set.d.ts +15 -1
- package/dist/extensions/permission-set.js +11 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/http/api.module.js +4 -4
- package/dist/http/gateway-routes.d.ts +1 -1
- package/dist/http/gateway-routes.js +1 -1
- package/dist/http/meta.controller.js +1 -1
- package/dist/identity/settings.d.ts +1 -1
- package/dist/identity/settings.js +6 -8
- package/dist/infra/config/kernel-config.service.js +2 -2
- package/dist/infra/outbox/registry.d.ts +0 -14
- package/dist/infra/outbox/registry.js +0 -15
- package/dist/infra/throttler/named-throttlers.d.ts +1 -1
- package/dist/infra/throttler/named-throttlers.js +1 -1
- package/dist/kernel.module.js +0 -3
- package/dist/orgs/settings.service.js +5 -10
- package/dist/overrides.d.ts +0 -4
- package/dist/overrides.js +0 -2
- package/dist/platform/exclusions.js +5 -5
- package/dist/platform/ops/admin.ops.js +1 -1
- package/dist/platform/ops/conversations.ops.js +5 -2
- package/dist/platform/ops/devices.ops.js +11 -24
- package/dist/platform/ops/inbox.ops.js +1 -1
- package/dist/roles/gateway-role.d.ts +3 -3
- package/dist/roles/gateway-role.js +4 -4
- package/dist/roles/gateway.module.d.ts +1 -1
- package/dist/roles/gateway.module.js +5 -5
- package/dist/runtime/context/device-paths.d.ts +4 -1
- package/dist/runtime/context/permission-profile.js +5 -5
- package/dist/runtime/maintenance.d.ts +2 -5
- package/dist/runtime/maintenance.js +9 -19
- package/dist/runtime/project/knowledge.js +4 -5
- package/dist/runtime/project/knowledge.service.js +2 -1
- package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
- package/dist/sandbox/cloud-permission-snapshot.js +1 -3
- package/dist/sandbox/device-reports.d.ts +74 -14
- package/dist/sandbox/device-reports.js +190 -33
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox.d.ts +39 -41
- package/dist/sandbox/device-sandbox.js +44 -83
- package/dist/sandbox/kernel-read.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.d.ts +11 -59
- package/dist/sandbox/legacy-retirement.js +34 -186
- package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
- package/dist/sandbox/legacy-retirement.module.js +2 -2
- package/dist/sandbox/managed-device-context.d.ts +16 -4
- package/dist/sandbox/managed-device-context.js +25 -8
- package/dist/sandbox/managed-device-context.module.js +4 -0
- package/dist/sandbox/modes.d.ts +3 -12
- package/dist/sandbox/modes.js +2 -14
- package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
- package/dist/{local-devices → sandbox}/network-grants.js +4 -49
- package/dist/sandbox/operation-authority-types.d.ts +2 -1
- package/dist/sandbox/operation-authority.d.ts +6 -20
- package/dist/sandbox/operation-authority.js +43 -104
- package/dist/sandbox/operation-authority.module.js +1 -1
- package/dist/sandbox/operation-intents.d.ts +4 -1
- package/dist/sandbox/operation-intents.js +11 -2
- package/dist/sandbox/operation-reconcile.job.js +2 -4
- package/dist/sandbox/permission-availability.d.ts +6 -7
- package/dist/sandbox/permission-availability.js +7 -10
- package/dist/sandbox/permission-call-grants.d.ts +2 -1
- package/dist/sandbox/permission-call-grants.js +1 -7
- package/dist/sandbox/permission-call-types.d.ts +4 -4
- package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
- package/dist/sandbox/permission-ceiling-writes.js +8 -35
- package/dist/sandbox/permission-config-publication.d.ts +9 -1
- package/dist/sandbox/permission-config-publication.js +29 -21
- package/dist/sandbox/permission-context-types.d.ts +17 -10
- package/dist/sandbox/permission-facts.d.ts +98 -95
- package/dist/sandbox/permission-facts.js +160 -314
- package/dist/sandbox/permission-instance-writes.d.ts +23 -37
- package/dist/sandbox/permission-instance-writes.js +44 -121
- package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
- package/dist/sandbox/permission-runtime-reports.js +105 -122
- package/dist/sandbox/providers.d.ts +26 -38
- package/dist/sandbox/providers.js +36 -18
- package/dist/sandbox/request-not-sent.d.ts +2 -13
- package/dist/sandbox/request-not-sent.js +2 -13
- package/dist/sandbox/review/permission-candidate.d.ts +13 -8
- package/dist/sandbox/review/permission-candidate.js +38 -48
- package/dist/sandbox/sandbox.module.js +7 -3
- package/dist/sandbox/sandbox.service.d.ts +49 -59
- package/dist/sandbox/sandbox.service.js +139 -259
- package/dist/schedules/fire.d.ts +15 -6
- package/dist/schedules/fire.js +27 -13
- package/dist/schedules/grant-rules.js +1 -1
- package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
- package/dist/schedules/scheduled-tasks.service.js +1 -4
- package/dist/schedules/schedules.module.js +5 -3
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +2 -3
- package/dist/tools/approvals.service.d.ts +8 -5
- package/dist/tools/approvals.service.js +5 -5
- package/dist/tools/builtins/sandbox/bash.js +1 -2
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +37 -38
- package/dist/tools/network-asks.d.ts +19 -22
- package/dist/tools/network-asks.js +15 -21
- package/dist/tools/pipeline.d.ts +6 -7
- package/dist/tools/pipeline.js +17 -21
- package/dist/tools/tools.module.js +3 -7
- package/package.json +3 -4
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-policy.service.d.ts +0 -213
- package/dist/local-devices/device-policy.service.js +0 -605
- package/dist/local-devices/instance-bindings.d.ts +0 -82
- package/dist/local-devices/instance-bindings.js +0 -307
- package/dist/local-devices/local-device-gateway.d.ts +0 -153
- package/dist/local-devices/local-device-provider.d.ts +0 -122
- package/dist/local-devices/local-device-provider.js +0 -326
- package/dist/local-devices/local-devices.module.d.ts +0 -31
- package/dist/local-devices/local-devices.module.js +0 -100
- package/dist/local-devices/machines.d.ts +0 -211
- package/dist/local-devices/machines.js +0 -766
- package/dist/local-devices/owner-report.d.ts +0 -81
- package/dist/local-devices/owner-report.js +0 -150
- package/dist/local-devices/owner-reports.d.ts +0 -48
- package/dist/local-devices/owner-reports.js +0 -208
- package/dist/local-devices/policy-op-jobs.d.ts +0 -15
- package/dist/local-devices/policy-op-jobs.js +0 -12
- package/dist/local-devices/policy-summary.d.ts +0 -102
- package/dist/local-devices/policy-summary.js +0 -155
- package/dist/local-devices/relay.d.ts +0 -166
- package/dist/local-devices/relay.js +0 -559
- package/dist/tools/device-op-resolver.d.ts +0 -34
- package/dist/tools/device-op-resolver.js +0 -120
- /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
- /package/dist/{local-devices → dial-in}/keys.js +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
- /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SandboxHandle, SandboxPermissionSupport, SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type UpdateObject } from "kysely";
|
|
3
3
|
import type { KernelDatabase } from "../db/kernel-schema.js";
|
|
4
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -7,14 +7,14 @@ import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
|
|
|
7
7
|
import { PermissionRuntimeReports } from "./permission-runtime-reports.js";
|
|
8
8
|
/** The greatest epoch millisecond a JavaScript Date (and so a generation) can represent. */
|
|
9
9
|
export declare const MAX_GENERATION_MS = 8640000000000000;
|
|
10
|
-
/** A
|
|
11
|
-
export interface
|
|
10
|
+
/** A provider's permission support read from the instance being committed (B-15). */
|
|
11
|
+
export interface SupportReport {
|
|
12
12
|
provider: string;
|
|
13
13
|
version: string;
|
|
14
14
|
report: SandboxPermissionSupport;
|
|
15
15
|
}
|
|
16
16
|
/** The instance a lifecycle holder probed: its handle, generation and limits before the probe. */
|
|
17
|
-
export interface
|
|
17
|
+
export interface ProbedInstance {
|
|
18
18
|
handle: SandboxHandle;
|
|
19
19
|
createdAt: number;
|
|
20
20
|
limits: unknown;
|
|
@@ -26,9 +26,7 @@ export declare class InconsistentGenerationError extends Error {
|
|
|
26
26
|
/**
|
|
27
27
|
* Final handle publication only; provider IO stays under the caller's exclusive lease outside this
|
|
28
28
|
* transaction. It also allocates the instance generation (permission runtime cutover B4): the
|
|
29
|
-
* row's `created_at` is an exact epoch millisecond above the device's durable high-water mark
|
|
30
|
-
* a local instance gets a fresh `awaiting-device` binding the lifecycle coordinator sends after
|
|
31
|
-
* commit.
|
|
29
|
+
* row's `created_at` is an exact epoch millisecond above the device's durable high-water mark.
|
|
32
30
|
*/
|
|
33
31
|
export declare class PermissionInstanceWrites {
|
|
34
32
|
private readonly db;
|
|
@@ -37,54 +35,42 @@ export declare class PermissionInstanceWrites {
|
|
|
37
35
|
private readonly reports;
|
|
38
36
|
constructor(db: KernelDb, txHost: TransactionHost, ceilings: PermissionCeilingWrites, reports: PermissionRuntimeReports);
|
|
39
37
|
/**
|
|
40
|
-
* `
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
38
|
+
* `evidence`: the permission support the lifecycle holder read from the new instance before this
|
|
39
|
+
* commit, recorded with the kernel-built identity in this same transaction, so the committed
|
|
40
|
+
* handle and its evidence appear together (B-15). Absent: none recorded (a failed read leaves
|
|
41
|
+
* the instance unprobed).
|
|
44
42
|
*/
|
|
45
|
-
commitHandle(orgId: string, deviceId: string, generation: number, roots: SandboxRoots, set: UpdateObject<KernelDatabase, "device_instances">, signal: AbortSignal,
|
|
43
|
+
commitHandle(orgId: string, deviceId: string, generation: number, roots: SandboxRoots, set: UpdateObject<KernelDatabase, "device_instances">, signal: AbortSignal, evidence?: SupportReport): Promise<Date>;
|
|
46
44
|
/**
|
|
47
|
-
* Records
|
|
48
|
-
*
|
|
45
|
+
* Records an instance's permission support read after a resume, a limits change, a provider
|
|
46
|
+
* version change or a new report revision, under the caller's lifecycle lease (B-15). Recorded only while the
|
|
49
47
|
* row still holds exactly the probed instance (its handle and generation) with the limits read
|
|
50
48
|
* before the probe: a holder whose lease was lost to one that replaced the instance or changed
|
|
51
49
|
* its limits records nothing, so it never overwrites newer evidence. Never provider IO inside
|
|
52
50
|
* the transaction.
|
|
53
51
|
*/
|
|
54
|
-
|
|
52
|
+
recordSupport(orgId: string, deviceId: string, held: ProbedInstance, support: SupportReport, signal: AbortSignal): Promise<boolean>;
|
|
55
53
|
/**
|
|
56
|
-
* Clears the recorded
|
|
57
|
-
*
|
|
58
|
-
*
|
|
54
|
+
* Clears the recorded identity of the probed instance (same checks as {@link recordSupport}): a
|
|
55
|
+
* resumed instance whose permission support could not be read is unprobed, never supported by
|
|
56
|
+
* evidence from before its suspension.
|
|
59
57
|
*/
|
|
60
|
-
|
|
61
|
-
/** Takes the device writer lock; true while the row still holds exactly the probed instance. */
|
|
62
|
-
private lockProbed;
|
|
58
|
+
clearSupport(orgId: string, deviceId: string, held: ProbedInstance, provider: string): Promise<boolean>;
|
|
63
59
|
/**
|
|
64
|
-
* The
|
|
65
|
-
*
|
|
66
|
-
* lands on those roots is proof of what was consented to, not a changed reach.
|
|
60
|
+
* The device row lock, before the authority writer lock (the device writers' order): the
|
|
61
|
+
* support recorded is stored on the device row too ({@link PermissionRuntimeReports.recordSupport}).
|
|
67
62
|
*/
|
|
68
|
-
private
|
|
63
|
+
private lockDevice;
|
|
64
|
+
/** Takes the device writer lock; true while the row still holds exactly the probed instance. */
|
|
65
|
+
private lockProbed;
|
|
69
66
|
/** Test seam: the database clock in epoch milliseconds. */
|
|
70
67
|
protected databaseNowMs(): Promise<number>;
|
|
71
68
|
/**
|
|
72
69
|
* `max(database now, highWater + 1)` under the device authority lock, committed with the
|
|
73
70
|
* instance row. The mark is initialized once from every recorded generation of the device
|
|
74
|
-
* (instance,
|
|
71
|
+
* (instance, operation intents, managed tasks, runtime reports), so a deleted row, a
|
|
75
72
|
* rolled-back clock or two creates in one millisecond never reuse a generation.
|
|
76
73
|
*/
|
|
77
74
|
private allocateGenerationLocked;
|
|
78
75
|
private initialHighWater;
|
|
79
|
-
/**
|
|
80
|
-
* The committed binding the coordinator sends. Its previous is the last binding committed for
|
|
81
|
-
* this machine credential, delivered or not: a device may have persisted a binding whose answer
|
|
82
|
-
* was lost, so the chain names what was sent (the device accepts a stored binding of its own
|
|
83
|
-
* credential up to that one). Another machine's bindings never chain, so a re-login starts
|
|
84
|
-
* fresh. Old rows are pruned, keeping the chain, each machine's latest installed binding and any
|
|
85
|
-
* generation a retirement still needs.
|
|
86
|
-
*/
|
|
87
|
-
private awaitDevice;
|
|
88
|
-
/** Bounded retention of a device's binding records (one per instance generation otherwise). */
|
|
89
|
-
private pruneBindings;
|
|
90
76
|
}
|
|
@@ -7,8 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { DEFAULT_SANDBOX_ROOTS, } from "@capybara-hq/plugin-sdk";
|
|
12
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
11
|
import { sql } from "kysely";
|
|
14
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -18,7 +16,6 @@ import { canonicalJson } from "../tools/canonical-json.js";
|
|
|
18
16
|
import { SandboxLockLostError } from "./leases.js";
|
|
19
17
|
import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
|
|
20
18
|
import { PermissionRuntimeReports } from "./permission-runtime-reports.js";
|
|
21
|
-
import { LOCAL_PROVIDER } from "./providers.js";
|
|
22
19
|
const rootKey = (r) => JSON.stringify([r.workspace, r.skills, r.tmp]);
|
|
23
20
|
/** The greatest epoch millisecond a JavaScript Date (and so a generation) can represent. */
|
|
24
21
|
export const MAX_GENERATION_MS = 8_640_000_000_000_000;
|
|
@@ -30,9 +27,7 @@ export class InconsistentGenerationError extends Error {
|
|
|
30
27
|
/**
|
|
31
28
|
* Final handle publication only; provider IO stays under the caller's exclusive lease outside this
|
|
32
29
|
* transaction. It also allocates the instance generation (permission runtime cutover B4): the
|
|
33
|
-
* row's `created_at` is an exact epoch millisecond above the device's durable high-water mark
|
|
34
|
-
* a local instance gets a fresh `awaiting-device` binding the lifecycle coordinator sends after
|
|
35
|
-
* commit.
|
|
30
|
+
* row's `created_at` is an exact epoch millisecond above the device's durable high-water mark.
|
|
36
31
|
*/
|
|
37
32
|
let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
38
33
|
db;
|
|
@@ -46,23 +41,27 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
46
41
|
this.reports = reports;
|
|
47
42
|
}
|
|
48
43
|
/**
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
44
|
+
* `evidence`: the permission support the lifecycle holder read from the new instance before this
|
|
45
|
+
* commit, recorded with the kernel-built identity in this same transaction, so the committed
|
|
46
|
+
* handle and its evidence appear together (B-15). Absent: none recorded (a failed read leaves
|
|
47
|
+
* the instance unprobed).
|
|
53
48
|
*/
|
|
54
|
-
async commitHandle(orgId, deviceId, generation, roots, set, signal,
|
|
49
|
+
async commitHandle(orgId, deviceId, generation, roots, set, signal, evidence) {
|
|
55
50
|
signal.throwIfAborted();
|
|
51
|
+
await this.lockDevice(orgId, deviceId);
|
|
56
52
|
await this.ceilings.lock({ orgId, deviceId }, "device");
|
|
57
53
|
const row = await this.db
|
|
58
54
|
.selectFrom("device_instances")
|
|
59
|
-
.select(["generation", "permission_roots"
|
|
55
|
+
.select(["generation", "permission_roots"])
|
|
60
56
|
.where("device_id", "=", deviceId)
|
|
61
57
|
.forUpdate()
|
|
62
58
|
.executeTakeFirst();
|
|
63
59
|
if (!row || row.generation !== generation)
|
|
64
60
|
throw new SandboxLockLostError(deviceId, "generation");
|
|
65
|
-
|
|
61
|
+
// a device that never had an instance has no committed roots: its first commit is what the
|
|
62
|
+
// person consented to (a consent names the device and its project, never roots it could not
|
|
63
|
+
// know yet), not a changed reach; a later instance on other roots is
|
|
64
|
+
if (row.permission_roots !== null && rootKey(row.permission_roots) !== rootKey(roots))
|
|
66
65
|
await this.ceilings.publishLocked({ orgId, deviceId }, "device", true, true);
|
|
67
66
|
signal.throwIfAborted();
|
|
68
67
|
const createdAt = new Date(await this.allocateGenerationLocked(deviceId));
|
|
@@ -76,46 +75,58 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
76
75
|
})
|
|
77
76
|
.where("device_id", "=", deviceId)
|
|
78
77
|
.where("generation", "=", generation)
|
|
79
|
-
.returning(
|
|
78
|
+
.returning("created_at")
|
|
80
79
|
.executeTakeFirst();
|
|
81
80
|
if (!updated)
|
|
82
81
|
throw new SandboxLockLostError(deviceId, "generation");
|
|
83
82
|
if (updated.created_at.getTime() !== createdAt.getTime())
|
|
84
83
|
throw new Error("Instance generation was not stored exactly; check the database clock type");
|
|
85
|
-
if (
|
|
86
|
-
await this.
|
|
87
|
-
else if (cloud)
|
|
88
|
-
await this.reports.recordCloud(deviceId, cloud.provider, cloud.version, cloud.report);
|
|
84
|
+
if (evidence)
|
|
85
|
+
await this.reports.recordSupport(deviceId, evidence.provider, evidence.version, evidence.report);
|
|
89
86
|
return updated.created_at;
|
|
90
87
|
}
|
|
91
88
|
/**
|
|
92
|
-
* Records
|
|
93
|
-
*
|
|
89
|
+
* Records an instance's permission support read after a resume, a limits change, a provider
|
|
90
|
+
* version change or a new report revision, under the caller's lifecycle lease (B-15). Recorded only while the
|
|
94
91
|
* row still holds exactly the probed instance (its handle and generation) with the limits read
|
|
95
92
|
* before the probe: a holder whose lease was lost to one that replaced the instance or changed
|
|
96
93
|
* its limits records nothing, so it never overwrites newer evidence. Never provider IO inside
|
|
97
94
|
* the transaction.
|
|
98
95
|
*/
|
|
99
|
-
async
|
|
96
|
+
async recordSupport(orgId, deviceId, held, support, signal) {
|
|
100
97
|
signal.throwIfAborted();
|
|
101
|
-
if (!(await this.lockProbed(orgId, deviceId, held,
|
|
98
|
+
if (!(await this.lockProbed(orgId, deviceId, held, support.provider)))
|
|
102
99
|
return false;
|
|
103
|
-
await this.reports.
|
|
100
|
+
await this.reports.recordSupport(deviceId, support.provider, support.version, support.report);
|
|
104
101
|
return true;
|
|
105
102
|
}
|
|
106
103
|
/**
|
|
107
|
-
* Clears the recorded
|
|
108
|
-
*
|
|
109
|
-
*
|
|
104
|
+
* Clears the recorded identity of the probed instance (same checks as {@link recordSupport}): a
|
|
105
|
+
* resumed instance whose permission support could not be read is unprobed, never supported by
|
|
106
|
+
* evidence from before its suspension.
|
|
110
107
|
*/
|
|
111
|
-
async
|
|
108
|
+
async clearSupport(orgId, deviceId, held, provider) {
|
|
112
109
|
if (!(await this.lockProbed(orgId, deviceId, held, provider)))
|
|
113
110
|
return false;
|
|
114
|
-
await this.reports.
|
|
111
|
+
await this.reports.clearSupport(deviceId, provider);
|
|
115
112
|
return true;
|
|
116
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The device row lock, before the authority writer lock (the device writers' order): the
|
|
116
|
+
* support recorded is stored on the device row too ({@link PermissionRuntimeReports.recordSupport}).
|
|
117
|
+
*/
|
|
118
|
+
async lockDevice(orgId, deviceId) {
|
|
119
|
+
await this.db
|
|
120
|
+
.selectFrom("devices")
|
|
121
|
+
.select("id")
|
|
122
|
+
.where("id", "=", deviceId)
|
|
123
|
+
.where("org_id", "=", orgId)
|
|
124
|
+
.forNoKeyUpdate()
|
|
125
|
+
.executeTakeFirst();
|
|
126
|
+
}
|
|
117
127
|
/** Takes the device writer lock; true while the row still holds exactly the probed instance. */
|
|
118
128
|
async lockProbed(orgId, deviceId, held, provider) {
|
|
129
|
+
await this.lockDevice(orgId, deviceId);
|
|
119
130
|
await this.ceilings.lock({ orgId, deviceId }, "device");
|
|
120
131
|
const row = await this.db
|
|
121
132
|
.selectFrom("device_instances")
|
|
@@ -130,23 +141,6 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
130
141
|
canonicalJson(row.handle) === canonicalJson(held.handle) &&
|
|
131
142
|
canonicalJson(row.instance_limits ?? null) === canonicalJson(held.limits ?? null));
|
|
132
143
|
}
|
|
133
|
-
/**
|
|
134
|
-
* The roots a person saw before the first instance: the machine's reported roots for a local
|
|
135
|
-
* device (what the Full consent displayed), else the provider defaults. The first create that
|
|
136
|
-
* lands on those roots is proof of what was consented to, not a changed reach.
|
|
137
|
-
*/
|
|
138
|
-
async displayedRoots(deviceId) {
|
|
139
|
-
const machine = await this.db
|
|
140
|
-
.selectFrom("device_machines")
|
|
141
|
-
.select("roots")
|
|
142
|
-
.where("device_id", "=", deviceId)
|
|
143
|
-
.where("revoked_at", "is", null)
|
|
144
|
-
.executeTakeFirst();
|
|
145
|
-
const reported = machine?.roots;
|
|
146
|
-
return reported && typeof reported === "object"
|
|
147
|
-
? { ...DEFAULT_SANDBOX_ROOTS, ...reported }
|
|
148
|
-
: DEFAULT_SANDBOX_ROOTS;
|
|
149
|
-
}
|
|
150
144
|
/** Test seam: the database clock in epoch milliseconds. */
|
|
151
145
|
async databaseNowMs() {
|
|
152
146
|
const r = await sql `
|
|
@@ -156,7 +150,7 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
156
150
|
/**
|
|
157
151
|
* `max(database now, highWater + 1)` under the device authority lock, committed with the
|
|
158
152
|
* instance row. The mark is initialized once from every recorded generation of the device
|
|
159
|
-
* (instance,
|
|
153
|
+
* (instance, operation intents, managed tasks, runtime reports), so a deleted row, a
|
|
160
154
|
* rolled-back clock or two creates in one millisecond never reuse a generation.
|
|
161
155
|
*/
|
|
162
156
|
async allocateGenerationLocked(deviceId) {
|
|
@@ -178,17 +172,12 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
178
172
|
return next;
|
|
179
173
|
}
|
|
180
174
|
async initialHighWater(deviceId) {
|
|
181
|
-
const [instance,
|
|
175
|
+
const [instance, intents, tasks, reports] = await Promise.all([
|
|
182
176
|
this.db
|
|
183
177
|
.selectFrom("device_instances")
|
|
184
178
|
.select(["created_at", "had_instance"])
|
|
185
179
|
.where("device_id", "=", deviceId)
|
|
186
180
|
.execute(),
|
|
187
|
-
this.db
|
|
188
|
-
.selectFrom("device_instance_bindings")
|
|
189
|
-
.select("instance_generation as g")
|
|
190
|
-
.where("device_id", "=", deviceId)
|
|
191
|
-
.execute(),
|
|
192
181
|
this.db
|
|
193
182
|
.selectFrom("sandbox_operation_intents")
|
|
194
183
|
.select("instance_generation as g")
|
|
@@ -210,7 +199,7 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
210
199
|
for (const r of instance)
|
|
211
200
|
if (r.had_instance)
|
|
212
201
|
high = Math.max(high, r.created_at.getTime());
|
|
213
|
-
for (const { g } of [...
|
|
202
|
+
for (const { g } of [...intents, ...tasks, ...reports]) {
|
|
214
203
|
if (g === null)
|
|
215
204
|
continue;
|
|
216
205
|
if (!GENERATION.test(g) || Number(g) > MAX_GENERATION_MS)
|
|
@@ -219,82 +208,16 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
|
|
|
219
208
|
}
|
|
220
209
|
return high;
|
|
221
210
|
}
|
|
222
|
-
/**
|
|
223
|
-
* The committed binding the coordinator sends. Its previous is the last binding committed for
|
|
224
|
-
* this machine credential, delivered or not: a device may have persisted a binding whose answer
|
|
225
|
-
* was lost, so the chain names what was sent (the device accepts a stored binding of its own
|
|
226
|
-
* credential up to that one). Another machine's bindings never chain, so a re-login starts
|
|
227
|
-
* fresh. Old rows are pruned, keeping the chain, each machine's latest installed binding and any
|
|
228
|
-
* generation a retirement still needs.
|
|
229
|
-
*/
|
|
230
|
-
async awaitDevice(deviceId, instanceGeneration) {
|
|
231
|
-
const machine = await this.db
|
|
232
|
-
.selectFrom("device_machines")
|
|
233
|
-
.select("id")
|
|
234
|
-
.where("device_id", "=", deviceId)
|
|
235
|
-
.where("revoked_at", "is", null)
|
|
236
|
-
.executeTakeFirst();
|
|
237
|
-
const previous = machine
|
|
238
|
-
? await this.db
|
|
239
|
-
.selectFrom("device_instance_bindings")
|
|
240
|
-
.select("instance_generation")
|
|
241
|
-
.where("device_id", "=", deviceId)
|
|
242
|
-
.where("machine_id", "=", machine.id)
|
|
243
|
-
.orderBy(sql `instance_generation::bigint`, "desc")
|
|
244
|
-
.limit(1)
|
|
245
|
-
.executeTakeFirst()
|
|
246
|
-
: undefined;
|
|
247
|
-
await this.db
|
|
248
|
-
.insertInto("device_instance_bindings")
|
|
249
|
-
.values({
|
|
250
|
-
device_id: deviceId,
|
|
251
|
-
instance_generation: instanceGeneration,
|
|
252
|
-
binding_id: randomUUID(),
|
|
253
|
-
provider: LOCAL_PROVIDER,
|
|
254
|
-
previous_generation: previous?.instance_generation ?? null,
|
|
255
|
-
status: "awaiting-device",
|
|
256
|
-
machine_id: machine?.id ?? null,
|
|
257
|
-
})
|
|
258
|
-
.execute();
|
|
259
|
-
await this.pruneBindings(deviceId, [
|
|
260
|
-
instanceGeneration,
|
|
261
|
-
...(previous ? [previous.instance_generation] : []),
|
|
262
|
-
]);
|
|
263
|
-
}
|
|
264
|
-
/** Bounded retention of a device's binding records (one per instance generation otherwise). */
|
|
265
|
-
async pruneBindings(deviceId, keep) {
|
|
266
|
-
await sql `
|
|
267
|
-
DELETE FROM capybara.device_instance_bindings b
|
|
268
|
-
WHERE b.device_id = ${deviceId}::uuid
|
|
269
|
-
AND b.instance_generation <> ALL(${[...keep]}::text[])
|
|
270
|
-
-- each machine's latest installed binding stays
|
|
271
|
-
AND b.instance_generation IS DISTINCT FROM (
|
|
272
|
-
SELECT max(l.instance_generation::bigint)::text FROM capybara.device_instance_bindings l
|
|
273
|
-
WHERE l.device_id = b.device_id AND l.machine_id IS NOT DISTINCT FROM b.machine_id
|
|
274
|
-
AND l.status = 'installed')
|
|
275
|
-
-- a generation a retirement still owes stays
|
|
276
|
-
AND NOT EXISTS (
|
|
277
|
-
SELECT 1 FROM capybara.sandbox_operation_intents i
|
|
278
|
-
WHERE i.device_id::text = b.device_id::text
|
|
279
|
-
AND i.instance_generation = b.instance_generation
|
|
280
|
-
AND (i.state NOT IN ('completed', 'revoked')
|
|
281
|
-
OR (i.state = 'revoked' AND NOT i.revoke_acknowledged)))
|
|
282
|
-
AND NOT EXISTS (
|
|
283
|
-
SELECT 1 FROM capybara.background_tasks t
|
|
284
|
-
WHERE t.device_id::text = b.device_id::text
|
|
285
|
-
AND t.instance_generation = b.instance_generation
|
|
286
|
-
AND t.launch_state <> 'terminal')`.execute(this.db.db);
|
|
287
|
-
}
|
|
288
211
|
};
|
|
289
212
|
__decorate([
|
|
290
213
|
Transactional({ propagation: "requires_new" })
|
|
291
214
|
], PermissionInstanceWrites.prototype, "commitHandle", null);
|
|
292
215
|
__decorate([
|
|
293
216
|
Transactional({ propagation: "requires_new" })
|
|
294
|
-
], PermissionInstanceWrites.prototype, "
|
|
217
|
+
], PermissionInstanceWrites.prototype, "recordSupport", null);
|
|
295
218
|
__decorate([
|
|
296
219
|
Transactional({ propagation: "requires_new" })
|
|
297
|
-
], PermissionInstanceWrites.prototype, "
|
|
220
|
+
], PermissionInstanceWrites.prototype, "clearSupport", null);
|
|
298
221
|
PermissionInstanceWrites = __decorate([
|
|
299
222
|
Injectable(),
|
|
300
223
|
__param(0, Inject(KernelDb)),
|
|
@@ -15,70 +15,78 @@ export interface PermissionRuntimeIdentity {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function runtimeIdentity(value: unknown): PermissionRuntimeIdentity;
|
|
17
17
|
/**
|
|
18
|
-
* The kernel-built runtime identity of a
|
|
19
|
-
* an in-process extension (full trust), so
|
|
20
|
-
* kernel facts, is the
|
|
21
|
-
* and version (`runtimeHash`), the committed instance handle (`helperHash`), the recorded
|
|
22
|
-
* limits with no provider-attested image digest
|
|
23
|
-
* Any of them changing
|
|
18
|
+
* The kernel-built runtime identity of a device's instance (B-15, Q1 option A; device-provider
|
|
19
|
+
* spec §6.7), one rule for every provider. A provider is an in-process extension (full trust), so
|
|
20
|
+
* its own permission support report, bound to these kernel facts, is the evidence: the provider
|
|
21
|
+
* plugin and version (`runtimeHash`), the committed instance handle (`helperHash`), the recorded
|
|
22
|
+
* applied limits with no provider-attested image digest and the device's stored report revision
|
|
23
|
+
* (`imageFingerprint`), and the instance generation. Any of them changing (a new report revision
|
|
24
|
+
* too) makes a recorded report unprobed until the lifecycle records it again.
|
|
24
25
|
*/
|
|
25
|
-
export declare function
|
|
26
|
+
export declare function runtimeIdentityOf(input: {
|
|
26
27
|
provider: string;
|
|
27
28
|
version: string;
|
|
28
29
|
handle: SandboxHandle;
|
|
29
30
|
instanceGeneration: string;
|
|
30
31
|
applied: AppliedLimits;
|
|
32
|
+
/** `devices.report->>'revision'`; null while no report is stored. */
|
|
33
|
+
reportRevision: string | null;
|
|
31
34
|
}): PermissionRuntimeIdentity;
|
|
32
35
|
/**
|
|
33
36
|
* A permission support report strictly parsed (`parseSandboxPermissionSupport`, version 2), or null
|
|
34
|
-
* when it is not one: a
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* when it is not one: a provider's answer (an in-process extension is trusted, but its answer is
|
|
38
|
+
* stored and read back later, so nothing beyond the contract's fields is kept) and a stored report
|
|
39
|
+
* read back (one recorded before version 2 is no report).
|
|
37
40
|
*/
|
|
38
|
-
export declare function
|
|
41
|
+
export declare function supportOf(value: unknown): SandboxPermissionSupport | null;
|
|
39
42
|
/**
|
|
40
|
-
* What
|
|
41
|
-
* the instance
|
|
42
|
-
*
|
|
43
|
-
*
|
|
43
|
+
* What an instance can enforce of its provider's report (B-12, spec §124): running outside the
|
|
44
|
+
* sandbox needs the instance applied in the `auto` tier (the platform and the org allowing it when
|
|
45
|
+
* it was made). An instance applied in the OS sandbox tier holds its outer network only through
|
|
46
|
+
* the restricted child filters that an escalated call leaves, so outside-sandbox reads as
|
|
47
|
+
* unsupported there whatever the provider reports; restricted support stands.
|
|
44
48
|
*/
|
|
45
|
-
export declare function
|
|
49
|
+
export declare function enforceable(report: SandboxPermissionSupport, instanceLimits: unknown): SandboxPermissionSupport;
|
|
46
50
|
/** No probe, provisioning or provider IO. A changed identity makes the previous report unprobed. */
|
|
47
51
|
export declare function readRuntimeReport(db: KernelSchemaDb, deviceId: string, provider: string, version: string | undefined): Promise<PermissionAvailability>;
|
|
48
52
|
/**
|
|
49
53
|
* {@link readRuntimeReport} plus the identity hash of the current report (null unless it is
|
|
50
|
-
* current
|
|
54
|
+
* current, which names the installed evidence) and the support it recorded (null unless it is
|
|
55
|
+
* current), whatever availability that support gives.
|
|
51
56
|
*/
|
|
52
57
|
export declare function readCurrentReport(db: KernelSchemaDb, deviceId: string, provider: string, version: string | undefined): Promise<{
|
|
53
58
|
availability: PermissionAvailability;
|
|
54
59
|
identityHash: string | null;
|
|
55
60
|
instanceGeneration: string | null;
|
|
61
|
+
support: SandboxPermissionSupport | null;
|
|
56
62
|
}>;
|
|
57
63
|
/**
|
|
58
|
-
* Whether a
|
|
64
|
+
* Whether a device's current instance owes a new runtime report (B-15): it can prove a
|
|
59
65
|
* kernel-built identity (a live instance of this provider version with a handle and recorded
|
|
60
|
-
* applied limits) but no current report is recorded for it
|
|
66
|
+
* applied limits) but no current report is recorded for it (none yet, or one recorded under an
|
|
67
|
+
* earlier report revision). Database reads only.
|
|
61
68
|
*/
|
|
62
|
-
export declare function
|
|
69
|
+
export declare function reportOwed(db: KernelSchemaDb, deviceId: string, provider: string, version: string | undefined): Promise<boolean>;
|
|
63
70
|
export declare class PermissionRuntimeReports {
|
|
64
71
|
private readonly db;
|
|
65
72
|
readonly txHost: TransactionHost;
|
|
66
73
|
private readonly locks;
|
|
67
74
|
constructor(db: KernelDb, txHost: TransactionHost, locks: PermissionAuthorityLock);
|
|
68
|
-
/** Caller holds the device authority writer lock and validates authenticated hello/source identity. */
|
|
69
|
-
record(deviceId: string, provider: string, version: string, identity: PermissionRuntimeIdentity | undefined, report: SandboxPermissionSupport): Promise<void>;
|
|
70
75
|
/**
|
|
71
|
-
* Records
|
|
72
|
-
* ({@link
|
|
76
|
+
* Records an instance's permission support with its kernel-built identity
|
|
77
|
+
* ({@link runtimeIdentityOf}, B-15), read from the committed row under the caller's device
|
|
73
78
|
* authority writer lock: the lifecycle holder calls it after create (in the handle commit's
|
|
74
79
|
* transaction) or after resume and limits changes, with the support it read from that exact
|
|
75
|
-
* instance under its lease.
|
|
76
|
-
* handle or without recorded applied limits records nothing new
|
|
80
|
+
* instance under its lease. An instance of another provider records nothing; one without a
|
|
81
|
+
* handle or without recorded applied limits records nothing new and clears a stale identity.
|
|
82
|
+
* The support recorded is also stored with the device's report (`devices.report.support`), so
|
|
83
|
+
* the stored support never lags what the runtime last said: the caller holds the device row
|
|
84
|
+
* lock (taken before the authority writer lock, the device writers' order).
|
|
77
85
|
*/
|
|
78
|
-
|
|
86
|
+
recordSupport(deviceId: string, provider: string, version: string, report: SandboxPermissionSupport): Promise<void>;
|
|
79
87
|
/**
|
|
80
|
-
* Clears
|
|
81
|
-
*
|
|
88
|
+
* Clears an instance's recorded identity (its report then reads unprobed). Caller holds the
|
|
89
|
+
* device authority writer lock and has checked the instance it probed.
|
|
82
90
|
*/
|
|
83
|
-
|
|
91
|
+
clearSupport(deviceId: string, provider: string): Promise<void>;
|
|
84
92
|
}
|