@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.55
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.schemas.d.ts +11 -1
- package/dist/catalog/catalog.module.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +5 -5
- package/dist/catalog/requests.service.js +9 -9
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +25 -16
- package/dist/channels/phrases.d.ts +15 -4
- package/dist/channels/phrases.js +15 -1
- package/dist/config/load.d.ts +26 -7
- package/dist/config/load.js +60 -9
- package/dist/config/permission-migration.d.ts +17 -9
- package/dist/config/permission-migration.js +60 -9
- package/dist/config/schema.d.ts +11 -1
- package/dist/config/schema.js +37 -11
- package/dist/conversations/events.d.ts +247 -5
- package/dist/conversations/events.js +127 -16
- package/dist/conversations/permission-profiles.controller.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.js +11 -4
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/devices/device-projects.service.d.ts +1 -1
- package/dist/devices/device-projects.service.js +6 -6
- package/dist/devices/devices.controller.d.ts +10 -8
- package/dist/devices/devices.controller.js +14 -18
- package/dist/devices/devices.schemas.d.ts +5 -5
- package/dist/devices/devices.schemas.js +5 -5
- package/dist/devices/devices.service.d.ts +188 -175
- package/dist/devices/devices.service.js +284 -292
- package/dist/devices/dto.d.ts +43 -23
- package/dist/devices/dto.js +45 -49
- package/dist/devices/project-rules.d.ts +0 -10
- package/dist/devices/project-rules.js +0 -5
- package/dist/errors.d.ts +24 -19
- package/dist/errors.js +24 -19
- package/dist/evals/reconstruct.d.ts +12 -3
- package/dist/evals/reconstruct.js +10 -6
- package/dist/evals/recorded-permission-context.d.ts +6 -4
- package/dist/evals/recorded-permission-context.js +15 -9
- package/dist/evals/run-replay.d.ts +6 -1
- package/dist/evals/run-replay.js +7 -2
- package/dist/evals/worker.js +3 -1
- package/dist/identity/settings.d.ts +45 -18
- package/dist/identity/settings.js +151 -51
- package/dist/infra/config/kernel-config.service.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +17 -5
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -4
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +18 -9
- package/dist/local-devices/device-policy.service.js +21 -61
- package/dist/local-devices/device-routes.d.ts +3 -1
- package/dist/local-devices/device-routes.js +15 -4
- package/dist/local-devices/instance-bindings.js +5 -2
- package/dist/local-devices/local-device-gateway.d.ts +2 -2
- package/dist/local-devices/local-device-gateway.js +3 -3
- package/dist/local-devices/local-device-provider.d.ts +4 -4
- package/dist/local-devices/local-device-provider.js +23 -9
- package/dist/local-devices/local-devices.module.d.ts +1 -1
- package/dist/local-devices/local-devices.module.js +1 -1
- package/dist/local-devices/machines.d.ts +40 -16
- package/dist/local-devices/machines.js +89 -61
- package/dist/local-devices/owner-report.d.ts +16 -14
- package/dist/local-devices/owner-report.js +24 -30
- package/dist/local-devices/owner-reports.js +26 -8
- package/dist/local-devices/policy-summary.d.ts +25 -44
- package/dist/local-devices/policy-summary.js +26 -71
- package/dist/local-devices/relay.d.ts +6 -6
- package/dist/local-devices/relay.js +10 -8
- package/dist/net/public-address.d.ts +1 -1
- package/dist/net/public-address.js +5 -2
- package/dist/orgs/device-network-setting.d.ts +82 -0
- package/dist/orgs/device-network-setting.js +142 -0
- package/dist/orgs/settings.service.d.ts +103 -66
- package/dist/orgs/settings.service.js +201 -137
- package/dist/overrides.d.ts +5 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.js +20 -11
- package/dist/platform/ops/devices.ops.js +70 -5
- package/dist/platform/ops/org-settings.ops.js +10 -6
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/runtime/context/permission-profile.d.ts +17 -8
- package/dist/runtime/context/permission-profile.js +126 -45
- package/dist/runtime/permission-context.service.d.ts +1 -1
- package/dist/runtime/permission-context.service.js +5 -3
- package/dist/runtime/project/knowledge.d.ts +5 -4
- package/dist/runtime/project/knowledge.js +2 -1
- package/dist/runtime/project/knowledge.service.js +16 -13
- package/dist/sandbox/cloud-permission-snapshot.js +22 -3
- package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
- package/dist/sandbox/device-sandbox-settings.js +470 -0
- package/dist/sandbox/device-sandbox.d.ts +187 -0
- package/dist/sandbox/device-sandbox.js +236 -0
- package/dist/sandbox/held-operations.js +15 -7
- package/dist/sandbox/modes.d.ts +49 -24
- package/dist/sandbox/modes.js +27 -19
- package/dist/sandbox/operation-authority-types.d.ts +6 -5
- package/dist/sandbox/operation-authority-types.js +7 -8
- package/dist/sandbox/operation-authority.d.ts +23 -9
- package/dist/sandbox/operation-authority.js +179 -97
- package/dist/sandbox/permission-auto-grants.d.ts +42 -0
- package/dist/sandbox/permission-auto-grants.js +145 -0
- package/dist/sandbox/permission-call-grants.d.ts +12 -4
- package/dist/sandbox/permission-call-grants.js +84 -35
- package/dist/sandbox/permission-call-grants.module.js +10 -3
- package/dist/sandbox/permission-call-types.d.ts +39 -5
- package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
- package/dist/sandbox/permission-ceiling-writes.js +38 -4
- package/dist/sandbox/permission-config-publication.d.ts +44 -2
- package/dist/sandbox/permission-config-publication.js +230 -59
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-facts.d.ts +144 -15
- package/dist/sandbox/permission-facts.js +258 -70
- package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
- package/dist/sandbox/permission-runtime-reports.js +19 -29
- package/dist/sandbox/review/classifier.d.ts +8 -0
- package/dist/sandbox/review/classifier.js +10 -0
- package/dist/sandbox/review/permission-candidate.d.ts +69 -5
- package/dist/sandbox/review/permission-candidate.js +153 -30
- package/dist/sandbox/review/review.service.d.ts +19 -3
- package/dist/sandbox/review/review.service.js +59 -11
- package/dist/sandbox/review/rules.js +23 -3
- package/dist/sandbox/sandbox.service.d.ts +29 -11
- package/dist/sandbox/sandbox.service.js +51 -26
- package/dist/skills/invoke.js +3 -2
- package/dist/tools/approvals.service.d.ts +26 -116
- package/dist/tools/approvals.service.js +42 -346
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +80 -28
- package/dist/tools/builtins/sandbox/common.d.ts +39 -14
- package/dist/tools/builtins/sandbox/common.js +47 -24
- package/dist/tools/builtins/sandbox/deliver.js +7 -4
- package/dist/tools/builtins/skill-load.d.ts +2 -2
- package/dist/tools/builtins/skill-load.js +4 -3
- package/dist/tools/device-op-resolver.d.ts +4 -10
- package/dist/tools/device-op-resolver.js +8 -19
- package/dist/tools/network-asks.d.ts +52 -15
- package/dist/tools/network-asks.js +55 -25
- package/dist/tools/pipeline.d.ts +26 -14
- package/dist/tools/pipeline.js +144 -61
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/tools.module.js +1 -1
- package/package.json +4 -4
- package/src/migrations/0165_device_network_columns.sql +50 -0
- package/src/migrations/0166_permission_grant_full_access.sql +17 -0
- package/src/migrations/0167_device_network_backfill.sql +32 -0
- package/src/migrations/0168_binding_installed_connection.sql +6 -0
- package/dist/orgs/cloud-network-setting.d.ts +0 -33
- package/dist/orgs/cloud-network-setting.js +0 -47
- package/dist/sandbox/platform-full-access.d.ts +0 -110
- package/dist/sandbox/platform-full-access.js +0 -198
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
11
|
+
import { EventLog } from "../conversations/event-log.js";
|
|
12
|
+
import { ApiError } from "../errors.js";
|
|
13
|
+
import { audit } from "../identity/audit.js";
|
|
14
|
+
import { afterCommit } from "../infra/database/after-commit.js";
|
|
15
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
17
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
18
|
+
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
19
|
+
import { PermissionCallGrants } from "./permission-call-grants.js";
|
|
20
|
+
import { permissionScopeHash } from "./permission-facts.js";
|
|
21
|
+
import { crossingOfCandidate } from "./review/permission-candidate.js";
|
|
22
|
+
/** Optional provider: the {@link PermissionAutoGrantHooks} (tests). */
|
|
23
|
+
export const PERMISSION_AUTO_GRANT_HOOKS = Symbol("PERMISSION_AUTO_GRANT_HOOKS");
|
|
24
|
+
/** The reason a Full access auto-grant's `permission_reviewed` event records. */
|
|
25
|
+
const AUTO_GRANT_REASON = "Full access grants this crossing within the device's limits.";
|
|
26
|
+
/**
|
|
27
|
+
* Full access auto-grants (approval-only profiles design, "Kernel: decision, admission and
|
|
28
|
+
* records"): one crossing granted for one call within the device's ceilings, recorded exactly once
|
|
29
|
+
* in one fenced transaction under the shared authority lock: the `permission_reviewed` event
|
|
30
|
+
* (decision source `full-access`, its crossing and any sensitive consents it skipped), the audit
|
|
31
|
+
* row `permission.crossing_auto_granted` and the grant itself (source `full-access`). The event is
|
|
32
|
+
* announced after the commit. A replica that lost the race for the same binding rolls back on the
|
|
33
|
+
* grant's immutable evidence (its event and audit row with it) and finds the winner's grant.
|
|
34
|
+
*/
|
|
35
|
+
let PermissionAutoGrants = class PermissionAutoGrants {
|
|
36
|
+
db;
|
|
37
|
+
txHost;
|
|
38
|
+
eventLog;
|
|
39
|
+
grants;
|
|
40
|
+
locks;
|
|
41
|
+
hooks;
|
|
42
|
+
constructor(db, txHost, eventLog, grants, locks, hooks) {
|
|
43
|
+
this.db = db;
|
|
44
|
+
this.txHost = txHost;
|
|
45
|
+
this.eventLog = eventLog;
|
|
46
|
+
this.grants = grants;
|
|
47
|
+
this.locks = locks;
|
|
48
|
+
this.hooks = hooks;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Records the auto-grant of `candidate`. `sensitive` are the sensitive-command consents (rule
|
|
52
|
+
* ids) Full access skipped for this call. Resolves once this call's grant exists, from this
|
|
53
|
+
* replica or another; anything else (a changed permission state, other evidence) throws.
|
|
54
|
+
*/
|
|
55
|
+
async record(candidate, sensitive = []) {
|
|
56
|
+
const b = candidate.binding;
|
|
57
|
+
const lock = () => this.locks.acquire({ orgId: b.orgId, deviceId: b.deviceId, rootConversationId: b.rootConversationId }, { kind: "admit" });
|
|
58
|
+
try {
|
|
59
|
+
await withTransactionFencePrelude(lock, () => this.recordIn(candidate, sensitive));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!(error instanceof ApiError) || error.code !== "conflict")
|
|
63
|
+
throw error;
|
|
64
|
+
const grant = await withTransactionFencePrelude(lock, () => this.findIn(b));
|
|
65
|
+
if (grant?.source !== "full-access" ||
|
|
66
|
+
grant.scopeKind !== candidate.scopeKind ||
|
|
67
|
+
permissionScopeHash(grant.expansion) !== permissionScopeHash(candidate.permissionScope))
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
findIn(binding) {
|
|
72
|
+
return this.grants.findForAdmission(binding);
|
|
73
|
+
}
|
|
74
|
+
async recordIn(candidate, sensitive) {
|
|
75
|
+
const b = candidate.binding;
|
|
76
|
+
await this.grants.assertCurrent(b);
|
|
77
|
+
// an exact retry (or the other replica's committed grant) is already the record
|
|
78
|
+
if (await this.grants.findForAdmission(b))
|
|
79
|
+
return;
|
|
80
|
+
await this.hooks?.afterPrecheck?.(b);
|
|
81
|
+
const crossing = crossingOfCandidate(candidate);
|
|
82
|
+
const skipped = [...new Set(sensitive)].sort();
|
|
83
|
+
const [event] = await this.eventLog.appendIn(b.conversationId, [
|
|
84
|
+
{
|
|
85
|
+
type: "permission_reviewed",
|
|
86
|
+
runId: b.runId,
|
|
87
|
+
payload: {
|
|
88
|
+
...candidate,
|
|
89
|
+
outcome: "allow",
|
|
90
|
+
reason: AUTO_GRANT_REASON,
|
|
91
|
+
decisionSource: "full-access",
|
|
92
|
+
crossing,
|
|
93
|
+
...(skipped.length > 0 ? { sensitive: skipped } : {}),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
if (!event)
|
|
98
|
+
throw new Error("The review event was not recorded");
|
|
99
|
+
await audit(this.db.db, {
|
|
100
|
+
actorAccountId: b.accountId,
|
|
101
|
+
orgId: b.orgId,
|
|
102
|
+
action: "permission.crossing_auto_granted",
|
|
103
|
+
target: b.deviceId,
|
|
104
|
+
detail: {
|
|
105
|
+
kind: crossing,
|
|
106
|
+
deviceId: b.deviceId,
|
|
107
|
+
conversationId: b.conversationId,
|
|
108
|
+
rootConversationId: b.rootConversationId,
|
|
109
|
+
runId: b.runId,
|
|
110
|
+
callId: b.callId,
|
|
111
|
+
toolKey: b.toolKey,
|
|
112
|
+
candidateHash: candidate.candidateHash,
|
|
113
|
+
reviewEventSeq: event.seq,
|
|
114
|
+
...(crossing === "outside-sandbox"
|
|
115
|
+
? { justification: candidate.escalation?.justification }
|
|
116
|
+
: { permissionScope: candidate.permissionScope }),
|
|
117
|
+
...(candidate.targetPath ? { targetPath: candidate.targetPath } : {}),
|
|
118
|
+
...(skipped.length > 0 ? { sensitive: skipped } : {}),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
await this.grants.issueLocked(candidate, {
|
|
122
|
+
source: "full-access",
|
|
123
|
+
reviewEventSeq: event.seq,
|
|
124
|
+
decidedBy: null,
|
|
125
|
+
});
|
|
126
|
+
afterCommit(() => this.eventLog.notify(b.conversationId, event.seq));
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
__decorate([
|
|
130
|
+
Transactional()
|
|
131
|
+
], PermissionAutoGrants.prototype, "findIn", null);
|
|
132
|
+
__decorate([
|
|
133
|
+
Transactional()
|
|
134
|
+
], PermissionAutoGrants.prototype, "recordIn", null);
|
|
135
|
+
PermissionAutoGrants = __decorate([
|
|
136
|
+
Injectable(),
|
|
137
|
+
__param(0, Inject(KernelDb)),
|
|
138
|
+
__param(1, Inject(TransactionHost)),
|
|
139
|
+
__param(2, Inject(EventLog)),
|
|
140
|
+
__param(3, Inject(PermissionCallGrants)),
|
|
141
|
+
__param(4, Inject(PermissionAuthorityLock)),
|
|
142
|
+
__param(5, Optional()),
|
|
143
|
+
__param(5, Inject(PERMISSION_AUTO_GRANT_HOOKS))
|
|
144
|
+
], PermissionAutoGrants);
|
|
145
|
+
export { PermissionAutoGrants };
|
|
@@ -6,7 +6,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
6
6
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
7
7
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
8
8
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
9
|
-
import type { PermissionCallBinding, PermissionCandidate, PermissionGrantDecision } from "./permission-call-types.js";
|
|
9
|
+
import type { PermissionCallBinding, PermissionCandidate, PermissionGrantDecision, PermissionGrantSource } from "./permission-call-types.js";
|
|
10
10
|
import { PermissionFacts } from "./permission-facts.js";
|
|
11
11
|
type GrantRow = Selectable<PermissionCallGrantsTable>;
|
|
12
12
|
export declare function bindingOfGrant(r: GrantRow): PermissionCallBinding;
|
|
@@ -18,8 +18,16 @@ export declare class PermissionCallGrants {
|
|
|
18
18
|
private readonly profiles;
|
|
19
19
|
private readonly facts;
|
|
20
20
|
constructor(db: KernelDb, txHost: TransactionHost, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore, profiles: PermissionProfileStore, facts: PermissionFacts);
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The caller takes authority before conversation/approval/run locks. No I/O occurs here.
|
|
23
|
+
* Returns the recorded input of the bound call.
|
|
24
|
+
*/
|
|
25
|
+
assertCurrent(binding: PermissionCallBinding): Promise<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the bound call's recorded command carries a credential consent, re-derived with the
|
|
28
|
+
* review rules against the working root and the owner's home (a missing command counts as one).
|
|
29
|
+
*/
|
|
30
|
+
private credentialConsentOf;
|
|
23
31
|
issueLocked(candidate: PermissionCandidate, decision: PermissionGrantDecision): Promise<{
|
|
24
32
|
id: string;
|
|
25
33
|
}>;
|
|
@@ -30,7 +38,7 @@ export declare class PermissionCallGrants {
|
|
|
30
38
|
id: string;
|
|
31
39
|
expansion: PermissionCandidate["permissionScope"];
|
|
32
40
|
scopeKind: PermissionCandidate["scopeKind"];
|
|
33
|
-
source:
|
|
41
|
+
source: PermissionGrantSource;
|
|
34
42
|
} | null>;
|
|
35
43
|
/** Starting authority belongs to this admitted exec, never to another call or native method. */
|
|
36
44
|
forExecution(operationId: string, deviceId: string, method: "exec" | "backgroundStart", scope: SandboxOperationScope, input: unknown): Promise<DeviceExecGrants | undefined>;
|
|
@@ -15,13 +15,14 @@ import { ApiError } from "../errors.js";
|
|
|
15
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
16
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
17
17
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
18
|
-
import {
|
|
18
|
+
import { hostGrantable } from "./device-sandbox.js";
|
|
19
19
|
import { isExecutionMethod, parseStartingExecutionGrants } from "./operation-authority-types.js";
|
|
20
20
|
import { describeOperationPayload } from "./operation-payloads.js";
|
|
21
21
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
22
22
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
23
23
|
import { PermissionFacts, permissionScopeHash } from "./permission-facts.js";
|
|
24
|
-
import { normalizePermissionExpansion, permissionCandidateHash, } from "./review/permission-candidate.js";
|
|
24
|
+
import { approverForCrossing, commandCarriesCredentialConsent, crossingOfCandidate, normalizePermissionExpansion, permissionCandidateHash, } from "./review/permission-candidate.js";
|
|
25
|
+
import { homeOf } from "./review/rules.js";
|
|
25
26
|
export function bindingOfGrant(r) {
|
|
26
27
|
return {
|
|
27
28
|
orgId: r.org_id,
|
|
@@ -56,7 +57,10 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
56
57
|
this.profiles = profiles;
|
|
57
58
|
this.facts = facts;
|
|
58
59
|
}
|
|
59
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The caller takes authority before conversation/approval/run locks. No I/O occurs here.
|
|
62
|
+
* Returns the recorded input of the bound call.
|
|
63
|
+
*/
|
|
60
64
|
async assertCurrent(binding) {
|
|
61
65
|
this.locks.assertHeld("root", binding.rootConversationId);
|
|
62
66
|
const root = await this.profiles.readOwnedRoot(binding.orgId, binding.conversationId, binding.accountId);
|
|
@@ -103,15 +107,45 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
103
107
|
const calls = messages.flatMap((row) => Array.isArray(row.payload.content)
|
|
104
108
|
? row.payload.content
|
|
105
109
|
: []);
|
|
106
|
-
|
|
110
|
+
const recorded = calls.find((call) => call.type === "tool_call" &&
|
|
107
111
|
call.id === binding.callId &&
|
|
108
112
|
call.name === binding.toolKey &&
|
|
109
|
-
permissionScopeHash(call.input) === binding.callInputHash)
|
|
113
|
+
permissionScopeHash(call.input) === binding.callInputHash);
|
|
114
|
+
if (!recorded)
|
|
110
115
|
throw new ApiError("forbidden", "Permission proposal does not match the recorded tool input");
|
|
116
|
+
return recorded.input;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether the bound call's recorded command carries a credential consent, re-derived with the
|
|
120
|
+
* review rules against the working root and the owner's home (a missing command counts as one).
|
|
121
|
+
*/
|
|
122
|
+
async credentialConsentOf(b, input) {
|
|
123
|
+
const command = input?.command;
|
|
124
|
+
if (typeof command !== "string")
|
|
125
|
+
return true;
|
|
126
|
+
const root = await this.profiles.readOwnedRoot(b.orgId, b.conversationId, b.accountId);
|
|
127
|
+
const [working, device] = await Promise.all([
|
|
128
|
+
this.facts.readWorkingFacts({
|
|
129
|
+
orgId: b.orgId,
|
|
130
|
+
rootConversationId: b.rootConversationId,
|
|
131
|
+
holderConversationId: b.conversationId,
|
|
132
|
+
deviceId: b.deviceId,
|
|
133
|
+
}),
|
|
134
|
+
this.facts.readDevice(b.orgId, b.deviceId),
|
|
135
|
+
]);
|
|
136
|
+
const workspace = root.project_path ?? working.workspace;
|
|
137
|
+
return commandCarriesCredentialConsent(command, {
|
|
138
|
+
workspace,
|
|
139
|
+
cwd: workspace,
|
|
140
|
+
home: working.home,
|
|
141
|
+
deviceHome: homeOf(working.workspace),
|
|
142
|
+
mode: device.policy.mode,
|
|
143
|
+
attended: true,
|
|
144
|
+
});
|
|
111
145
|
}
|
|
112
146
|
async issueLocked(candidate, decision) {
|
|
113
147
|
const b = candidate.binding;
|
|
114
|
-
await this.assertCurrent(b);
|
|
148
|
+
const recordedInput = await this.assertCurrent(b);
|
|
115
149
|
const { candidateHash, ...presentation } = candidate;
|
|
116
150
|
const escalation = candidate.scopeKind === "sandbox-escalation";
|
|
117
151
|
if (!["directories-and-hosts", "sandbox-escalation"].includes(candidate.scopeKind) ||
|
|
@@ -126,18 +160,37 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
126
160
|
candidate.targetPath !== undefined
|
|
127
161
|
: candidate.escalation !== undefined))
|
|
128
162
|
throw new ApiError("forbidden", "Permission proposal evidence does not match its exact directory scope");
|
|
129
|
-
|
|
130
|
-
|
|
163
|
+
// the automated sources only where the profile names them as the approver of this crossing
|
|
164
|
+
// (approval-only profiles design): the review model under Approve for me and for an
|
|
165
|
+
// escalation under Full access that a sub-agent asks for or that carries a credential consent
|
|
166
|
+
// (the review verdict knows the consents: issuance accepts the stricter review model for any
|
|
167
|
+
// Full access escalation), Full access itself for every other crossing, never a sub-agent's
|
|
168
|
+
// escalation. The person's own approval is always evidence; assertCurrent refused unattended
|
|
169
|
+
// and non-owner calls already
|
|
170
|
+
const crossing = crossingOfCandidate(candidate);
|
|
171
|
+
const approver = approverForCrossing({
|
|
172
|
+
profile: b.profile,
|
|
173
|
+
crossing,
|
|
174
|
+
subAgent: b.conversationId !== b.rootConversationId,
|
|
175
|
+
// re-derived from the recorded command, never taken from the pipeline's verdict
|
|
176
|
+
credentialConsent: escalation && b.profile === "full-access"
|
|
177
|
+
? await this.credentialConsentOf(b, recordedInput)
|
|
178
|
+
: false,
|
|
179
|
+
});
|
|
180
|
+
const reviewModelMay = approver === "review-model" ||
|
|
181
|
+
(b.profile === "full-access" && crossing === "outside-sandbox");
|
|
182
|
+
if ((decision.source === "review-model" && !reviewModelMay) ||
|
|
183
|
+
(decision.source === "full-access" && approver !== "none"))
|
|
131
184
|
throw new ApiError("forbidden", "This profile cannot issue an automated expansion grant");
|
|
132
185
|
const root = await this.profiles.readOwnedRoot(b.orgId, b.conversationId, b.accountId);
|
|
133
186
|
const view = await this.facts.view(b.orgId, b.accountId, root);
|
|
134
187
|
if (escalation) {
|
|
135
|
-
// the
|
|
188
|
+
// the outside-sandbox ceiling: owner, org and platform, and a runtime that can run outside
|
|
136
189
|
if (b.toolKey !== "Bash" ||
|
|
137
|
-
!view.
|
|
190
|
+
!view.outsideSandboxCeiling ||
|
|
138
191
|
view.availability.state !== "supported" ||
|
|
139
|
-
!view.availability.report.
|
|
140
|
-
throw new ApiError("forbidden", "Running this call outside the sandbox is
|
|
192
|
+
!view.availability.report.outsideSandbox)
|
|
193
|
+
throw new ApiError("forbidden", "Running this call outside the sandbox is beyond the current outside-sandbox ceiling");
|
|
141
194
|
await this.verifyEvidence(candidate, decision);
|
|
142
195
|
return this.insertGrant(candidate, decision);
|
|
143
196
|
}
|
|
@@ -147,27 +200,24 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
147
200
|
holderConversationId: b.conversationId,
|
|
148
201
|
deviceId: b.deviceId,
|
|
149
202
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.executeTakeFirstOrThrow();
|
|
156
|
-
const network = device.source === "local"
|
|
157
|
-
? { kind: "allowlist", hosts: policy.localAllowedDomains }
|
|
158
|
-
: policy.network;
|
|
159
|
-
if ((!view.broadProjectReach &&
|
|
203
|
+
// the device sandbox's per-call host ceiling, read live (`device-sandbox.ts`
|
|
204
|
+
// `hostGrantCeiling`): the one rule the candidate builder and admission read, so Full access
|
|
205
|
+
// never auto-grants beyond it
|
|
206
|
+
const { sandbox, hostCeiling, hostRefusal } = await this.facts.readDevice(b.orgId, b.deviceId);
|
|
207
|
+
if (!view.broadProjectReach &&
|
|
160
208
|
(candidate.permissionScope.readDirectories.length ||
|
|
161
|
-
candidate.permissionScope.writeDirectories.length))
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
209
|
+
candidate.permissionScope.writeDirectories.length))
|
|
210
|
+
throw new ApiError("forbidden", "Permission proposal exceeds the device owner's project reach");
|
|
211
|
+
const refused = candidate.permissionScope.hosts.flatMap((host) => hostGrantable(hostCeiling, host)
|
|
212
|
+
? []
|
|
213
|
+
: [`${host}: ${hostRefusal(host) ?? "it is beyond the device's network limits"}`]);
|
|
214
|
+
if (refused.length)
|
|
215
|
+
throw new ApiError("forbidden", `Permission proposal exceeds the device's per-call host ceiling (${refused.join("; ")})`);
|
|
165
216
|
const baseRoot = root.project_path ?? working.workspace;
|
|
166
217
|
const normalized = normalizePermissionExpansion(candidate.permissionScope, {
|
|
167
218
|
baseReadDirectories: [baseRoot],
|
|
168
219
|
baseWriteDirectories: [baseRoot],
|
|
169
|
-
baseHosts:
|
|
170
|
-
network.hosts.some((pattern) => coversHost(pattern, host))),
|
|
220
|
+
baseHosts: sandbox.networkMode === "allowlist" ? sandbox.hosts : [],
|
|
171
221
|
});
|
|
172
222
|
if (permissionScopeHash(normalized) !== permissionScopeHash(candidate.permissionScope))
|
|
173
223
|
throw new ApiError("forbidden", "Permission scope is not normalized");
|
|
@@ -207,7 +257,7 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
207
257
|
escalation: candidate.escalation ? JSON.stringify(candidate.escalation) : null,
|
|
208
258
|
source: decision.source,
|
|
209
259
|
approval_id: decision.source === "human" ? decision.approvalId : null,
|
|
210
|
-
review_event_seq: decision.source === "
|
|
260
|
+
review_event_seq: decision.source === "human" ? null : decision.reviewEventSeq,
|
|
211
261
|
decided_by: decision.decidedBy,
|
|
212
262
|
})
|
|
213
263
|
.onConflict((oc) => oc.column("binding_hash").doNothing())
|
|
@@ -225,8 +275,7 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
225
275
|
permissionScopeHash(row.escalation) !== permissionScopeHash(candidate.escalation ?? null) ||
|
|
226
276
|
row.source !== decision.source ||
|
|
227
277
|
row.approval_id !== (decision.source === "human" ? decision.approvalId : null) ||
|
|
228
|
-
row.review_event_seq !==
|
|
229
|
-
(decision.source === "review-model" ? decision.reviewEventSeq : null) ||
|
|
278
|
+
row.review_event_seq !== (decision.source === "human" ? null : decision.reviewEventSeq) ||
|
|
230
279
|
row.decided_by !== decision.decidedBy)
|
|
231
280
|
throw new ApiError("conflict", "This call already has different immutable permission evidence");
|
|
232
281
|
return { id: row.id };
|
|
@@ -264,9 +313,9 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
264
313
|
.executeTakeFirst();
|
|
265
314
|
if (!event ||
|
|
266
315
|
event.payload.outcome !== "allow" ||
|
|
267
|
-
event.payload.decisionSource !==
|
|
316
|
+
event.payload.decisionSource !== decision.source)
|
|
268
317
|
throw new ApiError("forbidden", "Permission grant requires its recorded allow verdict");
|
|
269
|
-
const { outcome: _outcome, reason: _reason, decisionSource: _source, ...proposal } = event.payload;
|
|
318
|
+
const { outcome: _outcome, reason: _reason, decisionSource: _source, crossing: _crossing, sensitive: _sensitive, ...proposal } = event.payload;
|
|
270
319
|
evidence = proposal;
|
|
271
320
|
}
|
|
272
321
|
if (permissionScopeHash(evidence) !== permissionScopeHash(candidate))
|
|
@@ -284,7 +333,7 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
284
333
|
await this.assertCurrent(binding);
|
|
285
334
|
if (row.source === "human" && (!row.approval_id || !row.decided_by))
|
|
286
335
|
throw new ApiError("forbidden", "The human permission evidence is incomplete");
|
|
287
|
-
if (row.source
|
|
336
|
+
if (row.source !== "human" && row.review_event_seq === null)
|
|
288
337
|
throw new ApiError("forbidden", "The review permission evidence is incomplete");
|
|
289
338
|
await this.verifyEvidence({
|
|
290
339
|
binding,
|
|
@@ -295,7 +344,7 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
295
344
|
candidateHash: row.candidate_hash,
|
|
296
345
|
}, row.source === "human"
|
|
297
346
|
? { source: "human", approvalId: row.approval_id ?? "", decidedBy: row.decided_by ?? "" }
|
|
298
|
-
: { source:
|
|
347
|
+
: { source: row.source, reviewEventSeq: row.review_event_seq ?? -1, decidedBy: null });
|
|
299
348
|
return { id: row.id, expansion: row.expansion, scopeKind: row.scope_kind, source: row.source };
|
|
300
349
|
}
|
|
301
350
|
/** Starting authority belongs to this admitted exec, never to another call or native method. */
|
|
@@ -5,17 +5,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
|
+
import { EventLogModule } from "../conversations/event-log.js";
|
|
8
9
|
import { PermissionProfileStoreModule } from "../conversations/permission-profile-store.module.js";
|
|
9
10
|
import { PermissionAuthorityModule } from "./permission-authority.module.js";
|
|
11
|
+
import { PermissionAutoGrants } from "./permission-auto-grants.js";
|
|
10
12
|
import { PermissionCallGrants } from "./permission-call-grants.js";
|
|
11
13
|
import { PermissionFactsModule } from "./permission-facts.module.js";
|
|
12
14
|
let PermissionCallGrantsModule = class PermissionCallGrantsModule {
|
|
13
15
|
};
|
|
14
16
|
PermissionCallGrantsModule = __decorate([
|
|
15
17
|
Module({
|
|
16
|
-
imports: [
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
imports: [
|
|
19
|
+
PermissionAuthorityModule,
|
|
20
|
+
PermissionFactsModule,
|
|
21
|
+
PermissionProfileStoreModule,
|
|
22
|
+
EventLogModule,
|
|
23
|
+
],
|
|
24
|
+
providers: [PermissionCallGrants, PermissionAutoGrants],
|
|
25
|
+
exports: [PermissionCallGrants, PermissionAutoGrants],
|
|
19
26
|
})
|
|
20
27
|
], PermissionCallGrantsModule);
|
|
21
28
|
export { PermissionCallGrantsModule };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PermissionProfile } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { HostGrantCeiling } from "./device-sandbox.js";
|
|
2
3
|
import type { EffectiveDevicePolicy } from "./modes.js";
|
|
3
4
|
import type { AppliedOuterNetwork } from "./permission-context-types.js";
|
|
4
5
|
export type PermissionCallRef = {
|
|
@@ -35,11 +36,29 @@ export type PermissionGrantDecision = {
|
|
|
35
36
|
source: "review-model";
|
|
36
37
|
reviewEventSeq: number;
|
|
37
38
|
decidedBy: null;
|
|
39
|
+
} | PermissionFullAccessGrantDecision;
|
|
40
|
+
/**
|
|
41
|
+
* Full access granted the crossing within the device's ceilings (approval-only profiles design,
|
|
42
|
+
* "Kernel: decision, admission and records"): its evidence is the `permission_reviewed` event
|
|
43
|
+
* (outcome allow, decision source `full-access`) written with an audit row
|
|
44
|
+
* `permission.crossing_auto_granted` and the grant in one fenced transaction.
|
|
45
|
+
*/
|
|
46
|
+
export type PermissionFullAccessGrantDecision = {
|
|
47
|
+
source: "full-access";
|
|
48
|
+
reviewEventSeq: number;
|
|
49
|
+
decidedBy: null;
|
|
38
50
|
};
|
|
51
|
+
/** Where a grant's evidence came from: the person, the review model or a Full access auto-grant. */
|
|
52
|
+
export type PermissionGrantSource = PermissionGrantDecision["source"];
|
|
53
|
+
/**
|
|
54
|
+
* The kind of one boundary crossing, as `ReviewRecord.crossing` records it: a directory outside the
|
|
55
|
+
* scope, a new host on an allowlist, running one call outside the sandbox, or a sensitive command.
|
|
56
|
+
*/
|
|
57
|
+
export type PermissionCrossingKind = "directory" | "host" | "outside-sandbox" | "sensitive";
|
|
39
58
|
/**
|
|
40
59
|
* What a call grant authorizes: an exact directory and host expansion of the restricted scope, or
|
|
41
60
|
* one Bash call run outside the OS sandbox (per-call sandbox escalation: full execution for that
|
|
42
|
-
* call only, within the device's
|
|
61
|
+
* call only, within the device's outside-sandbox setting).
|
|
43
62
|
*/
|
|
44
63
|
export type PermissionScopeKind = "directories-and-hosts" | "sandbox-escalation";
|
|
45
64
|
/**
|
|
@@ -69,7 +88,8 @@ export type PermissionCandidateResult = {
|
|
|
69
88
|
candidate: PermissionCandidate;
|
|
70
89
|
} | {
|
|
71
90
|
kind: "unsupported";
|
|
72
|
-
|
|
91
|
+
/** `protected-path`: its text already names the outside-sandbox escalation (no retry hint). */
|
|
92
|
+
code: "unbounded-scope" | "escalation-unavailable" | "protected-path";
|
|
73
93
|
message: string;
|
|
74
94
|
};
|
|
75
95
|
export type PermissionReviewSnapshot = Readonly<Omit<PermissionCallBinding, "toolKey" | "specHash" | "callInputHash" | "resolvedInputHash"> & {
|
|
@@ -77,7 +97,14 @@ export type PermissionReviewSnapshot = Readonly<Omit<PermissionCallBinding, "too
|
|
|
77
97
|
baseWriteDirectories: readonly string[];
|
|
78
98
|
baseHosts: readonly string[];
|
|
79
99
|
workingRoot: string;
|
|
80
|
-
|
|
100
|
+
/**
|
|
101
|
+
* The call's sandbox network (the device sandbox within the applied outer boundary): `open-public`,
|
|
102
|
+
* `allowlist` (the base hosts plus accepted host grants) or `none`. Absent reads as `none`.
|
|
103
|
+
*/
|
|
104
|
+
network?: "open-public" | "allowlist" | "none";
|
|
105
|
+
/** The provider's boundary; absent reads as `operation`. */
|
|
106
|
+
boundary?: "operation" | "instance";
|
|
107
|
+
outsideSandboxCeiling: boolean;
|
|
81
108
|
/** Restricted directory expansions beyond the working root (B2 broad project reach). */
|
|
82
109
|
broadProjectReach: boolean;
|
|
83
110
|
unattended: boolean;
|
|
@@ -98,10 +125,17 @@ export type PermissionReviewSnapshot = Readonly<Omit<PermissionCallBinding, "too
|
|
|
98
125
|
*/
|
|
99
126
|
outerNetwork?: AppliedOuterNetwork | null;
|
|
100
127
|
policy: EffectiveDevicePolicy;
|
|
128
|
+
/**
|
|
129
|
+
* The per-call host grant ceiling (`device-sandbox.ts` `hostGrantCeiling`): the org's
|
|
130
|
+
* exclusions and its hard allowlist ceiling. Absent: read `policy.network`.
|
|
131
|
+
*/
|
|
132
|
+
hostCeiling?: HostGrantCeiling;
|
|
133
|
+
/** Why a host is unavailable per call, naming who can add it; null when grantable. */
|
|
134
|
+
hostRefusal?: (host: string) => string | null;
|
|
101
135
|
/**
|
|
102
136
|
* Why this call could not run outside the sandbox (per-call escalation): an unattended run, a
|
|
103
|
-
* device, org or platform
|
|
104
|
-
*
|
|
137
|
+
* device, org or platform outside-sandbox setting that forbids it (one text per layer), or a
|
|
138
|
+
* runtime that cannot run a command outside its sandbox now. Null or absent when an escalation may be reviewed.
|
|
105
139
|
*/
|
|
106
140
|
escalationRefusal?: string | null;
|
|
107
141
|
}>;
|
|
@@ -27,13 +27,26 @@ export declare class PermissionCeilingWrites {
|
|
|
27
27
|
* compare running restricted scopes against (B2 reach narrowing). Cloud devices have none.
|
|
28
28
|
*/
|
|
29
29
|
export declare function localMachineRoots(db: KernelSchemaDb, orgId?: string): Promise<Map<string, string[]>>;
|
|
30
|
+
/**
|
|
31
|
+
* The narrowings a ceiling write publishes (approval-only profiles design, "Ceiling writes"), each
|
|
32
|
+
* bumping its epoch and revoking, in the same transaction, the admitted or started work it takes:
|
|
33
|
+
* - `outside-sandbox-off`: escalated work ({@link needsFullCeiling});
|
|
34
|
+
* - `network-allowlist`: work on the open public network ({@link needsOpenNetwork});
|
|
35
|
+
* - `hosts-removed`: allowlist work naming a host the new list no longer covers (the writer's own
|
|
36
|
+
* host check, which keeps hosts an independent grant still holds).
|
|
37
|
+
* Widening any of them resets Full consent instead (`invalidateFullConsent`); a profile change
|
|
38
|
+
* alone never revokes started work.
|
|
39
|
+
*/
|
|
40
|
+
export type CeilingNarrowing = "outside-sandbox-off" | "network-allowlist" | "hosts-removed";
|
|
41
|
+
/** Work on the open public network: what a network ceiling narrowed to `allowlist` takes away. */
|
|
42
|
+
export declare const needsOpenNetwork: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
|
|
30
43
|
/**
|
|
31
44
|
* What a platform or org Full ceiling turning off takes away (B2, same split as the owner writer):
|
|
32
45
|
* Full execution, broad browsing, and running restricted work outside the machine's roots, since
|
|
33
46
|
* the effective restricted reach narrows to the workspace.
|
|
34
47
|
*/
|
|
35
48
|
export declare const needsWiderDeviceCeiling: (scope: SandboxOperationScope | SandboxBrowseScope, machineRoots: readonly string[] | undefined) => boolean;
|
|
36
|
-
/**
|
|
49
|
+
/** Running outside the sandbox: an escalated call (`outside-sandbox-off` takes it). */
|
|
37
50
|
export declare const requiresFullExecution: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
|
|
38
51
|
/**
|
|
39
52
|
* Broad project reach: owner browsing outside the restricted workspace (B2: decided by the reach
|
|
@@ -41,7 +54,20 @@ export declare const requiresFullExecution: (scope: SandboxOperationScope | Sand
|
|
|
41
54
|
*/
|
|
42
55
|
export declare const requiresBroadProjectReach: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
|
|
43
56
|
/**
|
|
44
|
-
* What a platform or org
|
|
45
|
-
* wider device ceiling restricted reach depended on.
|
|
57
|
+
* What a platform or org outside-sandbox ceiling turning off takes away: escalated work and, as
|
|
58
|
+
* before, the wider device ceiling restricted reach depended on.
|
|
46
59
|
*/
|
|
47
60
|
export declare const needsFullCeiling: (scope: SandboxOperationScope | SandboxBrowseScope) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The cloud devices that follow their org's network default (no network choice of their own and
|
|
63
|
+
* no B1 allowlist snapshot), with their org: what narrowing a default (`devices.network.default`
|
|
64
|
+
* or an org's `deviceNetwork.default`, open to allowlist) moves to the allowlist, so their running
|
|
65
|
+
* open-network work is revoked. A local device follows its owner's network, never a default.
|
|
66
|
+
*/
|
|
67
|
+
export declare function cloudDevicesFollowingDefault(db: KernelSchemaDb, orgId?: string): Promise<Map<string, string>>;
|
|
68
|
+
/**
|
|
69
|
+
* Whether an allowlist execution names a host the new ceilings no longer allow (`hosts-removed`):
|
|
70
|
+
* a host neither in the org's effective hosts nor held by an independent run or task grant the new
|
|
71
|
+
* per-call ceiling still allows (`grantable`). Native methods and other networks reach no host.
|
|
72
|
+
*/
|
|
73
|
+
export declare function hostsNarrowed(scope: SandboxOperationScope | SandboxBrowseScope, row: Pick<Selectable<SandboxOperationIntentsTable>, "method" | "granted_hosts">, orgHosts: readonly string[], grantable: (host: string) => boolean): boolean;
|
|
@@ -13,7 +13,8 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
|
13
13
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
14
14
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
15
15
|
import { machineRootList, outsideMachineRoots } from "../local-devices/owner-report.js";
|
|
16
|
-
import {
|
|
16
|
+
import { coversHost } from "./modes.js";
|
|
17
|
+
import { isExecutionMethod, isFullExecutionScope, usesOpenNetwork, } from "./operation-authority-types.js";
|
|
17
18
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
18
19
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
19
20
|
import { PermissionTransitions } from "./permission-transitions.js";
|
|
@@ -204,13 +205,15 @@ export async function localMachineRoots(db, orgId) {
|
|
|
204
205
|
const rows = await q.execute();
|
|
205
206
|
return new Map(rows.map((r) => [r.device_id, machineRootList(r.roots)]));
|
|
206
207
|
}
|
|
208
|
+
/** Work on the open public network: what a network ceiling narrowed to `allowlist` takes away. */
|
|
209
|
+
export const needsOpenNetwork = (scope) => usesOpenNetwork(scope);
|
|
207
210
|
/**
|
|
208
211
|
* What a platform or org Full ceiling turning off takes away (B2, same split as the owner writer):
|
|
209
212
|
* Full execution, broad browsing, and running restricted work outside the machine's roots, since
|
|
210
213
|
* the effective restricted reach narrows to the workspace.
|
|
211
214
|
*/
|
|
212
215
|
export const needsWiderDeviceCeiling = (scope, machineRoots) => needsFullCeiling(scope) || outsideMachineRoots(scope, machineRoots);
|
|
213
|
-
/**
|
|
216
|
+
/** Running outside the sandbox: an escalated call (`outside-sandbox-off` takes it). */
|
|
214
217
|
export const requiresFullExecution = (scope) => isFullExecutionScope(scope);
|
|
215
218
|
/**
|
|
216
219
|
* Broad project reach: owner browsing outside the restricted workspace (B2: decided by the reach
|
|
@@ -218,7 +221,38 @@ export const requiresFullExecution = (scope) => isFullExecutionScope(scope);
|
|
|
218
221
|
*/
|
|
219
222
|
export const requiresBroadProjectReach = (scope) => !("profile" in scope) && scope.readRoots.includes("/");
|
|
220
223
|
/**
|
|
221
|
-
* What a platform or org
|
|
222
|
-
* wider device ceiling restricted reach depended on.
|
|
224
|
+
* What a platform or org outside-sandbox ceiling turning off takes away: escalated work and, as
|
|
225
|
+
* before, the wider device ceiling restricted reach depended on.
|
|
223
226
|
*/
|
|
224
227
|
export const needsFullCeiling = (scope) => requiresFullExecution(scope) || requiresBroadProjectReach(scope);
|
|
228
|
+
/**
|
|
229
|
+
* The cloud devices that follow their org's network default (no network choice of their own and
|
|
230
|
+
* no B1 allowlist snapshot), with their org: what narrowing a default (`devices.network.default`
|
|
231
|
+
* or an org's `deviceNetwork.default`, open to allowlist) moves to the allowlist, so their running
|
|
232
|
+
* open-network work is revoked. A local device follows its owner's network, never a default.
|
|
233
|
+
*/
|
|
234
|
+
export async function cloudDevicesFollowingDefault(db, orgId) {
|
|
235
|
+
let q = db
|
|
236
|
+
.selectFrom("devices")
|
|
237
|
+
.select(["id", "org_id", "outer_network"])
|
|
238
|
+
.where("source", "=", "cloud")
|
|
239
|
+
.where("network_mode", "is", null)
|
|
240
|
+
.where("deleted_at", "is", null);
|
|
241
|
+
if (orgId !== undefined)
|
|
242
|
+
q = q.where("org_id", "=", orgId);
|
|
243
|
+
const rows = await q.execute();
|
|
244
|
+
return new Map(rows
|
|
245
|
+
.filter((r) => r.outer_network?.kind !== "allowlist")
|
|
246
|
+
.map((r) => [r.id, r.org_id]));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Whether an allowlist execution names a host the new ceilings no longer allow (`hosts-removed`):
|
|
250
|
+
* a host neither in the org's effective hosts nor held by an independent run or task grant the new
|
|
251
|
+
* per-call ceiling still allows (`grantable`). Native methods and other networks reach no host.
|
|
252
|
+
*/
|
|
253
|
+
export function hostsNarrowed(scope, row, orgHosts, grantable) {
|
|
254
|
+
if (!("network" in scope) || !isExecutionMethod(row.method) || scope.network.kind !== "allowlist")
|
|
255
|
+
return false;
|
|
256
|
+
return scope.network.hosts.some((host) => !orgHosts.some((pattern) => coversHost(pattern.toLowerCase(), host.toLowerCase())) &&
|
|
257
|
+
!(row.granted_hosts.includes(host) && grantable(host)));
|
|
258
|
+
}
|