@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.
Files changed (113) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +14 -0
  3. package/dist/automations/automations.service.js +15 -21
  4. package/dist/automations/effective-settings.d.ts +3 -9
  5. package/dist/automations/effective-settings.js +3 -5
  6. package/dist/automations/fire.js +0 -11
  7. package/dist/automations/grant-rules.d.ts +7 -10
  8. package/dist/automations/grant-rules.js +9 -18
  9. package/dist/automations/unattended.d.ts +1 -4
  10. package/dist/automations/unattended.js +0 -2
  11. package/dist/catalog/org-extension.controller.d.ts +1 -20
  12. package/dist/catalog/org-extension.controller.js +1 -48
  13. package/dist/catalog/org-extension.schemas.d.ts +1 -9
  14. package/dist/catalog/org-extension.schemas.js +1 -17
  15. package/dist/config/schema.d.ts +12 -0
  16. package/dist/config/schema.js +16 -0
  17. package/dist/conversations/approval-profile.d.ts +8 -1
  18. package/dist/conversations/approval-profile.js +20 -0
  19. package/dist/conversations/conversations.service.d.ts +1 -1
  20. package/dist/conversations/conversations.service.js +8 -3
  21. package/dist/conversations/events.d.ts +25 -1
  22. package/dist/conversations/events.js +7 -2
  23. package/dist/conversations/permission-profiles.controller.d.ts +4 -0
  24. package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
  25. package/dist/conversations/permission-profiles.schemas.js +8 -0
  26. package/dist/conversations/permission-profiles.service.d.ts +8 -1
  27. package/dist/conversations/permission-profiles.service.js +13 -1
  28. package/dist/db/kernel-schema.d.ts +21 -0
  29. package/dist/device-access/device-access.service.d.ts +4 -1
  30. package/dist/device-access/device-access.service.js +26 -7
  31. package/dist/device-access/viewer.d.ts +3 -1
  32. package/dist/device-access/viewer.js +18 -9
  33. package/dist/errors.d.ts +6 -0
  34. package/dist/errors.js +6 -0
  35. package/dist/git/gateway.d.ts +8 -1
  36. package/dist/git/gateway.js +68 -11
  37. package/dist/git/git.module.d.ts +2 -3
  38. package/dist/git/git.module.js +4 -4
  39. package/dist/http/api.module.js +3 -3
  40. package/dist/identity/settings.d.ts +20 -5
  41. package/dist/identity/settings.js +52 -9
  42. package/dist/infra/config/kernel-config.service.js +4 -0
  43. package/dist/orgs/orgs.module.js +12 -1
  44. package/dist/orgs/orgs.schemas.js +3 -0
  45. package/dist/orgs/security-settings.service.d.ts +94 -0
  46. package/dist/orgs/security-settings.service.js +223 -0
  47. package/dist/orgs/settings.controller.d.ts +33 -0
  48. package/dist/orgs/settings.controller.js +41 -1
  49. package/dist/orgs/settings.service.d.ts +48 -63
  50. package/dist/orgs/settings.service.js +86 -103
  51. package/dist/platform/exclusions.js +1 -1
  52. package/dist/platform/operation.js +4 -0
  53. package/dist/platform/ops/admin.ops.js +18 -4
  54. package/dist/platform/ops/connectors.ops.js +2 -2
  55. package/dist/platform/ops/extensions.ops.d.ts +1 -3
  56. package/dist/platform/ops/extensions.ops.js +4 -131
  57. package/dist/platform/ops/org-settings.ops.d.ts +3 -1
  58. package/dist/platform/ops/org-settings.ops.js +76 -3
  59. package/dist/platform/ops/orgs.ops.js +2 -0
  60. package/dist/runtime/context/permission-profile.js +6 -0
  61. package/dist/runtime/subagents/dispatch.d.ts +3 -0
  62. package/dist/runtime/subagents/dispatch.js +2 -1
  63. package/dist/runtime/subagents/messages.d.ts +3 -1
  64. package/dist/runtime/subagents/messages.js +9 -6
  65. package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
  66. package/dist/sandbox/device-sandbox-settings.js +64 -1
  67. package/dist/sandbox/device-sandbox.d.ts +9 -1
  68. package/dist/sandbox/device-sandbox.js +17 -2
  69. package/dist/sandbox/device-services.d.ts +26 -3
  70. package/dist/sandbox/device-services.js +95 -16
  71. package/dist/sandbox/loopback-grant-records.d.ts +3 -2
  72. package/dist/sandbox/loopback-grant-records.js +32 -5
  73. package/dist/sandbox/operation-authority.d.ts +3 -2
  74. package/dist/sandbox/operation-authority.js +21 -1
  75. package/dist/sandbox/operation-intents.js +5 -1
  76. package/dist/sandbox/permission-call-types.d.ts +2 -1
  77. package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
  78. package/dist/sandbox/permission-ceiling-writes.js +122 -13
  79. package/dist/sandbox/permission-config-publication.d.ts +10 -0
  80. package/dist/sandbox/permission-config-publication.js +27 -5
  81. package/dist/sandbox/permission-facts.d.ts +21 -2
  82. package/dist/sandbox/permission-facts.js +101 -9
  83. package/dist/sandbox/permission-transitions.d.ts +1 -1
  84. package/dist/sandbox/sandbox.service.d.ts +2 -2
  85. package/dist/sandbox/sandbox.service.js +7 -3
  86. package/dist/tools/admin-connectors.js +2 -2
  87. package/dist/tools/approvals.service.d.ts +7 -2
  88. package/dist/tools/approvals.service.js +39 -7
  89. package/dist/tools/builtin-names.d.ts +0 -6
  90. package/dist/tools/builtin-names.js +0 -11
  91. package/dist/tools/builtins/sandbox/index.d.ts +3 -5
  92. package/dist/tools/builtins/sandbox/index.js +3 -5
  93. package/dist/tools/connector-account-policies.js +7 -4
  94. package/dist/tools/connectors.controller.d.ts +0 -6
  95. package/dist/tools/connectors.schemas.d.ts +1 -8
  96. package/dist/tools/connectors.schemas.js +1 -4
  97. package/dist/tools/connectors.service.d.ts +3 -7
  98. package/dist/tools/connectors.service.js +29 -44
  99. package/dist/tools/drift.js +12 -4
  100. package/dist/tools/git-push-policy.d.ts +1 -4
  101. package/dist/tools/git-push-policy.js +4 -5
  102. package/dist/tools/org-tool-policies.d.ts +24 -0
  103. package/dist/tools/org-tool-policies.js +113 -0
  104. package/dist/tools/org-tool-switches.d.ts +5 -70
  105. package/dist/tools/org-tool-switches.js +13 -141
  106. package/dist/tools/pipeline.d.ts +11 -5
  107. package/dist/tools/pipeline.js +173 -38
  108. package/dist/tools/policy.d.ts +3 -7
  109. package/dist/tools/policy.js +29 -48
  110. package/dist/tools/registry.d.ts +5 -0
  111. package/dist/tools/registry.js +44 -13
  112. package/package.json +1 -1
  113. package/src/migrations/0212_org_security_policy.sql +234 -0
@@ -16,9 +16,13 @@ import { productName } from "../config/product-name.js";
16
16
  import { audit } from "../identity/audit.js";
17
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
18
18
  import { KernelDb } from "../infra/database/kernel-db.js";
19
+ import { withOrgScope } from "../infra/database/org-scope.js";
20
+ import { TransactionHost } from "../infra/database/transaction-host.js";
21
+ import { Transactional } from "../infra/database/transactional.decorator.js";
19
22
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
20
23
  import { NetDeniedError } from "../net/public-address.js";
21
24
  import { safeFetch } from "../net/safe-fetch.js";
25
+ import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
22
26
  import { CredentialMissing, Credentials } from "../tools/credentials.js";
23
27
  import { gitAskedNote, gitNotConnectedNote, gitPolicyDeniedNote, gitUnattendedNote, recordGitAsk, } from "../tools/git-asks.js";
24
28
  import { decideGitPush } from "../tools/git-push-policy.js";
@@ -273,17 +277,21 @@ let GitGateway = class GitGateway {
273
277
  sources;
274
278
  credentials;
275
279
  db;
280
+ txHost;
281
+ authority;
276
282
  redis;
277
283
  config;
278
284
  log;
279
285
  upstreamOrigin;
280
- constructor(tickets, sources, credentials, db, redis,
286
+ constructor(tickets, sources, credentials, db, txHost, authority, redis,
281
287
  /** Read per request: `tools.git.*` is read live. */
282
288
  config, log, upstreamOrigin) {
283
289
  this.tickets = tickets;
284
290
  this.sources = sources;
285
291
  this.credentials = credentials;
286
292
  this.db = db;
293
+ this.txHost = txHost;
294
+ this.authority = authority;
287
295
  this.redis = redis;
288
296
  this.config = config;
289
297
  this.log = log;
@@ -335,6 +343,10 @@ let GitGateway = class GitGateway {
335
343
  if (!repoAllowed(binding.repos, target.repo)) {
336
344
  return this.done(text(403, repoRefused(target.repo)), fields, started);
337
345
  }
346
+ return withOrgScope(binding.orgId, () => this.handleBound(req, reply, binding, target, { started, fields, body, text, said }));
347
+ }
348
+ async handleBound(req, reply, binding, target, request) {
349
+ const { started, fields, body, text, said } = request;
338
350
  // the source is looked up on every request (the ticket's hosts are only an upper bound)
339
351
  const source = (await this.sources.sourcesFor(binding.orgId, binding.accountId)).find((s) => s.host === target.host);
340
352
  if (source === undefined) {
@@ -493,6 +505,7 @@ let GitGateway = class GitGateway {
493
505
  };
494
506
  const { meter, touch, ac } = transfer;
495
507
  let upstreamBody = c.body;
508
+ let refusePush;
496
509
  // pushes: the policy decides before any byte reaches the host
497
510
  if (target.service === "git-receive-pack") {
498
511
  if (target.endpoint === "info/refs") {
@@ -539,9 +552,8 @@ let GitGateway = class GitGateway {
539
552
  // a flush-only request updates nothing: not an attempt, not an error
540
553
  push.result = refs.length === 0 ? "empty" : "error";
541
554
  if (refs.length > 0) {
542
- const decision = await this.decide(binding, source, target);
543
- fields.push = decision.reason;
544
- if (decision.decision !== "allow") {
555
+ refusePush = async (decision) => {
556
+ fields.push = decision.reason;
545
557
  await this.recordRefusal(binding, source, target, refs, decision);
546
558
  push.result = `refused:${decision.reason}`;
547
559
  const note = refusalNote(target.repo, refs, decision);
@@ -558,8 +570,11 @@ let GitGateway = class GitGateway {
558
570
  .header("content-type", "application/x-git-receive-pack-result")
559
571
  .header("cache-control", "no-cache")
560
572
  .send(receivePackRefusal(parsed.capabilities, refs, said(note), decision.decision === "ask" ? "needs approval" : "not allowed"));
561
- return;
562
- }
573
+ };
574
+ const decision = await this.decide(binding, source, target);
575
+ fields.push = decision.reason;
576
+ if (decision.decision !== "allow")
577
+ return refusePush(decision);
563
578
  }
564
579
  // the bytes already read go first, then the rest of the body as it arrives
565
580
  upstreamBody = Readable.from((async function* () {
@@ -610,6 +625,12 @@ let GitGateway = class GitGateway {
610
625
  let value = "";
611
626
  try {
612
627
  value = await authorization();
628
+ if (refusePush !== undefined) {
629
+ const decision = await this.admitPush(binding, source, target, push.refs, ac.signal);
630
+ fields.push = decision.reason;
631
+ if (decision.decision !== "allow")
632
+ return refusePush(decision);
633
+ }
613
634
  res = await send(value);
614
635
  if (res.status === 401 && req.method === "GET") {
615
636
  // one forced refresh and one retry; a POST body is not replayable
@@ -690,6 +711,37 @@ let GitGateway = class GitGateway {
690
711
  if (fields.broken === undefined && push.result !== "empty")
691
712
  pushResult("ok");
692
713
  }
714
+ /** Commit the push intent under the same authority lock as an org security edit. */
715
+ async admitPush(binding, source, target, refs, signal) {
716
+ const org = await this.db.db
717
+ .selectFrom("orgs")
718
+ .select("id")
719
+ .where("id", "=", binding.orgId)
720
+ .where("deleted_at", "is", null)
721
+ .forKeyShare()
722
+ .executeTakeFirst();
723
+ if (org === undefined)
724
+ return { decision: "deny", reason: "unavailable", repo: target.repo };
725
+ await this.authority.acquire({ orgId: binding.orgId }, { kind: "admit" });
726
+ signal.throwIfAborted();
727
+ const decision = await this.decide(binding, source, target);
728
+ if (decision.decision === "allow") {
729
+ signal.throwIfAborted();
730
+ await audit(this.db.db, {
731
+ actorAccountId: binding.accountId,
732
+ orgId: binding.orgId,
733
+ action: "git.push_admitted",
734
+ target: `${target.host}/${target.repo}`,
735
+ detail: {
736
+ runId: binding.runId,
737
+ connectorId: source.connectorId,
738
+ refs,
739
+ reason: decision.reason,
740
+ },
741
+ });
742
+ }
743
+ return decision;
744
+ }
693
745
  /** The push decision for this target (spec §7). */
694
746
  decide(binding, source, target) {
695
747
  return decideGitPush(this.db.db, this.config, {
@@ -735,17 +787,22 @@ let GitGateway = class GitGateway {
735
787
  return row === undefined ? null : row.auth;
736
788
  }
737
789
  };
790
+ __decorate([
791
+ Transactional()
792
+ ], GitGateway.prototype, "admitPush", null);
738
793
  GitGateway = __decorate([
739
794
  Injectable(),
740
795
  __param(0, Inject(GitTickets)),
741
796
  __param(1, Inject(GitSources)),
742
797
  __param(2, Inject(Credentials)),
743
798
  __param(3, Inject(KernelDb)),
744
- __param(4, Inject(REDIS)),
745
- __param(5, Inject(KernelConfigService)),
746
- __param(6, Inject(KERNEL_LOGGER)),
747
- __param(7, Optional()),
748
- __param(7, Inject(GIT_UPSTREAM_ORIGIN))
799
+ __param(4, Inject(TransactionHost)),
800
+ __param(5, Inject(PermissionAuthorityLock)),
801
+ __param(6, Inject(REDIS)),
802
+ __param(7, Inject(KernelConfigService)),
803
+ __param(8, Inject(KERNEL_LOGGER)),
804
+ __param(9, Optional()),
805
+ __param(9, Inject(GIT_UPSTREAM_ORIGIN))
749
806
  ], GitGateway);
750
807
  export { GitGateway };
751
808
  const defaultOrigin = (host) => `https://${host}`;
@@ -2,9 +2,8 @@
2
2
  * The git gateway (sandbox git credentials spec §5, §6): run tickets ({@link GitTickets}), whose
3
3
  * connector serves a git host for an actor ({@link GitSources}) and the commit identity
4
4
  * ({@link GitIdentities}), the gateway's relay ({@link GitGateway}, served by the api role's raw
5
- * route `/git/v1/*`) and the run-end cleanup ({@link GitRunEnd}). It needs only the global infra
6
- * and the connector credentials (`CredentialsModule`, not `ToolsModule`), so the api role (the
7
- * gateway route) and the runtime and tool code (which issue tickets) can import it without a cycle.
5
+ * route `/git/v1/*`) and the run-end cleanup ({@link GitRunEnd}). The relay uses connector
6
+ * credentials and the same permission authority lock as org security settings.
8
7
  */
9
8
  export declare class GitModule {
10
9
  }
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
+ import { PermissionCeilingWritesModule } from "../sandbox/permission-authority.module.js";
8
9
  import { CredentialsModule } from "../tools/credentials.module.js";
9
10
  import { GitGateway } from "./gateway.js";
10
11
  import { GitIdentities } from "./identity.js";
@@ -15,15 +16,14 @@ import { GitTickets } from "./tickets.js";
15
16
  * The git gateway (sandbox git credentials spec §5, §6): run tickets ({@link GitTickets}), whose
16
17
  * connector serves a git host for an actor ({@link GitSources}) and the commit identity
17
18
  * ({@link GitIdentities}), the gateway's relay ({@link GitGateway}, served by the api role's raw
18
- * route `/git/v1/*`) and the run-end cleanup ({@link GitRunEnd}). It needs only the global infra
19
- * and the connector credentials (`CredentialsModule`, not `ToolsModule`), so the api role (the
20
- * gateway route) and the runtime and tool code (which issue tickets) can import it without a cycle.
19
+ * route `/git/v1/*`) and the run-end cleanup ({@link GitRunEnd}). The relay uses connector
20
+ * credentials and the same permission authority lock as org security settings.
21
21
  */
22
22
  let GitModule = class GitModule {
23
23
  };
24
24
  GitModule = __decorate([
25
25
  Module({
26
- imports: [CredentialsModule],
26
+ imports: [CredentialsModule, PermissionCeilingWritesModule],
27
27
  providers: [GitTickets, GitSources, GitIdentities, GitGateway, GitRunEnd],
28
28
  exports: [GitTickets, GitSources, GitIdentities, GitGateway, GitRunEnd],
29
29
  })
@@ -34,7 +34,7 @@ import { CatalogModule } from "../catalog/catalog.module.js";
34
34
  import { AdminComponentsController, OrgComponentsController, } from "../catalog/component-scope.controller.js";
35
35
  import { MarketplacesController, OrgMarketplacesController, } from "../catalog/marketplaces.controller.js";
36
36
  import { AdminCatalogRequestsController, OrgCatalogController, } from "../catalog/org-catalog.controller.js";
37
- import { OrgExtensionConfigsController, OrgExtensionOverridesController, OrgExtensionToolSwitchesController, } from "../catalog/org-extension.controller.js";
37
+ import { OrgExtensionConfigsController, OrgExtensionOverridesController, } from "../catalog/org-extension.controller.js";
38
38
  import { OrgOwnedPluginsController, OrgPluginUploadsController, } from "../catalog/org-plugin-uploads.controller.js";
39
39
  import { ChannelsModule } from "../channels/channels.module.js";
40
40
  import { ChannelConnectionsController } from "../channels/connections.controller.js";
@@ -84,7 +84,7 @@ import { DirectorySyncController } from "../orgs/directory-sync.controller.js";
84
84
  import { InvitationsController } from "../orgs/invitations.controller.js";
85
85
  import { OrgsController } from "../orgs/orgs.controller.js";
86
86
  import { OrgsModule } from "../orgs/orgs.module.js";
87
- import { OrgSettingsController } from "../orgs/settings.controller.js";
87
+ import { OrgSecuritySettingsController, OrgSettingsController, } from "../orgs/settings.controller.js";
88
88
  import { PlatformModule } from "../platform/platform.module.js";
89
89
  import { SealedRevealsController } from "../platform/sealed-reveals.controller.js";
90
90
  import { PushHostModule } from "../push/provider-host.js";
@@ -135,6 +135,7 @@ const CONTROLLERS = [
135
135
  SealedRevealsController,
136
136
  OrgsController,
137
137
  OrgSettingsController,
138
+ OrgSecuritySettingsController,
138
139
  InvitationsController,
139
140
  SetupController,
140
141
  AdminController,
@@ -153,7 +154,6 @@ const CONTROLLERS = [
153
154
  OrgMarketplacesController,
154
155
  OrgExtensionConfigsController,
155
156
  OrgExtensionOverridesController,
156
- OrgExtensionToolSwitchesController,
157
157
  AgentsController,
158
158
  AgentTemplatesController,
159
159
  AgentSaveAsTemplateController,
@@ -6,7 +6,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
6
  import { KernelDb } from "../infra/database/kernel-db.js";
7
7
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
8
  import type { KernelLogger } from "../log.js";
9
- import { type DeviceSandboxSettingsView, type DevicesNetworkPatch, type DevicesNetworkStored, type DevicesNetworkView, type DevicesOutsideSandboxPatch, type DevicesOutsideSandboxStored, type DevicesOutsideSandboxView } from "../sandbox/device-sandbox-settings.js";
9
+ import { type AllowedProfilesView, DEVICES_ALLOWED_PROFILES_PATCH, DEVICES_PROJECT_REACH_PATCH, type DeviceSandboxSettingsView, type DevicesNetworkPatch, type DevicesNetworkView, type DevicesOutsideSandboxPatch, type DevicesOutsideSandboxView, type ProjectReachView, type StoredDeviceSandbox } from "../sandbox/device-sandbox-settings.js";
10
10
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
11
11
  import { type ExternalSharingView, type ShareMaxExpiryView } from "../shares/settings.js";
12
12
  import { type UiArrangement } from "../ui/arrangement.js";
@@ -211,6 +211,8 @@ export type DeploymentSettingsView = DeploymentSettings & {
211
211
  devicesOutsideSandbox: DevicesOutsideSandboxView;
212
212
  /** The sandbox network's default and ceiling (the default never above the ceiling). */
213
213
  devicesNetwork: DevicesNetworkView;
214
+ devicesAllowedProfiles: AllowedProfilesView;
215
+ devicesProjectReach: ProjectReachView;
214
216
  /** The device provider that makes a person's default device (null: none) and its source. */
215
217
  devicesDefaultProvider: DevicesDefaultProviderView;
216
218
  attribution: PlatformAttributionView;
@@ -286,6 +288,20 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
286
288
  open: "open";
287
289
  }>>>;
288
290
  }, z.core.$strict>>;
291
+ devicesAllowedProfiles: z.ZodOptional<z.ZodObject<{
292
+ value: z.ZodNullable<z.ZodPipe<z.ZodArray<z.ZodEnum<{
293
+ "approve-for-me": "approve-for-me";
294
+ "full-access": "full-access";
295
+ "request-approval": "request-approval";
296
+ }>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>;
297
+ }, z.core.$strict>>;
298
+ devicesProjectReach: z.ZodOptional<z.ZodObject<{
299
+ ceiling: z.ZodNullable<z.ZodEnum<{
300
+ machine: "machine";
301
+ paths: "paths";
302
+ workspace: "workspace";
303
+ }>>;
304
+ }, z.core.$strict>>;
289
305
  devicesDefaultProvider: z.ZodOptional<z.ZodObject<{
290
306
  provider: z.ZodNullable<z.ZodString>;
291
307
  }, z.core.$strict>>;
@@ -401,13 +417,12 @@ export declare class SettingsService {
401
417
  checkDeviceSandbox(patch: {
402
418
  devicesOutsideSandbox?: DevicesOutsideSandboxPatch | undefined;
403
419
  devicesNetwork?: DevicesNetworkPatch | undefined;
420
+ devicesAllowedProfiles?: z.infer<typeof DEVICES_ALLOWED_PROFILES_PATCH> | undefined;
421
+ devicesProjectReach?: z.infer<typeof DEVICES_PROJECT_REACH_PATCH> | undefined;
404
422
  }, opts?: {
405
423
  onlyNarrows?: boolean;
406
424
  }): Promise<{
407
- next: {
408
- outsideSandbox: DevicesOutsideSandboxStored;
409
- network: DevicesNetworkStored;
410
- };
425
+ next: StoredDeviceSandbox;
411
426
  before: DeviceSandboxSettingsView;
412
427
  after: DeviceSandboxSettingsView;
413
428
  }>;
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { EXTENSION_NAME_RE } from "@capybara-hq/plugin-sdk";
10
+ import { EXTENSION_NAME_RE, narrowerProjectReach } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { z } from "zod";
13
13
  import { applyPlatformAttributionPatch, PLATFORM_ATTRIBUTION_FIELDS, PLATFORM_ATTRIBUTION_PATCH, PLATFORM_ATTRIBUTION_SETTING, readStoredPlatformAttribution, resolvePlatformAttribution, } from "../attribution/platform-attribution.js";
@@ -19,8 +19,8 @@ import { KernelDb } from "../infra/database/kernel-db.js";
19
19
  import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
20
20
  import { Transactional } from "../infra/database/transactional.decorator.js";
21
21
  import { KERNEL_LOGGER } from "../infra/tokens.js";
22
- import { applyDevicesNetworkPatch, applyDevicesOutsideSandboxPatch, configuredDeviceSandbox, DEVICES_NETWORK_PATCH, DEVICES_NETWORK_SETTING, DEVICES_OUTSIDE_SANDBOX_PATCH, DEVICES_OUTSIDE_SANDBOX_SETTING, orgDeviceSandboxOf, readDeviceSandboxSettingsView, readStoredDeviceSandbox, resolveDeviceSandboxSettings, } from "../sandbox/device-sandbox-settings.js";
23
- import { devicesFollowingDefault, needsFullCeiling, needsOpenNetwork, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
22
+ import { applyDevicesNetworkPatch, applyDevicesOutsideSandboxPatch, configuredDeviceSandbox, DEVICES_ALLOWED_PROFILES_PATCH, DEVICES_ALLOWED_PROFILES_SETTING, DEVICES_NETWORK_PATCH, DEVICES_NETWORK_SETTING, DEVICES_OUTSIDE_SANDBOX_PATCH, DEVICES_OUTSIDE_SANDBOX_SETTING, DEVICES_PROJECT_REACH_PATCH, DEVICES_PROJECT_REACH_SETTING, orgDeviceSandboxOf, readDeviceSandboxSettingsView, readStoredDeviceSandbox, resolveDeviceSandboxSettings, } from "../sandbox/device-sandbox-settings.js";
23
+ import { devicesFollowingDefault, needsFullCeiling, needsOpenNetwork, PermissionCeilingWrites, reachNarrowed, } from "../sandbox/permission-ceiling-writes.js";
24
24
  import { EXTERNAL_SHARING_SETTING, ExternalSharingValue, HTML_CDN_ALLOWLIST_DEFAULT, HtmlCdnAllowlistSchema, readExternalSharing, readHtmlCdnAllowlist, readShareMaxExpiry, SHARE_MAX_EXPIRY_DEFAULT, SHARE_MAX_EXPIRY_SETTING, ShareMaxExpiryDays, } from "../shares/settings.js";
25
25
  import { assertPlatformDefaultEligible, lockThemeShared } from "../themes/theme-state.js";
26
26
  import { mergeArrangement, UiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
@@ -333,6 +333,8 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
333
333
  * startup config is read-only (409 `deployment.setting_readonly`).
334
334
  */
335
335
  devicesNetwork: DEVICES_NETWORK_PATCH.optional(),
336
+ devicesAllowedProfiles: DEVICES_ALLOWED_PROFILES_PATCH.optional(),
337
+ devicesProjectReach: DEVICES_PROJECT_REACH_PATCH.optional(),
336
338
  /**
337
339
  * The platform's default device provider (the `device-provider@1` extension that makes a
338
340
  * person's default device): `provider` replaced, null clears it (back to none). A value set in
@@ -575,6 +577,8 @@ let SettingsService = class SettingsService {
575
577
  ...settings,
576
578
  devicesOutsideSandbox: deviceSandbox.outsideSandbox,
577
579
  devicesNetwork: deviceSandbox.network,
580
+ devicesAllowedProfiles: deviceSandbox.allowedProfiles,
581
+ devicesProjectReach: deviceSandbox.projectReach,
578
582
  devicesDefaultProvider,
579
583
  attribution: this.attributionView(attribution),
580
584
  externalSharing,
@@ -615,6 +619,16 @@ let SettingsService = class SettingsService {
615
619
  async checkDeviceSandbox(patch, opts = {}) {
616
620
  const configured = configuredDeviceSandbox(this.config);
617
621
  const readonly = [
622
+ [
623
+ "devicesAllowedProfiles.value",
624
+ patch.devicesAllowedProfiles !== undefined,
625
+ configured.sources.allowedProfiles,
626
+ ],
627
+ [
628
+ "devicesProjectReach.ceiling",
629
+ patch.devicesProjectReach !== undefined,
630
+ configured.sources.projectReach,
631
+ ],
618
632
  [
619
633
  "devicesOutsideSandbox.permission",
620
634
  patch.devicesOutsideSandbox !== undefined,
@@ -637,6 +651,12 @@ let SettingsService = class SettingsService {
637
651
  }
638
652
  const stored = await readStoredDeviceSandbox(this.db.db, this.log);
639
653
  const next = {
654
+ allowedProfiles: patch.devicesAllowedProfiles === undefined
655
+ ? stored.allowedProfiles
656
+ : (patch.devicesAllowedProfiles.value ?? undefined),
657
+ projectReach: patch.devicesProjectReach === undefined
658
+ ? stored.projectReach
659
+ : (patch.devicesProjectReach.ceiling ?? undefined),
640
660
  outsideSandbox: patch.devicesOutsideSandbox === undefined
641
661
  ? stored.outsideSandbox
642
662
  : applyDevicesOutsideSandboxPatch(stored.outsideSandbox, patch.devicesOutsideSandbox),
@@ -651,6 +671,10 @@ let SettingsService = class SettingsService {
651
671
  if (patch.devicesNetwork?.default === "open" && next.network.ceiling === "allowlist")
652
672
  throw networkNotAllowed("The network default open is above the ceiling allowlist; set the default to allowlist too, or open the ceiling", "default");
653
673
  if (opts.onlyNarrows) {
674
+ if (after.allowedProfiles.value.some((profile) => !before.allowedProfiles.value.includes(profile)) ||
675
+ narrowerProjectReach(before.projectReach.ceiling, after.projectReach.ceiling) !==
676
+ after.projectReach.ceiling)
677
+ throw new ApiError("deployment.security_widen_not_allowed", "A super admin can widen device security settings in the web admin settings at /admin/settings.");
654
678
  if (patch.devicesOutsideSandbox !== undefined &&
655
679
  before.outsideSandbox.permission === "off" &&
656
680
  after.outsideSandbox.permission === "allowed")
@@ -819,7 +843,10 @@ let SettingsService = class SettingsService {
819
843
  }
820
844
  async lockFor(patch, actorAccountId) {
821
845
  await this.adminLock.lockAndAuthorize(actorAccountId);
822
- if (patch.devicesOutsideSandbox !== undefined || patch.devicesNetwork !== undefined)
846
+ if (patch.devicesOutsideSandbox !== undefined ||
847
+ patch.devicesNetwork !== undefined ||
848
+ patch.devicesAllowedProfiles !== undefined ||
849
+ patch.devicesProjectReach !== undefined)
823
850
  await this.ceilings.lock({}, "platform");
824
851
  }
825
852
  async write(patch, actorAccountId, actorTokenId, auditDetail, opts) {
@@ -907,9 +934,18 @@ let SettingsService = class SettingsService {
907
934
  // the stored shapes keep every field optional, so clearing one (null) writes it out
908
935
  let deviceSandboxChange;
909
936
  const writes = Object.entries(next);
910
- if (patch.devicesOutsideSandbox !== undefined || patch.devicesNetwork !== undefined) {
937
+ if (patch.devicesOutsideSandbox !== undefined ||
938
+ patch.devicesNetwork !== undefined ||
939
+ patch.devicesAllowedProfiles !== undefined ||
940
+ patch.devicesProjectReach !== undefined) {
911
941
  const r = await this.checkDeviceSandbox(patch, opts);
912
942
  deviceSandboxChange = { before: r.before, after: r.after };
943
+ if (patch.devicesAllowedProfiles !== undefined) {
944
+ writes.push([DEVICES_ALLOWED_PROFILES_SETTING, { value: r.next.allowedProfiles }]);
945
+ await this.ceilings.reconcileAllowedProfilesLocked({}, "platform", r.before.allowedProfiles.value, r.after.allowedProfiles.value);
946
+ }
947
+ if (patch.devicesProjectReach !== undefined)
948
+ writes.push([DEVICES_PROJECT_REACH_SETTING, { ceiling: r.next.projectReach }]);
913
949
  if (patch.devicesOutsideSandbox !== undefined)
914
950
  writes.push([DEVICES_OUTSIDE_SANDBOX_SETTING, r.next.outsideSandbox]);
915
951
  if (patch.devicesNetwork !== undefined)
@@ -921,7 +957,11 @@ let SettingsService = class SettingsService {
921
957
  (a.default === "allowlist" && b.default === "open");
922
958
  const networkChanged = r.before.network.default !== r.after.network.default ||
923
959
  r.before.network.ceiling !== r.after.network.ceiling;
924
- if (outsideChanged || networkChanged) {
960
+ const reachChanged = r.before.projectReach.ceiling !== r.after.projectReach.ceiling;
961
+ const reachTightened = reachChanged &&
962
+ narrowerProjectReach(r.before.projectReach.ceiling, r.after.projectReach.ceiling) ===
963
+ r.after.projectReach.ceiling;
964
+ if (outsideChanged || networkChanged || reachChanged) {
925
965
  // a network ceiling narrowed to the allowlist takes running open-network work
926
966
  const networkNarrowed = r.before.network.ceiling === "open" && r.after.network.ceiling === "allowlist";
927
967
  // a default narrowed to the allowlist takes it from the devices that follow it
@@ -931,16 +971,19 @@ let SettingsService = class SettingsService {
931
971
  r.after.network.default === "allowlist"
932
972
  ? await this.devicesFollowingPlatformDefault()
933
973
  : null;
934
- const narrows = outsideOff || networkNarrowed || following !== null;
974
+ const narrows = outsideOff || networkNarrowed || following !== null || reachTightened;
935
975
  await this.ceilings.publishLocked({}, "platform", !narrows
936
976
  ? false
937
977
  : (scope, row) => (needsOpenNetwork(scope) &&
938
978
  (networkNarrowed || following?.has(row.device_id) === true)) ||
939
- (outsideOff && needsFullCeiling(scope)),
979
+ (outsideOff && needsFullCeiling(scope)) ||
980
+ (reachTightened && reachNarrowed(scope, r.after.projectReach.ceiling)),
940
981
  // only a widening resets Full consent: a narrowing keeps what it covered
941
982
  (r.before.outsideSandbox.permission === "off" &&
942
983
  r.after.outsideSandbox.permission === "allowed") ||
943
- widened(r.before.network, r.after.network));
984
+ widened(r.before.network, r.after.network), reachTightened, r.after.allowedProfiles.value);
985
+ if (reachChanged && !reachTightened)
986
+ await this.ceilings.invalidateProjectReachWideningLocked(r.before.projectReach.ceiling, r.after.projectReach.ceiling, r.after.allowedProfiles.value);
944
987
  }
945
988
  }
946
989
  // the platform's attribution defaults: a field set in the startup config is read-only
@@ -54,6 +54,8 @@ const HOT_APPLIERS = {
54
54
  // The device sandbox settings reader reads these at every device use and settings read; a
55
55
  // change is published first (`PERMISSION_CONFIG_PATHS`).
56
56
  "devices.outsideSandbox": () => { },
57
+ "devices.allowedProfiles": () => { },
58
+ "devices.projectReach.ceiling": () => { },
57
59
  "devices.network.default": () => { },
58
60
  "devices.network.ceiling": () => { },
59
61
  // The default device provider is read live at every default device creation and settings read.
@@ -103,6 +105,8 @@ const HOT_APPLIERS = {
103
105
  */
104
106
  const PERMISSION_CONFIG_PATHS = [
105
107
  "devices.outsideSandbox",
108
+ "devices.allowedProfiles",
109
+ "devices.projectReach.ceiling",
106
110
  "devices.network.default",
107
111
  "devices.network.ceiling",
108
112
  ];
@@ -12,6 +12,7 @@ import { ExtensionsModule } from "../extensions/extensions.module.js";
12
12
  import { LifecycleHooksModule } from "../extensions/lifecycle-hooks.js";
13
13
  import { IdentityModule } from "../identity/identity.module.js";
14
14
  import { QueueModule } from "../infra/queue/queue.module.js";
15
+ import { PlatformModule } from "../platform/platform.module.js";
15
16
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
16
17
  import { RuntimeModule } from "../runtime/runtime.module.js";
17
18
  import { SandboxModule } from "../sandbox/sandbox.module.js";
@@ -23,6 +24,7 @@ import { OrgNetworkAllowancesModule } from "./network-allowances.service.js";
23
24
  import { Offboarding } from "./offboarding.js";
24
25
  import { OrgLockModule } from "./org-lock.js";
25
26
  import { OrgsService } from "./orgs.service.js";
27
+ import { OrgSecuritySettingsService } from "./security-settings.service.js";
26
28
  import { OrgSettingsModule } from "./settings.service.js";
27
29
  /**
28
30
  * Organizations: orgs, org settings, members, invitations, offboarding (its owed work goes through
@@ -39,6 +41,7 @@ OrgsModule = __decorate([
39
41
  EventLogModule,
40
42
  OrgLockModule,
41
43
  OrgSettingsModule,
44
+ PlatformModule,
42
45
  ExtensionsModule,
43
46
  // offboarding and the org delete record lifecycle hook deliveries
44
47
  LifecycleHooksModule,
@@ -56,10 +59,18 @@ OrgsModule = __decorate([
56
59
  QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
57
60
  OrgNetworkAllowancesModule,
58
61
  ],
59
- providers: [OrgsService, MembersService, InvitationsService, Offboarding, DirectorySync],
62
+ providers: [
63
+ OrgsService,
64
+ MembersService,
65
+ InvitationsService,
66
+ Offboarding,
67
+ DirectorySync,
68
+ OrgSecuritySettingsService,
69
+ ],
60
70
  exports: [
61
71
  OrgLockModule,
62
72
  OrgSettingsModule,
73
+ OrgSecuritySettingsService,
63
74
  OrgsService,
64
75
  MembersService,
65
76
  InvitationsService,
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { INVITABLE_ROLES, MAX_INVITATION_HOURS } from "./invitations.service.js";
3
3
  import { ORG_ROLES } from "./roles.js";
4
+ import { OrgSecurityPatchSchema, OrgSecurityQuerySchema } from "./security-settings.service.js";
4
5
  import { OrgSettingsPatchSchema } from "./settings.service.js";
5
6
  export const OrgUpdateBody = z.object({
6
7
  name: z.string().min(1).max(100).optional(),
@@ -38,6 +39,8 @@ export const ORG_ROUTES = [
38
39
  { route: "GET /api/v1/orgs/:orgId/network-allowances" },
39
40
  ];
40
41
  export const ORG_SETTINGS_ROUTES = [
42
+ { route: "GET /api/v1/orgs/:orgId/settings/security", query: OrgSecurityQuerySchema },
43
+ { route: "PATCH /api/v1/orgs/:orgId/settings/security", body: OrgSecurityPatchSchema },
41
44
  { route: "GET /api/v1/orgs/:orgId/settings" },
42
45
  { route: "PATCH /api/v1/orgs/:orgId/settings", body: OrgSettingsPatchSchema },
43
46
  ];
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ import { KernelDb } from "../infra/database/kernel-db.js";
3
+ import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import { PlatformOperations } from "../platform/registry.js";
5
+ import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
6
+ import { OrgToolSwitches } from "../tools/org-tool-switches.js";
7
+ import { ToolRegistry } from "../tools/registry.js";
8
+ import { OrgLock } from "./org-lock.js";
9
+ import { OrgSettingsService } from "./settings.service.js";
10
+ type ToolSource = "builtin" | "connector" | "extension" | "operation" | "unavailable";
11
+ export declare const OrgSecurityQuerySchema: z.ZodObject<{
12
+ cursor: z.ZodOptional<z.ZodString>;
13
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
14
+ }, z.core.$strict>;
15
+ export declare const OrgSecurityPatchSchema: z.ZodObject<{
16
+ expectedRevision: z.ZodString;
17
+ confirmation: z.ZodOptional<z.ZodString>;
18
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
19
+ toolKey: z.ZodString;
20
+ policy: z.ZodEnum<{
21
+ allow: "allow";
22
+ ask: "ask";
23
+ deny: "deny";
24
+ }>;
25
+ unattendedPolicy: z.ZodEnum<{
26
+ allow: "allow";
27
+ ask: "ask";
28
+ deny: "deny";
29
+ }>;
30
+ }, z.core.$strict>>>;
31
+ gitPush: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ target: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string | null, string>>, z.ZodString>;
33
+ denied: z.ZodBoolean;
34
+ }, z.core.$strict>>>;
35
+ allowedProfiles: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodArray<z.ZodEnum<{
36
+ "approve-for-me": "approve-for-me";
37
+ "full-access": "full-access";
38
+ "request-approval": "request-approval";
39
+ }>>, z.ZodTransform<("approve-for-me" | "full-access" | "request-approval")[], ("approve-for-me" | "full-access" | "request-approval")[]>>>>;
40
+ projectReach: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
41
+ machine: "machine";
42
+ paths: "paths";
43
+ workspace: "workspace";
44
+ }>>>;
45
+ }, z.core.$strict>;
46
+ export type OrgSecurityQuery = z.infer<typeof OrgSecurityQuerySchema>;
47
+ export type OrgSecurityPatch = z.infer<typeof OrgSecurityPatchSchema>;
48
+ export declare class OrgSecuritySettingsService {
49
+ private readonly db;
50
+ readonly txHost: TransactionHost;
51
+ private readonly orgLock;
52
+ private readonly ceilings;
53
+ private readonly settings;
54
+ private readonly tools;
55
+ private readonly operations;
56
+ private readonly toolImpact;
57
+ constructor(db: KernelDb, txHost: TransactionHost, orgLock: OrgLock, ceilings: PermissionCeilingWrites, settings: OrgSettingsService, tools: ToolRegistry, operations: PlatformOperations, toolImpact: OrgToolSwitches);
58
+ private snapshot;
59
+ private toolSources;
60
+ view(orgId: string, query: OrgSecurityQuery): Promise<{
61
+ gitPushDenials: string[];
62
+ revision: string;
63
+ tools: {
64
+ toolKey: string;
65
+ source: ToolSource;
66
+ policy: import("../tools/org-tool-policies.js").OrgToolPolicy;
67
+ unattendedPolicy: import("../tools/org-tool-policies.js").OrgToolPolicy;
68
+ }[];
69
+ nextCursor: string | null;
70
+ allowedProfiles: {
71
+ configured: ("approve-for-me" | "full-access" | "request-approval")[] | null;
72
+ platform: import("@capybara-hq/plugin-sdk").PermissionProfile[];
73
+ effective: import("@capybara-hq/plugin-sdk").PermissionProfile[];
74
+ source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
75
+ };
76
+ projectReach: {
77
+ configured: "machine" | "paths" | "workspace" | null;
78
+ platform: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
79
+ effective: import("@capybara-hq/plugin-sdk").DeviceProjectReach;
80
+ source: import("../sandbox/device-sandbox-settings.js").DeviceSandboxSource;
81
+ limitingLayer: "org" | "platform";
82
+ };
83
+ }>;
84
+ update(orgId: string, patch: OrgSecurityPatch, actor: string, options: {
85
+ token?: string;
86
+ onlyNarrows?: boolean;
87
+ auditDetail?: Record<string, unknown>;
88
+ }): Promise<{
89
+ revision: string;
90
+ }>;
91
+ private lock;
92
+ private updateLocked;
93
+ }
94
+ export {};