@capybara-hq/kernel 0.1.0-rc.143 → 0.1.0-rc.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +30 -11
- package/dist/agents/admin-agents.js +51 -16
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/marketplace-fetch.d.ts +2 -0
- package/dist/catalog/marketplace-fetch.js +7 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +9 -0
- package/dist/config/schema.js +26 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -2
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.js +4 -3
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +30 -10
- package/dist/extensions/host.js +162 -43
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/isolated/tier.d.ts +14 -0
- package/dist/extensions/isolated/tier.js +27 -0
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/publisher-proof.job.d.ts +39 -0
- package/dist/extensions/publisher-proof.job.js +160 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +21 -1
- package/dist/orgs/orgs.service.js +40 -1
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/packages/official-publisher.d.ts +5 -0
- package/dist/packages/official-publisher.js +24 -3
- package/dist/packages/provenance.d.ts +6 -0
- package/dist/packages/provenance.js +26 -9
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +8 -8
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/roles/worker.module.js +6 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- package/src/migrations/0237_extension_handoff_health.sql +18 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EXTENSION_POINT_CARDINALITY, EXTENSION_POINTS, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { EXTENSION_POINT_CARDINALITY, EXTENSION_POINTS, extensionPointRefs, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import semver from "semver";
|
|
3
3
|
/**
|
|
4
4
|
* Code of the {@link ExtensionResolveError} for a single-provider extension point that more than
|
|
@@ -32,8 +32,7 @@ export function parseProviderConflict(detail) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* The single-provider extension points
|
|
36
|
-
* `config-source`; `EXTENSION_POINT_CARDINALITY`) among `provides`, sorted (the lock order).
|
|
35
|
+
* The single-provider extension points among `provides`, sorted in lock order.
|
|
37
36
|
*/
|
|
38
37
|
export function singlePointsOf(provides) {
|
|
39
38
|
return [
|
|
@@ -58,7 +57,7 @@ export function electSingleProviders(desired) {
|
|
|
58
57
|
const owners = new Map();
|
|
59
58
|
const losers = new Map();
|
|
60
59
|
for (const d of desired) {
|
|
61
|
-
const points = singlePointsOf(d.section.manifest.provides);
|
|
60
|
+
const points = singlePointsOf(extensionPointRefs(d.section.manifest.provides));
|
|
62
61
|
const lost = points.find((p) => owners.has(p));
|
|
63
62
|
if (lost !== undefined) {
|
|
64
63
|
losers.set(d.name, { extensionPoint: lost, winner: owners.get(lost) });
|
|
@@ -81,10 +80,10 @@ export class ExtensionResolveError extends Error {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
83
|
+
* Validate SDK ranges, dependencies, single-provider cardinality and cycles, then preserve input
|
|
84
|
+
* order within each dependency level. An absent required provider is an error. An optional provider
|
|
85
|
+
* participates in ordering and cycle detection when present. Storage permission implies ordering
|
|
86
|
+
* after the object-store provider. The approval gate marks missing storage providers pending.
|
|
88
87
|
*/
|
|
89
88
|
export function resolveExtensions(manifests, sdkVersion) {
|
|
90
89
|
const seen = new Set();
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
+
import { ExtensionApprovals } from "./approvals.js";
|
|
5
|
+
import { ExtensionBlobs } from "./blobs.js";
|
|
6
|
+
import { type PermissionSet } from "./permission-set.js";
|
|
7
|
+
import { ExtensionRevisionGrants, type NewRevisionGrant, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
|
|
8
|
+
/**
|
|
9
|
+
* Revision approvals in shadow mode (extension permission model plan task 1.2b; the rollout fence
|
|
10
|
+
* "shadow mode until 1.5a"). Every installed revision is resolved against its own revision grant,
|
|
11
|
+
* never against the grant of an older or newer version (no `isOlder`): a rollback rechecks the
|
|
12
|
+
* selected revision's own grant. The result sits next to the legacy snapshot decision, which keeps
|
|
13
|
+
* governing admission: nothing here refuses a start, load or call.
|
|
14
|
+
*
|
|
15
|
+
* No grant is minted from a legacy snapshot approval: that consent never showed purposes, realms or
|
|
16
|
+
* the full-access warning. First grants come from the review (plan task 1.3a) and the bootstrap
|
|
17
|
+
* approval (1.3c); until then every revision resolves to `missing_grant`.
|
|
18
|
+
*/
|
|
19
|
+
/** How the enforcing path (plan task 1.5a) would treat one installed revision. */
|
|
20
|
+
export type ShadowGrantStatus =
|
|
21
|
+
/** Its own live grant covers every current key. */
|
|
22
|
+
"granted"
|
|
23
|
+
/** Its own live grant does not serve some current keys; the rest would serve. */
|
|
24
|
+
| "partially_revoked"
|
|
25
|
+
/** No live grant of its own; it waits for review. */
|
|
26
|
+
| "missing_grant"
|
|
27
|
+
/** No live grant, and the manifest lacks bilingual purposes: Republish with purposes. */
|
|
28
|
+
| "missing_purposes"
|
|
29
|
+
/** The package sha512 is not recorded yet (the backfill job fills it); no grant can match. */
|
|
30
|
+
| "unknown_digest"
|
|
31
|
+
/** The stored package could not be read (storage unavailable, too large, refused). */
|
|
32
|
+
| "unreadable";
|
|
33
|
+
/** What the legacy snapshot path, which governs admission until 1.5a, decides. */
|
|
34
|
+
export type LegacyDecision = "approved" | "pending";
|
|
35
|
+
export interface ShadowRevisionDecision {
|
|
36
|
+
revision: {
|
|
37
|
+
plugin: string;
|
|
38
|
+
version: string;
|
|
39
|
+
sha512: string | null;
|
|
40
|
+
};
|
|
41
|
+
status: ShadowGrantStatus;
|
|
42
|
+
/** The generation of the live grant it resolved to. */
|
|
43
|
+
generation?: number;
|
|
44
|
+
/** Current keys its grant revoked or retired. */
|
|
45
|
+
refusedKeys: string[];
|
|
46
|
+
/** Current keys its grant never had (a key set that changed since the review). */
|
|
47
|
+
ungrantedKeys: string[];
|
|
48
|
+
/** Keys without a bilingual purpose. */
|
|
49
|
+
missingPurposes: string[];
|
|
50
|
+
/** Why the approved revision's grant does not carry over as continuity, when there is one. */
|
|
51
|
+
continuity?: string;
|
|
52
|
+
/** A required bootstrap install (the start gate). */
|
|
53
|
+
required: boolean;
|
|
54
|
+
/** Whether the enforcing path would register and serve it ("register only after the grant"). */
|
|
55
|
+
wouldServe: boolean;
|
|
56
|
+
/** The legacy snapshot decision, which governs today. */
|
|
57
|
+
legacy: LegacyDecision;
|
|
58
|
+
/** The legacy and the enforcing decision differ: what the cutover would change. */
|
|
59
|
+
diverges: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface ShadowStartGate {
|
|
62
|
+
/** Required installs the enforcing start gate would refuse. */
|
|
63
|
+
missingRequired: ShadowRevisionDecision[];
|
|
64
|
+
/** Every other install that would not serve (they would wait as pending). */
|
|
65
|
+
pending: ShadowRevisionDecision[];
|
|
66
|
+
/** Installs whose legacy and enforcing decisions differ: what the cutover would change. */
|
|
67
|
+
diverging: ShadowRevisionDecision[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The kernel-written purpose of a migration warnings digest key. The key carries the digest, so a
|
|
71
|
+
* revision whose risky migration statements changed has a key its predecessor's grant lacks, and
|
|
72
|
+
* continuity refuses it: the change goes to review.
|
|
73
|
+
*/
|
|
74
|
+
export declare function warningsPurpose(key: string): PurposeRow;
|
|
75
|
+
/**
|
|
76
|
+
* The reviewed purpose rows of a permission set, and the keys that lack one. A migration warnings
|
|
77
|
+
* digest key gets the kernel-written row of {@link warningsPurpose}: authors cannot write one, and
|
|
78
|
+
* the grant must still bind the digest.
|
|
79
|
+
*/
|
|
80
|
+
export declare function purposeRowsOf(set: PermissionSet): {
|
|
81
|
+
rows: PurposeRow[];
|
|
82
|
+
missing: string[];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The legacy decision for a revision's set against its snapshot, by `planApprovals`' approval rule:
|
|
86
|
+
* no snapshot or a new blocking key waits, unless `extensionPermissions.autoApprove` is on. Its
|
|
87
|
+
* dependency rule (an install whose required providers are all pending waits too) is not mirrored:
|
|
88
|
+
* the shadow report compares approval, not load order.
|
|
89
|
+
*/
|
|
90
|
+
export declare function legacyDecision(set: PermissionSet, snapshot: {
|
|
91
|
+
permissions: PermissionSet;
|
|
92
|
+
} | undefined, autoApprove?: boolean): LegacyDecision;
|
|
93
|
+
/**
|
|
94
|
+
* The shadow decision for one installed revision: resolved against its own live grant. `approved`
|
|
95
|
+
* is the live grant of the install's approved revision when that is another revision; it only
|
|
96
|
+
* explains whether continuity could carry over (the publisher evidence is not known here, so it
|
|
97
|
+
* never grants by itself).
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveRevisionGrant(input: {
|
|
100
|
+
revision: {
|
|
101
|
+
plugin: string;
|
|
102
|
+
version: string;
|
|
103
|
+
sha512: string | null;
|
|
104
|
+
};
|
|
105
|
+
set: PermissionSet;
|
|
106
|
+
required: boolean;
|
|
107
|
+
own: RevisionGrant | undefined;
|
|
108
|
+
approved: RevisionGrant | undefined;
|
|
109
|
+
legacy: LegacyDecision;
|
|
110
|
+
}): ShadowRevisionDecision;
|
|
111
|
+
/** What a reviewed promotion carries besides the revision: its verified publisher evidence. */
|
|
112
|
+
export interface PromotionEvidence {
|
|
113
|
+
publisher: NewRevisionGrant["publisher"];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* An upgrade may continue the approved revision's grant; a rollback never does: it is served
|
|
117
|
+
* only under the selected revision's own grant.
|
|
118
|
+
*/
|
|
119
|
+
export type PromotionKind = "upgrade" | "rollback";
|
|
120
|
+
export type PromotionOutcome = {
|
|
121
|
+
status: "promoted";
|
|
122
|
+
grant: RevisionGrant;
|
|
123
|
+
continued: boolean;
|
|
124
|
+
} | {
|
|
125
|
+
status: "pending";
|
|
126
|
+
reason: string;
|
|
127
|
+
};
|
|
128
|
+
/** The installed revisions' shadow decisions, and promotion with continuity. */
|
|
129
|
+
export declare class ExtensionRevisionApprovals {
|
|
130
|
+
private readonly kdb;
|
|
131
|
+
readonly txHost: TransactionHost;
|
|
132
|
+
private readonly grants;
|
|
133
|
+
private readonly approvals;
|
|
134
|
+
private readonly blobs;
|
|
135
|
+
private readonly config;
|
|
136
|
+
/** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
|
|
137
|
+
private readonly sets;
|
|
138
|
+
constructor(kdb: KernelDb, txHost: TransactionHost, grants: ExtensionRevisionGrants, approvals: Pick<ExtensionApprovals, "all">, blobs: Pick<ExtensionBlobs, "get">, config: KernelConfigService);
|
|
139
|
+
/**
|
|
140
|
+
* The shadow decision of every install record. A package that cannot be read is reported as
|
|
141
|
+
* `unreadable` and never hides the others.
|
|
142
|
+
*/
|
|
143
|
+
decisions(): Promise<ShadowRevisionDecision[]>;
|
|
144
|
+
/** The facts the enforcing start gate would act on; computed and reported, never refused. */
|
|
145
|
+
startGate(): Promise<ShadowStartGate>;
|
|
146
|
+
/**
|
|
147
|
+
* Makes a revision the approved one of its install. A revision with its own live grant is
|
|
148
|
+
* promoted under it (an upgrade or a rollback). An upgrade without one continues the install's
|
|
149
|
+
* approved revision when that has a live grant and the candidate is a continuation of it (the
|
|
150
|
+
* store's rules): the continuity grant is recorded in the same transaction before the promotion.
|
|
151
|
+
* Anything else leaves the revision as the install's candidate, pending review, with the reason;
|
|
152
|
+
* it never throws for a refusal. A continuation carries no full-access realm (narrower, so safe):
|
|
153
|
+
* realms and the `extension.full_access_continued` audit come with plan tasks 1.2e and 1.3a.
|
|
154
|
+
*
|
|
155
|
+
* The package is read before the transaction: no object storage call holds a connection.
|
|
156
|
+
*/
|
|
157
|
+
promote(candidate: RevisionIdentity, evidence: PromotionEvidence, kind?: PromotionKind): Promise<PromotionOutcome>;
|
|
158
|
+
private promoteIn;
|
|
159
|
+
/** The stored package of a revision, or undefined while its sha512 is not recorded. */
|
|
160
|
+
private sha256Of;
|
|
161
|
+
private setOf;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The review hash of a continuity grant: the kernel reviewed it against its source, so the hash
|
|
165
|
+
* binds the candidate, its purpose rows and the exact source generation.
|
|
166
|
+
*/
|
|
167
|
+
export declare function continuityReviewHash(source: RevisionGrant, candidate: RevisionIdentity, rows: readonly PurposeRow[]): string;
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { SDK_VERSION } from "@capybara-hq/plugin-sdk";
|
|
12
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
13
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.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 { canonicalJson } from "../tools/canonical-json.js";
|
|
18
|
+
import { ExtensionApprovals } from "./approvals.js";
|
|
19
|
+
import { ExtensionBlobs } from "./blobs.js";
|
|
20
|
+
import { permissionSetOfPackage, readExtensionPackage } from "./package.js";
|
|
21
|
+
import { blockingKeys, diffPermissions, permissionKeys, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
|
|
22
|
+
import { reviewPermissionRows } from "./permission-view.js";
|
|
23
|
+
import { continuityProblem, ExtensionRevisionGrants, effectiveKeys, RevisionGrantError, } from "./revision-grants.js";
|
|
24
|
+
/**
|
|
25
|
+
* The kernel-written purpose of a migration warnings digest key. The key carries the digest, so a
|
|
26
|
+
* revision whose risky migration statements changed has a key its predecessor's grant lacks, and
|
|
27
|
+
* continuity refuses it: the change goes to review.
|
|
28
|
+
*/
|
|
29
|
+
export function warningsPurpose(key) {
|
|
30
|
+
const digest = key.slice(WARNINGS_KEY_PREFIX.length);
|
|
31
|
+
return {
|
|
32
|
+
key,
|
|
33
|
+
zh: `迁移脚本含有需要审阅的语句(摘要 ${digest})`,
|
|
34
|
+
en: `The migration SQL contains statements that need review (digest ${digest})`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The reviewed purpose rows of a permission set, and the keys that lack one. A migration warnings
|
|
39
|
+
* digest key gets the kernel-written row of {@link warningsPurpose}: authors cannot write one, and
|
|
40
|
+
* the grant must still bind the digest.
|
|
41
|
+
*/
|
|
42
|
+
export function purposeRowsOf(set) {
|
|
43
|
+
const { rows } = reviewPermissionRows(set);
|
|
44
|
+
const purposes = new Map(rows.map((row) => [row.key, row.purpose]));
|
|
45
|
+
const out = [];
|
|
46
|
+
const missing = [];
|
|
47
|
+
for (const key of permissionKeys(set)) {
|
|
48
|
+
const purpose = purposes.get(key);
|
|
49
|
+
if (key.startsWith(WARNINGS_KEY_PREFIX))
|
|
50
|
+
out.push(warningsPurpose(key));
|
|
51
|
+
else if (purpose)
|
|
52
|
+
out.push({ key, zh: purpose.zh, en: purpose.en });
|
|
53
|
+
else
|
|
54
|
+
missing.push(key);
|
|
55
|
+
}
|
|
56
|
+
return { rows: out, missing };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The legacy decision for a revision's set against its snapshot, by `planApprovals`' approval rule:
|
|
60
|
+
* no snapshot or a new blocking key waits, unless `extensionPermissions.autoApprove` is on. Its
|
|
61
|
+
* dependency rule (an install whose required providers are all pending waits too) is not mirrored:
|
|
62
|
+
* the shadow report compares approval, not load order.
|
|
63
|
+
*/
|
|
64
|
+
export function legacyDecision(set, snapshot, autoApprove = false) {
|
|
65
|
+
if (autoApprove)
|
|
66
|
+
return "approved";
|
|
67
|
+
if (!snapshot)
|
|
68
|
+
return "pending";
|
|
69
|
+
const { added } = diffPermissions(snapshot.permissions, set);
|
|
70
|
+
return blockingKeys(added).length > 0 ? "pending" : "approved";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The shadow decision for one installed revision: resolved against its own live grant. `approved`
|
|
74
|
+
* is the live grant of the install's approved revision when that is another revision; it only
|
|
75
|
+
* explains whether continuity could carry over (the publisher evidence is not known here, so it
|
|
76
|
+
* never grants by itself).
|
|
77
|
+
*/
|
|
78
|
+
export function resolveRevisionGrant(input) {
|
|
79
|
+
const { revision, set, required, own, approved, legacy } = input;
|
|
80
|
+
const { rows, missing } = purposeRowsOf(set);
|
|
81
|
+
const decide = (status, wouldServe, extra = {}) => ({
|
|
82
|
+
revision,
|
|
83
|
+
status,
|
|
84
|
+
refusedKeys: [],
|
|
85
|
+
ungrantedKeys: [],
|
|
86
|
+
missingPurposes: missing,
|
|
87
|
+
required,
|
|
88
|
+
wouldServe,
|
|
89
|
+
legacy,
|
|
90
|
+
diverges: (legacy === "approved") !== wouldServe,
|
|
91
|
+
...extra,
|
|
92
|
+
});
|
|
93
|
+
if (revision.sha512 === null)
|
|
94
|
+
return decide("unknown_digest", false);
|
|
95
|
+
if (own) {
|
|
96
|
+
const serving = new Set(effectiveKeys(own));
|
|
97
|
+
const granted = new Set(own.keys);
|
|
98
|
+
const keys = permissionKeys(set).filter((key) => !serving.has(key));
|
|
99
|
+
const refusedKeys = keys.filter((key) => granted.has(key));
|
|
100
|
+
const ungrantedKeys = keys.filter((key) => !granted.has(key));
|
|
101
|
+
return decide(keys.length > 0 ? "partially_revoked" : "granted", true, {
|
|
102
|
+
generation: own.generation,
|
|
103
|
+
refusedKeys,
|
|
104
|
+
ungrantedKeys,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const continuity = approved
|
|
108
|
+
? (continuityProblem(approved, {
|
|
109
|
+
purposes: rows,
|
|
110
|
+
realms: {},
|
|
111
|
+
approvalScope: approved.approvalScope,
|
|
112
|
+
publisher: { evidence: "none" },
|
|
113
|
+
}) ?? "continuity is recorded when the revision is promoted")
|
|
114
|
+
: undefined;
|
|
115
|
+
return decide(missing.length > 0 ? "missing_purposes" : "missing_grant", false, {
|
|
116
|
+
...(continuity !== undefined && { continuity }),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const SET_CACHE_ENTRIES = 512;
|
|
120
|
+
/** The installed revisions' shadow decisions, and promotion with continuity. */
|
|
121
|
+
let ExtensionRevisionApprovals = class ExtensionRevisionApprovals {
|
|
122
|
+
kdb;
|
|
123
|
+
txHost;
|
|
124
|
+
grants;
|
|
125
|
+
approvals;
|
|
126
|
+
blobs;
|
|
127
|
+
config;
|
|
128
|
+
/** Permission sets by package sha256: content-addressed, so a cached set never goes stale. */
|
|
129
|
+
sets = new Map();
|
|
130
|
+
constructor(kdb, txHost, grants, approvals, blobs, config) {
|
|
131
|
+
this.kdb = kdb;
|
|
132
|
+
this.txHost = txHost;
|
|
133
|
+
this.grants = grants;
|
|
134
|
+
this.approvals = approvals;
|
|
135
|
+
this.blobs = blobs;
|
|
136
|
+
this.config = config;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The shadow decision of every install record. A package that cannot be read is reported as
|
|
140
|
+
* `unreadable` and never hides the others.
|
|
141
|
+
*/
|
|
142
|
+
async decisions() {
|
|
143
|
+
const installs = await this.kdb.db
|
|
144
|
+
.selectFrom("extension_installs as i")
|
|
145
|
+
.innerJoin("extension_packages as p", "p.sha256", "i.sha256")
|
|
146
|
+
.select([
|
|
147
|
+
"i.name",
|
|
148
|
+
"i.version",
|
|
149
|
+
"i.sha256",
|
|
150
|
+
"i.required",
|
|
151
|
+
"i.approved_version",
|
|
152
|
+
"i.approved_sha512",
|
|
153
|
+
"p.sha512",
|
|
154
|
+
])
|
|
155
|
+
.orderBy("i.name")
|
|
156
|
+
.execute();
|
|
157
|
+
const snapshots = await this.approvals.all();
|
|
158
|
+
const autoApprove = this.config.get().extensionPermissions.autoApprove === true;
|
|
159
|
+
const out = [];
|
|
160
|
+
for (const row of installs) {
|
|
161
|
+
const revision = { plugin: row.name, version: row.version, sha512: row.sha512 };
|
|
162
|
+
let set;
|
|
163
|
+
try {
|
|
164
|
+
set = await this.setOf(row.sha256);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
out.push({
|
|
168
|
+
revision,
|
|
169
|
+
status: "unreadable",
|
|
170
|
+
refusedKeys: [],
|
|
171
|
+
ungrantedKeys: [],
|
|
172
|
+
missingPurposes: [],
|
|
173
|
+
required: row.required,
|
|
174
|
+
wouldServe: false,
|
|
175
|
+
legacy: autoApprove || snapshots.has(row.name) ? "approved" : "pending",
|
|
176
|
+
diverges: autoApprove || snapshots.has(row.name),
|
|
177
|
+
});
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const own = row.sha512 === null
|
|
181
|
+
? undefined
|
|
182
|
+
: await this.grants.live({ ...revision, sha512: row.sha512 });
|
|
183
|
+
const approvedIsOther = row.approved_version !== null &&
|
|
184
|
+
row.approved_sha512 !== null &&
|
|
185
|
+
row.approved_sha512 !== row.sha512;
|
|
186
|
+
const approved = !own && approvedIsOther
|
|
187
|
+
? await this.grants.live({
|
|
188
|
+
plugin: row.name,
|
|
189
|
+
version: row.approved_version,
|
|
190
|
+
sha512: row.approved_sha512,
|
|
191
|
+
})
|
|
192
|
+
: undefined;
|
|
193
|
+
out.push(resolveRevisionGrant({
|
|
194
|
+
revision,
|
|
195
|
+
set,
|
|
196
|
+
required: row.required,
|
|
197
|
+
own,
|
|
198
|
+
approved,
|
|
199
|
+
legacy: legacyDecision(set, snapshots.get(row.name), autoApprove),
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
/** The facts the enforcing start gate would act on; computed and reported, never refused. */
|
|
205
|
+
async startGate() {
|
|
206
|
+
const all = await this.decisions();
|
|
207
|
+
return {
|
|
208
|
+
missingRequired: all.filter((d) => d.required && !d.wouldServe),
|
|
209
|
+
pending: all.filter((d) => !d.required && !d.wouldServe),
|
|
210
|
+
diverging: all.filter((d) => d.diverges),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Makes a revision the approved one of its install. A revision with its own live grant is
|
|
215
|
+
* promoted under it (an upgrade or a rollback). An upgrade without one continues the install's
|
|
216
|
+
* approved revision when that has a live grant and the candidate is a continuation of it (the
|
|
217
|
+
* store's rules): the continuity grant is recorded in the same transaction before the promotion.
|
|
218
|
+
* Anything else leaves the revision as the install's candidate, pending review, with the reason;
|
|
219
|
+
* it never throws for a refusal. A continuation carries no full-access realm (narrower, so safe):
|
|
220
|
+
* realms and the `extension.full_access_continued` audit come with plan tasks 1.2e and 1.3a.
|
|
221
|
+
*
|
|
222
|
+
* The package is read before the transaction: no object storage call holds a connection.
|
|
223
|
+
*/
|
|
224
|
+
async promote(candidate, evidence, kind = "upgrade") {
|
|
225
|
+
const sha256 = await this.sha256Of(candidate);
|
|
226
|
+
let purposes;
|
|
227
|
+
if (sha256 === undefined)
|
|
228
|
+
purposes = "unknown_digest";
|
|
229
|
+
else {
|
|
230
|
+
try {
|
|
231
|
+
purposes = purposeRowsOf(await this.setOf(sha256));
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// storage unavailable, the package too large or refused: a revision with its own grant
|
|
235
|
+
// still promotes, anything else waits
|
|
236
|
+
purposes = "unreadable";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return this.promoteIn(candidate, evidence, kind, purposes);
|
|
240
|
+
}
|
|
241
|
+
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
|
+
const pending = async (reason) => {
|
|
248
|
+
await this.grants.setCandidate(candidate.plugin, candidate);
|
|
249
|
+
return { status: "pending", reason };
|
|
250
|
+
};
|
|
251
|
+
const newest = await this.grants.get(candidate);
|
|
252
|
+
if (newest)
|
|
253
|
+
return pending(`its grant is ${newest.state}; it needs a new review`);
|
|
254
|
+
if (kind === "rollback")
|
|
255
|
+
return pending("a rollback is served only under its own grant");
|
|
256
|
+
if (purposes === "unknown_digest")
|
|
257
|
+
return pending("the package digest is not recorded");
|
|
258
|
+
if (purposes === "unreadable")
|
|
259
|
+
return pending("the stored package cannot be read");
|
|
260
|
+
if (purposes.missing.length > 0) {
|
|
261
|
+
return pending(`missing purposes: ${purposes.missing.join(", ")}`);
|
|
262
|
+
}
|
|
263
|
+
const { approved } = await this.grants.installRevisions(candidate.plugin);
|
|
264
|
+
const source = approved ? await this.grants.live(approved) : undefined;
|
|
265
|
+
if (!approved || !source)
|
|
266
|
+
return pending("no live grant to continue");
|
|
267
|
+
const problem = continuityProblem(source, {
|
|
268
|
+
purposes: purposes.rows,
|
|
269
|
+
realms: {},
|
|
270
|
+
approvalScope: source.approvalScope,
|
|
271
|
+
publisher: evidence.publisher,
|
|
272
|
+
});
|
|
273
|
+
if (problem)
|
|
274
|
+
return pending(problem);
|
|
275
|
+
let grant;
|
|
276
|
+
try {
|
|
277
|
+
// The store checks continuity again under the source's share lock.
|
|
278
|
+
grant = await this.grants.record({
|
|
279
|
+
revision: candidate,
|
|
280
|
+
purposes: purposes.rows,
|
|
281
|
+
reviewHash: continuityReviewHash(source, candidate, purposes.rows),
|
|
282
|
+
approvalScope: source.approvalScope,
|
|
283
|
+
source: "continuity",
|
|
284
|
+
publisher: evidence.publisher,
|
|
285
|
+
continuedFrom: source.revision,
|
|
286
|
+
approvedBy: null,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
// The source was revoked meanwhile, or no longer continues: the candidate waits.
|
|
291
|
+
if (err instanceof RevisionGrantError &&
|
|
292
|
+
(err.code === "not_live" || err.code === "not_continuous" || err.code === "terminal")) {
|
|
293
|
+
return pending(err.message);
|
|
294
|
+
}
|
|
295
|
+
throw err;
|
|
296
|
+
}
|
|
297
|
+
await this.grants.promote(candidate);
|
|
298
|
+
return { status: "promoted", grant, continued: true };
|
|
299
|
+
}
|
|
300
|
+
/** The stored package of a revision, or undefined while its sha512 is not recorded. */
|
|
301
|
+
async sha256Of(revision) {
|
|
302
|
+
const row = await this.kdb.db
|
|
303
|
+
.selectFrom("extension_packages")
|
|
304
|
+
.select("sha256")
|
|
305
|
+
.where("name", "=", revision.plugin)
|
|
306
|
+
.where("version", "=", revision.version)
|
|
307
|
+
.where("sha512", "=", revision.sha512)
|
|
308
|
+
.executeTakeFirst();
|
|
309
|
+
return row?.sha256;
|
|
310
|
+
}
|
|
311
|
+
async setOf(sha256) {
|
|
312
|
+
const cached = this.sets.get(sha256);
|
|
313
|
+
if (cached)
|
|
314
|
+
return cached;
|
|
315
|
+
const pkg = await readExtensionPackage(await this.blobs.get(sha256), {
|
|
316
|
+
maxBytes: this.config.get().packages.maxBytes,
|
|
317
|
+
hostSdkVersion: SDK_VERSION,
|
|
318
|
+
});
|
|
319
|
+
const set = permissionSetOfPackage(pkg);
|
|
320
|
+
// a bound on memory only: a dropped entry is read again from the package store
|
|
321
|
+
if (this.sets.size >= SET_CACHE_ENTRIES)
|
|
322
|
+
this.sets.clear();
|
|
323
|
+
this.sets.set(sha256, set);
|
|
324
|
+
return set;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
__decorate([
|
|
328
|
+
Transactional()
|
|
329
|
+
], ExtensionRevisionApprovals.prototype, "promoteIn", null);
|
|
330
|
+
ExtensionRevisionApprovals = __decorate([
|
|
331
|
+
Injectable(),
|
|
332
|
+
__param(0, Inject(KernelDb)),
|
|
333
|
+
__param(1, Inject(TransactionHost)),
|
|
334
|
+
__param(2, Inject(ExtensionRevisionGrants)),
|
|
335
|
+
__param(3, Inject(ExtensionApprovals)),
|
|
336
|
+
__param(4, Inject(ExtensionBlobs)),
|
|
337
|
+
__param(5, Inject(KernelConfigService))
|
|
338
|
+
], ExtensionRevisionApprovals);
|
|
339
|
+
export { ExtensionRevisionApprovals };
|
|
340
|
+
/**
|
|
341
|
+
* The review hash of a continuity grant: the kernel reviewed it against its source, so the hash
|
|
342
|
+
* binds the candidate, its purpose rows and the exact source generation.
|
|
343
|
+
*/
|
|
344
|
+
export function continuityReviewHash(source, candidate, rows) {
|
|
345
|
+
const digest = createHash("sha256")
|
|
346
|
+
.update(canonicalJson({
|
|
347
|
+
candidate,
|
|
348
|
+
purposes: rows,
|
|
349
|
+
source: { ...source.revision, generation: source.generation },
|
|
350
|
+
}))
|
|
351
|
+
.digest("hex");
|
|
352
|
+
return `continuity:${digest}`;
|
|
353
|
+
}
|