@capybara-hq/kernel 0.1.0-rc.144 → 0.1.0-rc.146
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/agents/admin-agents.d.ts +20 -3
- package/dist/agents/admin-agents.js +38 -7
- 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/provenance.d.ts +69 -0
- package/dist/catalog/provenance.js +108 -0
- package/dist/ctx/create-ctx.d.ts +16 -0
- package/dist/ctx/create-ctx.js +269 -34
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +2 -2
- package/dist/extensions/execution-realm.d.ts +96 -0
- package/dist/extensions/execution-realm.js +141 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/grant-epoch.d.ts +4 -2
- package/dist/extensions/grant-epoch.js +4 -2
- package/dist/extensions/host.d.ts +26 -3
- package/dist/extensions/host.js +135 -10
- package/dist/extensions/instance.d.ts +2 -0
- package/dist/extensions/instance.js +1 -0
- package/dist/extensions/isolated/admission.d.ts +6 -0
- package/dist/extensions/isolated/admission.js +17 -0
- package/dist/extensions/isolated/tier.d.ts +14 -0
- package/dist/extensions/isolated/tier.js +27 -0
- package/dist/extensions/ledger.d.ts +5 -0
- package/dist/extensions/ledger.js +16 -0
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/publisher-proof.job.d.ts +39 -0
- package/dist/extensions/publisher-proof.job.js +160 -0
- package/dist/extensions/registry.d.ts +6 -0
- package/dist/extensions/registry.js +8 -0
- package/dist/extensions/review-hash.d.ts +114 -0
- package/dist/extensions/review-hash.js +145 -0
- package/dist/extensions/revision-grants.d.ts +10 -0
- package/dist/extensions/revocation-leases.d.ts +273 -0
- package/dist/extensions/revocation-leases.js +533 -0
- package/dist/extensions/revocation.d.ts +78 -0
- package/dist/extensions/revocation.js +202 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +24 -18
- package/dist/overrides.d.ts +5 -1
- package/dist/overrides.js +2 -0
- package/dist/packages/official-publisher.d.ts +44 -0
- package/dist/packages/official-publisher.js +147 -48
- package/dist/packages/provenance.d.ts +6 -0
- package/dist/packages/provenance.js +26 -9
- package/dist/platform/ops/admin-items.ops.js +1 -1
- package/dist/roles/worker.module.js +3 -0
- package/package.json +2 -2
|
@@ -34,6 +34,22 @@ export class RegistrationLedger {
|
|
|
34
34
|
seal() {
|
|
35
35
|
this.closed = true;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Takes every entry of one kind off the ledger and disposes it (newest first): the handles held
|
|
39
|
+
* under a revoked permission (plan task 1.3e). A failure goes to `onError`; the rest continue.
|
|
40
|
+
*/
|
|
41
|
+
async disposeKind(kind, onError) {
|
|
42
|
+
const taken = this.items.filter((r) => r.kind === kind).reverse();
|
|
43
|
+
this.items = this.items.filter((r) => r.kind !== kind);
|
|
44
|
+
for (const r of taken) {
|
|
45
|
+
try {
|
|
46
|
+
await r.dispose();
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
onError(r, e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
37
53
|
/** 封账并按登记的倒序逐项撤销;单项失败交给 `onError`,继续其余各项。 */
|
|
38
54
|
async disposeAll(onError) {
|
|
39
55
|
this.seal();
|
|
@@ -7,9 +7,9 @@ import type { ExtensionSource } from "./sources.js";
|
|
|
7
7
|
export declare function reviewPermissionRows(set: PermissionSet): {
|
|
8
8
|
rows: {
|
|
9
9
|
key: string;
|
|
10
|
-
family: "config.deployment" | "config.deployment.secret" | "execution.full-access" | "execution.provider.unsupported" | "host.no-isolation" | "migration.warnings" | "optional" | "optional.custodian" | "permissions.agents" | "permissions.bus" | "permissions.client" | "permissions.conversations" | "permissions.deviceaccess" | "permissions.deviceaccess.host" | "permissions.deviceaccess.loopbackports" | "permissions.deviceaccess.siteaccess" | "permissions.dialin" | "permissions.fullaccess.rawegress" | "permissions.hooks.observe" | "permissions.hooks.policy" | "permissions.hooks.sensitive" | "permissions.http" | "permissions.inbox" | "permissions.kv" | "permissions.lock" | "permissions.models" | "permissions.network" | "permissions.outbox" | "permissions.people" | "permissions.queue" | "permissions.secrets" | "permissions.storage" | "permissions.tools" | "permissions.triggers" | "provides" | "provides.standard" | "requires" | "requires.custodian" | "setup.check" | "table" | "ui.action" | "ui.component" | "ui.embed" | "ui.query" | "ui.view";
|
|
10
|
+
family: "config.deployment" | "config.deployment.secret" | "execution.config.unsupported" | "execution.full-access" | "execution.provider.unsupported" | "host.no-isolation" | "migration.warnings" | "optional" | "optional.custodian" | "permissions.agents" | "permissions.bus" | "permissions.client" | "permissions.conversations" | "permissions.deviceaccess" | "permissions.deviceaccess.host" | "permissions.deviceaccess.loopbackports" | "permissions.deviceaccess.siteaccess" | "permissions.dialin" | "permissions.fullaccess.rawegress" | "permissions.hooks.observe" | "permissions.hooks.policy" | "permissions.hooks.sensitive" | "permissions.http" | "permissions.inbox" | "permissions.kv" | "permissions.lock" | "permissions.models" | "permissions.network" | "permissions.outbox" | "permissions.people" | "permissions.queue" | "permissions.secrets" | "permissions.storage" | "permissions.tools" | "permissions.triggers" | "provides" | "provides.standard" | "requires" | "requires.custodian" | "setup.check" | "table" | "ui.action" | "ui.component" | "ui.embed" | "ui.query" | "ui.view";
|
|
11
11
|
risk: "custodian" | "fullAccess" | "informational" | "sensitive" | "standard";
|
|
12
|
-
reason: "Accepts connections from devices that use this protocol." | "Calls the model mapped to this declared purpose." | "Can deny the protected action at this mount." | "Can request a grant for a device loopback port." | "Can request approved actions on websites from the person's device." | "Contains migration statements that require review." | "Coordinates work using locks in the extension namespace." | "Creates a table in the extension database schema." | "Depends on a provider that handles a protected resource." | "Emits durable events of this type." | "Handles this named action for its extension UI." | "Handles this named query for its extension UI." | "Implements a kernel capability and sees the resource it serves." | "Implements this kernel capability." | "Makes network requests outside the kernel egress broker." | "Observes bounded metadata at this mount." | "Observes model or tool data at this mount." | "Orders startup after this extension point when present." | "Posts to the inbox of members of enabled orgs." | "Publishes and receives events in the extension namespace." | "Reads and writes keys in the extension namespace." | "Reads metadata for conversations about its own subjects." | "Reads or stores secrets in its approved namespace." | "Reads or writes objects in its scoped storage prefix." | "Reads the names and avatars of org members." | "Reads which agents a member can use." | "Receives requests and data for this route and audience." | "Receives this field from effective configuration." | "Renders this named component in the app." | "Renders this named view through the kernel." | "Requires this extension point at startup." | "Runs this named tool with its input and scoped call context." | "Runs this read-only setup check." | "Runs this service outside the device sandbox." | "Runs with the privileges of the approved execution realm." | "Runs without a host isolation supervisor." | "Schedules work in the extension namespace." | "Sends requests and data to this destination." | "Serves an embedded page for this view." | "Stages durable effects in the extension namespace." | "Supplies client code for the app." | "This provider contract does not yet have an isolated execution form." | "Uses this confidential configuration field." | "Uses this service on a person's device.";
|
|
12
|
+
reason: "Accepts connections from devices that use this protocol." | "Calls the model mapped to this declared purpose." | "Can deny the protected action at this mount." | "Can request a grant for a device loopback port." | "Can request approved actions on websites from the person's device." | "Contains migration statements that require review." | "Coordinates work using locks in the extension namespace." | "Creates a table in the extension database schema." | "Depends on a provider that handles a protected resource." | "Emits durable events of this type." | "Handles this named action for its extension UI." | "Handles this named query for its extension UI." | "Implements a kernel capability and sees the resource it serves." | "Implements this kernel capability." | "Makes network requests outside the kernel egress broker." | "Observes bounded metadata at this mount." | "Observes model or tool data at this mount." | "Orders startup after this extension point when present." | "Posts to the inbox of members of enabled orgs." | "Publishes and receives events in the extension namespace." | "Reads and writes keys in the extension namespace." | "Reads metadata for conversations about its own subjects." | "Reads or stores secrets in its approved namespace." | "Reads or writes objects in its scoped storage prefix." | "Reads the names and avatars of org members." | "Reads which agents a member can use." | "Receives requests and data for this route and audience." | "Receives this field from effective configuration." | "Renders this named component in the app." | "Renders this named view through the kernel." | "Requires this extension point at startup." | "Runs this named tool with its input and scoped call context." | "Runs this read-only setup check." | "Runs this service outside the device sandbox." | "Runs with the privileges of the approved execution realm." | "Runs without a host isolation supervisor." | "Schedules work in the extension namespace." | "Sends requests and data to this destination." | "Serves an embedded page for this view." | "Stages durable effects in the extension namespace." | "Supplies client code for the app." | "The deployment config schema is outside the isolated tier's declarative subset." | "This provider contract does not yet have an isolated execution form." | "Uses this confidential configuration field." | "Uses this service on a person's device.";
|
|
13
13
|
purpose: import("@capybara-hq/plugin-sdk").PermissionPurpose | undefined;
|
|
14
14
|
}[];
|
|
15
15
|
errors: string[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
3
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
5
|
+
import type { KernelLogger } from "../log.js";
|
|
6
|
+
export declare const PUBLISHER_PROOF_RECHECK_JOB = "extension-publisher-proof-recheck";
|
|
7
|
+
/**
|
|
8
|
+
* A definite failure (no provenance, another signer, digest or name) is not fetched again before
|
|
9
|
+
* this long: the registry's answer rarely changes. A transient one (network, timeout, 5xx) is
|
|
10
|
+
* retried on the next tick.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PUBLISHER_PROOF_RETRY_MS: number;
|
|
13
|
+
/**
|
|
14
|
+
* Records the publisher proof of installed official-marketplace revisions imported before the
|
|
15
|
+
* kernel recorded one (kernel rc.165 made it an admission condition). Admission itself never
|
|
16
|
+
* fetches: this worker job (`@LockedInterval`, once per tick across replicas, run at start) fetches
|
|
17
|
+
* the npm publish and workflow attestations of exactly `name@version`, verifies them with the same
|
|
18
|
+
* code an import uses against the bundled trust root and the recorded integrity, and writes the
|
|
19
|
+
* proof into the revision's `source_detail` in one conditional statement (only while still
|
|
20
|
+
* missing, so a concurrent upgrade or a second run changes nothing). Every replica then admits the
|
|
21
|
+
* revision on its next convergence. A revision that cannot be verified (no attestations, other
|
|
22
|
+
* signer, other digest) keeps being refused with the "publisher proof missing" reason; the failure
|
|
23
|
+
* is recorded and retried after {@link PUBLISHER_PROOF_RETRY_MS}, a network or registry hiccup on
|
|
24
|
+
* the next tick. Under the super admin's pin-only choice nothing is fetched.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PublisherProofRecheckJob {
|
|
27
|
+
private readonly kdb;
|
|
28
|
+
private readonly bus;
|
|
29
|
+
readonly config: KernelConfigService;
|
|
30
|
+
readonly lockService: LockService;
|
|
31
|
+
readonly log: KernelLogger;
|
|
32
|
+
constructor(kdb: KernelDb, bus: Pick<ExtensionContext["bus"], "publish">, config: KernelConfigService, lockService: LockService, log: KernelLogger);
|
|
33
|
+
recheck(stop?: AbortSignal): Promise<void>;
|
|
34
|
+
/** One pass (the locked tick runs it); returns how many proofs it recorded and how many failed. */
|
|
35
|
+
run(stop?: AbortSignal): Promise<{
|
|
36
|
+
recorded: number;
|
|
37
|
+
failed: number;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
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 { publisherCheckTransient, requireMarketplacePublisher, } from "../catalog/marketplace-fetch.js";
|
|
13
|
+
import { OFFICIAL_MARKETPLACE_ID, officialPublisherProofMode, } from "../catalog/publisher-policy.js";
|
|
14
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
15
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
17
|
+
import { LockedInterval } from "../infra/schedule/locked-interval.js";
|
|
18
|
+
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
19
|
+
import { PLUGINS_RECONCILE_TOPIC } from "./lifecycle-topics.js";
|
|
20
|
+
export const PUBLISHER_PROOF_RECHECK_JOB = "extension-publisher-proof-recheck";
|
|
21
|
+
const PUBLISHER_PROOF_RECHECK_PERIOD_MS = 15 * 60_000;
|
|
22
|
+
/**
|
|
23
|
+
* A definite failure (no provenance, another signer, digest or name) is not fetched again before
|
|
24
|
+
* this long: the registry's answer rarely changes. A transient one (network, timeout, 5xx) is
|
|
25
|
+
* retried on the next tick.
|
|
26
|
+
*/
|
|
27
|
+
export const PUBLISHER_PROOF_RETRY_MS = 6 * 60 * 60_000;
|
|
28
|
+
/** Revisions checked per tick (each is one bounded attestation fetch). */
|
|
29
|
+
const PUBLISHER_PROOF_BATCH = 20;
|
|
30
|
+
/**
|
|
31
|
+
* Records the publisher proof of installed official-marketplace revisions imported before the
|
|
32
|
+
* kernel recorded one (kernel rc.165 made it an admission condition). Admission itself never
|
|
33
|
+
* fetches: this worker job (`@LockedInterval`, once per tick across replicas, run at start) fetches
|
|
34
|
+
* the npm publish and workflow attestations of exactly `name@version`, verifies them with the same
|
|
35
|
+
* code an import uses against the bundled trust root and the recorded integrity, and writes the
|
|
36
|
+
* proof into the revision's `source_detail` in one conditional statement (only while still
|
|
37
|
+
* missing, so a concurrent upgrade or a second run changes nothing). Every replica then admits the
|
|
38
|
+
* revision on its next convergence. A revision that cannot be verified (no attestations, other
|
|
39
|
+
* signer, other digest) keeps being refused with the "publisher proof missing" reason; the failure
|
|
40
|
+
* is recorded and retried after {@link PUBLISHER_PROOF_RETRY_MS}, a network or registry hiccup on
|
|
41
|
+
* the next tick. Under the super admin's pin-only choice nothing is fetched.
|
|
42
|
+
*/
|
|
43
|
+
let PublisherProofRecheckJob = class PublisherProofRecheckJob {
|
|
44
|
+
kdb;
|
|
45
|
+
bus;
|
|
46
|
+
config;
|
|
47
|
+
lockService;
|
|
48
|
+
log;
|
|
49
|
+
constructor(kdb, bus, config, lockService, log) {
|
|
50
|
+
this.kdb = kdb;
|
|
51
|
+
this.bus = bus;
|
|
52
|
+
this.config = config;
|
|
53
|
+
this.lockService = lockService;
|
|
54
|
+
this.log = log;
|
|
55
|
+
}
|
|
56
|
+
async recheck(stop) {
|
|
57
|
+
await this.run(stop);
|
|
58
|
+
}
|
|
59
|
+
/** One pass (the locked tick runs it); returns how many proofs it recorded and how many failed. */
|
|
60
|
+
async run(stop) {
|
|
61
|
+
const db = this.kdb.db;
|
|
62
|
+
if ((await officialPublisherProofMode(db)) === "pin-only")
|
|
63
|
+
return { recorded: 0, failed: 0 };
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
const rows = await db
|
|
66
|
+
.selectFrom("extension_installs")
|
|
67
|
+
.innerJoin("catalog_items", "catalog_items.id", "extension_installs.catalog_item_id")
|
|
68
|
+
.innerJoin("catalog_item_versions as revision", (join) => join
|
|
69
|
+
.onRef("revision.item_id", "=", "catalog_items.id")
|
|
70
|
+
.onRef("revision.extension_sha256", "=", "extension_installs.sha256")
|
|
71
|
+
.onRef("revision.version", "=", "extension_installs.version"))
|
|
72
|
+
.select([
|
|
73
|
+
"revision.item_id",
|
|
74
|
+
"revision.version",
|
|
75
|
+
"revision.integrity",
|
|
76
|
+
"catalog_items.package_name",
|
|
77
|
+
])
|
|
78
|
+
.where("extension_installs.source", "=", "catalog")
|
|
79
|
+
.where("catalog_items.marketplace_id", "=", OFFICIAL_MARKETPLACE_ID)
|
|
80
|
+
.where("revision.source", "=", "marketplace")
|
|
81
|
+
.where("revision.integrity", "is not", null)
|
|
82
|
+
.where("catalog_items.package_name", "is not", null)
|
|
83
|
+
.where(sql `NOT (coalesce(revision.source_detail, '{}'::jsonb) ? 'publisherProof')`)
|
|
84
|
+
.where(sql `coalesce(revision.source_detail -> 'publisherProofCheck' ->> 'retryAt', '') <= ${new Date(now).toISOString()}`)
|
|
85
|
+
.orderBy("revision.item_id")
|
|
86
|
+
.limit(PUBLISHER_PROOF_BATCH)
|
|
87
|
+
.execute();
|
|
88
|
+
let recorded = 0;
|
|
89
|
+
let failed = 0;
|
|
90
|
+
for (const row of rows) {
|
|
91
|
+
if (stop?.aborted)
|
|
92
|
+
break;
|
|
93
|
+
const revision = {
|
|
94
|
+
name: row.package_name,
|
|
95
|
+
version: row.version,
|
|
96
|
+
integrity: row.integrity,
|
|
97
|
+
};
|
|
98
|
+
let detail;
|
|
99
|
+
try {
|
|
100
|
+
detail = {
|
|
101
|
+
publisherProof: await requireMarketplacePublisher(this.config.get(), revision, stop),
|
|
102
|
+
};
|
|
103
|
+
recorded += 1;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
if (stop?.aborted)
|
|
107
|
+
break;
|
|
108
|
+
failed += 1;
|
|
109
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
110
|
+
const transient = publisherCheckTransient(err);
|
|
111
|
+
this.log.warn("cannot verify the official publisher of an installed revision", {
|
|
112
|
+
plugin: revision.name,
|
|
113
|
+
version: revision.version,
|
|
114
|
+
reason,
|
|
115
|
+
transient,
|
|
116
|
+
});
|
|
117
|
+
const failedAt = Date.now();
|
|
118
|
+
detail = {
|
|
119
|
+
publisherProofCheck: {
|
|
120
|
+
failedAt: new Date(failedAt).toISOString(),
|
|
121
|
+
reason,
|
|
122
|
+
transient,
|
|
123
|
+
retryAt: new Date(transient ? failedAt : failedAt + PUBLISHER_PROOF_RETRY_MS).toISOString(),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// One conditional statement is its own transaction: nothing else is written with it, and the
|
|
128
|
+
// condition keeps a proof an upgrade or another pass recorded meanwhile.
|
|
129
|
+
await db
|
|
130
|
+
.updateTable("catalog_item_versions")
|
|
131
|
+
.set({
|
|
132
|
+
source_detail: sql `(coalesce(source_detail, '{}'::jsonb) - 'publisherProofCheck') || ${JSON.stringify(detail)}::jsonb`,
|
|
133
|
+
})
|
|
134
|
+
.where("item_id", "=", row.item_id)
|
|
135
|
+
.where("version", "=", row.version)
|
|
136
|
+
.where("integrity", "=", revision.integrity)
|
|
137
|
+
.where(sql `NOT (coalesce(source_detail, '{}'::jsonb) ? 'publisherProof')`)
|
|
138
|
+
.execute();
|
|
139
|
+
}
|
|
140
|
+
if (recorded > 0) {
|
|
141
|
+
this.log.info("recorded official publisher proofs of installed revisions", { recorded });
|
|
142
|
+
await this.bus.publish(PLUGINS_RECONCILE_TOPIC, {});
|
|
143
|
+
}
|
|
144
|
+
return { recorded, failed };
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
__decorate([
|
|
148
|
+
LockedInterval(PUBLISHER_PROOF_RECHECK_JOB, () => PUBLISHER_PROOF_RECHECK_PERIOD_MS, {
|
|
149
|
+
runOnStart: true,
|
|
150
|
+
})
|
|
151
|
+
], PublisherProofRecheckJob.prototype, "recheck", null);
|
|
152
|
+
PublisherProofRecheckJob = __decorate([
|
|
153
|
+
Injectable(),
|
|
154
|
+
__param(0, Inject(KernelDb)),
|
|
155
|
+
__param(1, Inject(KERNEL_BUS)),
|
|
156
|
+
__param(2, Inject(KernelConfigService)),
|
|
157
|
+
__param(3, Inject(LockService)),
|
|
158
|
+
__param(4, Inject(KERNEL_LOGGER))
|
|
159
|
+
], PublisherProofRecheckJob);
|
|
160
|
+
export { PublisherProofRecheckJob };
|
|
@@ -60,6 +60,12 @@ export declare class ExtensionRegistry {
|
|
|
60
60
|
manifests(): ExtensionManifest[];
|
|
61
61
|
/** 每次激活 / 摘下加一(给按版本缓存的派生视图用,如插件路由表)。 */
|
|
62
62
|
revision(): number;
|
|
63
|
+
/**
|
|
64
|
+
* An active instance withdrew registrations (a revoked permission, plan task 1.3e): derived views
|
|
65
|
+
* cached by {@link revision} rebuild and the change listeners refresh (the HTTP dispatcher, the
|
|
66
|
+
* gateway's channel supervisor and webhook cache), as for a replaced instance.
|
|
67
|
+
*/
|
|
68
|
+
registrationsChanged(name: string): void;
|
|
63
69
|
/**
|
|
64
70
|
* 订阅变化(激活 / 替换 / 摘下,参数为插件名)。只通知本进程的消费方(渠道 supervisor、界面等),不跨副本。
|
|
65
71
|
* 监听函数同步调用,抛错被吞掉(不影响注册表与其他监听方)。返回取消订阅函数。
|
|
@@ -112,6 +112,14 @@ let ExtensionRegistry = class ExtensionRegistry {
|
|
|
112
112
|
revision() {
|
|
113
113
|
return this.rev;
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* An active instance withdrew registrations (a revoked permission, plan task 1.3e): derived views
|
|
117
|
+
* cached by {@link revision} rebuild and the change listeners refresh (the HTTP dispatcher, the
|
|
118
|
+
* gateway's channel supervisor and webhook cache), as for a replaced instance.
|
|
119
|
+
*/
|
|
120
|
+
registrationsChanged(name) {
|
|
121
|
+
this.changed(name);
|
|
122
|
+
}
|
|
115
123
|
/**
|
|
116
124
|
* 订阅变化(激活 / 替换 / 摘下,参数为插件名)。只通知本进程的消费方(渠道 supervisor、界面等),不跨副本。
|
|
117
125
|
* 监听函数同步调用,抛错被吞掉(不影响注册表与其他监听方)。返回取消订阅函数。
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type PermissionRisk } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { PublisherEvidence } from "../catalog/provenance.js";
|
|
3
|
+
import { type ExecutionDecision, type ExecutionInput, type HostIsolation } from "./execution-realm.js";
|
|
4
|
+
import { type PermissionSet } from "./permission-set.js";
|
|
5
|
+
import { type ApprovalScope, type ExecutionRealm, type GrantAuthority, type PurposeRow, type RevisionGrant, type RevisionIdentity } from "./revision-grants.js";
|
|
6
|
+
/**
|
|
7
|
+
* The reviewed display and its hash (extension permission model spec, "Review, updates and
|
|
8
|
+
* provenance" step 1; plan task 1.2e). Pure. A review binds everything the approver is shown: the
|
|
9
|
+
* exact revision, every permission row with its risk and bilingual purpose (the kernel-written rows
|
|
10
|
+
* of migration warnings and full access included), the execution realms and their forcing keys,
|
|
11
|
+
* the org scope, the approver authority, the publisher evidence, the previous approval and the diff
|
|
12
|
+
* against it, and the risk-contract version. Any change to one of them changes the hash, so a
|
|
13
|
+
* confirmation made against an older display is refused (1.3a) and a bootstrap batch hash (1.3c)
|
|
14
|
+
* covers each revision's display.
|
|
15
|
+
*/
|
|
16
|
+
/** Bump when the display's shape or the meaning of a field changes. */
|
|
17
|
+
export declare const REVIEW_CONTRACT_VERSION = 1;
|
|
18
|
+
/**
|
|
19
|
+
* The kernel-written purpose of full access in one realm: one fixed sentence per realm. The forcing
|
|
20
|
+
* keys are bound separately (the grant's `realms`, the display's `execution.realms`), so a
|
|
21
|
+
* continuation whose forcing keys shrink keeps an identical purpose row.
|
|
22
|
+
*/
|
|
23
|
+
export declare function fullAccessPurpose(realm: ExecutionRealm): PurposeRow;
|
|
24
|
+
/**
|
|
25
|
+
* The purpose rows a grant for this revision records: the declared purposes, the kernel's rows of
|
|
26
|
+
* migration warnings ({@link purposeRowsOf}) and one full-access row per realm of the decision.
|
|
27
|
+
* `missing` lists declared keys without a purpose (the revision must be republished with them).
|
|
28
|
+
*/
|
|
29
|
+
export declare function grantPurposeRows(set: PermissionSet, decision: Pick<ExecutionDecision, "fullAccess">): {
|
|
30
|
+
rows: PurposeRow[];
|
|
31
|
+
missing: string[];
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Against the previous approval: `added` (new, or no previous approval), `retained` (served by the
|
|
35
|
+
* previous grant with the same purpose), `purpose_changed`, `regranted` (the previous grant had
|
|
36
|
+
* the key but revoked or retired it: confirming grants it again), or `broadened` (a full-access
|
|
37
|
+
* realm the previous grant still serves, now forced by a key it does not cover, such as a retired
|
|
38
|
+
* `host.no-isolation` coming back).
|
|
39
|
+
*/
|
|
40
|
+
export type RowChange = "added" | "retained" | "purpose_changed" | "regranted" | "broadened";
|
|
41
|
+
export interface ReviewRow extends PurposeRow {
|
|
42
|
+
family: string | null;
|
|
43
|
+
risk: PermissionRisk | null;
|
|
44
|
+
/** The kernel's risk sentence for the family. */
|
|
45
|
+
reason: string | null;
|
|
46
|
+
/** Against the previous approval; `added` without one. */
|
|
47
|
+
change: RowChange;
|
|
48
|
+
}
|
|
49
|
+
export interface ReviewInput {
|
|
50
|
+
revision: RevisionIdentity;
|
|
51
|
+
set: PermissionSet;
|
|
52
|
+
/** Where the revision runs: computed here from the set, so it cannot disagree with it. */
|
|
53
|
+
host: HostIsolation;
|
|
54
|
+
server: boolean;
|
|
55
|
+
client?: ExecutionInput["client"];
|
|
56
|
+
configSchemaIsolatable?: boolean;
|
|
57
|
+
approvalScope: ApprovalScope;
|
|
58
|
+
authority: GrantAuthority;
|
|
59
|
+
publisher: PublisherEvidence;
|
|
60
|
+
/** The digest of the verified attestations, when there are some. */
|
|
61
|
+
evidenceDigest?: string | undefined;
|
|
62
|
+
/** The live grant of the install's approved revision, if any. */
|
|
63
|
+
previous?: RevisionGrant | undefined;
|
|
64
|
+
}
|
|
65
|
+
export interface ReviewDisplay {
|
|
66
|
+
contract: number;
|
|
67
|
+
catalog: number;
|
|
68
|
+
revision: RevisionIdentity;
|
|
69
|
+
rows: ReviewRow[];
|
|
70
|
+
/** Declared keys without a purpose: the review cannot be confirmed until republished. */
|
|
71
|
+
missingPurposes: string[];
|
|
72
|
+
/** Keys of the previous approval this revision no longer has. */
|
|
73
|
+
removed: string[];
|
|
74
|
+
execution: {
|
|
75
|
+
kind: ExecutionDecision["kind"];
|
|
76
|
+
server: ExecutionDecision["server"]["mode"];
|
|
77
|
+
browser: ExecutionDecision["browser"]["mode"];
|
|
78
|
+
device: ExecutionDecision["device"]["mode"];
|
|
79
|
+
realms: Partial<Record<ExecutionRealm, string[]>>;
|
|
80
|
+
/** False when a key matched no catalog row: the review cannot be confirmed. */
|
|
81
|
+
confirmable: boolean;
|
|
82
|
+
};
|
|
83
|
+
unknownKeys: string[];
|
|
84
|
+
approvalScope: {
|
|
85
|
+
mode: ApprovalScope["mode"];
|
|
86
|
+
orgs: string[];
|
|
87
|
+
};
|
|
88
|
+
authority: GrantAuthority;
|
|
89
|
+
publisher: PublisherEvidence;
|
|
90
|
+
evidenceDigest: string | null;
|
|
91
|
+
previous: {
|
|
92
|
+
revision: RevisionIdentity;
|
|
93
|
+
generation: number;
|
|
94
|
+
reviewHash: string;
|
|
95
|
+
state: RevisionGrant["state"];
|
|
96
|
+
disabledKeys: string[];
|
|
97
|
+
retiredKeys: string[];
|
|
98
|
+
retiredForcing: Partial<Record<ExecutionRealm, string[]>>;
|
|
99
|
+
/** The full-access realms the previous grant still covers, net of revocation and retirement. */
|
|
100
|
+
realms: Partial<Record<ExecutionRealm, string[]>>;
|
|
101
|
+
approvalScope: {
|
|
102
|
+
mode: ApprovalScope["mode"];
|
|
103
|
+
orgs: string[];
|
|
104
|
+
};
|
|
105
|
+
publisher: {
|
|
106
|
+
evidence: RevisionGrant["publisherEvidence"];
|
|
107
|
+
identity: RevisionGrant["publisher"];
|
|
108
|
+
};
|
|
109
|
+
} | null;
|
|
110
|
+
}
|
|
111
|
+
/** The canonical display of a review: what the approver sees, in a stable order. */
|
|
112
|
+
export declare function reviewDisplay(input: ReviewInput): ReviewDisplay;
|
|
113
|
+
/** `review:v<contract>:<sha256 hex of the canonical display>`. */
|
|
114
|
+
export declare function revisionReviewHash(display: ReviewDisplay): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { PERMISSION_CATALOG_VERSION, permissionCatalogMatches, } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { canonicalJson } from "../tools/canonical-json.js";
|
|
4
|
+
import { executionDecision, } from "./execution-realm.js";
|
|
5
|
+
import { permissionKeys } from "./permission-set.js";
|
|
6
|
+
import { purposeRowsOf } from "./revision-approvals.js";
|
|
7
|
+
import { EXECUTION_REALMS, effectiveKeys, effectiveRealms, fullAccessKey, } from "./revision-grants.js";
|
|
8
|
+
/**
|
|
9
|
+
* The reviewed display and its hash (extension permission model spec, "Review, updates and
|
|
10
|
+
* provenance" step 1; plan task 1.2e). Pure. A review binds everything the approver is shown: the
|
|
11
|
+
* exact revision, every permission row with its risk and bilingual purpose (the kernel-written rows
|
|
12
|
+
* of migration warnings and full access included), the execution realms and their forcing keys,
|
|
13
|
+
* the org scope, the approver authority, the publisher evidence, the previous approval and the diff
|
|
14
|
+
* against it, and the risk-contract version. Any change to one of them changes the hash, so a
|
|
15
|
+
* confirmation made against an older display is refused (1.3a) and a bootstrap batch hash (1.3c)
|
|
16
|
+
* covers each revision's display.
|
|
17
|
+
*/
|
|
18
|
+
/** Bump when the display's shape or the meaning of a field changes. */
|
|
19
|
+
export const REVIEW_CONTRACT_VERSION = 1;
|
|
20
|
+
/**
|
|
21
|
+
* The kernel-written purpose of full access in one realm: one fixed sentence per realm. The forcing
|
|
22
|
+
* keys are bound separately (the grant's `realms`, the display's `execution.realms`), so a
|
|
23
|
+
* continuation whose forcing keys shrink keeps an identical purpose row.
|
|
24
|
+
*/
|
|
25
|
+
export function fullAccessPurpose(realm) {
|
|
26
|
+
const zh = {
|
|
27
|
+
server: "在内核进程中运行,拥有内核的权限",
|
|
28
|
+
browser: "在应用页面中运行,拥有查看者的浏览器会话",
|
|
29
|
+
device: "在设备沙箱之外运行,拥有设备用户的权限",
|
|
30
|
+
}[realm];
|
|
31
|
+
const en = {
|
|
32
|
+
server: "Runs in the kernel process with the kernel's privileges",
|
|
33
|
+
browser: "Runs in the app page with the viewer's browser session",
|
|
34
|
+
device: "Runs outside the device sandbox as the device user",
|
|
35
|
+
}[realm];
|
|
36
|
+
return { key: fullAccessKey(realm), zh, en };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The purpose rows a grant for this revision records: the declared purposes, the kernel's rows of
|
|
40
|
+
* migration warnings ({@link purposeRowsOf}) and one full-access row per realm of the decision.
|
|
41
|
+
* `missing` lists declared keys without a purpose (the revision must be republished with them).
|
|
42
|
+
*/
|
|
43
|
+
export function grantPurposeRows(set, decision) {
|
|
44
|
+
const { rows, missing } = purposeRowsOf(set);
|
|
45
|
+
const realms = Object.entries(decision.fullAccess);
|
|
46
|
+
const full = realms.map(([realm]) => fullAccessPurpose(realm));
|
|
47
|
+
return {
|
|
48
|
+
rows: [...rows, ...full].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)),
|
|
49
|
+
missing,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const sortedRealms = (realms) => Object.fromEntries(EXECUTION_REALMS.filter((realm) => realms[realm] !== undefined).map((realm) => [
|
|
53
|
+
realm,
|
|
54
|
+
[...(realms[realm] ?? [])].sort(),
|
|
55
|
+
]));
|
|
56
|
+
/** The canonical display of a review: what the approver sees, in a stable order. */
|
|
57
|
+
export function reviewDisplay(input) {
|
|
58
|
+
const execution = executionDecision({
|
|
59
|
+
keys: permissionKeys(input.set),
|
|
60
|
+
server: input.server,
|
|
61
|
+
client: input.client,
|
|
62
|
+
host: input.host,
|
|
63
|
+
...(input.configSchemaIsolatable !== undefined && {
|
|
64
|
+
configSchemaIsolatable: input.configSchemaIsolatable,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
const { rows, missing } = grantPurposeRows(input.set, execution);
|
|
68
|
+
const previous = input.previous;
|
|
69
|
+
const before = new Map(previous?.purposes.map((row) => [row.key, row]) ?? []);
|
|
70
|
+
const serving = new Set(previous ? effectiveKeys(previous) : []);
|
|
71
|
+
const previousRealms = previous ? effectiveRealms(previous) : {};
|
|
72
|
+
const fullAccessRealm = new Map(EXECUTION_REALMS.map((realm) => [fullAccessKey(realm), realm]));
|
|
73
|
+
const reviewRows = rows.map((row) => {
|
|
74
|
+
const [match] = permissionCatalogMatches(row.key);
|
|
75
|
+
const old = before.get(row.key);
|
|
76
|
+
const realm = fullAccessRealm.get(row.key);
|
|
77
|
+
const covered = new Set(realm ? (previousRealms[realm] ?? []) : []);
|
|
78
|
+
const broadened = realm !== undefined &&
|
|
79
|
+
(execution.fullAccess[realm] ?? []).some((forcing) => !covered.has(forcing));
|
|
80
|
+
const change = !old
|
|
81
|
+
? "added"
|
|
82
|
+
: !serving.has(row.key)
|
|
83
|
+
? "regranted"
|
|
84
|
+
: broadened
|
|
85
|
+
? "broadened"
|
|
86
|
+
: old.zh === row.zh && old.en === row.en
|
|
87
|
+
? "retained"
|
|
88
|
+
: "purpose_changed";
|
|
89
|
+
return {
|
|
90
|
+
...row,
|
|
91
|
+
family: match?.family ?? null,
|
|
92
|
+
risk: match?.risk ?? null,
|
|
93
|
+
reason: match?.reason ?? null,
|
|
94
|
+
change,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
const current = new Set(rows.map((row) => row.key));
|
|
98
|
+
return {
|
|
99
|
+
contract: REVIEW_CONTRACT_VERSION,
|
|
100
|
+
catalog: PERMISSION_CATALOG_VERSION,
|
|
101
|
+
revision: { ...input.revision },
|
|
102
|
+
rows: reviewRows,
|
|
103
|
+
missingPurposes: [...missing].sort(),
|
|
104
|
+
removed: (previous?.keys ?? []).filter((key) => !current.has(key)).sort(),
|
|
105
|
+
execution: {
|
|
106
|
+
kind: execution.kind,
|
|
107
|
+
server: execution.server.mode,
|
|
108
|
+
browser: execution.browser.mode,
|
|
109
|
+
device: execution.device.mode,
|
|
110
|
+
realms: execution.fullAccess,
|
|
111
|
+
confirmable: execution.confirmable,
|
|
112
|
+
},
|
|
113
|
+
unknownKeys: [...execution.unknownKeys],
|
|
114
|
+
approvalScope: {
|
|
115
|
+
mode: input.approvalScope.mode,
|
|
116
|
+
orgs: input.approvalScope.mode === "named" ? [...new Set(input.approvalScope.orgs)].sort() : [],
|
|
117
|
+
},
|
|
118
|
+
authority: input.authority,
|
|
119
|
+
publisher: input.publisher,
|
|
120
|
+
evidenceDigest: input.evidenceDigest ?? null,
|
|
121
|
+
previous: previous
|
|
122
|
+
? {
|
|
123
|
+
revision: { ...previous.revision },
|
|
124
|
+
generation: previous.generation,
|
|
125
|
+
reviewHash: previous.reviewHash,
|
|
126
|
+
state: previous.state,
|
|
127
|
+
disabledKeys: [...previous.disabledKeys].sort(),
|
|
128
|
+
retiredKeys: [...previous.retiredKeys].sort(),
|
|
129
|
+
retiredForcing: sortedRealms(previous.retiredForcing),
|
|
130
|
+
realms: sortedRealms(previousRealms),
|
|
131
|
+
approvalScope: {
|
|
132
|
+
mode: previous.approvalScope.mode,
|
|
133
|
+
orgs: previous.approvalScope.mode === "named"
|
|
134
|
+
? [...new Set(previous.approvalScope.orgs)].sort()
|
|
135
|
+
: [],
|
|
136
|
+
},
|
|
137
|
+
publisher: { evidence: previous.publisherEvidence, identity: previous.publisher },
|
|
138
|
+
}
|
|
139
|
+
: null,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** `review:v<contract>:<sha256 hex of the canonical display>`. */
|
|
143
|
+
export function revisionReviewHash(display) {
|
|
144
|
+
return `review:v${display.contract}:${createHash("sha256").update(canonicalJson(display)).digest("hex")}`;
|
|
145
|
+
}
|
|
@@ -41,11 +41,21 @@ export interface PurposeRow {
|
|
|
41
41
|
zh: string;
|
|
42
42
|
en: string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* A verified publisher identity, normalized by `catalog/provenance.ts`. Continuity compares it
|
|
46
|
+
* exactly: a changed repository, its ids, the workflow or the ref class needs a new review.
|
|
47
|
+
*/
|
|
44
48
|
export interface PublisherIdentity {
|
|
45
49
|
issuer: string;
|
|
50
|
+
/** `<repository>/<workflow>`: who builds, without the ref (that is `refClass`). */
|
|
46
51
|
identity: string;
|
|
47
52
|
repository?: string;
|
|
53
|
+
/** The repository's and owner's numeric ids: a repository recreated under the same name differs. */
|
|
54
|
+
repositoryId?: string;
|
|
55
|
+
ownerId?: string;
|
|
48
56
|
workflow?: string;
|
|
57
|
+
/** A branch ref exactly (`refs/heads/main`), or `refs/tags/*` for any release tag. */
|
|
58
|
+
refClass?: string;
|
|
49
59
|
}
|
|
50
60
|
export interface NewRevisionGrant {
|
|
51
61
|
revision: RevisionIdentity;
|