@capybara-hq/kernel 0.1.0-rc.128 → 0.1.0-rc.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +3 -3
- package/dist/admin/admin.schemas.d.ts +14 -0
- package/dist/automations/automations.service.js +15 -21
- package/dist/automations/effective-settings.d.ts +3 -9
- package/dist/automations/effective-settings.js +3 -5
- package/dist/automations/fire.js +0 -11
- package/dist/automations/grant-rules.d.ts +7 -10
- package/dist/automations/grant-rules.js +9 -18
- package/dist/automations/unattended.d.ts +1 -4
- package/dist/automations/unattended.js +0 -2
- package/dist/catalog/org-extension.controller.d.ts +1 -20
- package/dist/catalog/org-extension.controller.js +1 -48
- package/dist/catalog/org-extension.schemas.d.ts +1 -9
- package/dist/catalog/org-extension.schemas.js +1 -17
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +16 -0
- package/dist/conversations/approval-profile.d.ts +8 -1
- package/dist/conversations/approval-profile.js +20 -0
- package/dist/conversations/conversations.service.d.ts +1 -1
- package/dist/conversations/conversations.service.js +8 -3
- package/dist/conversations/events.d.ts +25 -1
- package/dist/conversations/events.js +7 -2
- package/dist/conversations/permission-profiles.controller.d.ts +4 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
- package/dist/conversations/permission-profiles.schemas.js +8 -0
- package/dist/conversations/permission-profiles.service.d.ts +8 -1
- package/dist/conversations/permission-profiles.service.js +13 -1
- package/dist/db/kernel-schema.d.ts +21 -0
- package/dist/device-access/device-access.service.d.ts +4 -1
- package/dist/device-access/device-access.service.js +26 -7
- package/dist/device-access/viewer.d.ts +3 -1
- package/dist/device-access/viewer.js +18 -9
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/git/gateway.d.ts +8 -1
- package/dist/git/gateway.js +68 -11
- package/dist/git/git.module.d.ts +2 -3
- package/dist/git/git.module.js +4 -4
- package/dist/http/api.module.js +3 -3
- package/dist/identity/settings.d.ts +20 -5
- package/dist/identity/settings.js +52 -9
- package/dist/infra/config/kernel-config.service.js +4 -0
- package/dist/orgs/orgs.module.js +12 -1
- package/dist/orgs/orgs.schemas.js +3 -0
- package/dist/orgs/security-settings.service.d.ts +94 -0
- package/dist/orgs/security-settings.service.js +223 -0
- package/dist/orgs/settings.controller.d.ts +33 -0
- package/dist/orgs/settings.controller.js +41 -1
- package/dist/orgs/settings.service.d.ts +48 -63
- package/dist/orgs/settings.service.js +86 -103
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +18 -4
- package/dist/platform/ops/connectors.ops.js +2 -2
- package/dist/platform/ops/extensions.ops.d.ts +1 -3
- package/dist/platform/ops/extensions.ops.js +4 -131
- package/dist/platform/ops/org-settings.ops.d.ts +3 -1
- package/dist/platform/ops/org-settings.ops.js +76 -3
- package/dist/platform/ops/orgs.ops.js +2 -0
- package/dist/runtime/context/permission-profile.js +6 -0
- package/dist/runtime/subagents/dispatch.d.ts +3 -0
- package/dist/runtime/subagents/dispatch.js +2 -1
- package/dist/runtime/subagents/messages.d.ts +3 -1
- package/dist/runtime/subagents/messages.js +9 -6
- package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
- package/dist/sandbox/device-sandbox-settings.js +64 -1
- package/dist/sandbox/device-sandbox.d.ts +9 -1
- package/dist/sandbox/device-sandbox.js +17 -2
- package/dist/sandbox/device-services.d.ts +26 -3
- package/dist/sandbox/device-services.js +95 -16
- package/dist/sandbox/loopback-grant-records.d.ts +3 -2
- package/dist/sandbox/loopback-grant-records.js +32 -5
- package/dist/sandbox/operation-authority.d.ts +3 -2
- package/dist/sandbox/operation-authority.js +21 -1
- package/dist/sandbox/operation-intents.js +5 -1
- package/dist/sandbox/permission-call-types.d.ts +2 -1
- package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
- package/dist/sandbox/permission-ceiling-writes.js +122 -13
- package/dist/sandbox/permission-config-publication.d.ts +10 -0
- package/dist/sandbox/permission-config-publication.js +27 -5
- package/dist/sandbox/permission-facts.d.ts +21 -2
- package/dist/sandbox/permission-facts.js +101 -9
- package/dist/sandbox/permission-transitions.d.ts +1 -1
- package/dist/sandbox/sandbox.service.d.ts +2 -2
- package/dist/sandbox/sandbox.service.js +7 -3
- package/dist/tools/admin-connectors.js +2 -2
- package/dist/tools/approvals.service.d.ts +7 -2
- package/dist/tools/approvals.service.js +39 -7
- package/dist/tools/builtin-names.d.ts +0 -6
- package/dist/tools/builtin-names.js +0 -11
- package/dist/tools/builtins/sandbox/index.d.ts +3 -5
- package/dist/tools/builtins/sandbox/index.js +3 -5
- package/dist/tools/connector-account-policies.js +7 -4
- package/dist/tools/connectors.controller.d.ts +0 -6
- package/dist/tools/connectors.schemas.d.ts +1 -8
- package/dist/tools/connectors.schemas.js +1 -4
- package/dist/tools/connectors.service.d.ts +3 -7
- package/dist/tools/connectors.service.js +29 -44
- package/dist/tools/drift.js +12 -4
- package/dist/tools/git-push-policy.d.ts +1 -4
- package/dist/tools/git-push-policy.js +4 -5
- package/dist/tools/org-tool-policies.d.ts +24 -0
- package/dist/tools/org-tool-policies.js +113 -0
- package/dist/tools/org-tool-switches.d.ts +5 -70
- package/dist/tools/org-tool-switches.js +13 -141
- package/dist/tools/pipeline.d.ts +11 -5
- package/dist/tools/pipeline.js +173 -38
- package/dist/tools/policy.d.ts +3 -7
- package/dist/tools/policy.js +29 -48
- package/dist/tools/registry.d.ts +5 -0
- package/dist/tools/registry.js +44 -13
- package/package.json +1 -1
- package/src/migrations/0212_org_security_policy.sql +234 -0
|
@@ -0,0 +1,223 @@
|
|
|
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 { createHash } from "node:crypto";
|
|
11
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { normalizeGitRepo } from "../automations/grant-rules.js";
|
|
14
|
+
import { ApiError } from "../errors.js";
|
|
15
|
+
import { audit } from "../identity/audit.js";
|
|
16
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
|
+
import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
|
|
18
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
19
|
+
import { PlatformOperations } from "../platform/registry.js";
|
|
20
|
+
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
21
|
+
import { readOrgGitPushDenials, readOrgToolPolicies, writeOrgGitPushDenial, writeOrgToolPolicy, } from "../tools/org-tool-policies.js";
|
|
22
|
+
import { OrgToolSwitches } from "../tools/org-tool-switches.js";
|
|
23
|
+
import { ToolRegistry } from "../tools/registry.js";
|
|
24
|
+
import { OrgLock } from "./org-lock.js";
|
|
25
|
+
import { OrgSecurityCeilingsPatchSchema, OrgSettingsService } from "./settings.service.js";
|
|
26
|
+
const ToolKey = z.string().min(1).max(200);
|
|
27
|
+
const Policy = z.enum(["allow", "ask", "deny"]);
|
|
28
|
+
const POLICY_RANK = { allow: 0, ask: 1, deny: 2 };
|
|
29
|
+
const Revision = z.string().regex(/^[a-f0-9]{64}$/);
|
|
30
|
+
const GitTarget = z
|
|
31
|
+
.string()
|
|
32
|
+
.min(1)
|
|
33
|
+
.max(200)
|
|
34
|
+
.transform((value) => (value.trim() === "*" ? "*" : normalizeGitRepo(value)))
|
|
35
|
+
.pipe(z.string());
|
|
36
|
+
export const OrgSecurityQuerySchema = z
|
|
37
|
+
.object({
|
|
38
|
+
cursor: ToolKey.optional(),
|
|
39
|
+
limit: z.coerce.number().int().min(1).max(100).default(50),
|
|
40
|
+
})
|
|
41
|
+
.strict();
|
|
42
|
+
export const OrgSecurityPatchSchema = OrgSecurityCeilingsPatchSchema.extend({
|
|
43
|
+
expectedRevision: Revision,
|
|
44
|
+
confirmation: Revision.optional(),
|
|
45
|
+
tools: z
|
|
46
|
+
.array(z.object({ toolKey: ToolKey, policy: Policy, unattendedPolicy: Policy }).strict())
|
|
47
|
+
.max(100)
|
|
48
|
+
.optional(),
|
|
49
|
+
gitPush: z
|
|
50
|
+
.array(z.object({ target: GitTarget, denied: z.boolean() }).strict())
|
|
51
|
+
.max(100)
|
|
52
|
+
.optional(),
|
|
53
|
+
})
|
|
54
|
+
.strict()
|
|
55
|
+
.superRefine((input, ctx) => {
|
|
56
|
+
if (new Set(input.tools?.map(({ toolKey }) => toolKey)).size !== (input.tools?.length ?? 0))
|
|
57
|
+
ctx.addIssue({ code: "custom", path: ["tools"], message: "Each tool can be edited once" });
|
|
58
|
+
if (new Set(input.gitPush?.map(({ target }) => target)).size !== (input.gitPush?.length ?? 0))
|
|
59
|
+
ctx.addIssue({
|
|
60
|
+
code: "custom",
|
|
61
|
+
path: ["gitPush"],
|
|
62
|
+
message: "Each Git target can be edited once",
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
function digest(value) {
|
|
66
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
67
|
+
}
|
|
68
|
+
let OrgSecuritySettingsService = class OrgSecuritySettingsService {
|
|
69
|
+
db;
|
|
70
|
+
txHost;
|
|
71
|
+
orgLock;
|
|
72
|
+
ceilings;
|
|
73
|
+
settings;
|
|
74
|
+
tools;
|
|
75
|
+
operations;
|
|
76
|
+
toolImpact;
|
|
77
|
+
constructor(db, txHost, orgLock, ceilings, settings, tools, operations, toolImpact) {
|
|
78
|
+
this.db = db;
|
|
79
|
+
this.txHost = txHost;
|
|
80
|
+
this.orgLock = orgLock;
|
|
81
|
+
this.ceilings = ceilings;
|
|
82
|
+
this.settings = settings;
|
|
83
|
+
this.tools = tools;
|
|
84
|
+
this.operations = operations;
|
|
85
|
+
this.toolImpact = toolImpact;
|
|
86
|
+
}
|
|
87
|
+
async snapshot(orgId) {
|
|
88
|
+
const [ceilings, policies, gitPushDenials] = await Promise.all([
|
|
89
|
+
this.settings.securityCeilings(orgId),
|
|
90
|
+
readOrgToolPolicies(this.db.db, orgId),
|
|
91
|
+
readOrgGitPushDenials(this.db.db, orgId),
|
|
92
|
+
]);
|
|
93
|
+
return {
|
|
94
|
+
...ceilings,
|
|
95
|
+
policies,
|
|
96
|
+
gitPushDenials,
|
|
97
|
+
revision: digest([
|
|
98
|
+
ceilings,
|
|
99
|
+
policies.map((row) => [row.toolKey, row.rowRevision]),
|
|
100
|
+
gitPushDenials,
|
|
101
|
+
]),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async toolSources(orgId) {
|
|
105
|
+
const catalog = await this.tools.securityCatalog(orgId);
|
|
106
|
+
const operations = this.operations.all();
|
|
107
|
+
const sources = new Map(catalog.map(({ toolKey, source }) => [toolKey, source]));
|
|
108
|
+
for (const { id } of operations)
|
|
109
|
+
sources.set(`Platform:${id}`, "operation");
|
|
110
|
+
return sources;
|
|
111
|
+
}
|
|
112
|
+
async view(orgId, query) {
|
|
113
|
+
const [{ policies, ...snapshot }, sources] = await Promise.all([
|
|
114
|
+
this.snapshot(orgId),
|
|
115
|
+
this.toolSources(orgId),
|
|
116
|
+
]);
|
|
117
|
+
const rows = new Map(policies.map((row) => [row.toolKey, row]));
|
|
118
|
+
for (const { toolKey } of policies)
|
|
119
|
+
if (!sources.has(toolKey))
|
|
120
|
+
sources.set(toolKey, "unavailable");
|
|
121
|
+
const keys = [...sources.keys()]
|
|
122
|
+
.filter((key) => query.cursor === undefined || key > query.cursor)
|
|
123
|
+
.sort();
|
|
124
|
+
const page = keys.slice(0, query.limit);
|
|
125
|
+
return {
|
|
126
|
+
...snapshot,
|
|
127
|
+
tools: page.map((toolKey) => ({
|
|
128
|
+
toolKey,
|
|
129
|
+
source: sources.get(toolKey) ?? "unavailable",
|
|
130
|
+
policy: rows.get(toolKey)?.policy ?? "allow",
|
|
131
|
+
unattendedPolicy: rows.get(toolKey)?.unattendedPolicy ?? "allow",
|
|
132
|
+
})),
|
|
133
|
+
nextCursor: keys.length > page.length ? (page.at(-1) ?? null) : null,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async update(orgId, patch, actor, options) {
|
|
137
|
+
return withOrderedLocks(() => this.lock(orgId, actor), () => this.updateLocked(orgId, patch, actor, options));
|
|
138
|
+
}
|
|
139
|
+
async lock(orgId, actor) {
|
|
140
|
+
await this.orgLock.lockAndAuthorize(orgId, actor, "org.update");
|
|
141
|
+
await this.ceilings.lock({ orgId }, "org");
|
|
142
|
+
}
|
|
143
|
+
async updateLocked(orgId, patch, actor, options) {
|
|
144
|
+
await this.lock(orgId, actor);
|
|
145
|
+
const before = await this.snapshot(orgId);
|
|
146
|
+
if (patch.expectedRevision !== before.revision)
|
|
147
|
+
throw new ApiError("org.security_revision_conflict", "Reload the organization security settings before saving");
|
|
148
|
+
const rows = new Map(before.policies.map((row) => [row.toolKey, row]));
|
|
149
|
+
if (options.onlyNarrows &&
|
|
150
|
+
(patch.tools?.some((row) => {
|
|
151
|
+
const old = rows.get(row.toolKey);
|
|
152
|
+
return (POLICY_RANK[row.policy] < POLICY_RANK[old?.policy ?? "allow"] ||
|
|
153
|
+
POLICY_RANK[row.unattendedPolicy] < POLICY_RANK[old?.unattendedPolicy ?? "allow"]);
|
|
154
|
+
}) ||
|
|
155
|
+
patch.gitPush?.some(({ target, denied }) => !denied && before.gitPushDenials.includes(target))))
|
|
156
|
+
throw new ApiError("org.security_widening_not_allowed", "Open /settings/security on the web to widen the organization security settings");
|
|
157
|
+
if (patch.tools?.length) {
|
|
158
|
+
const catalog = await this.toolSources(orgId);
|
|
159
|
+
for (const { toolKey } of patch.tools) {
|
|
160
|
+
if (!rows.has(toolKey) && !catalog.has(toolKey))
|
|
161
|
+
throw new ApiError("validation_failed", "Choose a canonical tool key from the security tool catalog", [{ path: "tools", toolKey }]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const newlyDenied = patch.tools?.filter(({ toolKey, policy }) => policy === "deny" && rows.get(toolKey)?.policy !== "deny") ?? [];
|
|
165
|
+
if (newlyDenied.length) {
|
|
166
|
+
const affected = (await Promise.all(newlyDenied.map(async ({ toolKey }) => ({
|
|
167
|
+
toolKey,
|
|
168
|
+
agents: await this.toolImpact.affectedAgents(orgId, toolKey),
|
|
169
|
+
})))).filter(({ agents }) => agents.length > 0);
|
|
170
|
+
if (affected.length) {
|
|
171
|
+
const confirmation = digest([
|
|
172
|
+
orgId,
|
|
173
|
+
actor,
|
|
174
|
+
{ ...patch, confirmation: undefined },
|
|
175
|
+
affected,
|
|
176
|
+
]);
|
|
177
|
+
if (patch.confirmation !== confirmation)
|
|
178
|
+
throw new ApiError("org.security_confirmation_required", "Review the affected agents before denying these tools", [{ confirmation, affected }]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await this.settings.updateSecurityCeilingsLocked(orgId, patch, actor, options.token, options.onlyNarrows === true, options.auditDetail);
|
|
182
|
+
for (const row of patch.tools ?? [])
|
|
183
|
+
await writeOrgToolPolicy(this.db.db, orgId, row, actor);
|
|
184
|
+
for (const { target, denied } of patch.gitPush ?? [])
|
|
185
|
+
await writeOrgGitPushDenial(this.db.db, orgId, target, denied, actor);
|
|
186
|
+
const after = await this.snapshot(orgId);
|
|
187
|
+
if (after.revision !== before.revision) {
|
|
188
|
+
await audit(this.db.db, {
|
|
189
|
+
actorAccountId: actor,
|
|
190
|
+
...(options.token && { actorTokenId: options.token }),
|
|
191
|
+
orgId,
|
|
192
|
+
action: "org.security_updated",
|
|
193
|
+
target: orgId,
|
|
194
|
+
detail: {
|
|
195
|
+
before: before.revision,
|
|
196
|
+
after: after.revision,
|
|
197
|
+
tools: patch.tools,
|
|
198
|
+
gitPush: patch.gitPush,
|
|
199
|
+
...options.auditDetail,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return { revision: after.revision };
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
__decorate([
|
|
207
|
+
Transactional({ propagation: "mandatory" })
|
|
208
|
+
], OrgSecuritySettingsService.prototype, "lock", null);
|
|
209
|
+
__decorate([
|
|
210
|
+
Transactional()
|
|
211
|
+
], OrgSecuritySettingsService.prototype, "updateLocked", null);
|
|
212
|
+
OrgSecuritySettingsService = __decorate([
|
|
213
|
+
Injectable(),
|
|
214
|
+
__param(0, Inject(KernelDb)),
|
|
215
|
+
__param(1, Inject(TransactionHost)),
|
|
216
|
+
__param(2, Inject(OrgLock)),
|
|
217
|
+
__param(3, Inject(PermissionCeilingWrites)),
|
|
218
|
+
__param(4, Inject(OrgSettingsService)),
|
|
219
|
+
__param(5, Inject(ToolRegistry)),
|
|
220
|
+
__param(6, Inject(PlatformOperations)),
|
|
221
|
+
__param(7, Inject(OrgToolSwitches))
|
|
222
|
+
], OrgSecuritySettingsService);
|
|
223
|
+
export { OrgSecuritySettingsService };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Principal } from "../identity/principal.js";
|
|
2
2
|
import { type OrgContext } from "./org.guard.js";
|
|
3
|
+
import { type OrgSecurityPatch, type OrgSecurityQuery, OrgSecuritySettingsService } from "./security-settings.service.js";
|
|
3
4
|
import { type OrgSettingsPatch, type OrgSettingsResponse, OrgSettingsService } from "./settings.service.js";
|
|
4
5
|
/** Organization settings, readable by members and writable by org admins. */
|
|
5
6
|
export declare class OrgSettingsController {
|
|
@@ -8,3 +9,35 @@ export declare class OrgSettingsController {
|
|
|
8
9
|
get(principal: Principal, org: OrgContext): Promise<OrgSettingsResponse>;
|
|
9
10
|
update(principal: Principal, org: OrgContext, body: OrgSettingsPatch): Promise<OrgSettingsResponse>;
|
|
10
11
|
}
|
|
12
|
+
/** Organization security ceilings require the organization admin role even for reads. */
|
|
13
|
+
export declare class OrgSecuritySettingsController {
|
|
14
|
+
private readonly security;
|
|
15
|
+
constructor(security: OrgSecuritySettingsService);
|
|
16
|
+
get(org: OrgContext, query: OrgSecurityQuery): Promise<{
|
|
17
|
+
gitPushDenials: string[];
|
|
18
|
+
revision: string;
|
|
19
|
+
tools: {
|
|
20
|
+
toolKey: string;
|
|
21
|
+
source: "builtin" | "connector" | "extension" | "operation" | "unavailable";
|
|
22
|
+
policy: import("../tools/org-tool-policies.js").OrgToolPolicy;
|
|
23
|
+
unattendedPolicy: import("../tools/org-tool-policies.js").OrgToolPolicy;
|
|
24
|
+
}[];
|
|
25
|
+
nextCursor: string | null;
|
|
26
|
+
allowedProfiles: {
|
|
27
|
+
configured: ("approve-for-me" | "full-access" | "request-approval")[] | null;
|
|
28
|
+
platform: import("@capybara-hq/plugin-sdk").PermissionProfile[];
|
|
29
|
+
effective: import("@capybara-hq/plugin-sdk").PermissionProfile[];
|
|
30
|
+
source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
|
|
31
|
+
};
|
|
32
|
+
projectReach: {
|
|
33
|
+
configured: "machine" | "paths" | "workspace" | null;
|
|
34
|
+
platform: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
|
|
35
|
+
effective: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
|
|
36
|
+
source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
|
|
37
|
+
limitingLayer: "org" | "platform";
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
update(principal: Principal, org: OrgContext, body: OrgSecurityPatch): Promise<{
|
|
41
|
+
revision: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
@@ -10,8 +10,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Controller, Get, Inject, Patch } from "@nestjs/common";
|
|
11
11
|
import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
|
|
12
12
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
13
|
-
import { ZBody } from "../infra/validation/zod-params.js";
|
|
13
|
+
import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
|
|
14
14
|
import { CurrentOrg, OrgAction } from "./org.guard.js";
|
|
15
|
+
import { OrgSecurityPatchSchema, OrgSecurityQuerySchema, OrgSecuritySettingsService, } from "./security-settings.service.js";
|
|
15
16
|
import { OrgSettingsPatchSchema, OrgSettingsService, } from "./settings.service.js";
|
|
16
17
|
class OrgSettingsPatchBody extends createZodDto(OrgSettingsPatchSchema, "OrgSettingsPatch") {
|
|
17
18
|
}
|
|
@@ -54,3 +55,42 @@ OrgSettingsController = __decorate([
|
|
|
54
55
|
__param(0, Inject(OrgSettingsService))
|
|
55
56
|
], OrgSettingsController);
|
|
56
57
|
export { OrgSettingsController };
|
|
58
|
+
class OrgSecurityQueryDto extends createZodDto(OrgSecurityQuerySchema, "OrgSecurityQuery") {
|
|
59
|
+
}
|
|
60
|
+
class OrgSecurityPatchDto extends createZodDto(OrgSecurityPatchSchema, "OrgSecurityPatch") {
|
|
61
|
+
}
|
|
62
|
+
/** Organization security ceilings require the organization admin role even for reads. */
|
|
63
|
+
let OrgSecuritySettingsController = class OrgSecuritySettingsController {
|
|
64
|
+
security;
|
|
65
|
+
constructor(security) {
|
|
66
|
+
this.security = security;
|
|
67
|
+
}
|
|
68
|
+
get(org, query) {
|
|
69
|
+
return this.security.view(org.orgId, query);
|
|
70
|
+
}
|
|
71
|
+
update(principal, org, body) {
|
|
72
|
+
const user = requireUser(principal);
|
|
73
|
+
const token = patTokenId(user);
|
|
74
|
+
return this.security.update(org.orgId, body, user.account.id, {
|
|
75
|
+
...(token !== undefined && { token, onlyNarrows: true }),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
__decorate([
|
|
80
|
+
Get(),
|
|
81
|
+
OrgAction("org.update"),
|
|
82
|
+
__param(0, CurrentOrg()),
|
|
83
|
+
__param(1, ZQuery(OrgSecurityQueryDto))
|
|
84
|
+
], OrgSecuritySettingsController.prototype, "get", null);
|
|
85
|
+
__decorate([
|
|
86
|
+
Patch(),
|
|
87
|
+
OrgAction("org.update"),
|
|
88
|
+
__param(0, CurrentPrincipal()),
|
|
89
|
+
__param(1, CurrentOrg()),
|
|
90
|
+
__param(2, ZBody(OrgSecurityPatchDto))
|
|
91
|
+
], OrgSecuritySettingsController.prototype, "update", null);
|
|
92
|
+
OrgSecuritySettingsController = __decorate([
|
|
93
|
+
Controller("api/v1/orgs/:orgId/settings/security"),
|
|
94
|
+
__param(0, Inject(OrgSecuritySettingsService))
|
|
95
|
+
], OrgSecuritySettingsController);
|
|
96
|
+
export { OrgSecuritySettingsController };
|
|
@@ -9,7 +9,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
9
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
10
10
|
import type { KernelLogger } from "../log.js";
|
|
11
11
|
import { type DeviceNetworkMode } from "../sandbox/device-sandbox.js";
|
|
12
|
-
import { type DevicesNetworkView, type DevicesOutsideSandboxView } from "../sandbox/device-sandbox-settings.js";
|
|
12
|
+
import { type DeviceSandboxSettingsView, type DevicesNetworkView, type DevicesOutsideSandboxView } from "../sandbox/device-sandbox-settings.js";
|
|
13
13
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
14
14
|
import { type ExternalSharingView } from "../shares/settings.js";
|
|
15
15
|
import { type DeviceNetworkSetting } from "./device-network-setting.js";
|
|
@@ -23,9 +23,6 @@ import { type OrgRole } from "./roles.js";
|
|
|
23
23
|
* (D11, default on).
|
|
24
24
|
* - `locale`: the org's default language (`zh` / `en`, default en); the bot's fixed phrases in IM
|
|
25
25
|
* follow it.
|
|
26
|
-
* - `sandboxToolPolicy`: the default policy of the sandbox tools (M5 T8, default allow). With
|
|
27
|
-
* `ask`, every tool but the read-only `Read` / `Glob` / `Grep` needs approval (read live at
|
|
28
|
-
* execution). An invalid stored value reads as `ask` (narrower, never wider) and is logged.
|
|
29
26
|
* - `wakeOnBackgroundTask`: the org's override of `runtime.wakeOnBackgroundTask` (absent follows
|
|
30
27
|
* the deployment), see {@link effectiveWakeOnBackgroundTask}.
|
|
31
28
|
* - `outsideSandbox`: whether devices of the org may be granted running a call outside their
|
|
@@ -76,12 +73,7 @@ export declare const OrgThemeSettingSchema: z.ZodObject<{
|
|
|
76
73
|
export type OrgThemeSetting = z.infer<typeof OrgThemeSettingSchema>;
|
|
77
74
|
/** The theme setting of an org that has none: follow the platform, personal picks allowed. */
|
|
78
75
|
export declare const DEFAULT_ORG_THEME: OrgThemeSetting;
|
|
79
|
-
/**
|
|
80
|
-
* Org settings of automations (spec §9); every field reads leniently (invalid = default,
|
|
81
|
-
* except `forbiddenTools`, which keeps its valid entries). A stored `forbiddenTools` that is not a
|
|
82
|
-
* list (or a group that is not an object) reads as `[]` here, for display; enforcement checks
|
|
83
|
-
* {@link invalidStoredForbiddenTools} and fails unattended runs instead (never wider).
|
|
84
|
-
*/
|
|
76
|
+
/** Organization automation settings with per-field defaults. */
|
|
85
77
|
export declare const AutomationsSettingsSchema: z.ZodObject<{
|
|
86
78
|
enabled: z.ZodCatch<z.ZodDefault<z.ZodBoolean>>;
|
|
87
79
|
minIntervalMinutes: z.ZodCatch<z.ZodDefault<z.ZodNumber>>;
|
|
@@ -104,12 +96,11 @@ export declare const AutomationsSettingsSchema: z.ZodObject<{
|
|
|
104
96
|
off: "off";
|
|
105
97
|
}>>>;
|
|
106
98
|
eventSourcesOff: z.ZodCatch<z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodString>>, unknown>>;
|
|
107
|
-
forbiddenTools: z.ZodCatch<z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodString>>, unknown>>;
|
|
108
99
|
}, z.core.$strip>;
|
|
109
100
|
export type AutomationsSettings = z.infer<typeof AutomationsSettingsSchema>;
|
|
110
101
|
/**
|
|
111
102
|
* The PATCH form: a partial merge into the group (fields left out keep their stored value; see
|
|
112
|
-
* `OrgSettingsService.update`). A field
|
|
103
|
+
* `OrgSettingsService.update`). A supplied field replaces that field.
|
|
113
104
|
*/
|
|
114
105
|
export declare const AutomationsPatchSchema: z.ZodObject<{
|
|
115
106
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -133,7 +124,6 @@ export declare const AutomationsPatchSchema: z.ZodObject<{
|
|
|
133
124
|
off: "off";
|
|
134
125
|
}>>;
|
|
135
126
|
eventSourcesOff: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
136
|
-
forbiddenTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
137
127
|
}, z.core.$strict>;
|
|
138
128
|
/**
|
|
139
129
|
* The org's git gateway setting (sandbox git credentials spec §9): `enabled: false` switches the
|
|
@@ -179,15 +169,21 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
179
169
|
en: "en";
|
|
180
170
|
zh: "zh";
|
|
181
171
|
}>>>;
|
|
182
|
-
sandboxToolPolicy: z.ZodCatch<z.ZodDefault<z.ZodEnum<{
|
|
183
|
-
allow: "allow";
|
|
184
|
-
ask: "ask";
|
|
185
|
-
}>>>;
|
|
186
172
|
platformTool: z.ZodCatch<z.ZodDefault<z.ZodEnum<{
|
|
187
173
|
off: "off";
|
|
188
174
|
on: "on";
|
|
189
175
|
"read-only": "read-only";
|
|
190
176
|
}>>>;
|
|
177
|
+
allowedProfiles: z.ZodCatch<z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodEnum<{
|
|
178
|
+
"approve-for-me": "approve-for-me";
|
|
179
|
+
"full-access": "full-access";
|
|
180
|
+
"request-approval": "request-approval";
|
|
181
|
+
}>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>>;
|
|
182
|
+
projectReach: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
|
|
183
|
+
machine: "machine";
|
|
184
|
+
paths: "paths";
|
|
185
|
+
workspace: "workspace";
|
|
186
|
+
}>>>;
|
|
191
187
|
outsideSandbox: z.ZodCatch<z.ZodOptional<z.ZodEnum<{
|
|
192
188
|
allowed: "allowed";
|
|
193
189
|
off: "off";
|
|
@@ -266,7 +262,6 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
266
262
|
off: "off";
|
|
267
263
|
}>>>;
|
|
268
264
|
eventSourcesOff: z.ZodCatch<z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodString>>, unknown>>;
|
|
269
|
-
forbiddenTools: z.ZodCatch<z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodString>>, unknown>>;
|
|
270
265
|
}, z.core.$strip>>>;
|
|
271
266
|
compaction: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
272
267
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -291,18 +286,21 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
291
286
|
on: "on";
|
|
292
287
|
}>>>;
|
|
293
288
|
}, z.core.$strip>;
|
|
289
|
+
export declare const OrgSecurityCeilingsPatchSchema: z.ZodObject<{
|
|
290
|
+
allowedProfiles: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodArray<z.ZodEnum<{
|
|
291
|
+
"approve-for-me": "approve-for-me";
|
|
292
|
+
"full-access": "full-access";
|
|
293
|
+
"request-approval": "request-approval";
|
|
294
|
+
}>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>>;
|
|
295
|
+
projectReach: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
296
|
+
machine: "machine";
|
|
297
|
+
paths: "paths";
|
|
298
|
+
workspace: "workspace";
|
|
299
|
+
}>>>;
|
|
300
|
+
}, z.core.$strip>;
|
|
301
|
+
export type OrgSecurityCeilingsPatch = z.infer<typeof OrgSecurityCeilingsPatchSchema>;
|
|
294
302
|
export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
|
|
295
|
-
|
|
296
|
-
* The settings as the responses carry them: {@link OrgSettings} plus
|
|
297
|
-
* `automations.forbiddenToolsUnreadable: true` when the stored list cannot be read
|
|
298
|
-
* ({@link invalidStoredForbiddenTools}; `forbiddenTools` then reads `[]`), so the settings page
|
|
299
|
-
* says so and saves the list. Never stored.
|
|
300
|
-
*/
|
|
301
|
-
export type OrgSettingsView = OrgSettings & {
|
|
302
|
-
automations: OrgSettings["automations"] & {
|
|
303
|
-
forbiddenToolsUnreadable?: true;
|
|
304
|
-
};
|
|
305
|
-
};
|
|
303
|
+
export type OrgSettingsView = OrgSettings;
|
|
306
304
|
/** PATCH 体:只改给出的字段;未知字段 → 400。 */
|
|
307
305
|
export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
308
306
|
toolSearch: z.ZodOptional<z.ZodEnum<{
|
|
@@ -313,10 +311,6 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
313
311
|
en: "en";
|
|
314
312
|
zh: "zh";
|
|
315
313
|
}>>;
|
|
316
|
-
sandboxToolPolicy: z.ZodOptional<z.ZodEnum<{
|
|
317
|
-
allow: "allow";
|
|
318
|
-
ask: "ask";
|
|
319
|
-
}>>;
|
|
320
314
|
platformTool: z.ZodOptional<z.ZodEnum<{
|
|
321
315
|
off: "off";
|
|
322
316
|
on: "on";
|
|
@@ -384,7 +378,6 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
384
378
|
off: "off";
|
|
385
379
|
}>>;
|
|
386
380
|
eventSourcesOff: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
387
|
-
forbiddenTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
388
381
|
}, z.core.$strict>>;
|
|
389
382
|
compaction: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
390
383
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -434,6 +427,8 @@ export interface OrgEffectiveNetwork {
|
|
|
434
427
|
}
|
|
435
428
|
/** The deployment defaults the settings page shows for "follow the platform" (`GET` returns them). */
|
|
436
429
|
export interface OrgSettingsDeployment {
|
|
430
|
+
allowedProfiles: DeviceSandboxSettingsView["allowedProfiles"];
|
|
431
|
+
projectReach: DeviceSandboxSettingsView["projectReach"];
|
|
437
432
|
/** The platform's outside-sandbox ceiling and where it comes from. */
|
|
438
433
|
outsideSandbox: DevicesOutsideSandboxView;
|
|
439
434
|
/**
|
|
@@ -477,32 +472,8 @@ export interface OrgSettingsResponse {
|
|
|
477
472
|
export declare function parseOrgSettings(raw: unknown): OrgSettings;
|
|
478
473
|
/** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
|
|
479
474
|
export declare function readStoredOrgSettings(db: KernelSchemaDb, orgId: string): Promise<unknown>;
|
|
480
|
-
/**
|
|
481
|
-
|
|
482
|
-
* a missing or deleted org reads as the defaults. With `log`, an
|
|
483
|
-
* unreadable security setting ({@link logUnreadableSecuritySettings}) is logged.
|
|
484
|
-
*/
|
|
485
|
-
export declare function readOrgSettings(db: KernelSchemaDb, orgId: string,
|
|
486
|
-
/** Per-call paths (the tool policy) log at debug; the settings reads and the fire warn. */
|
|
487
|
-
log?: Pick<KernelLogger, "debug">): Promise<OrgSettings>;
|
|
488
|
-
/** Whether a stored settings object holds a `sandboxToolPolicy` this version reads as `ask`. */
|
|
489
|
-
export declare function invalidStoredSandboxToolPolicy(raw: unknown): boolean;
|
|
490
|
-
/**
|
|
491
|
-
* Whether the stored automation `forbiddenTools` cannot be read: the group or the field is
|
|
492
|
-
* present but not an object / a list. Unattended runs of such an org fail
|
|
493
|
-
* ({@link FORBIDDEN_TOOLS_UNREADABLE_ERROR}) rather than run with nothing forbidden. Invalid
|
|
494
|
-
* entries inside a list are dropped instead (the valid ones stay forbidden).
|
|
495
|
-
*/
|
|
496
|
-
export declare function invalidStoredForbiddenTools(raw: unknown): boolean;
|
|
497
|
-
/** The refusal of an unattended run of an org whose `forbiddenTools` cannot be read. */
|
|
498
|
-
export declare const FORBIDDEN_TOOLS_UNREADABLE_ERROR = "The organization's forbidden tool list for automations is unreadable, so this scheduled run cannot continue; an org admin must save the list again in the organization's automation settings.";
|
|
499
|
-
/** The refusal of a new task grant while the org's `forbiddenTools` cannot be read. */
|
|
500
|
-
export declare const FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR = "The organization's forbidden tool list for automations is unreadable, so no tool can be approved for a task now; an org admin must save the list again in the organization's automation settings.";
|
|
501
|
-
/**
|
|
502
|
-
* Logs (through `log`, at the caller's level) the security settings a stored value reads narrower
|
|
503
|
-
* than written, with the org id.
|
|
504
|
-
*/
|
|
505
|
-
export declare function logUnreadableSecuritySettings(log: (msg: string, fields: Record<string, unknown>) => void, orgId: string, raw: unknown): void;
|
|
475
|
+
/** Reads the org settings live; a missing or deleted org reads as the defaults. */
|
|
476
|
+
export declare function readOrgSettings(db: KernelSchemaDb, orgId: string): Promise<OrgSettings>;
|
|
506
477
|
/** Whether a stored settings object holds an `externalSharing` this version reads as `off`. */
|
|
507
478
|
export declare function invalidStoredExternalSharing(raw: unknown): boolean;
|
|
508
479
|
/** Whether a stored settings object holds a `promptSuggestions` this version reads as `off`. */
|
|
@@ -574,12 +545,26 @@ export declare class OrgSettingsService {
|
|
|
574
545
|
strict: false;
|
|
575
546
|
}): Pick<ExtensionPointDefaults, "providersFor">;
|
|
576
547
|
} | undefined);
|
|
577
|
-
/** Parses stored settings
|
|
578
|
-
* invalid `deviceNetwork` to an empty allowlist, or a security setting reads narrower
|
|
579
|
-
* ({@link logUnreadableSecuritySettings}, warn). */
|
|
548
|
+
/** Parses stored settings and warns when malformed network or capability fields narrow. */
|
|
580
549
|
private parseStored;
|
|
581
550
|
/** The deployment defaults (what "follow the platform" means on the settings page). */
|
|
582
551
|
deployment(): Promise<OrgSettingsDeployment>;
|
|
552
|
+
securityCeilings(orgId: string): Promise<{
|
|
553
|
+
allowedProfiles: {
|
|
554
|
+
configured: ("approve-for-me" | "full-access" | "request-approval")[] | null;
|
|
555
|
+
platform: import("@capybara-hq/plugin-sdk").PermissionProfile[];
|
|
556
|
+
effective: import("@capybara-hq/plugin-sdk").PermissionProfile[];
|
|
557
|
+
source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
|
|
558
|
+
};
|
|
559
|
+
projectReach: {
|
|
560
|
+
configured: "machine" | "paths" | "workspace" | null;
|
|
561
|
+
platform: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
|
|
562
|
+
effective: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
|
|
563
|
+
source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
|
|
564
|
+
limitingLayer: "org" | "platform";
|
|
565
|
+
};
|
|
566
|
+
}>;
|
|
567
|
+
updateSecurityCeilingsLocked(orgId: string, patch: OrgSecurityCeilingsPatch, actor: string, token: string | undefined, onlyNarrows: boolean, auditDetail: Record<string, unknown> | undefined): Promise<void>;
|
|
583
568
|
/** Whether prompt suggestions run for the org now: one read of the platform and of the org. */
|
|
584
569
|
promptSuggestionsEnabled(orgId: string): Promise<boolean>;
|
|
585
570
|
/**
|