@capybara-hq/kernel 0.1.0-rc.146 → 0.1.0-rc.147

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 (168) hide show
  1. package/dist/admin/extensions.controller.d.ts +0 -11
  2. package/dist/admin/extensions.controller.js +0 -28
  3. package/dist/admin/health.service.d.ts +25 -1
  4. package/dist/admin/health.service.js +50 -18
  5. package/dist/audit/full-access.d.ts +78 -0
  6. package/dist/audit/full-access.js +283 -0
  7. package/dist/automations/automations.service.d.ts +1 -0
  8. package/dist/automations/automations.service.js +3 -1
  9. package/dist/automations/calendar.js +3 -1
  10. package/dist/automations/grant-rules.d.ts +2 -1
  11. package/dist/automations/grant-rules.js +8 -1
  12. package/dist/automations/unattended.d.ts +13 -1
  13. package/dist/automations/unattended.js +13 -1
  14. package/dist/catalog/admin-catalog.controller.d.ts +8 -0
  15. package/dist/catalog/admin-catalog.controller.js +8 -2
  16. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  17. package/dist/catalog/admin-catalog.schemas.js +8 -1
  18. package/dist/catalog/catalog-content.d.ts +6 -0
  19. package/dist/catalog/catalog-scope.service.d.ts +22 -2
  20. package/dist/catalog/catalog-scope.service.js +27 -3
  21. package/dist/catalog/catalog.service.js +19 -2
  22. package/dist/catalog/marketplaces.service.d.ts +1 -1
  23. package/dist/catalog/org-catalog.service.d.ts +8 -1
  24. package/dist/catalog/org-catalog.service.js +36 -3
  25. package/dist/catalog/platform-components.js +3 -2
  26. package/dist/catalog/platform-import-update.d.ts +2 -0
  27. package/dist/catalog/platform-import-update.js +8 -1
  28. package/dist/catalog/plugin-connectors.d.ts +11 -0
  29. package/dist/catalog/plugin-connectors.js +33 -0
  30. package/dist/catalog/plugin-import.d.ts +35 -15
  31. package/dist/catalog/plugin-import.js +110 -35
  32. package/dist/catalog/plugin-install.js +6 -0
  33. package/dist/catalog/provenance.d.ts +2 -0
  34. package/dist/catalog/provenance.js +5 -1
  35. package/dist/config/auto-approve.d.ts +16 -0
  36. package/dist/config/auto-approve.js +24 -0
  37. package/dist/config/capacity-presets.d.ts +243 -0
  38. package/dist/config/capacity-presets.js +195 -0
  39. package/dist/config/env.d.ts +2 -1
  40. package/dist/config/env.js +6 -1
  41. package/dist/config/load.js +15 -0
  42. package/dist/config/schema.d.ts +46 -9
  43. package/dist/config/schema.js +154 -30
  44. package/dist/ctx/net.d.ts +5 -1
  45. package/dist/ctx/net.js +62 -12
  46. package/dist/db/kernel-schema.d.ts +31 -0
  47. package/dist/db/migrator.js +0 -36
  48. package/dist/dial-in/routes.js +1 -1
  49. package/dist/erasure/org-batches.js +1 -6
  50. package/dist/erasure/org-catalog.js +6 -2
  51. package/dist/erasure/org-rules.js +1 -0
  52. package/dist/erasure/org-worker.js +0 -13
  53. package/dist/errors.d.ts +6 -0
  54. package/dist/errors.js +6 -0
  55. package/dist/extensions/admin-ops.d.ts +14 -1
  56. package/dist/extensions/admin-ops.js +30 -3
  57. package/dist/extensions/admin-view.d.ts +21 -1
  58. package/dist/extensions/admin-view.js +43 -0
  59. package/dist/extensions/bootstrap-packages.d.ts +5 -0
  60. package/dist/extensions/bootstrap-packages.js +1 -1
  61. package/dist/extensions/bootstrap-review.d.ts +251 -0
  62. package/dist/extensions/bootstrap-review.js +676 -0
  63. package/dist/extensions/bootstrap.d.ts +21 -1
  64. package/dist/extensions/bootstrap.js +72 -2
  65. package/dist/extensions/cli.d.ts +6 -0
  66. package/dist/extensions/cli.js +4 -0
  67. package/dist/extensions/enabled.d.ts +3 -0
  68. package/dist/extensions/extensions.module.js +9 -0
  69. package/dist/extensions/full-access-disclosure.d.ts +15 -0
  70. package/dist/extensions/full-access-disclosure.js +57 -0
  71. package/dist/extensions/grant-epoch.d.ts +5 -0
  72. package/dist/extensions/grant-epoch.js +9 -0
  73. package/dist/extensions/host.d.ts +71 -2
  74. package/dist/extensions/host.js +293 -27
  75. package/dist/extensions/installs.d.ts +18 -0
  76. package/dist/extensions/installs.js +28 -0
  77. package/dist/extensions/isolated/admission.d.ts +17 -2
  78. package/dist/extensions/isolated/admission.js +15 -7
  79. package/dist/extensions/isolated/authorization.d.ts +8 -2
  80. package/dist/extensions/isolated/authorization.js +11 -3
  81. package/dist/extensions/isolated/broker.d.ts +3 -0
  82. package/dist/extensions/isolated/broker.js +50 -14
  83. package/dist/extensions/isolated/configured-package.d.ts +5 -0
  84. package/dist/extensions/isolated/configured-package.js +2 -0
  85. package/dist/extensions/isolated/lanes.d.ts +44 -3
  86. package/dist/extensions/isolated/lanes.js +263 -80
  87. package/dist/extensions/isolated/metrics.d.ts +146 -0
  88. package/dist/extensions/isolated/metrics.js +304 -0
  89. package/dist/extensions/isolated/revision.d.ts +7 -1
  90. package/dist/extensions/isolated/revision.js +26 -5
  91. package/dist/extensions/isolated/rpc.d.ts +5 -0
  92. package/dist/extensions/isolated/rpc.js +7 -2
  93. package/dist/extensions/isolated/sandbox.d.ts +23 -0
  94. package/dist/extensions/isolated/sandbox.js +50 -0
  95. package/dist/extensions/isolated/status.d.ts +79 -0
  96. package/dist/extensions/isolated/status.js +216 -0
  97. package/dist/extensions/isolated/tier.d.ts +127 -2
  98. package/dist/extensions/isolated/tier.js +266 -7
  99. package/dist/extensions/isolated/usage.d.ts +134 -0
  100. package/dist/extensions/isolated/usage.js +322 -0
  101. package/dist/extensions/lifecycle.d.ts +42 -2
  102. package/dist/extensions/lifecycle.js +100 -4
  103. package/dist/extensions/org-config.js +11 -0
  104. package/dist/extensions/package.d.ts +14 -0
  105. package/dist/extensions/package.js +23 -0
  106. package/dist/extensions/permissions.controller.d.ts +35 -0
  107. package/dist/extensions/permissions.controller.js +98 -0
  108. package/dist/extensions/permissions.schemas.d.ts +288 -0
  109. package/dist/extensions/permissions.schemas.js +96 -0
  110. package/dist/extensions/permissions.service.d.ts +116 -0
  111. package/dist/extensions/permissions.service.js +428 -0
  112. package/dist/extensions/realm-retirement.d.ts +65 -0
  113. package/dist/extensions/realm-retirement.js +150 -0
  114. package/dist/extensions/revision-approvals.d.ts +58 -3
  115. package/dist/extensions/revision-approvals.js +135 -14
  116. package/dist/extensions/revision-review.d.ts +144 -0
  117. package/dist/extensions/revision-review.js +297 -0
  118. package/dist/extensions/revocation.js +3 -0
  119. package/dist/extensions/state.module.js +12 -0
  120. package/dist/git/run-end.d.ts +35 -7
  121. package/dist/git/run-end.js +87 -38
  122. package/dist/http/api.module.js +2 -0
  123. package/dist/identity/audit.d.ts +2 -1
  124. package/dist/identity/audit.js +4 -17
  125. package/dist/index.d.ts +4 -0
  126. package/dist/index.js +4 -0
  127. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  128. package/dist/infra/config/kernel-config.service.js +21 -0
  129. package/dist/infra/outbox/registry.d.ts +13 -0
  130. package/dist/infra/outbox/registry.js +8 -0
  131. package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
  132. package/dist/lifecycle/kernel-lifecycle.js +73 -18
  133. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  134. package/dist/net/private-endpoint-preflight.js +417 -0
  135. package/dist/net/private-endpoints.d.ts +68 -0
  136. package/dist/net/private-endpoints.js +164 -0
  137. package/dist/net/public-address.d.ts +14 -0
  138. package/dist/net/public-address.js +15 -1
  139. package/dist/net/safe-fetch.d.ts +2 -1
  140. package/dist/net/safe-fetch.js +10 -3
  141. package/dist/overrides.d.ts +4 -0
  142. package/dist/overrides.js +2 -0
  143. package/dist/packages/official-publisher.d.ts +26 -1
  144. package/dist/packages/official-publisher.js +48 -1
  145. package/dist/packages/provenance.d.ts +11 -0
  146. package/dist/packages/provenance.js +24 -0
  147. package/dist/platform/exclusions.js +4 -4
  148. package/dist/platform/ops/automations.ops.js +1 -1
  149. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  150. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  151. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  152. package/dist/platform/platform-ops.module.d.ts +2 -1
  153. package/dist/platform/platform-ops.module.js +2 -0
  154. package/dist/platform/route-schemas.js +2 -0
  155. package/dist/retention/purge-batch.js +10 -14
  156. package/dist/runtime/maintenance.d.ts +4 -2
  157. package/dist/runtime/maintenance.js +16 -3
  158. package/dist/runtime/run-finish.d.ts +3 -3
  159. package/dist/runtime/run-finish.js +7 -3
  160. package/dist/sandbox/permission-availability.d.ts +17 -2
  161. package/dist/sandbox/permission-availability.js +22 -1
  162. package/dist/sandbox/permission-facts.js +7 -1
  163. package/dist/tools/builtins/sandbox/common.js +2 -0
  164. package/dist/tools/pipeline.d.ts +2 -1
  165. package/dist/tools/pipeline.js +7 -2
  166. package/package.json +4 -3
  167. package/src/migrations/0238_extension_usage.sql +40 -0
  168. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -3,8 +3,10 @@ import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
4
  import { ExtensionApprovals } from "./approvals.js";
5
5
  import { ExtensionBlobs } from "./blobs.js";
6
+ import { IsolationStatusReader } from "./isolated/status.js";
7
+ import { type ReviewedGrants } from "./isolated/tier.js";
6
8
  import { type PermissionSet } from "./permission-set.js";
7
- import { ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
9
+ import { type ApprovalScope, type ExecutionRealm, ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
8
10
  /**
9
11
  * Revision approvals in shadow mode (extension permission model plan task 1.2b; the rollout fence
10
12
  * "shadow mode until 1.5a"). Every installed revision is resolved against its own revision grant,
@@ -24,6 +26,24 @@ export type ShadowGrantStatus =
24
26
  | "partially_revoked"
25
27
  /** No live grant of its own; it waits for review. */
26
28
  | "missing_grant"
29
+ /**
30
+ * No live grant of its own, and its review needs full access acknowledged per realm: a
31
+ * confirmation without the acknowledgement (plan task 1.3d) records none. A prediction: a
32
+ * revision that continues its approved grant at promotion (verified publisher evidence, which
33
+ * this report does not have) needs no acknowledgement; `continuity` says why it would not.
34
+ */
35
+ | "awaiting_acknowledgement"
36
+ /**
37
+ * Its own live grant covers its keys, but its catalog item's org scope is wider than the grant's
38
+ * approval scope: widening the scope needs a new review (enforced by plan task 1.5a).
39
+ */
40
+ | "scope_exceeds_grant"
41
+ /**
42
+ * Its own live grant does not cover full access in a realm its execution decision needs (a
43
+ * forcing key not reviewed, or retired, or the realm's key revoked): it would not serve until a
44
+ * new review (`uncoveredForcing` lists the keys).
45
+ */
46
+ | "realm_uncovered"
27
47
  /** No live grant, and the manifest lacks bilingual purposes: Republish with purposes. */
28
48
  | "missing_purposes"
29
49
  /** The package sha512 is not recorded yet (the backfill job fills it); no grant can match. */
@@ -47,6 +67,8 @@ export interface ShadowRevisionDecision {
47
67
  ungrantedKeys: string[];
48
68
  /** Keys without a bilingual purpose. */
49
69
  missingPurposes: string[];
70
+ /** Per realm, the forcing keys its own grant does not cover (`realm_uncovered`). */
71
+ uncoveredForcing?: Partial<Record<ExecutionRealm, string[]>>;
50
72
  /** Why the approved revision's grant does not carry over as continuity, when there is one. */
51
73
  continuity?: string;
52
74
  /** A required bootstrap install (the start gate). */
@@ -107,7 +129,18 @@ export declare function resolveRevisionGrant(input: {
107
129
  own: RevisionGrant | undefined;
108
130
  approved: RevisionGrant | undefined;
109
131
  legacy: LegacyDecision;
132
+ /** Its review needs full access acknowledged (the realms of its execution decision). */
133
+ fullAccess?: boolean;
134
+ /** Its catalog item's current org scope, when it is installed from a catalog item. */
135
+ itemScope?: ApprovalScope | undefined;
136
+ /**
137
+ * Per realm of its execution decision, the forcing keys its own grant does not cover
138
+ * (`isolated/tier.ts` `uncoveredForcing`, plan task 1.3b); empty or absent: covered.
139
+ */
140
+ uncovered?: Partial<Record<ExecutionRealm, string[]>> | undefined;
110
141
  }): ShadowRevisionDecision;
142
+ /** Whether `scope` reaches orgs `granted` does not (`all` ⊇ `optional` ⊇ `named`, named subsets). */
143
+ export declare function scopeWider(scope: ApprovalScope, granted: ApprovalScope): boolean;
111
144
  /** What a reviewed promotion carries besides the revision: its verified publisher evidence. */
112
145
  export interface PromotionEvidence {
113
146
  publisher: NewRevisionGrant["publisher"];
@@ -126,21 +159,39 @@ export type PromotionOutcome = {
126
159
  reason: string;
127
160
  };
128
161
  /** The installed revisions' shadow decisions, and promotion with continuity. */
129
- export declare class ExtensionRevisionApprovals {
162
+ export declare class ExtensionRevisionApprovals implements ReviewedGrants {
130
163
  private readonly kdb;
131
164
  readonly txHost: TransactionHost;
132
165
  private readonly grants;
133
166
  private readonly approvals;
134
167
  private readonly blobs;
135
168
  private readonly config;
169
+ /** The deployment-wide isolation state the shadow decisions are computed for (1.4j). */
170
+ private readonly isolation?;
136
171
  /** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
137
172
  private readonly sets;
138
- constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService);
173
+ constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService,
174
+ /** The deployment-wide isolation state the shadow decisions are computed for (1.4j). */
175
+ isolation?: Pick<IsolationStatusReader, "hostIsolation"> | undefined);
139
176
  /**
140
177
  * The shadow decision of every install record. A package that cannot be read is reported as
141
178
  * `unreadable` and never hides the others.
142
179
  */
143
180
  decisions(): Promise<ShadowRevisionDecision[]>;
181
+ /**
182
+ * The live grant (approved or partially_revoked) of exactly this revision when a person made it:
183
+ * source review, operator_cli or operator_config, whatever its publisher evidence (pin_only and
184
+ * none included). Undefined otherwise: no grant, a revoked or retired one, a continuity or auto
185
+ * grant. Admission (plan task 1.3b, `isolated/tier.ts`) accepts an official revision without a
186
+ * publisher proof when this returns a grant (#1368). A plain read; safe on every replica.
187
+ */
188
+ reviewedGrant(revision: RevisionIdentity): Promise<RevisionGrant | undefined>;
189
+ /**
190
+ * {@link promote} for an install that has just moved to `candidate` in the caller's transaction
191
+ * (`ExtensionAdminOps.install`): the package was read before it, so its permission set is given
192
+ * and no object storage call holds the transaction. A downgrade is a rollback.
193
+ */
194
+ promoteInstalled(candidate: RevisionIdentity, set: PermissionSet, kind: PromotionKind): Promise<PromotionOutcome>;
144
195
  /** The facts the enforcing start gate would act on; computed and reported, never refused. */
145
196
  startGate(): Promise<ShadowStartGate>;
146
197
  /**
@@ -159,6 +210,10 @@ export declare class ExtensionRevisionApprovals {
159
210
  /** The stored package of a revision, or undefined while its sha512 is not recorded. */
160
211
  private sha256Of;
161
212
  private setOf;
213
+ /** A package's permission set and section, cached by sha256 (content-addressed, never stale). */
214
+ private packageOf;
215
+ /** The current org scope of the catalog item an install comes from, if any. */
216
+ private itemScope;
162
217
  }
163
218
  /**
164
219
  * The review hash of a continuity grant: the kernel reviewed it against its source, so the hash
@@ -9,14 +9,19 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { createHash } from "node:crypto";
11
11
  import { SDK_VERSION } from "@capybara-hq/plugin-sdk";
12
- import { Inject, Injectable } from "@nestjs/common";
12
+ import { Inject, Injectable, Optional } from "@nestjs/common";
13
13
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
14
14
  import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { asPlatform } from "../infra/database/org-scope.js";
15
16
  import { TransactionHost } from "../infra/database/transaction-host.js";
16
17
  import { Transactional } from "../infra/database/transactional.decorator.js";
17
18
  import { canonicalJson } from "../tools/canonical-json.js";
18
19
  import { ExtensionApprovals } from "./approvals.js";
19
20
  import { ExtensionBlobs } from "./blobs.js";
21
+ import { executionDecision } from "./execution-realm.js";
22
+ import { deploymentConfigIsolatable } from "./isolated/admission.js";
23
+ import { IsolationStatusReader } from "./isolated/status.js";
24
+ import { uncoveredForcing } from "./isolated/tier.js";
20
25
  import { permissionSetOfPackage, readExtensionPackage } from "./package.js";
21
26
  import { blockingKeys, diffPermissions, permissionKeys, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
22
27
  import { reviewPermissionRows } from "./permission-view.js";
@@ -98,7 +103,17 @@ export function resolveRevisionGrant(input) {
98
103
  const keys = permissionKeys(set).filter((key) => !serving.has(key));
99
104
  const refusedKeys = keys.filter((key) => granted.has(key));
100
105
  const ungrantedKeys = keys.filter((key) => !granted.has(key));
101
- return decide(keys.length > 0 ? "partially_revoked" : "granted", true, {
106
+ const widened = input.itemScope !== undefined && scopeWider(input.itemScope, own.approvalScope);
107
+ const uncovered = Object.fromEntries(Object.entries(input.uncovered ?? {}).filter(([, forcing]) => (forcing ?? []).length > 0));
108
+ if (Object.keys(uncovered).length > 0) {
109
+ return decide("realm_uncovered", false, {
110
+ generation: own.generation,
111
+ refusedKeys,
112
+ ungrantedKeys,
113
+ uncoveredForcing: uncovered,
114
+ });
115
+ }
116
+ return decide(keys.length > 0 ? "partially_revoked" : widened ? "scope_exceeds_grant" : "granted", true, {
102
117
  generation: own.generation,
103
118
  refusedKeys,
104
119
  ungrantedKeys,
@@ -112,10 +127,32 @@ export function resolveRevisionGrant(input) {
112
127
  publisher: { evidence: "none" },
113
128
  }) ?? "continuity is recorded when the revision is promoted")
114
129
  : undefined;
115
- return decide(missing.length > 0 ? "missing_purposes" : "missing_grant", false, {
130
+ const status = missing.length > 0
131
+ ? "missing_purposes"
132
+ : input.fullAccess === true
133
+ ? "awaiting_acknowledgement"
134
+ : "missing_grant";
135
+ return decide(status, false, {
116
136
  ...(continuity !== undefined && { continuity }),
117
137
  });
118
138
  }
139
+ const SCOPE_BREADTH = { named: 0, optional: 1, all: 2 };
140
+ /** Whether `scope` reaches orgs `granted` does not (`all` ⊇ `optional` ⊇ `named`, named subsets). */
141
+ export function scopeWider(scope, granted) {
142
+ if (SCOPE_BREADTH[scope.mode] !== SCOPE_BREADTH[granted.mode]) {
143
+ return SCOPE_BREADTH[scope.mode] > SCOPE_BREADTH[granted.mode];
144
+ }
145
+ if (scope.mode !== "named" || granted.mode !== "named")
146
+ return false;
147
+ const allowed = new Set(granted.orgs);
148
+ return scope.orgs.some((org) => !allowed.has(org));
149
+ }
150
+ /** Grant sources made by a person's review: they lift the official pin-only refusal (#1368). */
151
+ const REVIEWED_SOURCES = new Set([
152
+ "review",
153
+ "operator_cli",
154
+ "operator_config",
155
+ ]);
119
156
  const SET_CACHE_ENTRIES = 512;
120
157
  /** The installed revisions' shadow decisions, and promotion with continuity. */
121
158
  let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
@@ -125,15 +162,19 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
125
162
  approvals;
126
163
  blobs;
127
164
  config;
165
+ isolation;
128
166
  /** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
129
167
  sets = new Map();
130
- constructor(kdb, txHost, grants, approvals, blobs, config) {
168
+ constructor(kdb, txHost, grants, approvals, blobs, config,
169
+ /** The deployment-wide isolation state the shadow decisions are computed for (1.4j). */
170
+ isolation) {
131
171
  this.kdb = kdb;
132
172
  this.txHost = txHost;
133
173
  this.grants = grants;
134
174
  this.approvals = approvals;
135
175
  this.blobs = blobs;
136
176
  this.config = config;
177
+ this.isolation = isolation;
137
178
  }
138
179
  /**
139
180
  * The shadow decision of every install record. A package that cannot be read is reported as
@@ -150,6 +191,7 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
150
191
  "i.required",
151
192
  "i.approved_version",
152
193
  "i.approved_sha512",
194
+ "i.catalog_item_id",
153
195
  "p.sha512",
154
196
  ])
155
197
  .orderBy("i.name")
@@ -157,11 +199,14 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
157
199
  const snapshots = await this.approvals.all();
158
200
  const autoApprove = this.config.get().extensionPermissions.autoApprove === true;
159
201
  const out = [];
202
+ const host = (await this.isolation?.hostIsolation()) ??
203
+ (this.config.get().extensionHost.isolation ? "failing" : "not_configured");
160
204
  for (const row of installs) {
161
205
  const revision = { plugin: row.name, version: row.version, sha512: row.sha512 };
162
206
  let set;
207
+ let section;
163
208
  try {
164
- set = await this.setOf(row.sha256);
209
+ ({ set, section } = await this.packageOf(row.sha256));
165
210
  }
166
211
  catch {
167
212
  out.push({
@@ -190,6 +235,17 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
190
235
  sha512: row.approved_sha512,
191
236
  })
192
237
  : undefined;
238
+ const decision = executionDecision({
239
+ keys: permissionKeys(set),
240
+ server: true,
241
+ client: section.client !== undefined ? {} : undefined,
242
+ host,
243
+ configSchemaIsolatable: deploymentConfigIsolatable(section),
244
+ });
245
+ // awaiting_acknowledgement only where a person's catalog review grants it: a required
246
+ // (bootstrap) install is granted by the bootstrap approval (1.3c), and unknown keys block
247
+ // any review
248
+ const fullAccess = Object.keys(decision.fullAccess).length > 0 && decision.confirmable && !row.required;
193
249
  out.push(resolveRevisionGrant({
194
250
  revision,
195
251
  set,
@@ -197,10 +253,34 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
197
253
  own,
198
254
  approved,
199
255
  legacy: legacyDecision(set, snapshots.get(row.name), autoApprove),
256
+ fullAccess,
257
+ // 1.3b's one realm coverage rule: a realm whose forcing keys the grant does not cover
258
+ // would not serve
259
+ uncovered: own ? uncoveredForcing(decision, own) : undefined,
260
+ itemScope: own ? await this.itemScope(row.catalog_item_id) : undefined,
200
261
  }));
201
262
  }
202
263
  return out;
203
264
  }
265
+ /**
266
+ * The live grant (approved or partially_revoked) of exactly this revision when a person made it:
267
+ * source review, operator_cli or operator_config, whatever its publisher evidence (pin_only and
268
+ * none included). Undefined otherwise: no grant, a revoked or retired one, a continuity or auto
269
+ * grant. Admission (plan task 1.3b, `isolated/tier.ts`) accepts an official revision without a
270
+ * publisher proof when this returns a grant (#1368). A plain read; safe on every replica.
271
+ */
272
+ async reviewedGrant(revision) {
273
+ const grant = await this.grants.live(revision);
274
+ return grant && REVIEWED_SOURCES.has(grant.source) ? grant : undefined;
275
+ }
276
+ /**
277
+ * {@link promote} for an install that has just moved to `candidate` in the caller's transaction
278
+ * (`ExtensionAdminOps.install`): the package was read before it, so its permission set is given
279
+ * and no object storage call holds the transaction. A downgrade is a rollback.
280
+ */
281
+ async promoteInstalled(candidate, set, kind) {
282
+ return this.promoteIn(candidate, { publisher: { evidence: "none" } }, kind, purposeRowsOf(set));
283
+ }
204
284
  /** The facts the enforcing start gate would act on; computed and reported, never refused. */
205
285
  async startGate() {
206
286
  const all = await this.decisions();
@@ -239,15 +319,26 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
239
319
  return this.promoteIn(candidate, evidence, kind, purposes);
240
320
  }
241
321
  async promoteIn(candidate, evidence, kind, purposes) {
242
- const own = await this.grants.live(candidate);
243
- if (own) {
244
- await this.grants.promote(candidate);
245
- return { status: "promoted", grant: own, continued: false };
246
- }
247
322
  const pending = async (reason) => {
248
323
  await this.grants.setCandidate(candidate.plugin, candidate);
249
324
  return { status: "pending", reason };
250
325
  };
326
+ const own = await this.grants.live(candidate);
327
+ if (own) {
328
+ try {
329
+ // rechecked under the grant's row lock: a revocation committed since the read leaves the
330
+ // revision a candidate, it never fails the install that called (shadow mode)
331
+ await this.grants.promote(candidate);
332
+ }
333
+ catch (err) {
334
+ if (err instanceof RevisionGrantError &&
335
+ (err.code === "not_found" || err.code === "terminal")) {
336
+ return pending(err.message);
337
+ }
338
+ throw err;
339
+ }
340
+ return { status: "promoted", grant: own, continued: false };
341
+ }
251
342
  const newest = await this.grants.get(candidate);
252
343
  if (newest)
253
344
  return pending(`its grant is ${newest.state}; it needs a new review`);
@@ -309,6 +400,10 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
309
400
  return row?.sha256;
310
401
  }
311
402
  async setOf(sha256) {
403
+ return (await this.packageOf(sha256)).set;
404
+ }
405
+ /** A package's permission set and section, cached by sha256 (content-addressed, never stale). */
406
+ async packageOf(sha256) {
312
407
  const cached = this.sets.get(sha256);
313
408
  if (cached)
314
409
  return cached;
@@ -316,14 +411,38 @@ let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
316
411
  maxBytes: this.config.get().packages.maxBytes,
317
412
  hostSdkVersion: SDK_VERSION,
318
413
  });
319
- const set = permissionSetOfPackage(pkg);
414
+ const entry = { set: permissionSetOfPackage(pkg), section: pkg.section };
320
415
  // a bound on memory only: a dropped entry is read again from the package store
321
416
  if (this.sets.size >= SET_CACHE_ENTRIES)
322
417
  this.sets.clear();
323
- this.sets.set(sha256, set);
324
- return set;
418
+ this.sets.set(sha256, entry);
419
+ return entry;
420
+ }
421
+ /** The current org scope of the catalog item an install comes from, if any. */
422
+ async itemScope(itemId) {
423
+ if (itemId === null)
424
+ return undefined;
425
+ const item = await this.kdb.db
426
+ .selectFrom("catalog_items")
427
+ .select("scope")
428
+ .where("id", "=", itemId)
429
+ .executeTakeFirst();
430
+ if (item === undefined)
431
+ return undefined;
432
+ if (item.scope !== "named")
433
+ return { mode: item.scope };
434
+ // org-filter: deployment-wide: the item's whole named list (spans orgs), keyed by its item id
435
+ const orgs = await asPlatform("read the named scope of the catalog item of an install", () => this.kdb.db
436
+ .selectFrom("catalog_item_scope_orgs")
437
+ .select("org_id")
438
+ .where("item_id", "=", itemId)
439
+ .execute());
440
+ return { mode: "named", orgs: orgs.map((r) => r.org_id) };
325
441
  }
326
442
  };
443
+ __decorate([
444
+ Transactional({ propagation: "mandatory" })
445
+ ], ExtensionRevisionApprovals.prototype, "promoteInstalled", null);
327
446
  __decorate([
328
447
  Transactional()
329
448
  ], ExtensionRevisionApprovals.prototype, "promoteIn", null);
@@ -334,7 +453,9 @@ ExtensionRevisionApprovals = __decorate([
334
453
  __param(2, Inject(ExtensionRevisionGrants)),
335
454
  __param(3, Inject(ExtensionApprovals)),
336
455
  __param(4, Inject(ExtensionBlobs)),
337
- __param(5, Inject(KernelConfigService))
456
+ __param(5, Inject(KernelConfigService)),
457
+ __param(6, Optional()),
458
+ __param(6, Inject(IsolationStatusReader))
338
459
  ], ExtensionRevisionApprovals);
339
460
  export { ExtensionRevisionApprovals };
340
461
  /**
@@ -0,0 +1,144 @@
1
+ import type { PublisherEvidence } from "../catalog/provenance.js";
2
+ import { KernelDb } from "../infra/database/kernel-db.js";
3
+ import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import { type HostIsolation } from "./execution-realm.js";
5
+ import { IsolationStatusReader } from "./isolated/status.js";
6
+ import type { ExtensionPackage } from "./package.js";
7
+ import { type PermissionSet } from "./permission-set.js";
8
+ import { type ReviewDisplay } from "./review-hash.js";
9
+ import { type ApprovalScope, type ExecutionRealm, ExtensionRevisionGrants, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
10
+ /**
11
+ * The permission review of one extension revision at catalog prepare and confirm (extension
12
+ * permission model spec, "Review, updates and provenance"; plan tasks 1.3a and 1.3d).
13
+ *
14
+ * Prepare binds the 1.2e display and its `review:v1:` hash: identity, every permission and purpose
15
+ * row, the previous approval and the diff against it, the org scope, the approver authority, the
16
+ * risk contract version, the publisher evidence and the execution realms. It also decides whether
17
+ * a confirmation re-consents (a `review` grant, `super_admin`) or continues the install's approved
18
+ * grant (a `continuity` grant carrying its authority): re-consent is exactly "not a continuation"
19
+ * (the store's `continuityProblem`): a new or broadened key, informational rows included, a
20
+ * changed purpose in either language, a widened org scope, full access not covered by the
21
+ * approved grant, or a publisher that is not the same verified one (pin-only and unverified
22
+ * evidence never continue, #1368: they get the same review and decision with no continuity).
23
+ *
24
+ * Confirm recomputes the display with the prepared scope: any drift (the approved grant revoked
25
+ * or replaced, the host's isolation, the evidence) makes the review stale. The grant binds the
26
+ * display with the scope actually chosen.
27
+ *
28
+ * Shadow mode until plan task 1.5a: the grant is minted and the decisions computed while the
29
+ * legacy snapshot keeps governing admission, so a confirmation that cannot mint a grant still
30
+ * completes the import; the result says why. A full-access review grant needs one explicit
31
+ * acknowledgement per affected realm bound to the review hash (1.3d): a missing one only skips the
32
+ * grant until 1.5a, a wrong one (another hash, a missing or extra realm) refuses the confirm.
33
+ */
34
+ export interface RevisionReview {
35
+ revision: RevisionIdentity;
36
+ publisher: PublisherEvidence;
37
+ evidenceDigest: string | null;
38
+ /** The org scope the display was prepared with; confirm rechecks against it. */
39
+ preparedScope: ApprovalScope;
40
+ display: ReviewDisplay;
41
+ /** `review:v1:<sha256>` of {@link display}: what a full-access acknowledgement binds. */
42
+ hash: string;
43
+ /**
44
+ * `granted`: this exact revision has a live grant already, which a confirmation keeps;
45
+ * `continuity`: a confirmation continues the install's approved grant, with no re-consent;
46
+ * `review`: it records a new review grant, `reason` says why it is not a continuation.
47
+ */
48
+ consent: {
49
+ kind: "granted";
50
+ generation: number;
51
+ } | {
52
+ kind: "continuity";
53
+ } | {
54
+ kind: "review";
55
+ reason: string;
56
+ };
57
+ /** The realms whose full access a review grant needs acknowledged, sorted ([] for continuity). */
58
+ acknowledge: ExecutionRealm[];
59
+ /** Why no grant can be minted from this review (missing purposes, unknown keys). */
60
+ blocked?: string;
61
+ }
62
+ /** The per-realm acknowledgement a confirm sends (1.3d). */
63
+ export interface FullAccessAcknowledgement {
64
+ /** The {@link RevisionReview.hash} the approver confirmed. */
65
+ reviewHash: string;
66
+ realms: ExecutionRealm[];
67
+ }
68
+ /** What a confirmation did with the grant. */
69
+ export type RevisionGrantOutcome = {
70
+ status: "granted";
71
+ generation: number;
72
+ } | {
73
+ status: "kept";
74
+ generation: number;
75
+ } | {
76
+ status: "continued";
77
+ generation: number;
78
+ fullAccess: ExecutionRealm[];
79
+ } | {
80
+ status: "skipped";
81
+ reason: string;
82
+ };
83
+ export interface RevisionReviewInput {
84
+ revision: RevisionIdentity;
85
+ pkg: Pick<ExtensionPackage, "section">;
86
+ set: PermissionSet;
87
+ host: HostIsolation;
88
+ approvalScope: ApprovalScope;
89
+ publisher: PublisherEvidence;
90
+ evidenceDigest?: string | undefined;
91
+ /** The live grant of the install's approved revision, if any. */
92
+ previous?: RevisionGrant | undefined;
93
+ /** The newest grant of this exact revision in any state, if any. */
94
+ own?: RevisionGrant | undefined;
95
+ /**
96
+ * The authority a review grant would exercise: `super_admin` (a person on the web, default) or
97
+ * `operator` (`capybara extensions approve`). The display binds it.
98
+ */
99
+ authority?: "super_admin" | "operator" | undefined;
100
+ }
101
+ /** The review of one revision. Pure. */
102
+ export declare function buildRevisionReview(input: RevisionReviewInput): RevisionReview;
103
+ /**
104
+ * Checks a full-access acknowledgement sent with a confirm against the prepared review (1.3d).
105
+ * Absent is allowed until plan task 1.5a (the grant is skipped); present, it must name the
106
+ * review's hash and exactly the realms the review needs acknowledged, else 409
107
+ * `plugin.full_access_ack_invalid`.
108
+ */
109
+ export declare function checkAcknowledgement(review: RevisionReview, ack: FullAccessAcknowledgement | undefined): void;
110
+ /** Prepare and confirm of revision reviews, and the grant a confirmation records. */
111
+ export declare class RevisionReviews {
112
+ private readonly kdb;
113
+ readonly txHost: TransactionHost;
114
+ private readonly grants;
115
+ /** The host profile a review binds (plan task 1.4j): configured or not. */
116
+ private readonly isolation;
117
+ constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants,
118
+ /** The host profile a review binds (plan task 1.4j): configured or not. */
119
+ isolation: Pick<IsolationStatusReader, "reviewProfile">);
120
+ /** The live grant of the install's approved revision, if any. */
121
+ previousGrant(plugin: string): Promise<RevisionGrant | undefined>;
122
+ /** The review of a revision as prepare shows it. */
123
+ prepare(input: Omit<RevisionReviewInput, "host" | "previous">): Promise<RevisionReview>;
124
+ /**
125
+ * At confirm, in the confirm's transaction (under the extension's install lock): rechecks the
126
+ * prepared review against the current previous grant and host, then records the grant for the
127
+ * chosen scope. Returns `stale` when the review no longer holds; never throws for a grant that
128
+ * cannot be recorded in shadow mode (the outcome says why).
129
+ */
130
+ confirm(input: {
131
+ actor: string | null;
132
+ actorTokenId?: string | undefined;
133
+ prepared: RevisionReview;
134
+ pkg: Pick<ExtensionPackage, "section">;
135
+ set: PermissionSet;
136
+ approvalScope: ApprovalScope;
137
+ ack: FullAccessAcknowledgement | undefined;
138
+ /**
139
+ * The operator approves from the CLI (`actor` null): an `operator_cli` grant, prepared with the
140
+ * `operator` authority. Without it a confirm without a person records none.
141
+ */
142
+ operator?: boolean | undefined;
143
+ }): Promise<RevisionGrantOutcome | "stale">;
144
+ }