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

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 (172) 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 +18 -8
  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 +24 -3
  106. package/dist/extensions/permission-set.d.ts +12 -3
  107. package/dist/extensions/permission-set.js +5 -5
  108. package/dist/extensions/permission-view.d.ts +12 -5
  109. package/dist/extensions/permission-view.js +23 -2
  110. package/dist/extensions/permissions.controller.d.ts +35 -0
  111. package/dist/extensions/permissions.controller.js +98 -0
  112. package/dist/extensions/permissions.schemas.d.ts +288 -0
  113. package/dist/extensions/permissions.schemas.js +96 -0
  114. package/dist/extensions/permissions.service.d.ts +116 -0
  115. package/dist/extensions/permissions.service.js +428 -0
  116. package/dist/extensions/realm-retirement.d.ts +65 -0
  117. package/dist/extensions/realm-retirement.js +150 -0
  118. package/dist/extensions/revision-approvals.d.ts +58 -3
  119. package/dist/extensions/revision-approvals.js +135 -14
  120. package/dist/extensions/revision-review.d.ts +144 -0
  121. package/dist/extensions/revision-review.js +297 -0
  122. package/dist/extensions/revocation.js +3 -0
  123. package/dist/extensions/state.module.js +12 -0
  124. package/dist/git/run-end.d.ts +35 -7
  125. package/dist/git/run-end.js +87 -38
  126. package/dist/http/api.module.js +2 -0
  127. package/dist/identity/audit.d.ts +2 -1
  128. package/dist/identity/audit.js +4 -17
  129. package/dist/index.d.ts +6 -2
  130. package/dist/index.js +6 -2
  131. package/dist/infra/config/kernel-config.service.d.ts +6 -0
  132. package/dist/infra/config/kernel-config.service.js +21 -0
  133. package/dist/infra/outbox/registry.d.ts +13 -0
  134. package/dist/infra/outbox/registry.js +8 -0
  135. package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
  136. package/dist/lifecycle/kernel-lifecycle.js +73 -18
  137. package/dist/net/private-endpoint-preflight.d.ts +159 -0
  138. package/dist/net/private-endpoint-preflight.js +417 -0
  139. package/dist/net/private-endpoints.d.ts +68 -0
  140. package/dist/net/private-endpoints.js +164 -0
  141. package/dist/net/public-address.d.ts +14 -0
  142. package/dist/net/public-address.js +15 -1
  143. package/dist/net/safe-fetch.d.ts +2 -1
  144. package/dist/net/safe-fetch.js +10 -3
  145. package/dist/overrides.d.ts +4 -0
  146. package/dist/overrides.js +2 -0
  147. package/dist/packages/official-publisher.d.ts +26 -1
  148. package/dist/packages/official-publisher.js +48 -1
  149. package/dist/packages/provenance.d.ts +11 -0
  150. package/dist/packages/provenance.js +24 -0
  151. package/dist/platform/exclusions.js +4 -4
  152. package/dist/platform/ops/automations.ops.js +1 -1
  153. package/dist/platform/ops/catalog-admin.ops.js +25 -4
  154. package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
  155. package/dist/platform/ops/extension-permissions.ops.js +159 -0
  156. package/dist/platform/platform-ops.module.d.ts +2 -1
  157. package/dist/platform/platform-ops.module.js +2 -0
  158. package/dist/platform/route-schemas.js +2 -0
  159. package/dist/retention/purge-batch.js +10 -14
  160. package/dist/runtime/maintenance.d.ts +4 -2
  161. package/dist/runtime/maintenance.js +16 -3
  162. package/dist/runtime/run-finish.d.ts +3 -3
  163. package/dist/runtime/run-finish.js +7 -3
  164. package/dist/sandbox/permission-availability.d.ts +17 -2
  165. package/dist/sandbox/permission-availability.js +22 -1
  166. package/dist/sandbox/permission-facts.js +7 -1
  167. package/dist/tools/builtins/sandbox/common.js +2 -0
  168. package/dist/tools/pipeline.d.ts +2 -1
  169. package/dist/tools/pipeline.js +7 -2
  170. package/package.json +4 -3
  171. package/src/migrations/0238_extension_usage.sql +40 -0
  172. package/src/migrations/0239_extension_replica_isolation.sql +28 -0
@@ -0,0 +1,65 @@
1
+ import type { ExtensionContext } from "@capybara-hq/plugin-sdk";
2
+ import { KernelDb } from "../infra/database/kernel-db.js";
3
+ import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import type { KernelLogger } from "../log.js";
5
+ import { ExtensionHost } from "./host.js";
6
+ import { ExtensionRevisionGrants, type RevisionIdentity } from "./revision-grants.js";
7
+ /**
8
+ * Retiring the host reason (extension permission model spec, "Purpose and boundary"; plan task
9
+ * 1.3b). A revision approved to run in process because its host had no isolation carries the
10
+ * kernel-generated forcing key `host.no-isolation` in its server realm. Once this replica's
11
+ * isolation supervisor is stably ready (configured, and its own Engine and image checks passed over
12
+ * the lifecycle's stability window), that reason no longer applies: it is retired from every live
13
+ * grant. When it was the realm's last forcing key, `execution.full-access:server` retires with it
14
+ * and the revision belongs in the isolated tier; when another forcing key still applies, only the
15
+ * reviewed exception stays.
16
+ *
17
+ * The retirement and its audit commit in one transaction. The grant tables' triggers (migration
18
+ * 0235) advance the grant epoch, which fences every replica's leases within the 5 s bound. After
19
+ * the commit this replica fences its own leases and publishes the revocation hint, the fast path
20
+ * for the others. Leases then report the lost server full access. From task 1.5a they enforce it:
21
+ * the in-process generation is drained and unloaded, and an isolated one starts (1.3e's path).
22
+ * Until then the swap is only reported.
23
+ *
24
+ * Retirement is final: a later loss of isolation does not restore the reason. The revision then
25
+ * needs a new review before it may run in process again.
26
+ *
27
+ * Grants are deployment rows, so the first ready replica retires for every replica. During a
28
+ * rolling change that turns isolation on, replicas still without isolation then report the
29
+ * revision as `hostReasonRetired` (pending review once enforcing) until they are replaced; that is
30
+ * the spec's rule that a host without isolation needs its reason in force.
31
+ *
32
+ * Exactly one writer per grant generation: the live row is locked and re-read before writing, so
33
+ * replicas racing on the same generation end with one retirement, one audit row and one epoch
34
+ * bump.
35
+ */
36
+ export interface RetiredHostReason {
37
+ revision: RevisionIdentity;
38
+ generation: number;
39
+ /** The server realm's full access retired with it (no other forcing key remained). */
40
+ realmRetired: boolean;
41
+ /** The server realm's forcing keys still in force. */
42
+ remaining: string[];
43
+ }
44
+ export declare class HostReasonRetirement {
45
+ private readonly kdb;
46
+ readonly txHost: TransactionHost;
47
+ private readonly grants;
48
+ private readonly host;
49
+ private readonly bus;
50
+ private readonly log;
51
+ constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, host: Pick<ExtensionHost, "fenceRevocation">, bus: Pick<ExtensionContext["bus"], "publish">, log: KernelLogger);
52
+ /**
53
+ * Retires `host.no-isolation` from every live grant that still carries it in its server realm.
54
+ * Call only on a positive readiness signal of the isolation supervisor. One failing grant is
55
+ * logged and never stops the others.
56
+ */
57
+ retireAll(): Promise<RetiredHostReason[]>;
58
+ /**
59
+ * Retires the host reason of one grant generation. Returns undefined when that generation is no
60
+ * longer live or no longer carries an unretired host reason (another replica got there first).
61
+ */
62
+ retire(revision: RevisionIdentity, generation: number): Promise<RetiredHostReason | undefined>;
63
+ /** Live grants whose server realm still carries an unretired `host.no-isolation`. */
64
+ private candidates;
65
+ }
@@ -0,0 +1,150 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { sql } from "kysely";
12
+ import { audit } from "../identity/audit.js";
13
+ import { afterCommit } from "../infra/database/after-commit.js";
14
+ import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { TransactionHost } from "../infra/database/transaction-host.js";
16
+ import { Transactional } from "../infra/database/transactional.decorator.js";
17
+ import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
18
+ import { HOST_NO_ISOLATION_KEY } from "./execution-realm.js";
19
+ import { ExtensionHost } from "./host.js";
20
+ import { ExtensionRevisionGrants, fullAccessKey, } from "./revision-grants.js";
21
+ import { GRANT_REVOKED_TOPIC } from "./revocation.js";
22
+ let HostReasonRetirement = class HostReasonRetirement {
23
+ kdb;
24
+ txHost;
25
+ grants;
26
+ host;
27
+ bus;
28
+ log;
29
+ constructor(kdb, txHost, grants, host, bus, log) {
30
+ this.kdb = kdb;
31
+ this.txHost = txHost;
32
+ this.grants = grants;
33
+ this.host = host;
34
+ this.bus = bus;
35
+ this.log = log;
36
+ }
37
+ /**
38
+ * Retires `host.no-isolation` from every live grant that still carries it in its server realm.
39
+ * Call only on a positive readiness signal of the isolation supervisor. One failing grant is
40
+ * logged and never stops the others.
41
+ */
42
+ async retireAll() {
43
+ const out = [];
44
+ for (const candidate of await this.candidates()) {
45
+ try {
46
+ const retired = await this.retire(candidate, candidate.generation);
47
+ if (retired)
48
+ out.push(retired);
49
+ }
50
+ catch (err) {
51
+ this.log.warn("retiring host.no-isolation from a revision grant failed", {
52
+ plugin: candidate.plugin,
53
+ version: candidate.version,
54
+ err,
55
+ });
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+ /**
61
+ * Retires the host reason of one grant generation. Returns undefined when that generation is no
62
+ * longer live or no longer carries an unretired host reason (another replica got there first).
63
+ */
64
+ async retire(revision, generation) {
65
+ const locked = await this.kdb.db
66
+ .selectFrom("extension_revision_grants")
67
+ .select("generation")
68
+ .where("plugin", "=", revision.plugin)
69
+ .where("version", "=", revision.version)
70
+ .where("sha512", "=", revision.sha512)
71
+ .where("generation", "=", generation)
72
+ .where("state", "in", ["approved", "partially_revoked"])
73
+ .forNoKeyUpdate()
74
+ .executeTakeFirst();
75
+ if (!locked)
76
+ return undefined;
77
+ const before = await this.grants.live(revision);
78
+ if (!before || before.generation !== generation || !carriesHostReason(before)) {
79
+ return undefined;
80
+ }
81
+ const after = await this.grants.retireForcing(revision, "server", HOST_NO_ISOLATION_KEY, null);
82
+ const retiredForcing = new Set(after.retiredForcing.server ?? []);
83
+ const remaining = (after.realms.server ?? []).filter((key) => !retiredForcing.has(key));
84
+ const realmRetired = after.retiredKeys.includes(fullAccessKey("server"));
85
+ await audit(this.kdb.db, {
86
+ actorAccountId: null,
87
+ action: "extension.full_access_retired",
88
+ target: revision.plugin,
89
+ detail: {
90
+ plugin: revision.plugin,
91
+ version: revision.version,
92
+ sha512: revision.sha512,
93
+ generation,
94
+ realm: "server",
95
+ forcingKey: HOST_NO_ISOLATION_KEY,
96
+ reason: "isolation supervisor available",
97
+ realmRetired,
98
+ remaining,
99
+ state: after.state,
100
+ reviewHash: after.reviewHash,
101
+ publisherEvidence: after.publisherEvidence,
102
+ },
103
+ });
104
+ const { plugin } = revision;
105
+ afterCommit(async () => {
106
+ await this.host
107
+ .fenceRevocation(plugin)
108
+ .catch((err) => this.log.warn("host reason retirement fence failed", { plugin, err }));
109
+ try {
110
+ await this.bus.publish(GRANT_REVOKED_TOPIC, { plugin });
111
+ }
112
+ catch (err) {
113
+ this.log.warn("cannot publish a grant change hint; the grant epoch fences replicas", {
114
+ plugin,
115
+ err,
116
+ });
117
+ }
118
+ });
119
+ return { revision, generation, realmRetired, remaining };
120
+ }
121
+ /** Live grants whose server realm still carries an unretired `host.no-isolation`. */
122
+ async candidates() {
123
+ const key = JSON.stringify([HOST_NO_ISOLATION_KEY]);
124
+ return this.kdb.db
125
+ .selectFrom("extension_revision_grants")
126
+ .select(["plugin", "version", "sha512", "generation"])
127
+ .where("state", "in", ["approved", "partially_revoked"])
128
+ .where(sql `coalesce(realms -> 'server', '[]'::jsonb) @> ${key}::jsonb`)
129
+ .where(sql `NOT coalesce(retired_forcing -> 'server', '[]'::jsonb) @> ${key}::jsonb`)
130
+ .orderBy("plugin")
131
+ .execute();
132
+ }
133
+ };
134
+ __decorate([
135
+ Transactional()
136
+ ], HostReasonRetirement.prototype, "retire", null);
137
+ HostReasonRetirement = __decorate([
138
+ Injectable(),
139
+ __param(0, Inject(KernelDb)),
140
+ __param(1, Inject(TransactionHost)),
141
+ __param(2, Inject(ExtensionRevisionGrants)),
142
+ __param(3, Inject(ExtensionHost)),
143
+ __param(4, Inject(KERNEL_BUS)),
144
+ __param(5, Inject(KERNEL_LOGGER))
145
+ ], HostReasonRetirement);
146
+ export { HostReasonRetirement };
147
+ function carriesHostReason(grant) {
148
+ return ((grant.realms.server ?? []).includes(HOST_NO_ISOLATION_KEY) &&
149
+ !(grant.retiredForcing.server ?? []).includes(HOST_NO_ISOLATION_KEY));
150
+ }
@@ -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
  /**