@capybara-hq/kernel 0.1.0-rc.127 → 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 (122) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/admin.schemas.d.ts +14 -0
  3. package/dist/agents/readiness.service.d.ts +6 -0
  4. package/dist/agents/readiness.service.js +1 -1
  5. package/dist/automations/automations.service.js +15 -21
  6. package/dist/automations/effective-settings.d.ts +3 -9
  7. package/dist/automations/effective-settings.js +3 -5
  8. package/dist/automations/fire.js +0 -11
  9. package/dist/automations/grant-rules.d.ts +7 -10
  10. package/dist/automations/grant-rules.js +9 -18
  11. package/dist/automations/unattended.d.ts +1 -4
  12. package/dist/automations/unattended.js +0 -2
  13. package/dist/catalog/catalog-items.d.ts +7 -4
  14. package/dist/catalog/catalog-items.js +8 -7
  15. package/dist/catalog/catalog-scope.service.d.ts +3 -2
  16. package/dist/catalog/catalog-scope.service.js +5 -4
  17. package/dist/catalog/org-extension.controller.d.ts +1 -20
  18. package/dist/catalog/org-extension.controller.js +1 -48
  19. package/dist/catalog/org-extension.schemas.d.ts +1 -9
  20. package/dist/catalog/org-extension.schemas.js +1 -17
  21. package/dist/config/schema.d.ts +12 -0
  22. package/dist/config/schema.js +16 -0
  23. package/dist/conversations/approval-profile.d.ts +8 -1
  24. package/dist/conversations/approval-profile.js +20 -0
  25. package/dist/conversations/conversations.service.d.ts +1 -1
  26. package/dist/conversations/conversations.service.js +8 -3
  27. package/dist/conversations/events.d.ts +25 -1
  28. package/dist/conversations/events.js +7 -2
  29. package/dist/conversations/permission-profiles.controller.d.ts +4 -0
  30. package/dist/conversations/permission-profiles.schemas.d.ts +5 -0
  31. package/dist/conversations/permission-profiles.schemas.js +8 -0
  32. package/dist/conversations/permission-profiles.service.d.ts +8 -1
  33. package/dist/conversations/permission-profiles.service.js +13 -1
  34. package/dist/db/kernel-schema.d.ts +21 -0
  35. package/dist/device-access/device-access.service.d.ts +4 -1
  36. package/dist/device-access/device-access.service.js +26 -7
  37. package/dist/device-access/viewer.d.ts +3 -1
  38. package/dist/device-access/viewer.js +18 -9
  39. package/dist/errors.d.ts +6 -0
  40. package/dist/errors.js +6 -0
  41. package/dist/extensions/admin-view.d.ts +1 -3
  42. package/dist/extensions/admin-view.js +5 -8
  43. package/dist/git/gateway.d.ts +8 -1
  44. package/dist/git/gateway.js +68 -11
  45. package/dist/git/git.module.d.ts +2 -3
  46. package/dist/git/git.module.js +4 -4
  47. package/dist/http/api.module.js +3 -3
  48. package/dist/identity/settings.d.ts +20 -5
  49. package/dist/identity/settings.js +52 -9
  50. package/dist/infra/config/kernel-config.service.js +4 -0
  51. package/dist/orgs/orgs.module.js +12 -1
  52. package/dist/orgs/orgs.schemas.js +3 -0
  53. package/dist/orgs/security-settings.service.d.ts +94 -0
  54. package/dist/orgs/security-settings.service.js +223 -0
  55. package/dist/orgs/settings.controller.d.ts +33 -0
  56. package/dist/orgs/settings.controller.js +41 -1
  57. package/dist/orgs/settings.service.d.ts +48 -63
  58. package/dist/orgs/settings.service.js +86 -103
  59. package/dist/platform/exclusions.js +1 -1
  60. package/dist/platform/operation.js +4 -0
  61. package/dist/platform/ops/admin.ops.js +18 -4
  62. package/dist/platform/ops/agents.ops.js +1 -1
  63. package/dist/platform/ops/connectors.ops.js +2 -2
  64. package/dist/platform/ops/extensions.ops.d.ts +1 -3
  65. package/dist/platform/ops/extensions.ops.js +4 -131
  66. package/dist/platform/ops/org-settings.ops.d.ts +3 -1
  67. package/dist/platform/ops/org-settings.ops.js +76 -3
  68. package/dist/platform/ops/orgs.ops.js +2 -0
  69. package/dist/runtime/context/permission-profile.js +6 -0
  70. package/dist/runtime/subagents/dispatch.d.ts +3 -0
  71. package/dist/runtime/subagents/dispatch.js +2 -1
  72. package/dist/runtime/subagents/messages.d.ts +3 -1
  73. package/dist/runtime/subagents/messages.js +9 -6
  74. package/dist/sandbox/device-sandbox-settings.d.ts +55 -1
  75. package/dist/sandbox/device-sandbox-settings.js +64 -1
  76. package/dist/sandbox/device-sandbox.d.ts +9 -1
  77. package/dist/sandbox/device-sandbox.js +17 -2
  78. package/dist/sandbox/device-services.d.ts +26 -3
  79. package/dist/sandbox/device-services.js +95 -16
  80. package/dist/sandbox/loopback-grant-records.d.ts +3 -2
  81. package/dist/sandbox/loopback-grant-records.js +32 -5
  82. package/dist/sandbox/operation-authority.d.ts +3 -2
  83. package/dist/sandbox/operation-authority.js +21 -1
  84. package/dist/sandbox/operation-intents.js +5 -1
  85. package/dist/sandbox/permission-call-types.d.ts +2 -1
  86. package/dist/sandbox/permission-ceiling-writes.d.ts +14 -5
  87. package/dist/sandbox/permission-ceiling-writes.js +122 -13
  88. package/dist/sandbox/permission-config-publication.d.ts +10 -0
  89. package/dist/sandbox/permission-config-publication.js +27 -5
  90. package/dist/sandbox/permission-facts.d.ts +21 -2
  91. package/dist/sandbox/permission-facts.js +101 -9
  92. package/dist/sandbox/permission-transitions.d.ts +1 -1
  93. package/dist/sandbox/sandbox.service.d.ts +2 -2
  94. package/dist/sandbox/sandbox.service.js +7 -3
  95. package/dist/tools/admin-connectors.js +2 -2
  96. package/dist/tools/approvals.service.d.ts +7 -2
  97. package/dist/tools/approvals.service.js +39 -7
  98. package/dist/tools/builtin-names.d.ts +0 -6
  99. package/dist/tools/builtin-names.js +0 -11
  100. package/dist/tools/builtins/sandbox/index.d.ts +3 -5
  101. package/dist/tools/builtins/sandbox/index.js +3 -5
  102. package/dist/tools/connector-account-policies.js +7 -4
  103. package/dist/tools/connectors.controller.d.ts +0 -6
  104. package/dist/tools/connectors.schemas.d.ts +1 -8
  105. package/dist/tools/connectors.schemas.js +1 -4
  106. package/dist/tools/connectors.service.d.ts +3 -7
  107. package/dist/tools/connectors.service.js +29 -44
  108. package/dist/tools/drift.js +12 -4
  109. package/dist/tools/git-push-policy.d.ts +1 -4
  110. package/dist/tools/git-push-policy.js +4 -5
  111. package/dist/tools/org-tool-policies.d.ts +24 -0
  112. package/dist/tools/org-tool-policies.js +113 -0
  113. package/dist/tools/org-tool-switches.d.ts +5 -70
  114. package/dist/tools/org-tool-switches.js +13 -141
  115. package/dist/tools/pipeline.d.ts +11 -5
  116. package/dist/tools/pipeline.js +173 -38
  117. package/dist/tools/policy.d.ts +3 -7
  118. package/dist/tools/policy.js +29 -48
  119. package/dist/tools/registry.d.ts +5 -0
  120. package/dist/tools/registry.js +44 -13
  121. package/package.json +1 -1
  122. package/src/migrations/0212_org_security_policy.sql +234 -0
@@ -20,6 +20,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
20
20
  import { withOrgScope } from "../infra/database/org-scope.js";
21
21
  import { LockService } from "../infra/lock/lock.service.js";
22
22
  import { KERNEL_LOGGER, KEYRING } from "../infra/tokens.js";
23
+ import { DeviceServices } from "../sandbox/device-services.js";
23
24
  import { SandboxService } from "../sandbox/sandbox.service.js";
24
25
  import { DeviceAccessService } from "./device-access.service.js";
25
26
  /**
@@ -363,6 +364,9 @@ export function parseTicketRecord(raw) {
363
364
  for (const k of keys)
364
365
  if (typeof r[k] !== "string" || r[k] === "")
365
366
  return null;
367
+ const reach = r.projectReach;
368
+ if (reach !== undefined && reach !== "workspace" && reach !== "paths" && reach !== "machine")
369
+ return null;
366
370
  return {
367
371
  orgId: r.orgId,
368
372
  accountId: r.accountId,
@@ -370,6 +374,7 @@ export function parseTicketRecord(raw) {
370
374
  rootConversationId: r.rootConversationId,
371
375
  deviceId: r.deviceId,
372
376
  providerName: r.providerName,
377
+ ...(reach !== undefined && { projectReach: reach }),
373
378
  service: r.service,
374
379
  extension: r.extension,
375
380
  };
@@ -416,6 +421,7 @@ export function parseTicketRecord(raw) {
416
421
  let DeviceStreamViewers = class DeviceStreamViewers {
417
422
  access;
418
423
  sandbox;
424
+ services;
419
425
  gateway;
420
426
  handlers;
421
427
  kdb;
@@ -433,9 +439,10 @@ let DeviceStreamViewers = class DeviceStreamViewers {
433
439
  pausedLimitMs = VIEWER_PAUSED_LIMIT_MS;
434
440
  /** {@link VIEWER_RECHECK_MS} (a test seam). */
435
441
  recheckMs = VIEWER_RECHECK_MS;
436
- constructor(access, sandbox, gateway, handlers, kdb, locks, keyring, config, log) {
442
+ constructor(access, sandbox, services, gateway, handlers, kdb, locks, keyring, config, log) {
437
443
  this.access = access;
438
444
  this.sandbox = sandbox;
445
+ this.services = services;
439
446
  this.gateway = gateway;
440
447
  this.handlers = handlers;
441
448
  this.kdb = kdb;
@@ -675,7 +682,8 @@ let DeviceStreamViewers = class DeviceStreamViewers {
675
682
  let stream;
676
683
  try {
677
684
  // the provider knows the service by its id: the ticket's extension and service name
678
- stream = await hold.p.openStream(hold.h, { service: deviceServiceId(record.extension, record.service) }, hold.signal);
685
+ const service = deviceServiceId(record.extension, record.service);
686
+ stream = await this.services.withConfirmedReach(record.orgId, record.deviceId, service, hold.h, hold.p, hold.signal, () => hold.p.openStream(hold.h, { service }, hold.signal));
679
687
  }
680
688
  catch (err) {
681
689
  await hold.release();
@@ -844,13 +852,14 @@ DeviceStreamViewers = __decorate([
844
852
  Injectable(),
845
853
  __param(0, Inject(DeviceAccessService)),
846
854
  __param(1, Inject(SandboxService)),
847
- __param(2, Inject(DialInGateway)),
848
- __param(3, Inject(DialInHandlers)),
849
- __param(4, Inject(KernelDb)),
850
- __param(5, Inject(LockService)),
851
- __param(6, Inject(KEYRING)),
852
- __param(7, Inject(KernelConfigService)),
853
- __param(8, Inject(KERNEL_LOGGER))
855
+ __param(2, Inject(DeviceServices)),
856
+ __param(3, Inject(DialInGateway)),
857
+ __param(4, Inject(DialInHandlers)),
858
+ __param(5, Inject(KernelDb)),
859
+ __param(6, Inject(LockService)),
860
+ __param(7, Inject(KEYRING)),
861
+ __param(8, Inject(KernelConfigService)),
862
+ __param(9, Inject(KERNEL_LOGGER))
854
863
  ], DeviceStreamViewers);
855
864
  export { DeviceStreamViewers };
856
865
  const isElsewhere = (e) => typeof e === "object" &&
package/dist/errors.d.ts CHANGED
@@ -68,6 +68,11 @@ export declare const ERROR_CODES: {
68
68
  * through an API token or the Platform tool.
69
69
  */
70
70
  readonly "org.network_not_allowed": 400;
71
+ readonly "org.security_ceiling_not_allowed": 400;
72
+ readonly "org.security_widening_not_allowed": 403;
73
+ readonly "org.security_revision_conflict": 409;
74
+ readonly "org.security_confirmation_required": 409;
75
+ readonly "org.permission_profile_not_allowed": 400;
71
76
  /** The org's default device provider names an extension that is not a `device-provider@1` provider on in the org. */
72
77
  readonly "org.device_provider_not_available": 400;
73
78
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
@@ -91,6 +96,7 @@ export declare const ERROR_CODES: {
91
96
  * token or the Platform tool.
92
97
  */
93
98
  readonly "deployment.network_not_allowed": 400;
99
+ readonly "deployment.security_widen_not_allowed": 400;
94
100
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
95
101
  readonly "deployment.external_sharing_not_allowed": 400;
96
102
  /**
package/dist/errors.js CHANGED
@@ -68,6 +68,11 @@ export const ERROR_CODES = {
68
68
  * through an API token or the Platform tool.
69
69
  */
70
70
  "org.network_not_allowed": 400,
71
+ "org.security_ceiling_not_allowed": 400,
72
+ "org.security_widening_not_allowed": 403,
73
+ "org.security_revision_conflict": 409,
74
+ "org.security_confirmation_required": 409,
75
+ "org.permission_profile_not_allowed": 400,
71
76
  /** The org's default device provider names an extension that is not a `device-provider@1` provider on in the org. */
72
77
  "org.device_provider_not_available": 400,
73
78
  /** An org network allowance entry that is malformed, names a link-local address, or is over the cap. */
@@ -91,6 +96,7 @@ export const ERROR_CODES = {
91
96
  * token or the Platform tool.
92
97
  */
93
98
  "deployment.network_not_allowed": 400,
99
+ "deployment.security_widen_not_allowed": 400,
94
100
  /** Allowing external sharing at the platform level through an API token or the Platform tool. */
95
101
  "deployment.external_sharing_not_allowed": 400,
96
102
  /**
@@ -108,12 +108,10 @@ export declare class ExtensionAdmin {
108
108
  * recomputed now -> `extension.approval_stale`; a config-declared extension's `sha256` must be
109
109
  * null (otherwise `validation_failed`);
110
110
  * - the snapshot already covers the current permission set (nothing to approve, F-N) ->
111
- * `extension.not_pending`, except with `confirmBootstrap` when the snapshot is the bootstrap
112
- * step's (the catalog's confirm re-writes it with source web).
111
+ * `extension.not_pending` (a snapshot the bootstrap step wrote included: the pin is consent).
113
112
  */
114
113
  approve(actor: string, name: string, body: ApproveBody, opts?: {
115
114
  actorTokenId?: string;
116
- confirmBootstrap?: boolean;
117
115
  }): Promise<AdminExtensionView>;
118
116
  private writeApproval;
119
117
  /** 配置声明 → 安装记录(与配置声明重名的安装记录不生效,不单列)。`only` 给出时只取这一个。 */
@@ -166,8 +166,7 @@ let ExtensionAdmin = class ExtensionAdmin {
166
166
  * recomputed now -> `extension.approval_stale`; a config-declared extension's `sha256` must be
167
167
  * null (otherwise `validation_failed`);
168
168
  * - the snapshot already covers the current permission set (nothing to approve, F-N) ->
169
- * `extension.not_pending`, except with `confirmBootstrap` when the snapshot is the bootstrap
170
- * step's (the catalog's confirm re-writes it with source web).
169
+ * `extension.not_pending` (a snapshot the bootstrap step wrote included: the pin is consent).
171
170
  */
172
171
  async approve(actor, name, body, opts = {}) {
173
172
  const s = (await this.subjects(name))[0];
@@ -182,7 +181,7 @@ let ExtensionAdmin = class ExtensionAdmin {
182
181
  throw stale();
183
182
  if (body.reviewHash !== reviewHash(s.set, s.warnings))
184
183
  throw stale();
185
- await this.writeApproval(actor, name, s, opts.actorTokenId, stale, opts.confirmBootstrap === true);
184
+ await this.writeApproval(actor, name, s, opts.actorTokenId, stale);
186
185
  try {
187
186
  await this.bus.publish(PLUGINS_CHANGED_TOPIC, { plugin: name });
188
187
  }
@@ -198,7 +197,7 @@ let ExtensionAdmin = class ExtensionAdmin {
198
197
  }
199
198
  return this.get(name);
200
199
  }
201
- async writeApproval(actor, name, s, actorTokenId, stale, confirmBootstrap) {
200
+ async writeApproval(actor, name, s, actorTokenId, stale) {
202
201
  const db = this.db;
203
202
  await this.adminLock.lockAndAuthorize(actor);
204
203
  await this.approveLock.lock(name);
@@ -218,7 +217,7 @@ let ExtensionAdmin = class ExtensionAdmin {
218
217
  }
219
218
  const snapRow = await db
220
219
  .selectFrom("extension_permission_snapshots")
221
- .select(["version", "permissions", "source"])
220
+ .select(["version", "permissions"])
222
221
  .where("plugin", "=", name)
223
222
  .forUpdate()
224
223
  .executeTakeFirst();
@@ -226,9 +225,7 @@ let ExtensionAdmin = class ExtensionAdmin {
226
225
  version: snapRow.version,
227
226
  permissions: snapRow.permissions,
228
227
  };
229
- // `confirmBootstrap` (the catalog's confirm): a snapshot the bootstrap step wrote was never
230
- // confirmed by a person, so a covered one is still taken over
231
- if (snapshotCovers(snap, s.set) && !(confirmBootstrap && snapRow?.source === "bootstrap")) {
228
+ if (snapshotCovers(snap, s.set)) {
232
229
  throw new ApiError("extension.not_pending", `Extension ${name} ${s.version} has no new permissions awaiting approval`);
233
230
  }
234
231
  const { added, removed } = diffPermissions(snap?.permissions, s.set);
@@ -3,7 +3,9 @@ import type { Redis } from "ioredis";
3
3
  import type { KernelConfig } from "../config/schema.js";
4
4
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
+ import { TransactionHost } from "../infra/database/transaction-host.js";
6
7
  import type { KernelLogger } from "../log.js";
8
+ import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
7
9
  import { Credentials } from "../tools/credentials.js";
8
10
  import { GitSources } from "./sources.js";
9
11
  import { GitTickets } from "./tickets.js";
@@ -62,18 +64,21 @@ export declare class GitGateway {
62
64
  private readonly sources;
63
65
  private readonly credentials;
64
66
  private readonly db;
67
+ readonly txHost: TransactionHost;
68
+ private readonly authority;
65
69
  private readonly redis;
66
70
  /** Read per request: `tools.git.*` is read live. */
67
71
  private readonly config;
68
72
  private readonly log;
69
73
  private readonly upstreamOrigin?;
70
- constructor(tickets: Pick<GitTickets, "resolve">, sources: Pick<GitSources, "sourcesFor">, credentials: Pick<Credentials, "gitAuthorization" | "gitUnauthorized">, db: KernelDb, redis: Redis,
74
+ constructor(tickets: Pick<GitTickets, "resolve">, sources: Pick<GitSources, "sourcesFor">, credentials: Pick<Credentials, "gitAuthorization" | "gitUnauthorized">, db: KernelDb, txHost: TransactionHost, authority: PermissionAuthorityLock, redis: Redis,
71
75
  /** Read per request: `tools.git.*` is read live. */
72
76
  config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "info" | "warn" | "debug">, upstreamOrigin?: GitUpstreamOrigin | undefined);
73
77
  /** `message` as git prints it from this gateway: with the platform name before it. */
74
78
  says(message: string): string;
75
79
  /** Handles one gateway request (the raw route's handler). */
76
80
  handle(req: FastifyRequest, reply: FastifyReply): Promise<void>;
81
+ private handleBound;
77
82
  /** The `git.push` audit row of a receive-pack and the run's fetch counters (best effort). */
78
83
  private afterRequest;
79
84
  /**
@@ -84,6 +89,8 @@ export declare class GitGateway {
84
89
  private acquireOrgSlot;
85
90
  private done;
86
91
  private relay;
92
+ /** Commit the push intent under the same authority lock as an org security edit. */
93
+ private admitPush;
87
94
  /** The push decision for this target (spec §7). */
88
95
  private decide;
89
96
  /**
@@ -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
  }>;