@capybara-hq/kernel 0.1.0-rc.33 → 0.1.0-rc.34
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/catalog/requests.service.d.ts +8 -6
- package/dist/catalog/requests.service.js +52 -29
- package/dist/config/schema.d.ts +4 -0
- package/dist/config/schema.js +7 -1
- package/dist/devices/devices.service.js +8 -4
- package/dist/local-devices/network-grants.d.ts +1 -1
- package/dist/local-devices/network-grants.js +2 -3
- package/dist/orgs/settings.controller.d.ts +3 -1
- package/dist/orgs/settings.controller.js +7 -3
- package/dist/orgs/settings.service.d.ts +78 -31
- package/dist/orgs/settings.service.js +109 -52
- package/dist/platform/ops/org-settings.ops.js +20 -10
- package/dist/sandbox/modes.d.ts +31 -19
- package/dist/sandbox/modes.js +43 -24
- package/dist/sandbox/sandbox.service.d.ts +4 -1
- package/dist/sandbox/sandbox.service.js +11 -0
- package/dist/schedules/grant-rules.d.ts +2 -0
- package/dist/schedules/grant-rules.js +3 -1
- package/dist/schedules/schedule-math.js +21 -2
- package/dist/schedules/scheduled-tasks.service.js +3 -1
- package/dist/tools/network-asks.d.ts +7 -0
- package/dist/tools/network-asks.js +11 -1
- package/dist/tools/pipeline.js +7 -1
- package/package.json +1 -1
- package/src/migrations/0134_org_cloud_network_delta.sql +38 -0
package/bootstrap.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"marketplace": {
|
|
5
5
|
"url": "https://github.com/capybara-hq/plugins.git",
|
|
6
|
-
"commit": "
|
|
6
|
+
"commit": "85aaf6598bee6f27ed9da9836084e2295eb29e03"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"name": "sandbox-docker",
|
|
91
91
|
"source": "npm",
|
|
92
92
|
"npm": "@capybara-hq/plugin-sandbox-docker",
|
|
93
|
-
"version": "0.1.0-rc.
|
|
94
|
-
"integrity": "sha512-
|
|
93
|
+
"version": "0.1.0-rc.16",
|
|
94
|
+
"integrity": "sha512-6LQ9TA4wRbqYJ7cfzYXrD4A+ICBvwDck9QmREal7M9kneO/Bb25hoSPsBpCxJT8/d6K+Gg7gmUd3+8rsueHeKg==",
|
|
95
95
|
"required": false
|
|
96
96
|
},
|
|
97
97
|
{
|
|
@@ -265,12 +265,14 @@ export declare class CatalogRequestsService {
|
|
|
265
265
|
private writeDecision;
|
|
266
266
|
/**
|
|
267
267
|
* Approves a `network_allowlist` request inside its decision's transaction: the hosts the org's
|
|
268
|
-
* sandbox allowlist does not hold yet are added to the
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* list
|
|
272
|
-
*
|
|
273
|
-
* spec K1).
|
|
268
|
+
* sandbox allowlist does not hold yet are added to the org's `cloudNetwork` delta (an extra
|
|
269
|
+
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
270
|
+
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
271
|
+
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
272
|
+
* The org's network mode is kept: the hosts cap local sandbox devices, and approving a host
|
|
273
|
+
* never turns an open cloud network into an allowlist (auto mode hardening spec K1). A host
|
|
274
|
+
* beyond the platform's ceiling (`orgHosts: within`) refuses the whole request. The platform
|
|
275
|
+
* kill switch, more
|
|
274
276
|
* than {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} hosts -> `catalog.request_invalid`; decided with an API
|
|
275
277
|
* token -> `org.sandbox_egress_not_allowed` (only a person widens the network). Hosts all allowed
|
|
276
278
|
* already: nothing is written.
|
|
@@ -24,7 +24,7 @@ import { orgAllows } from "../local-devices/network-grants.js";
|
|
|
24
24
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
25
25
|
import { roleAtLeast } from "../orgs/roles.js";
|
|
26
26
|
import { ORG_SANDBOX_ALLOW_HOSTS_MAX, OrgSettingsService, readOrgSettings, } from "../orgs/settings.service.js";
|
|
27
|
-
import {
|
|
27
|
+
import { orgEffectiveHosts, orgHostOutsideCeiling } from "../sandbox/modes.js";
|
|
28
28
|
import { CatalogService } from "./catalog.service.js";
|
|
29
29
|
import { CatalogScopeService } from "./catalog-scope.service.js";
|
|
30
30
|
import { assertEntryNotDeprecated, loadMarketplaceEntry } from "./marketplaces.service.js";
|
|
@@ -43,19 +43,16 @@ const alreadyDecided = () => new ApiError("catalog.request_decided", "This reque
|
|
|
43
43
|
const pendingExists = () => new ApiError("catalog.request_pending", "This organization already has a pending request of this kind for it");
|
|
44
44
|
const deploymentEgressNone = () => new ApiError("catalog.request_invalid", "The platform turned sandbox network off; only a super admin can turn it on");
|
|
45
45
|
/**
|
|
46
|
-
* The allowlist the organization's sandbox-mode devices reach (
|
|
47
|
-
* hosts
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* its network ask tells the person to ask an admin about must be addable (network ask spec §5.3).
|
|
46
|
+
* The allowlist the organization's sandbox-mode devices reach (org egress ceiling spec §D3): the
|
|
47
|
+
* org's effective hosts, whatever its cloud mode. An open cloud network does not make a host
|
|
48
|
+
* "already allowed": a local device in sandbox mode always receives the allowlist, so a host its
|
|
49
|
+
* network ask tells the person to ask an admin about must be addable (network ask spec §5.3).
|
|
51
50
|
*/
|
|
52
|
-
function sandboxAllowlist(
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
kind: "allowlist",
|
|
56
|
-
hosts: network.kind === "allowlist" ? network.hosts : (org?.allowHosts ?? deployment.allowHosts),
|
|
57
|
-
};
|
|
51
|
+
function sandboxAllowlist(limits, org) {
|
|
52
|
+
return { kind: "allowlist", hosts: orgEffectiveHosts(limits, org) };
|
|
58
53
|
}
|
|
54
|
+
/** Hosts beyond the platform's ceiling: only a super admin adds them (spec §D2). */
|
|
55
|
+
const outsideCeiling = (hosts) => new ApiError("catalog.request_invalid", `The platform limits sandbox hosts to its allowlist; only a super admin can add ${hosts.join(", ")} (sandbox.limits.allowHosts)`);
|
|
59
56
|
/** A unique violation (the partial index of pending requests). */
|
|
60
57
|
const isUniqueViolation = (e) => typeof e === "object" && e !== null && e.code === "23505";
|
|
61
58
|
/** The deployment-level kinds (decided by the super admin). */
|
|
@@ -215,14 +212,17 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
215
212
|
const t = this.db;
|
|
216
213
|
await this.orgLock.lockAndAuthorize(orgId, actor, "catalog.request");
|
|
217
214
|
const hosts = [...new Set(input.hosts.map((h) => h.toLowerCase()))].sort();
|
|
218
|
-
|
|
215
|
+
const limits = this.config.get().sandbox.limits;
|
|
216
|
+
if (limits.egress === "none")
|
|
219
217
|
throw deploymentEgressNone();
|
|
220
|
-
const deployment = (await this.orgSettings.deployment()).cloudNetwork;
|
|
221
218
|
const settings = await readOrgSettings(t, orgId);
|
|
222
|
-
const network = sandboxAllowlist(
|
|
219
|
+
const network = sandboxAllowlist(limits, settings.cloudNetwork);
|
|
223
220
|
if (hosts.every((h) => orgAllows(h, { network }))) {
|
|
224
221
|
throw new ApiError("catalog.request_invalid", "This organization's sandbox network already allows these hosts; nothing to request");
|
|
225
222
|
}
|
|
223
|
+
const beyond = hosts.filter((h) => orgHostOutsideCeiling(limits, h));
|
|
224
|
+
if (beyond.length > 0)
|
|
225
|
+
throw outsideCeiling(beyond);
|
|
226
226
|
if (input.conversationId !== undefined) {
|
|
227
227
|
const c = await t
|
|
228
228
|
.selectFrom("conversations")
|
|
@@ -621,36 +621,59 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
621
621
|
}
|
|
622
622
|
/**
|
|
623
623
|
* Approves a `network_allowlist` request inside its decision's transaction: the hosts the org's
|
|
624
|
-
* sandbox allowlist does not hold yet are added to the
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* list
|
|
628
|
-
*
|
|
629
|
-
* spec K1).
|
|
624
|
+
* sandbox allowlist does not hold yet are added to the org's `cloudNetwork` delta (an extra
|
|
625
|
+
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
626
|
+
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
627
|
+
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
628
|
+
* The org's network mode is kept: the hosts cap local sandbox devices, and approving a host
|
|
629
|
+
* never turns an open cloud network into an allowlist (auto mode hardening spec K1). A host
|
|
630
|
+
* beyond the platform's ceiling (`orgHosts: within`) refuses the whole request. The platform
|
|
631
|
+
* kill switch, more
|
|
630
632
|
* than {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} hosts -> `catalog.request_invalid`; decided with an API
|
|
631
633
|
* token -> `org.sandbox_egress_not_allowed` (only a person widens the network). Hosts all allowed
|
|
632
634
|
* already: nothing is written.
|
|
633
635
|
*/
|
|
634
636
|
async approveNetwork(orgId, actor, requestId, detail, opts) {
|
|
635
637
|
const hosts = detail?.hosts ?? [];
|
|
636
|
-
|
|
638
|
+
const limits = this.config.get().sandbox.limits;
|
|
639
|
+
if (limits.egress === "none")
|
|
637
640
|
throw deploymentEgressNone();
|
|
638
|
-
const deployment = (await this.orgSettings.deployment()).cloudNetwork;
|
|
639
641
|
const current = (await readOrgSettings(this.db, orgId)).cloudNetwork;
|
|
640
642
|
// the hosts the org's sandbox-mode devices reach now (an open cloud network still gives them
|
|
641
643
|
// the allowlist: a host their network ask names must be addable)
|
|
642
|
-
const network = sandboxAllowlist(
|
|
644
|
+
const network = sandboxAllowlist(limits, current);
|
|
643
645
|
const missing = hosts.filter((h) => !orgAllows(h, { network }));
|
|
644
646
|
if (missing.length === 0)
|
|
645
647
|
return;
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
649
|
-
throw
|
|
648
|
+
// the whole request is refused when a host is beyond the platform's ceiling (never partly)
|
|
649
|
+
const beyond = missing.filter((h) => orgHostOutsideCeiling(limits, h));
|
|
650
|
+
if (beyond.length > 0)
|
|
651
|
+
throw outsideCeiling(beyond);
|
|
652
|
+
// a delta, never a copy of the platform's list: a host the org had dropped from the platform's
|
|
653
|
+
// list comes back out of the exclusions (base platform), any other becomes an extra
|
|
654
|
+
const excluded = current?.excludedHosts ?? [];
|
|
655
|
+
const platformBase = (current?.base ?? "platform") === "platform";
|
|
656
|
+
const readmit = platformBase
|
|
657
|
+
? missing.filter((h) => excluded.includes(h) && limits.allowHosts.includes(h))
|
|
658
|
+
: [];
|
|
659
|
+
const added = missing.filter((h) => !readmit.includes(h));
|
|
660
|
+
const extraHosts = [...new Set([...(current?.extraHosts ?? []), ...added])];
|
|
661
|
+
if (extraHosts.length > ORG_SANDBOX_ALLOW_HOSTS_MAX) {
|
|
662
|
+
throw new ApiError("catalog.request_invalid", `The organization's sandbox allowlist would exceed ${ORG_SANDBOX_ALLOW_HOSTS_MAX} extra hosts; remove some in the organization settings first`);
|
|
650
663
|
}
|
|
664
|
+
const excludedHosts = excluded.filter((h) => !readmit.includes(h));
|
|
665
|
+
// the stored value is sent back whole with the hosts changed; the mode is never written
|
|
666
|
+
// (approving a host never turns an open cloud network into an allowlist, K1)
|
|
667
|
+
const cloudNetwork = {
|
|
668
|
+
...current,
|
|
669
|
+
...(extraHosts.length > 0 ? { extraHosts } : {}),
|
|
670
|
+
...(excludedHosts.length > 0 ? { excludedHosts } : {}),
|
|
671
|
+
};
|
|
672
|
+
if (excludedHosts.length === 0)
|
|
673
|
+
delete cloudNetwork.excludedHosts;
|
|
651
674
|
// approving widens the org's network allowlist: only a person in a session does that, never an
|
|
652
675
|
// API token (auto mode spec §4.3; the Platform tool has no decide operation at all)
|
|
653
|
-
await this.orgSettings.update(orgId, { cloudNetwork
|
|
676
|
+
await this.orgSettings.update(orgId, { cloudNetwork }, actor, opts.actorTokenId, { requestId }, { onlyNarrows: opts.actorTokenId !== undefined });
|
|
654
677
|
}
|
|
655
678
|
/**
|
|
656
679
|
* The requester dismisses a decided request from the inbox (`POST /orgs/:orgId/
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -241,6 +241,10 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
241
241
|
none: "none";
|
|
242
242
|
}>>;
|
|
243
243
|
allowHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
244
|
+
orgHosts: z.ZodDefault<z.ZodEnum<{
|
|
245
|
+
extend: "extend";
|
|
246
|
+
within: "within";
|
|
247
|
+
}>>;
|
|
244
248
|
}, z.core.$strip>>;
|
|
245
249
|
}, z.core.$strip>>;
|
|
246
250
|
devices: z.ZodPrefault<z.ZodObject<{
|
package/dist/config/schema.js
CHANGED
|
@@ -1337,7 +1337,13 @@ export const KernelConfigSchema = z.object({
|
|
|
1337
1337
|
});
|
|
1338
1338
|
})
|
|
1339
1339
|
.meta(meta({
|
|
1340
|
-
description: "
|
|
1340
|
+
description: "Host list of the allowlist: in sandbox mode, the hosts a cloud device instance may reach on allowlist and a local device's allowlist; organizations follow it, adding or dropping hosts of their own (see orgHosts); lowercase hostnames, optional leading '*.', no IPs, ports or internal-only names; applies to instances created after the change",
|
|
1341
|
+
})),
|
|
1342
|
+
orgHosts: z
|
|
1343
|
+
.enum(["extend", "within"])
|
|
1344
|
+
.default("extend")
|
|
1345
|
+
.meta(meta({
|
|
1346
|
+
description: "Whether organizations may go beyond allowHosts in sandbox mode: extend (the default: an organization may use the open cloud network and add hosts, and its admins approve network requests) or within (allowHosts is the ceiling: an organization's cloud network in sandbox mode is the allowlist, and it may only keep or drop hosts the list covers; only a super admin adds others). Auto mode is not limited by it: devices.autoMode governs auto mode's open network, so set devices.autoMode off as well for a hard ceiling",
|
|
1341
1347
|
})),
|
|
1342
1348
|
})
|
|
1343
1349
|
.prefault({}),
|
|
@@ -1043,16 +1043,20 @@ killSwitch = false) {
|
|
|
1043
1043
|
const networkKind = local ? "allowlist" : policy.network.kind;
|
|
1044
1044
|
const org = settings.cloudNetwork;
|
|
1045
1045
|
// "org" only when the org supplied what is in effect: the kill switch always wins; auto mode
|
|
1046
|
-
// ignores the org's network; a local device's list is the org's only when the org
|
|
1047
|
-
// a sandbox cloud device's kind is the org's when it
|
|
1046
|
+
// ignores the org's network; a local device's list is the org's only when the org changed the
|
|
1047
|
+
// platform's (its own base or a delta); a sandbox cloud device's kind is the org's when it
|
|
1048
|
+
// matches the mode the org chose (the platform ceiling may force the allowlist)
|
|
1049
|
+
const orgHosts = org?.base === "none" ||
|
|
1050
|
+
(org?.extraHosts?.length ?? 0) > 0 ||
|
|
1051
|
+
(org?.excludedHosts?.length ?? 0) > 0;
|
|
1048
1052
|
const source = killSwitch
|
|
1049
1053
|
? "platform"
|
|
1050
1054
|
: local
|
|
1051
|
-
? policy.mode === "sandbox" &&
|
|
1055
|
+
? policy.mode === "sandbox" && orgHosts
|
|
1052
1056
|
? "org"
|
|
1053
1057
|
: "platform"
|
|
1054
1058
|
: policy.mode === "sandbox" &&
|
|
1055
|
-
org !== undefined &&
|
|
1059
|
+
org?.mode !== undefined &&
|
|
1056
1060
|
(org.mode === "open" ? networkKind === "open-public" : networkKind === "allowlist")
|
|
1057
1061
|
? "org"
|
|
1058
1062
|
: "platform";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DeviceExecGrants, type NetworkBlockedHost, type SandboxLimits } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type SandboxMode } from "../sandbox/modes.js";
|
|
4
4
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
5
5
|
export declare const MAX_GRANT_HOSTS = 100;
|
|
6
6
|
/** What a run tree's network asks add up to (network ask-to-allow spec §6.8). */
|
|
@@ -12,6 +12,7 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
14
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
15
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
15
16
|
import { taskGrantsRunOf } from "../schedules/unattended.js";
|
|
16
17
|
import { localModeOf } from "./policy-summary.js";
|
|
17
18
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
@@ -229,14 +230,12 @@ const normalize = (host) => {
|
|
|
229
230
|
const h = host.toLowerCase();
|
|
230
231
|
return h.endsWith(".") ? h.slice(0, -1) : h;
|
|
231
232
|
};
|
|
232
|
-
/** Whether the allowlist entry `pattern` admits `host` (`*.x.com`: subdomains, never the apex). */
|
|
233
|
-
const covers = (pattern, host) => pattern === host || (pattern.startsWith("*.") && host.endsWith(pattern.slice(1)));
|
|
234
233
|
/** Whether the org's sandbox-mode network lets a command reach `host`. */
|
|
235
234
|
export function orgAllows(host, limits) {
|
|
236
235
|
if (limits.network.kind === "open-public")
|
|
237
236
|
return true;
|
|
238
237
|
const h = normalize(host);
|
|
239
|
-
return limits.network.hosts.some((p) =>
|
|
238
|
+
return limits.network.hosts.some((p) => coversHost(p.toLowerCase(), h));
|
|
240
239
|
}
|
|
241
240
|
/**
|
|
242
241
|
* The kernel's own layer for a device's report (auto mode spec §4.2): it trusts the device's word
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Principal } from "../identity/principal.js";
|
|
2
2
|
import { type OrgContext } from "./org.guard.js";
|
|
3
|
-
import { type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService } from "./settings.service.js";
|
|
3
|
+
import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService } from "./settings.service.js";
|
|
4
4
|
/**
|
|
5
5
|
* 组织设置(`/api/v1/orgs/:orgId/settings`):成员可读,修改需 `org.update`(admin)。
|
|
6
6
|
* 响应带 `deployment`(部署默认值,如沙箱出站),设置页据此展示「跟随部署」时的实际取值;
|
|
@@ -9,6 +9,8 @@ import { type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, ty
|
|
|
9
9
|
type SettingsResponse = {
|
|
10
10
|
settings: OrgSettings;
|
|
11
11
|
deployment: OrgSettingsDeployment;
|
|
12
|
+
/** The org's effective sandbox-mode network (org egress ceiling spec §D4). */
|
|
13
|
+
effectiveNetwork: OrgEffectiveNetwork;
|
|
12
14
|
sandboxLimits: OrgSandboxLimits;
|
|
13
15
|
};
|
|
14
16
|
export declare class OrgSettingsController {
|
|
@@ -21,18 +21,22 @@ let OrgSettingsController = class OrgSettingsController {
|
|
|
21
21
|
this.settings = settings;
|
|
22
22
|
}
|
|
23
23
|
async get(org) {
|
|
24
|
+
const settings = await this.settings.get(org.orgId);
|
|
24
25
|
return {
|
|
25
|
-
settings
|
|
26
|
+
settings,
|
|
26
27
|
deployment: await this.settings.deployment(),
|
|
28
|
+
effectiveNetwork: this.settings.effectiveNetwork(settings),
|
|
27
29
|
sandboxLimits: await this.settings.sandboxLimits(org.orgId),
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
async update(principal, org, body) {
|
|
31
33
|
const p = requireUser(principal);
|
|
34
|
+
// an API token may narrow auto mode and the cloud network, never widen them (auto mode spec §4.3)
|
|
35
|
+
const settings = await this.settings.update(org.orgId, body, p.account.id, patTokenId(p), undefined, { onlyNarrows: patTokenId(p) !== undefined });
|
|
32
36
|
return {
|
|
33
|
-
|
|
34
|
-
settings: await this.settings.update(org.orgId, body, p.account.id, patTokenId(p), undefined, { onlyNarrows: patTokenId(p) !== undefined }),
|
|
37
|
+
settings,
|
|
35
38
|
deployment: await this.settings.deployment(),
|
|
39
|
+
effectiveNetwork: this.settings.effectiveNetwork(settings),
|
|
36
40
|
sandboxLimits: await this.settings.sandboxLimits(org.orgId),
|
|
37
41
|
};
|
|
38
42
|
}
|
|
@@ -20,9 +20,9 @@ import { OrgLock } from "./org-lock.js";
|
|
|
20
20
|
* - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
|
|
21
21
|
* follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
|
|
22
22
|
* (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
|
|
23
|
-
* - `cloudNetwork`: the org's network
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* - `cloudNetwork`: the org's sandbox-mode network as a delta over the platform's allowlist (org
|
|
24
|
+
* egress ceiling spec §D1, {@link CloudNetworkSettingSchema}). An invalid stored value reads as
|
|
25
|
+
* `{ mode: "allowlist", base: "none" }`, the empty allowlist (narrower, never wider).
|
|
26
26
|
* - `platformTool`: the `Platform` builtin for the whole org (Platform tool spec §3): `on`,
|
|
27
27
|
* `read-only` (writes listed as unavailable) or `off` (default `on`).
|
|
28
28
|
* - `timeZone`: the org's default time zone (IANA; absent = UTC) for senders without one of their
|
|
@@ -37,19 +37,31 @@ import { OrgLock } from "./org-lock.js";
|
|
|
37
37
|
/** The org cloud-network allowlist's host limit. */
|
|
38
38
|
export declare const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
|
|
39
39
|
/**
|
|
40
|
-
* The org's network
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
40
|
+
* The org's sandbox-mode network (org egress ceiling spec §D1), stored as a delta over the
|
|
41
|
+
* platform's `sandbox.limits.allowHosts`, never a copy of it, so platform changes keep reaching the
|
|
42
|
+
* org:
|
|
43
|
+
* - `mode`: the cloud network of a cloud device in sandbox mode, `open` (any public host; loopback,
|
|
44
|
+
* private and cloud metadata addresses are blocked outside the container) or `allowlist`; absent
|
|
45
|
+
* follows the platform's default (open). `sandbox.limits.orgHosts: within` makes it the allowlist.
|
|
46
|
+
* - `base`: `platform` (the default: start from the platform's list) or `none` (only the org's own
|
|
47
|
+
* hosts).
|
|
48
|
+
* - `extraHosts`: hosts the org adds (ignored outside the platform list under `within`).
|
|
49
|
+
* - `excludedHosts`: platform entries the org drops (exact entries; any host is accepted, since the
|
|
50
|
+
* platform may drop an entry later).
|
|
51
|
+
* The effective hosts ({@link orgEffectiveHosts} in `sandbox/modes.ts`) are also the ceiling a local
|
|
52
|
+
* device in sandbox mode reaches (the device intersects them with its own list).
|
|
46
53
|
*/
|
|
47
54
|
export declare const CloudNetworkSettingSchema: z.ZodObject<{
|
|
48
|
-
mode: z.ZodEnum<{
|
|
55
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
49
56
|
allowlist: "allowlist";
|
|
50
57
|
open: "open";
|
|
51
|
-
}
|
|
52
|
-
|
|
58
|
+
}>>;
|
|
59
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
60
|
+
none: "none";
|
|
61
|
+
platform: "platform";
|
|
62
|
+
}>>;
|
|
63
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
65
|
}, z.core.$strict>;
|
|
54
66
|
export type CloudNetworkSetting = z.infer<typeof CloudNetworkSettingSchema>;
|
|
55
67
|
/** What an invalid stored `cloudNetwork` reads as: the allowlist with no host (never wider). */
|
|
@@ -154,11 +166,16 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
154
166
|
off: "off";
|
|
155
167
|
}>>>;
|
|
156
168
|
cloudNetwork: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
157
|
-
mode: z.ZodEnum<{
|
|
169
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
158
170
|
allowlist: "allowlist";
|
|
159
171
|
open: "open";
|
|
160
|
-
}
|
|
161
|
-
|
|
172
|
+
}>>;
|
|
173
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
174
|
+
none: "none";
|
|
175
|
+
platform: "platform";
|
|
176
|
+
}>>;
|
|
177
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
178
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
162
179
|
}, z.core.$strict>>>;
|
|
163
180
|
wakeOnBackgroundTask: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
164
181
|
timeZone: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
@@ -223,11 +240,16 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
223
240
|
off: "off";
|
|
224
241
|
}>>>;
|
|
225
242
|
cloudNetwork: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
226
|
-
mode: z.ZodEnum<{
|
|
243
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
227
244
|
allowlist: "allowlist";
|
|
228
245
|
open: "open";
|
|
229
|
-
}
|
|
230
|
-
|
|
246
|
+
}>>;
|
|
247
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
248
|
+
none: "none";
|
|
249
|
+
platform: "platform";
|
|
250
|
+
}>>;
|
|
251
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
252
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
231
253
|
}, z.core.$strict>>>;
|
|
232
254
|
timeZone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
233
255
|
theme: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
@@ -279,17 +301,24 @@ export interface OrgSandboxLimits {
|
|
|
279
301
|
memoryMb: number;
|
|
280
302
|
source: "deployment" | "override";
|
|
281
303
|
}
|
|
304
|
+
/** The org's effective sandbox-mode network (`effectiveNetwork` of the settings responses). */
|
|
305
|
+
export interface OrgEffectiveNetwork {
|
|
306
|
+
mode: "open" | "allowlist";
|
|
307
|
+
hosts: string[];
|
|
308
|
+
}
|
|
282
309
|
/** The deployment defaults the settings page shows for "follow the platform" (`GET` returns them). */
|
|
283
310
|
export interface OrgSettingsDeployment {
|
|
284
311
|
/** The platform's auto-mode switch and where it comes from. */
|
|
285
312
|
autoMode: DevicesAutoModeView;
|
|
286
313
|
/**
|
|
287
|
-
* The
|
|
288
|
-
* `sandbox.limits.
|
|
314
|
+
* The platform's network: its allowlist (what an org's delta applies to), whether orgs may go
|
|
315
|
+
* beyond it (`sandbox.limits.orgHosts`) and the kill switch (`off`: `sandbox.limits.egress` is
|
|
316
|
+
* `none`).
|
|
289
317
|
*/
|
|
290
318
|
cloudNetwork: {
|
|
291
|
-
mode: "open" | "allowlist";
|
|
292
319
|
allowHosts: string[];
|
|
320
|
+
orgHosts: "extend" | "within";
|
|
321
|
+
off: boolean;
|
|
293
322
|
};
|
|
294
323
|
/** The platform's effective attribution defaults for agent-created commits and pull requests. */
|
|
295
324
|
attribution: PlatformAttribution;
|
|
@@ -309,6 +338,14 @@ export declare function readOrgSettings(db: KernelSchemaDb, orgId: string): Prom
|
|
|
309
338
|
export declare function invalidStoredAutoMode(raw: unknown): boolean;
|
|
310
339
|
/** Whether a stored settings object holds a `cloudNetwork` this version reads as an empty allowlist. */
|
|
311
340
|
export declare function invalidStoredCloudNetwork(raw: unknown): boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Whether `next` (absent: follow the platform) widens `prev` (spec §D3), both normalized (mode
|
|
343
|
+
* open, base platform, empty lists): the open mode where it was the allowlist; base none to
|
|
344
|
+
* platform; with base platform, dropping one of the stored exclusions; an extra host no stored
|
|
345
|
+
* extra covers. Over-strict on purpose: moving to base none with a platform entry as an extra is a
|
|
346
|
+
* narrowing these rules refuse (a token cannot pin a platform host the platform may drop later).
|
|
347
|
+
*/
|
|
348
|
+
export declare function cloudNetworkWidens(prev: CloudNetworkSetting | undefined, next: CloudNetworkSetting | undefined): boolean;
|
|
312
349
|
/** 组织设置服务:读取与修改(修改需 `org.update`,锁内实时复核角色,写审计)。 */
|
|
313
350
|
export declare class OrgSettingsService {
|
|
314
351
|
private readonly db;
|
|
@@ -331,11 +368,27 @@ export declare class OrgSettingsService {
|
|
|
331
368
|
private parseStored;
|
|
332
369
|
/** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
|
|
333
370
|
deployment(): Promise<OrgSettingsDeployment>;
|
|
371
|
+
/**
|
|
372
|
+
* The org's effective sandbox-mode network (spec §D3): the cloud network's mode and the hosts,
|
|
373
|
+
* from the platform's `sandbox.limits` and the org's stored delta.
|
|
374
|
+
*/
|
|
375
|
+
effectiveNetwork(settings: Pick<OrgSettings, "cloudNetwork">): OrgEffectiveNetwork;
|
|
334
376
|
/** 组织实际生效的沙箱 cpu / 内存(只读;由超级管理员在部署设置里覆盖)。 */
|
|
335
377
|
sandboxLimits(orgId: string): Promise<OrgSandboxLimits>;
|
|
336
378
|
get(orgId: string): Promise<OrgSettings>;
|
|
337
|
-
/**
|
|
379
|
+
/**
|
|
380
|
+
* The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
|
|
381
|
+
* auto mode where the platform turned it off.
|
|
382
|
+
*/
|
|
338
383
|
check(patch: OrgSettingsPatch): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* Under `sandbox.limits.orgHosts: within` (spec §D2), refuses what would widen past the platform
|
|
386
|
+
* ceiling compared with the stored value `before`: the open cloud network where the org did not
|
|
387
|
+
* store it, or an extra host outside the platform's allowlist that the org did not store. Stored
|
|
388
|
+
* values are sent back as they are (the PATCH replaces `cloudNetwork` whole) and have no effect
|
|
389
|
+
* under the ceiling (they are filtered on read), so they never block a write.
|
|
390
|
+
*/
|
|
391
|
+
assertWithinCeiling(before: OrgSettings, patch: OrgSettingsPatch): void;
|
|
339
392
|
update(orgId: string, patch: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string,
|
|
340
393
|
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
341
394
|
auditDetail?: Record<string, unknown>,
|
|
@@ -351,15 +404,9 @@ export declare class OrgSettingsService {
|
|
|
351
404
|
* never the Platform tool or an API token):
|
|
352
405
|
* - `autoMode`: `allowed` where the organization runs `off` (an absent value follows the
|
|
353
406
|
* platform); clearing it follows the platform too, never wider than the platform allows;
|
|
354
|
-
* - `cloudNetwork`:
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* `sandbox/modes.ts` becomes `deviceLimits.localAllowedDomains`, which the device intersects
|
|
358
|
-
* with its own list): an org with no `cloudNetwork` still caps its local devices at the
|
|
359
|
-
* deployment's list, and an org whose network is `open` still caps them at its own `allowHosts`.
|
|
360
|
-
* The host comparison therefore applies to both shapes, whatever the target mode: a patch may
|
|
361
|
-
* only keep or lower the host set. Switching from `open` is a widening by itself, and the host
|
|
362
|
-
* set must not grow even when the target stays `open` (spec §4.2, §4.3).
|
|
407
|
+
* - `cloudNetwork`: compared as stored deltas ({@link cloudNetworkWidens}), never as effective
|
|
408
|
+
* values: under the kill switch or the platform ceiling the effective values hide a widening
|
|
409
|
+
* that takes effect when the platform relaxes (org egress ceiling spec §D3).
|
|
363
410
|
*/
|
|
364
411
|
assertOnlyNarrows(before: OrgSettings, patch: OrgSettingsPatch): Promise<void>;
|
|
365
412
|
private updateIn;
|