@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
|
@@ -58,12 +58,22 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
|
|
|
58
58
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
59
59
|
disabled: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
60
|
}, z.core.$strict>>;
|
|
61
|
-
|
|
61
|
+
devicesOutsideSandbox: z.ZodOptional<z.ZodObject<{
|
|
62
62
|
permission: z.ZodNullable<z.ZodEnum<{
|
|
63
63
|
allowed: "allowed";
|
|
64
64
|
off: "off";
|
|
65
65
|
}>>;
|
|
66
66
|
}, z.core.$strict>>;
|
|
67
|
+
devicesNetwork: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
default: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
69
|
+
allowlist: "allowlist";
|
|
70
|
+
open: "open";
|
|
71
|
+
}>>>;
|
|
72
|
+
ceiling: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
73
|
+
allowlist: "allowlist";
|
|
74
|
+
open: "open";
|
|
75
|
+
}>>>;
|
|
76
|
+
}, z.core.$strict>>;
|
|
67
77
|
attribution: z.ZodOptional<z.ZodObject<{
|
|
68
78
|
commit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
79
|
pr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -49,7 +49,7 @@ CatalogModule = __decorate([
|
|
|
49
49
|
ExtensionsModule,
|
|
50
50
|
SuperAdminLockModule,
|
|
51
51
|
OrgLockModule,
|
|
52
|
-
// approving a network request writes the org's
|
|
52
|
+
// approving a network request writes the org's deviceNetwork allowlist
|
|
53
53
|
OrgSettingsModule,
|
|
54
54
|
StorageModule,
|
|
55
55
|
SkillsModule,
|
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.39";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -139,7 +139,7 @@ export declare const CATALOG_REQUESTS_LIST_MAX = 200;
|
|
|
139
139
|
* (`PendingConnectorRequests`), closed by binding (`approved`) or the agent's deletion
|
|
140
140
|
* (`cancelled`); here it is listed and rejected;
|
|
141
141
|
* - `network_allowlist` (network ask-to-allow spec §5.3): a member asks the org admins to add hosts
|
|
142
|
-
* to the org's cloud network allowlist; approving merges them into the org's `
|
|
142
|
+
* to the org's cloud network allowlist; approving merges them into the org's `deviceNetwork`.
|
|
143
143
|
* A rejection stores an optional reason. Decided requests show in the requester's inbox until
|
|
144
144
|
* dismissed. No in-process state.
|
|
145
145
|
*/
|
|
@@ -153,7 +153,7 @@ export declare class CatalogRequestsService {
|
|
|
153
153
|
private readonly catalog;
|
|
154
154
|
private readonly config;
|
|
155
155
|
private readonly pluginImport;
|
|
156
|
-
/** Approving a network request writes the org's `
|
|
156
|
+
/** Approving a network request writes the org's `deviceNetwork` through the settings path. */
|
|
157
157
|
private readonly orgSettings;
|
|
158
158
|
readonly txHost: TransactionHost;
|
|
159
159
|
/** Serializes the approvals of one `import` request (`@WithLock`). */
|
|
@@ -161,7 +161,7 @@ export declare class CatalogRequestsService {
|
|
|
161
161
|
constructor(kdb: KernelDb,
|
|
162
162
|
/** The org row and super admin locks: both join the caller's transaction. */
|
|
163
163
|
orgLock: OrgLock, adminLock: SuperAdminLock, orgCatalog: OrgCatalogService, scope: CatalogScopeService, catalog: CatalogService, config: KernelConfigService, pluginImport: PluginImport,
|
|
164
|
-
/** Approving a network request writes the org's `
|
|
164
|
+
/** Approving a network request writes the org's `deviceNetwork` through the settings path. */
|
|
165
165
|
orgSettings: OrgSettingsService, txHost: TransactionHost,
|
|
166
166
|
/** Serializes the approvals of one `import` request (`@WithLock`). */
|
|
167
167
|
lockService: LockService);
|
|
@@ -217,7 +217,7 @@ export declare class CatalogRequestsService {
|
|
|
217
217
|
* An org admin decides a member's `enable`, `network_allowlist` or `connector_setup` request
|
|
218
218
|
* (`catalog.decide`). Not this org's request of those kinds -> `catalog.request_not_found`;
|
|
219
219
|
* decided -> `catalog.request_decided`. Approving a `network_allowlist` request merges its hosts
|
|
220
|
-
* into the org's `
|
|
220
|
+
* into the org's `deviceNetwork` (`approveNetwork`). Approving an `enable` request switches the
|
|
221
221
|
* item on in the org as the deciding admin ({@link OrgCatalogService.setSwitch}: its errors, e.g. inputs the install
|
|
222
222
|
* needs, leave the request pending); the install itself resolves the request. A
|
|
223
223
|
* `connector_setup` request is approved only by binding its connectors (ruling P4-T6-6):
|
|
@@ -265,7 +265,7 @@ 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 org's `
|
|
268
|
+
* sandbox allowlist does not hold yet are added to the org's `deviceNetwork` delta (an extra
|
|
269
269
|
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
270
270
|
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
271
271
|
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
@@ -75,7 +75,7 @@ const ORG_KINDS = ["enable", "connector_setup", "network_allowlist"];
|
|
|
75
75
|
* (`PendingConnectorRequests`), closed by binding (`approved`) or the agent's deletion
|
|
76
76
|
* (`cancelled`); here it is listed and rejected;
|
|
77
77
|
* - `network_allowlist` (network ask-to-allow spec §5.3): a member asks the org admins to add hosts
|
|
78
|
-
* to the org's cloud network allowlist; approving merges them into the org's `
|
|
78
|
+
* to the org's cloud network allowlist; approving merges them into the org's `deviceNetwork`.
|
|
79
79
|
* A rejection stores an optional reason. Decided requests show in the requester's inbox until
|
|
80
80
|
* dismissed. No in-process state.
|
|
81
81
|
*/
|
|
@@ -94,7 +94,7 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
94
94
|
constructor(kdb,
|
|
95
95
|
/** The org row and super admin locks: both join the caller's transaction. */
|
|
96
96
|
orgLock, adminLock, orgCatalog, scope, catalog, config, pluginImport,
|
|
97
|
-
/** Approving a network request writes the org's `
|
|
97
|
+
/** Approving a network request writes the org's `deviceNetwork` through the settings path. */
|
|
98
98
|
orgSettings, txHost,
|
|
99
99
|
/** Serializes the approvals of one `import` request (`@WithLock`). */
|
|
100
100
|
lockService) {
|
|
@@ -216,7 +216,7 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
216
216
|
if (limits.egress === "none")
|
|
217
217
|
throw deploymentEgressNone();
|
|
218
218
|
const settings = await readOrgSettings(t, orgId);
|
|
219
|
-
const network = sandboxAllowlist(limits, settings.
|
|
219
|
+
const network = sandboxAllowlist(limits, settings.deviceNetwork);
|
|
220
220
|
if (hosts.every((h) => orgAllows(h, { network }))) {
|
|
221
221
|
throw new ApiError("catalog.request_invalid", "This organization's sandbox network already allows these hosts; nothing to request");
|
|
222
222
|
}
|
|
@@ -386,7 +386,7 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
386
386
|
* An org admin decides a member's `enable`, `network_allowlist` or `connector_setup` request
|
|
387
387
|
* (`catalog.decide`). Not this org's request of those kinds -> `catalog.request_not_found`;
|
|
388
388
|
* decided -> `catalog.request_decided`. Approving a `network_allowlist` request merges its hosts
|
|
389
|
-
* into the org's `
|
|
389
|
+
* into the org's `deviceNetwork` (`approveNetwork`). Approving an `enable` request switches the
|
|
390
390
|
* item on in the org as the deciding admin ({@link OrgCatalogService.setSwitch}: its errors, e.g. inputs the install
|
|
391
391
|
* needs, leave the request pending); the install itself resolves the request. A
|
|
392
392
|
* `connector_setup` request is approved only by binding its connectors (ruling P4-T6-6):
|
|
@@ -621,7 +621,7 @@ 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 org's `
|
|
624
|
+
* sandbox allowlist does not hold yet are added to the org's `deviceNetwork` delta (an extra
|
|
625
625
|
* host, or out of the exclusions for a platform host the org had dropped), through
|
|
626
626
|
* {@link OrgSettingsService.update} (audited `org.settings_updated` with `requestId`). The
|
|
627
627
|
* platform's list is never copied, so the org keeps following it (org egress ceiling spec §D1).
|
|
@@ -638,7 +638,7 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
638
638
|
const limits = this.config.get().sandbox.limits;
|
|
639
639
|
if (limits.egress === "none")
|
|
640
640
|
throw deploymentEgressNone();
|
|
641
|
-
const current = (await readOrgSettings(this.db, orgId)).
|
|
641
|
+
const current = (await readOrgSettings(this.db, orgId)).deviceNetwork;
|
|
642
642
|
// the hosts the org's sandbox-mode devices reach now (an open cloud network still gives them
|
|
643
643
|
// the allowlist: a host their network ask names must be addable)
|
|
644
644
|
const network = sandboxAllowlist(limits, current);
|
|
@@ -664,16 +664,16 @@ let CatalogRequestsService = class CatalogRequestsService {
|
|
|
664
664
|
const excludedHosts = excluded.filter((h) => !readmit.includes(h));
|
|
665
665
|
// the stored value is sent back whole with the hosts changed; the mode is never written
|
|
666
666
|
// (approving a host never turns an open cloud network into an allowlist, K1)
|
|
667
|
-
const
|
|
667
|
+
const deviceNetwork = {
|
|
668
668
|
...current,
|
|
669
669
|
...(extraHosts.length > 0 ? { extraHosts } : {}),
|
|
670
670
|
...(excludedHosts.length > 0 ? { excludedHosts } : {}),
|
|
671
671
|
};
|
|
672
672
|
if (excludedHosts.length === 0)
|
|
673
|
-
delete
|
|
673
|
+
delete deviceNetwork.excludedHosts;
|
|
674
674
|
// approving widens the org's network allowlist: only a person in a session does that, never an
|
|
675
675
|
// API token (auto mode spec §4.3; the Platform tool has no decide operation at all)
|
|
676
|
-
await this.orgSettings.update(orgId, {
|
|
676
|
+
await this.orgSettings.update(orgId, { deviceNetwork }, actor, opts.actorTokenId, { requestId }, { onlyNarrows: opts.actorTokenId !== undefined });
|
|
677
677
|
}
|
|
678
678
|
/**
|
|
679
679
|
* The requester dismisses a decided request from the inbox (`POST /orgs/:orgId/
|
package/dist/channels/cards.d.ts
CHANGED
|
@@ -71,11 +71,12 @@ export declare function networkCardText(detail: Pick<NetworkAskView, "hosts" | "
|
|
|
71
71
|
export declare function gitCardText(detail: Pick<GitAskView, "host" | "repo" | "refs" | "command">, locale: ChannelLocale, redact?: (s: string) => string): NetworkCardText;
|
|
72
72
|
/**
|
|
73
73
|
* A command review ask's card text (auto mode spec §5.4): the title asks to run the command (a
|
|
74
|
-
* write: to write the file), the preview is the review's reason
|
|
75
|
-
*
|
|
74
|
+
* write or read: to write or read the file), the preview is the review's reason (a directory
|
|
75
|
+
* crossing of a file: a line in the card's language) and the held command clipped to
|
|
76
|
+
* {@link CARD_SUMMARY_MAX} (a file ask: its target path). The scopes are the approval's; `session` is
|
|
76
77
|
* labelled only when offered. Model-controlled values are redacted by `redact`.
|
|
77
78
|
*/
|
|
78
|
-
export declare function commandCardText(detail: Pick<CommandAskDetail, "kind" | "command" | "reason"> & {
|
|
79
|
+
export declare function commandCardText(detail: Pick<CommandAskDetail, "kind" | "command" | "reason" | "permissionScope"> & {
|
|
79
80
|
path?: string;
|
|
80
81
|
escalation?: PermissionEscalation;
|
|
81
82
|
workingRoot?: string;
|
package/dist/channels/cards.js
CHANGED
|
@@ -189,10 +189,8 @@ export function networkCardText(detail, locale, redact = (s) => s) {
|
|
|
189
189
|
...(command !== "" ? ["", command] : []),
|
|
190
190
|
...(hosts.length > 1 ? ["", phrase("networkAllHosts", locale)] : []),
|
|
191
191
|
].join("\n"),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
always: phrase("networkAllowAlways", locale),
|
|
195
|
-
},
|
|
192
|
+
// a run grant only: the owner adds hosts to a device's allowlist on the machine
|
|
193
|
+
scopeLabels: { once: phrase("networkAllowOnce", locale) },
|
|
196
194
|
};
|
|
197
195
|
}
|
|
198
196
|
/**
|
|
@@ -219,16 +217,23 @@ export function gitCardText(detail, locale, redact = (s) => s) {
|
|
|
219
217
|
}
|
|
220
218
|
/**
|
|
221
219
|
* A command review ask's card text (auto mode spec §5.4): the title asks to run the command (a
|
|
222
|
-
* write: to write the file), the preview is the review's reason
|
|
223
|
-
*
|
|
220
|
+
* write or read: to write or read the file), the preview is the review's reason (a directory
|
|
221
|
+
* crossing of a file: a line in the card's language) and the held command clipped to
|
|
222
|
+
* {@link CARD_SUMMARY_MAX} (a file ask: its target path). The scopes are the approval's; `session` is
|
|
224
223
|
* labelled only when offered. Model-controlled values are redacted by `redact`.
|
|
225
224
|
*/
|
|
226
225
|
export function commandCardText(detail, scopes, locale, redact = (s) => s) {
|
|
227
226
|
const write = detail.kind === "write";
|
|
228
|
-
|
|
227
|
+
// a file ask (write or read) names its target path; the command text there is the tool key
|
|
228
|
+
const file = detail.kind !== "command";
|
|
229
|
+
const text = file ? (detail.path ?? detail.command) : detail.command;
|
|
229
230
|
const shown = cut(redact(text.trim()), CARD_SUMMARY_MAX);
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
// a file crossing (a directory outside the scope) is worded from its kind in the card's
|
|
232
|
+
// language; the kernel's English reason is model-facing text, kept for every other ask
|
|
233
|
+
const reason = file && detail.permissionScope !== undefined
|
|
234
|
+
? phrase(write ? "commandWriteLine" : "commandReadLine", locale)
|
|
235
|
+
: cut(redact(detail.reason.trim()), CARD_SUMMARY_MAX);
|
|
236
|
+
const escalation = file ? undefined : detail.escalation;
|
|
232
237
|
// an escalation states the crossing from its own facts, never from the reason alone (a review
|
|
233
238
|
// model's ask may word the reason any way); the reason follows only when it adds something
|
|
234
239
|
const lines = escalation
|
|
@@ -251,11 +256,13 @@ export function commandCardText(detail, scopes, locale, redact = (s) => s) {
|
|
|
251
256
|
return {
|
|
252
257
|
title: phrase(write
|
|
253
258
|
? "commandWriteTitle"
|
|
254
|
-
:
|
|
255
|
-
? "
|
|
256
|
-
: escalation
|
|
257
|
-
? "
|
|
258
|
-
:
|
|
259
|
+
: file
|
|
260
|
+
? "commandReadTitle"
|
|
261
|
+
: escalation?.background === true
|
|
262
|
+
? "escalationBackgroundTitle"
|
|
263
|
+
: escalation
|
|
264
|
+
? "escalationTitle"
|
|
265
|
+
: "commandTitle", locale),
|
|
259
266
|
inputPreview: [...lines, ...(shown !== "" ? ["", shown] : [])].join("\n"),
|
|
260
267
|
scopeLabels: {
|
|
261
268
|
...(scopes.includes("once") ? { once: phrase("commandAllowOnce", locale) } : {}),
|
|
@@ -299,8 +306,10 @@ export async function approvalCard(d, approvalId, base, locale, redact) {
|
|
|
299
306
|
// the field keeps its contract name; it carries the call line (a network ask's hosts and
|
|
300
307
|
// command, a command ask's reason and command), never the raw input
|
|
301
308
|
inputPreview: special?.inputPreview ?? callSummary(v, display, locale, redact),
|
|
302
|
-
// the scopes the approval allows (the kernel stores them for per-call policies)
|
|
303
|
-
|
|
309
|
+
// the scopes the approval allows (the kernel stores them for per-call policies); a network,
|
|
310
|
+
// git or command ask offers only those it labels (an older network ask may still list
|
|
311
|
+
// `always`, which the decision refuses)
|
|
312
|
+
scopes: special !== null ? v.scopes.filter((k) => Object.hasOwn(special.scopeLabels, k)) : v.scopes,
|
|
304
313
|
// the labels of the scopes offered only
|
|
305
314
|
...(special !== null && {
|
|
306
315
|
scopeLabels: Object.fromEntries(Object.entries(special.scopeLabels).filter(([k]) => v.scopes.includes(k))),
|
|
@@ -112,10 +112,6 @@ export declare const CHANNEL_PHRASES: {
|
|
|
112
112
|
readonly en: "Allow this time";
|
|
113
113
|
};
|
|
114
114
|
/** A network ask's 「always」 button. */
|
|
115
|
-
readonly networkAllowAlways: {
|
|
116
|
-
readonly zh: "这台设备一直允许";
|
|
117
|
-
readonly en: "Always allow on this device";
|
|
118
|
-
};
|
|
119
115
|
/** A git push ask's card title (`{repo}`; sandbox git credentials spec §7). */
|
|
120
116
|
readonly gitTitle: {
|
|
121
117
|
readonly zh: "智能体想推送到 {repo},允许吗?";
|
|
@@ -141,6 +137,21 @@ export declare const CHANNEL_PHRASES: {
|
|
|
141
137
|
readonly zh: "智能体想写入这个文件,允许吗?";
|
|
142
138
|
readonly en: "The agent wants to write this file. Allow?";
|
|
143
139
|
};
|
|
140
|
+
/** A file-read review ask's card title (the path is in the preview). */
|
|
141
|
+
readonly commandReadTitle: {
|
|
142
|
+
readonly zh: "智能体想读取这个文件,允许吗?";
|
|
143
|
+
readonly en: "The agent wants to read this file. Allow?";
|
|
144
|
+
};
|
|
145
|
+
/** A file-write crossing's preview line: the file is outside what the agent may write now. */
|
|
146
|
+
readonly commandWriteLine: {
|
|
147
|
+
readonly zh: "这个文件不在智能体现在可以写入的范围内。允许后,仅这一次调用可以写入它所在的目录。";
|
|
148
|
+
readonly en: "This file is outside what the agent may write now. If you allow it, only this call may write in its directory.";
|
|
149
|
+
};
|
|
150
|
+
/** A file-read crossing's preview line: the file is outside what the agent may read now. */
|
|
151
|
+
readonly commandReadLine: {
|
|
152
|
+
readonly zh: "这个文件不在智能体现在可以读取的范围内。允许后,仅这一次调用可以读取它所在的目录。";
|
|
153
|
+
readonly en: "This file is outside what the agent may read now. If you allow it, only this call may read its directory.";
|
|
154
|
+
};
|
|
144
155
|
/** A per-call sandbox escalation ask's card title (approval profiles design). */
|
|
145
156
|
readonly escalationTitle: {
|
|
146
157
|
readonly zh: "智能体想在沙箱外运行这条命令,允许吗?";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -95,7 +95,6 @@ export const CHANNEL_PHRASES = {
|
|
|
95
95
|
/** A network ask's 「once」 button. */
|
|
96
96
|
networkAllowOnce: { zh: "这次允许", en: "Allow this time" },
|
|
97
97
|
/** A network ask's 「always」 button. */
|
|
98
|
-
networkAllowAlways: { zh: "这台设备一直允许", en: "Always allow on this device" },
|
|
99
98
|
/** A git push ask's card title (`{repo}`; sandbox git credentials spec §7). */
|
|
100
99
|
gitTitle: {
|
|
101
100
|
zh: "智能体想推送到 {repo},允许吗?",
|
|
@@ -115,6 +114,21 @@ export const CHANNEL_PHRASES = {
|
|
|
115
114
|
zh: "智能体想写入这个文件,允许吗?",
|
|
116
115
|
en: "The agent wants to write this file. Allow?",
|
|
117
116
|
},
|
|
117
|
+
/** A file-read review ask's card title (the path is in the preview). */
|
|
118
|
+
commandReadTitle: {
|
|
119
|
+
zh: "智能体想读取这个文件,允许吗?",
|
|
120
|
+
en: "The agent wants to read this file. Allow?",
|
|
121
|
+
},
|
|
122
|
+
/** A file-write crossing's preview line: the file is outside what the agent may write now. */
|
|
123
|
+
commandWriteLine: {
|
|
124
|
+
zh: "这个文件不在智能体现在可以写入的范围内。允许后,仅这一次调用可以写入它所在的目录。",
|
|
125
|
+
en: "This file is outside what the agent may write now. If you allow it, only this call may write in its directory.",
|
|
126
|
+
},
|
|
127
|
+
/** A file-read crossing's preview line: the file is outside what the agent may read now. */
|
|
128
|
+
commandReadLine: {
|
|
129
|
+
zh: "这个文件不在智能体现在可以读取的范围内。允许后,仅这一次调用可以读取它所在的目录。",
|
|
130
|
+
en: "This file is outside what the agent may read now. If you allow it, only this call may read its directory.",
|
|
131
|
+
},
|
|
118
132
|
/** A per-call sandbox escalation ask's card title (approval profiles design). */
|
|
119
133
|
escalationTitle: {
|
|
120
134
|
zh: "智能体想在沙箱外运行这条命令,允许吗?",
|
package/dist/config/load.d.ts
CHANGED
|
@@ -7,18 +7,37 @@ export declare function selectConfigSource(env: NodeJS.ProcessEnv): ConfigSource
|
|
|
7
7
|
/** 深合并:对象递归合并,其余(含数组)由 override 整体替换。 */
|
|
8
8
|
export declare function deepMerge(base: unknown, override: unknown): unknown;
|
|
9
9
|
/**
|
|
10
|
-
* The permission keys
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The permission keys the approval-only profiles design replaced, each with its replacement (B1's
|
|
11
|
+
* `devices.autoMode` and its successor `devices.fullAccess`, both now `devices.outsideSandbox`).
|
|
12
|
+
* The old keys are no longer read: {@link refuseLegacyPermissionKeys} refuses them with the
|
|
13
|
+
* conversion message, and `capybara config migrate-permissions` (`permission-migration.ts`)
|
|
14
|
+
* converts a config file. The values are the same (`allowed` / `off`); an old `off` also kept every
|
|
15
|
+
* device on the allowlist, so its conversion adds `devices.network.ceiling: allowlist` (never wider).
|
|
13
16
|
*/
|
|
14
17
|
export declare const LEGACY_PERMISSION_KEYS: readonly [{
|
|
15
18
|
readonly path: readonly ["devices", "autoMode"];
|
|
16
|
-
readonly replacement: readonly ["devices", "
|
|
19
|
+
readonly replacement: readonly ["devices", "outsideSandbox"];
|
|
17
20
|
readonly env: "CAPYBARA_DEVICES__AUTO_MODE";
|
|
18
|
-
readonly replacementEnv: "
|
|
21
|
+
readonly replacementEnv: "CAPYBARA_DEVICES__OUTSIDE_SANDBOX";
|
|
22
|
+
}, {
|
|
23
|
+
readonly path: readonly ["devices", "fullAccess"];
|
|
24
|
+
readonly replacement: readonly ["devices", "outsideSandbox"];
|
|
25
|
+
readonly env: "CAPYBARA_DEVICES__FULL_ACCESS";
|
|
26
|
+
readonly replacementEnv: "CAPYBARA_DEVICES__OUTSIDE_SANDBOX";
|
|
19
27
|
}];
|
|
20
|
-
/**
|
|
21
|
-
export declare
|
|
28
|
+
/** The key and variable an old `off` adds, so a converted deployment never widens a device. */
|
|
29
|
+
export declare const LEGACY_OFF_NETWORK_CEILING: {
|
|
30
|
+
readonly path: readonly ["devices", "network", "ceiling"];
|
|
31
|
+
readonly env: "CAPYBARA_DEVICES__NETWORK__CEILING";
|
|
32
|
+
readonly value: "allowlist";
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Deep-merges the environment overrides (highest precedence) into the raw configuration, then
|
|
36
|
+
* validates it; hot reload and startup share it. Errors name only paths, never values.
|
|
37
|
+
* `previous` (a hot reload: the applied config) lets a change that only narrows the device network
|
|
38
|
+
* through ({@link refuseDefaultAboveCeiling}).
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveConfig(raw: unknown, env: NodeJS.ProcessEnv, previous?: KernelConfig): KernelConfig;
|
|
22
41
|
/** 选来源 → 深合并环境变量覆盖(优先级最高)→ 校验。 */
|
|
23
42
|
export declare function loadConfig(env: NodeJS.ProcessEnv): Promise<KernelConfig>;
|
|
24
43
|
/**
|
package/dist/config/load.js
CHANGED
|
@@ -64,18 +64,33 @@ export function deepMerge(base, override) {
|
|
|
64
64
|
return out;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* The permission keys
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
* The permission keys the approval-only profiles design replaced, each with its replacement (B1's
|
|
68
|
+
* `devices.autoMode` and its successor `devices.fullAccess`, both now `devices.outsideSandbox`).
|
|
69
|
+
* The old keys are no longer read: {@link refuseLegacyPermissionKeys} refuses them with the
|
|
70
|
+
* conversion message, and `capybara config migrate-permissions` (`permission-migration.ts`)
|
|
71
|
+
* converts a config file. The values are the same (`allowed` / `off`); an old `off` also kept every
|
|
72
|
+
* device on the allowlist, so its conversion adds `devices.network.ceiling: allowlist` (never wider).
|
|
70
73
|
*/
|
|
71
74
|
export const LEGACY_PERMISSION_KEYS = [
|
|
72
75
|
{
|
|
73
76
|
path: ["devices", "autoMode"],
|
|
74
|
-
replacement: ["devices", "
|
|
77
|
+
replacement: ["devices", "outsideSandbox"],
|
|
75
78
|
env: "CAPYBARA_DEVICES__AUTO_MODE",
|
|
76
|
-
replacementEnv: "
|
|
79
|
+
replacementEnv: "CAPYBARA_DEVICES__OUTSIDE_SANDBOX",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
path: ["devices", "fullAccess"],
|
|
83
|
+
replacement: ["devices", "outsideSandbox"],
|
|
84
|
+
env: "CAPYBARA_DEVICES__FULL_ACCESS",
|
|
85
|
+
replacementEnv: "CAPYBARA_DEVICES__OUTSIDE_SANDBOX",
|
|
77
86
|
},
|
|
78
87
|
];
|
|
88
|
+
/** The key and variable an old `off` adds, so a converted deployment never widens a device. */
|
|
89
|
+
export const LEGACY_OFF_NETWORK_CEILING = {
|
|
90
|
+
path: ["devices", "network", "ceiling"],
|
|
91
|
+
env: "CAPYBARA_DEVICES__NETWORK__CEILING",
|
|
92
|
+
value: "allowlist",
|
|
93
|
+
};
|
|
79
94
|
/**
|
|
80
95
|
* The conversion message of every old permission key in ONE config source (the file / Nacos
|
|
81
96
|
* document, or the environment overrides), empty when it names none. The old key is refused even
|
|
@@ -90,8 +105,8 @@ function legacyPermissionKeyProblems(source, label) {
|
|
|
90
105
|
if (!isPlainObject(parent) || !(old in parent))
|
|
91
106
|
continue;
|
|
92
107
|
problems.push(label === "env"
|
|
93
|
-
? ` - ${key.env} is no longer read: set ${key.replacementEnv} instead (the same values, allowed or off)`
|
|
94
|
-
: ` - ${key.path.join(".")} is no longer read: rename it to ${key.replacement.join(".")} (the same values, allowed or off); capybara config migrate-permissions --in <file> --out <file> converts a config file or Nacos document`);
|
|
108
|
+
? ` - ${key.env} is no longer read: set ${key.replacementEnv} instead (the same values, allowed or off; with off, also set ${LEGACY_OFF_NETWORK_CEILING.env}=${LEGACY_OFF_NETWORK_CEILING.value} so no device widens)`
|
|
109
|
+
: ` - ${key.path.join(".")} is no longer read: rename it to ${key.replacement.join(".")} (the same values, allowed or off; with off, also set ${LEGACY_OFF_NETWORK_CEILING.path.join(".")}: ${LEGACY_OFF_NETWORK_CEILING.value} so no device widens); capybara config migrate-permissions --in <file> --out <file> converts a config file or Nacos document`);
|
|
95
110
|
}
|
|
96
111
|
return problems;
|
|
97
112
|
}
|
|
@@ -104,8 +119,43 @@ function refuseLegacyPermissionKeys(raw, env) {
|
|
|
104
119
|
if (problems.length > 0)
|
|
105
120
|
throw new ConfigError(`invalid configuration:\n${problems.join("\n")}`);
|
|
106
121
|
}
|
|
107
|
-
|
|
108
|
-
|
|
122
|
+
const modeAt = (source, field) => {
|
|
123
|
+
const devices = source.devices;
|
|
124
|
+
const network = isPlainObject(devices) ? devices.network : undefined;
|
|
125
|
+
const v = isPlainObject(network) ? network[field] : undefined;
|
|
126
|
+
return v === "open" || v === "allowlist" ? v : undefined;
|
|
127
|
+
};
|
|
128
|
+
/** Whether the mode opens from `was` to `now` (absent reads as open, the default). */
|
|
129
|
+
const opens = (was, now) => (was ?? "open") === "allowlist" && (now ?? "open") === "open";
|
|
130
|
+
/**
|
|
131
|
+
* Refuses a `devices.network.default` of `open` under a `ceiling` of `allowlist` set in the SAME
|
|
132
|
+
* source (the file / Nacos document, or the environment); across sources the reader clamps the
|
|
133
|
+
* default to the ceiling. A hot reload that only narrows the network (`previous`: the applied
|
|
134
|
+
* config) is never refused, even when it leaves such a pair: the reader clamps it.
|
|
135
|
+
*/
|
|
136
|
+
function refuseDefaultAboveCeiling(raw, env, previous, merged) {
|
|
137
|
+
if (previous !== undefined) {
|
|
138
|
+
const was = previous.devices.network;
|
|
139
|
+
const now = merged.devices.network;
|
|
140
|
+
if (!opens(was.default, now.default) && !opens(was.ceiling, now.ceiling))
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const problems = [
|
|
144
|
+
["file", raw],
|
|
145
|
+
["env", env],
|
|
146
|
+
]
|
|
147
|
+
.filter(([, source]) => modeAt(source, "default") === "open" && modeAt(source, "ceiling") === "allowlist")
|
|
148
|
+
.map(([label]) => ` - devices.network.default: open is above devices.network.ceiling allowlist in the same ${label === "env" ? "environment" : "config source"}; choose a default no wider than the ceiling`);
|
|
149
|
+
if (problems.length > 0)
|
|
150
|
+
throw new ConfigError(`invalid configuration:\n${problems.join("\n")}`);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Deep-merges the environment overrides (highest precedence) into the raw configuration, then
|
|
154
|
+
* validates it; hot reload and startup share it. Errors name only paths, never values.
|
|
155
|
+
* `previous` (a hot reload: the applied config) lets a change that only narrows the device network
|
|
156
|
+
* through ({@link refuseDefaultAboveCeiling}).
|
|
157
|
+
*/
|
|
158
|
+
export function resolveConfig(raw, env, previous) {
|
|
109
159
|
if (!isPlainObject(raw))
|
|
110
160
|
throw new ConfigError("config file root must be a mapping");
|
|
111
161
|
const overrides = envOverrides(env);
|
|
@@ -123,6 +173,7 @@ export function resolveConfig(raw, env) {
|
|
|
123
173
|
});
|
|
124
174
|
throw new ConfigError(`invalid configuration:\n${lines.join("\n")}`);
|
|
125
175
|
}
|
|
176
|
+
refuseDefaultAboveCeiling(raw, overrides, previous, result.data);
|
|
126
177
|
// Cross-section rule (the loopback exception lives under `tools`)
|
|
127
178
|
const webhookProblem = webhookBaseUrlProblem(result.data);
|
|
128
179
|
if (webhookProblem !== null) {
|
|
@@ -6,21 +6,29 @@ export interface PermissionConfigMigration {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* The offline conversion of one config document (a config file, or a Nacos data id's content) to
|
|
9
|
-
* the permission keys
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* old
|
|
13
|
-
*
|
|
9
|
+
* the permission keys of the approval-only profiles design (`capybara config migrate-permissions`):
|
|
10
|
+
* every old key (`devices.autoMode`, `devices.fullAccess`) is renamed in place to
|
|
11
|
+
* `devices.outsideSandbox`, so unrelated keys, values, order and comments stay as they were. An
|
|
12
|
+
* old key equal to an already present new key is dropped; a different one, or an invalid old
|
|
13
|
+
* value, is refused (never pick the wider one, never guess). An old `off` also kept every device on
|
|
14
|
+
* the allowlist, so the conversion sets `devices.network.ceiling: allowlist` (and narrows an open
|
|
15
|
+
* `devices.network.default`): nothing widens. Nothing is read from or written to the environment,
|
|
16
|
+
* PG or Nacos here: applying the result is the operator's reviewed change.
|
|
14
17
|
*/
|
|
15
18
|
export declare function migratePermissionConfigText(text: string): PermissionConfigMigration;
|
|
16
19
|
/** One environment variable the operator must rename before the old one stops being read. */
|
|
17
|
-
export
|
|
20
|
+
export type PermissionEnvRename = {
|
|
18
21
|
from: string;
|
|
19
22
|
to: string;
|
|
20
23
|
}
|
|
24
|
+
/** A variable to add (name=value; the value is a fixed narrowing, never an operator's value). */
|
|
25
|
+
| {
|
|
26
|
+
add: string;
|
|
27
|
+
};
|
|
21
28
|
/**
|
|
22
|
-
* The old permission environment variables set in `env`, each with its replacement
|
|
23
|
-
*
|
|
24
|
-
*
|
|
29
|
+
* The old permission environment variables set in `env`, each with its replacement, plus the
|
|
30
|
+
* network ceiling variable to add when an old one is `off` (never wider). The values are never
|
|
31
|
+
* returned (the operator renames the variable and keeps its value). An old and a new variable, or
|
|
32
|
+
* two old ones, with different values are refused, like the startup config does.
|
|
25
33
|
*/
|
|
26
34
|
export declare function legacyPermissionEnvRenames(env: NodeJS.ProcessEnv): PermissionEnvRename[];
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { isMap, isScalar, parseDocument } from "yaml";
|
|
2
|
-
import { LEGACY_PERMISSION_KEYS } from "./load.js";
|
|
2
|
+
import { LEGACY_OFF_NETWORK_CEILING, LEGACY_PERMISSION_KEYS } from "./load.js";
|
|
3
3
|
import { ConfigError } from "./types.js";
|
|
4
4
|
const VALUES = ["allowed", "off"];
|
|
5
5
|
/**
|
|
6
6
|
* The offline conversion of one config document (a config file, or a Nacos data id's content) to
|
|
7
|
-
* the permission keys
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* old
|
|
11
|
-
*
|
|
7
|
+
* the permission keys of the approval-only profiles design (`capybara config migrate-permissions`):
|
|
8
|
+
* every old key (`devices.autoMode`, `devices.fullAccess`) is renamed in place to
|
|
9
|
+
* `devices.outsideSandbox`, so unrelated keys, values, order and comments stay as they were. An
|
|
10
|
+
* old key equal to an already present new key is dropped; a different one, or an invalid old
|
|
11
|
+
* value, is refused (never pick the wider one, never guess). An old `off` also kept every device on
|
|
12
|
+
* the allowlist, so the conversion sets `devices.network.ceiling: allowlist` (and narrows an open
|
|
13
|
+
* `devices.network.default`): nothing widens. Nothing is read from or written to the environment,
|
|
14
|
+
* PG or Nacos here: applying the result is the operator's reviewed change.
|
|
12
15
|
*/
|
|
13
16
|
export function migratePermissionConfigText(text) {
|
|
14
17
|
const doc = parseDocument(text);
|
|
15
18
|
if (doc.errors.length > 0)
|
|
16
19
|
throw new ConfigError("invalid YAML in the config document");
|
|
17
20
|
const changed = [];
|
|
21
|
+
let off = false;
|
|
18
22
|
for (const key of LEGACY_PERMISSION_KEYS) {
|
|
19
23
|
const [section, old] = key.path;
|
|
20
24
|
const [, next] = key.replacement;
|
|
@@ -26,6 +30,8 @@ export function migratePermissionConfigText(text) {
|
|
|
26
30
|
const value = parent.get(old);
|
|
27
31
|
if (typeof value !== "string" || !VALUES.includes(value))
|
|
28
32
|
throw new ConfigError(`${from} must be allowed or off; fix it before converting`);
|
|
33
|
+
if (value === "off")
|
|
34
|
+
off = true;
|
|
29
35
|
if (parent.has(next)) {
|
|
30
36
|
if (parent.get(next) !== value)
|
|
31
37
|
throw new ConfigError(`${from} and ${to} are both set and differ; keep one of them before converting`);
|
|
@@ -42,15 +48,52 @@ export function migratePermissionConfigText(text) {
|
|
|
42
48
|
}
|
|
43
49
|
changed.push(`${from} -> ${to}`);
|
|
44
50
|
}
|
|
51
|
+
if (off && narrowNetworkToAllowlist(doc))
|
|
52
|
+
changed.push(`${LEGACY_OFF_NETWORK_CEILING.path.join(".")}: ${LEGACY_OFF_NETWORK_CEILING.value} (an old off kept every device on the allowlist)`);
|
|
45
53
|
return { text: changed.length === 0 ? text : doc.toString(), changed };
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
56
|
+
* Sets `devices.network.ceiling` (and an open `devices.network.default`) to the allowlist, adding
|
|
57
|
+
* the `network` map right after `devices.outsideSandbox` when there is none. Returns whether it
|
|
58
|
+
* changed anything.
|
|
59
|
+
*/
|
|
60
|
+
function narrowNetworkToAllowlist(doc) {
|
|
61
|
+
const devices = doc.get("devices", true);
|
|
62
|
+
if (!isMap(devices))
|
|
63
|
+
return false;
|
|
64
|
+
const network = devices.get("network", true);
|
|
65
|
+
if (network === undefined || network === null) {
|
|
66
|
+
const node = doc.createNode({ ceiling: LEGACY_OFF_NETWORK_CEILING.value });
|
|
67
|
+
const at = devices.items.findIndex((p) => (isScalar(p.key) ? p.key.value : p.key) === "outsideSandbox");
|
|
68
|
+
devices.items.splice(at + 1, 0, doc.createPair("network", node));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (!isMap(network))
|
|
72
|
+
throw new ConfigError("devices.network must be a mapping; fix it before converting");
|
|
73
|
+
let changed = false;
|
|
74
|
+
for (const field of ["default", "ceiling"]) {
|
|
75
|
+
const value = network.get(field);
|
|
76
|
+
if (field === "default" && value === undefined)
|
|
77
|
+
continue;
|
|
78
|
+
if (value === LEGACY_OFF_NETWORK_CEILING.value)
|
|
79
|
+
continue;
|
|
80
|
+
if (value !== undefined && value !== "open")
|
|
81
|
+
throw new ConfigError(`devices.network.${field} must be open or allowlist; fix it before converting`);
|
|
82
|
+
network.set(field, LEGACY_OFF_NETWORK_CEILING.value);
|
|
83
|
+
changed = true;
|
|
84
|
+
}
|
|
85
|
+
return changed;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The old permission environment variables set in `env`, each with its replacement, plus the
|
|
89
|
+
* network ceiling variable to add when an old one is `off` (never wider). The values are never
|
|
90
|
+
* returned (the operator renames the variable and keeps its value). An old and a new variable, or
|
|
91
|
+
* two old ones, with different values are refused, like the startup config does.
|
|
51
92
|
*/
|
|
52
93
|
export function legacyPermissionEnvRenames(env) {
|
|
53
94
|
const out = [];
|
|
95
|
+
let off = false;
|
|
96
|
+
const seen = new Map();
|
|
54
97
|
for (const key of LEGACY_PERMISSION_KEYS) {
|
|
55
98
|
const old = env[key.env];
|
|
56
99
|
if (old === undefined)
|
|
@@ -58,7 +101,15 @@ export function legacyPermissionEnvRenames(env) {
|
|
|
58
101
|
const current = env[key.replacementEnv];
|
|
59
102
|
if (current !== undefined && current !== old)
|
|
60
103
|
throw new ConfigError(`${key.env} and ${key.replacementEnv} are both set and differ; keep one of them`);
|
|
104
|
+
for (const [other, value] of seen)
|
|
105
|
+
if (value !== old)
|
|
106
|
+
throw new ConfigError(`${other} and ${key.env} are both set and differ; keep one of them`);
|
|
107
|
+
seen.set(key.env, old);
|
|
108
|
+
if (old === "off")
|
|
109
|
+
off = true;
|
|
61
110
|
out.push({ from: key.env, to: key.replacementEnv });
|
|
62
111
|
}
|
|
112
|
+
if (off)
|
|
113
|
+
out.push({ add: `${LEGACY_OFF_NETWORK_CEILING.env}=${LEGACY_OFF_NETWORK_CEILING.value}` });
|
|
63
114
|
return out;
|
|
64
115
|
}
|