@capybara-hq/kernel 0.1.0-rc.145 → 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/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/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 +25 -2
- package/dist/extensions/host.js +120 -8
- 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/ledger.d.ts +5 -0
- package/dist/extensions/ledger.js +16 -0
- package/dist/extensions/permission-view.d.ts +2 -2
- 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 +39 -0
- package/dist/packages/official-publisher.js +125 -47
- package/package.json +2 -2
|
@@ -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;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
import { type GrantEpochView } from "./isolated/authorization.js";
|
|
3
|
+
import { type ExecutionRealm, type RevisionGrant, type RevisionGrantState } from "./revision-grants.js";
|
|
4
|
+
/**
|
|
5
|
+
* Revocation on a serving replica (extension permission model spec 2026-12-04, "Revocation, audit
|
|
6
|
+
* and people"; plan task 1.3e). The write side is {@link ExtensionRevocations} in `revocation.ts`;
|
|
7
|
+
* this file holds what the host and `ctx` need without depending on the Nest service: the key
|
|
8
|
+
* classes, the serving surface of a grant, and the replica-local permission leases.
|
|
9
|
+
*
|
|
10
|
+
* A lease belongs to one extension instance (one loaded generation of one package revision). It
|
|
11
|
+
* caches the revision's grant state, valid only at the grant epoch it was confirmed at and while
|
|
12
|
+
* that epoch is fresh: every committed grant change advances the epoch (the grant tables' triggers
|
|
13
|
+
* of migration 0235, on the 0234 epoch),
|
|
14
|
+
* so a replica that missed the fan-out hint still revalidates within the 5 s bound. Revalidations
|
|
15
|
+
* are coalesced, and a read started before a change can only confirm the epoch it started at.
|
|
16
|
+
*
|
|
17
|
+
* Shadow mode until plan task 1.5a (the plan's rollout fence): the revocation is written, audited and
|
|
18
|
+
* advances the epoch, and every lease computes its decision within the bound and reports it (logs,
|
|
19
|
+
* {@link RevisionLeases.statesOf}, the Partially revoked view), but nothing is refused, aborted,
|
|
20
|
+
* withdrawn or unloaded on account of it, and no call waits on a lease read: the legacy approval
|
|
21
|
+
* path keeps governing. Task 1.5a sets {@link REVOCATION_ENFORCED} and removes the shadow branch.
|
|
22
|
+
* When enforcing, a revision with no grant never refuses, and one with a grant fails closed while
|
|
23
|
+
* its state cannot be confirmed.
|
|
24
|
+
*/
|
|
25
|
+
/** The rollout fence: false until plan task 1.5a turns enforcement on and deletes this switch. */
|
|
26
|
+
export declare const REVOCATION_ENFORCED: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The kernel test seam that enforces revocation before task 1.5a (a kernel test's
|
|
29
|
+
* `KernelAppOptions.overrides`, value `true`), so the dual-replica tests exercise the enforcing
|
|
30
|
+
* branches. Task 1.5a removes it with {@link REVOCATION_ENFORCED}.
|
|
31
|
+
*/
|
|
32
|
+
export declare const REVOCATION_ENFORCEMENT: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* A revision whose grant no longer lets it run where it would (whole grant revoked, or server full
|
|
35
|
+
* access revoked while the remaining grant still needs it, or no isolated form): it waits for a new
|
|
36
|
+
* review instead of failing (enforcing only).
|
|
37
|
+
*/
|
|
38
|
+
export declare class RevocationPendingError extends Error {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
/** What revoking one key does (the spec's revocation table). */
|
|
42
|
+
export type KeyClass =
|
|
43
|
+
/** A registration (route, tool, provider, hook, view, setup check): withdrawn. */
|
|
44
|
+
{
|
|
45
|
+
kind: "registration";
|
|
46
|
+
}
|
|
47
|
+
/** A `ctx` resource or operation: refused with `ExtensionPermissionError`, handles closed. */
|
|
48
|
+
| {
|
|
49
|
+
kind: "capability";
|
|
50
|
+
}
|
|
51
|
+
/** `execution.full-access:<realm>`: the privileged generation is unloaded. */
|
|
52
|
+
| {
|
|
53
|
+
kind: "full_access";
|
|
54
|
+
realm: ExecutionRealm;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A key no running surface can withdraw on its own (network, config, tables, embeds,
|
|
58
|
+
* dependencies, client code, raw egress, migration warnings): only a whole-grant revocation,
|
|
59
|
+
* which unloads the revision, takes it away, so {@link revocableKeys} refuses it alone.
|
|
60
|
+
*/
|
|
61
|
+
| {
|
|
62
|
+
kind: "unenforced";
|
|
63
|
+
};
|
|
64
|
+
export declare function classifyKey(key: string): KeyClass;
|
|
65
|
+
/** The keys a partial revocation cannot honour on its own (revoke the whole grant instead). */
|
|
66
|
+
export declare function unrevocableKeys(keys: readonly string[]): string[];
|
|
67
|
+
/** The grant fields revocation reads. */
|
|
68
|
+
export type GrantSurface = Pick<RevisionGrant, "keys" | "disabledKeys" | "retiredKeys" | "realms" | "retiredForcing" | "state" | "generation">;
|
|
69
|
+
/**
|
|
70
|
+
* What a full-access realm whose key no longer serves becomes: `isolated` when the remaining grant
|
|
71
|
+
* fits the sandbox, otherwise `pending_approval`. The remaining grant fits when none of the realm's
|
|
72
|
+
* forcing keys still applies: each was retired, or is a permission key that no longer serves (a
|
|
73
|
+
* host reason such as `host.no-isolation` is never a grant key, so it keeps the realm pending).
|
|
74
|
+
*/
|
|
75
|
+
export declare function realmAfterRevocation(grant: GrantSurface, realm: ExecutionRealm): "isolated" | "pending_approval";
|
|
76
|
+
/**
|
|
77
|
+
* A revision grant as the inventory shows it: the withdrawn keys by class and the remaining
|
|
78
|
+
* serving surface (**Partially revoked** when some, not all, keys are withdrawn).
|
|
79
|
+
*/
|
|
80
|
+
export interface RevocationView {
|
|
81
|
+
state: RevisionGrantState;
|
|
82
|
+
generation: number;
|
|
83
|
+
/** Keys revoked or retired (every key once the grant is revoked). */
|
|
84
|
+
withdrawn: string[];
|
|
85
|
+
/** Keys still serving. */
|
|
86
|
+
serving: string[];
|
|
87
|
+
registrations: string[];
|
|
88
|
+
capabilities: string[];
|
|
89
|
+
fullAccess: {
|
|
90
|
+
realm: ExecutionRealm;
|
|
91
|
+
next: "isolated" | "pending_approval";
|
|
92
|
+
}[];
|
|
93
|
+
}
|
|
94
|
+
export declare function revocationView(grant: GrantSurface): RevocationView;
|
|
95
|
+
/** A revision's grant state as one lease caches it. */
|
|
96
|
+
export interface LeaseState {
|
|
97
|
+
status: "no_grant" | RevisionGrantState;
|
|
98
|
+
generation?: number;
|
|
99
|
+
/** Grant keys that no longer serve: revoked or retired, every key once the grant is revoked. */
|
|
100
|
+
refused: ReadonlySet<string>;
|
|
101
|
+
/** Realms the grant reviewed whose full access no longer serves. */
|
|
102
|
+
realmsRevoked: readonly ExecutionRealm[];
|
|
103
|
+
}
|
|
104
|
+
export declare const NO_GRANT: LeaseState;
|
|
105
|
+
/**
|
|
106
|
+
* The lease state of a revision's newest grant generation. A retired grant is not a revocation
|
|
107
|
+
* (its revision was superseded; admission of a superseded revision belongs to the enforcing
|
|
108
|
+
* cutover), so it refuses nothing here.
|
|
109
|
+
*/
|
|
110
|
+
export declare function leaseStateOf(grant: GrantSurface | undefined): LeaseState;
|
|
111
|
+
/**
|
|
112
|
+
* The newest grant generation of each revision stored under the given package sha256s (the
|
|
113
|
+
* package's sha512 names the revision): one query for all of them. A package without a recorded
|
|
114
|
+
* digest or a review has no entry. Grants and packages are deployment rows (no org_id), read
|
|
115
|
+
* outside any org scope.
|
|
116
|
+
*/
|
|
117
|
+
export declare function readGrantSurfacesBySha256(db: KernelSchemaDb, sha256s: readonly string[]): Promise<Map<string, GrantSurface>>;
|
|
118
|
+
/** The newest grant generation of the revision stored under one package sha256, or undefined. */
|
|
119
|
+
export declare function readGrantSurfaceBySha256(db: KernelSchemaDb, sha256: string): Promise<GrantSurface | undefined>;
|
|
120
|
+
/** Newly refused keys of a lease, after a revalidation that saw them (enforcing only). */
|
|
121
|
+
export type LeaseRefusalListener = (keys: string[], state: LeaseState) => void;
|
|
122
|
+
export interface LeaseOptions {
|
|
123
|
+
plugin: string;
|
|
124
|
+
/** The package of the instance; null (a config-declared extension): no lease. */
|
|
125
|
+
sha256: string | null;
|
|
126
|
+
/** The instance runs in the kernel process (full access for the server realm, today's trusted tier). */
|
|
127
|
+
inProcess: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The enforcing decision for one key under a confirmed lease state: refused when the grant no
|
|
131
|
+
* longer serves it, when the whole grant is revoked, or when an in-process generation lost its
|
|
132
|
+
* server full access. Keys the grant never reviewed are not revocation's to refuse.
|
|
133
|
+
*/
|
|
134
|
+
export declare function leaseAllows(state: LeaseState, key: string, inProcess: boolean): boolean;
|
|
135
|
+
/** One revalidation's read: the epoch captured before it, and the state (undefined: it failed). */
|
|
136
|
+
interface LeaseRead {
|
|
137
|
+
epoch: string | undefined;
|
|
138
|
+
checkedAt: number;
|
|
139
|
+
state: (sha256: string) => LeaseState | undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The revision authority of one extension instance. {@link check} answers synchronously while the
|
|
143
|
+
* state is confirmed at the fresh epoch, and otherwise after one coalesced revalidation.
|
|
144
|
+
*/
|
|
145
|
+
export declare class PermissionLease {
|
|
146
|
+
private readonly owner;
|
|
147
|
+
readonly plugin: string;
|
|
148
|
+
readonly sha256: string;
|
|
149
|
+
readonly inProcess: boolean;
|
|
150
|
+
private state;
|
|
151
|
+
/** The epoch the state was confirmed at; undefined while unconfirmed. */
|
|
152
|
+
private epoch;
|
|
153
|
+
private checkedAt;
|
|
154
|
+
/** The last revalidation failed (no epoch or no grant read): what is known is not confirmed. */
|
|
155
|
+
private readFailed;
|
|
156
|
+
private pending;
|
|
157
|
+
private readonly controllers;
|
|
158
|
+
/** Aborted when the whole lease is fenced: closes every handle that relied on it. */
|
|
159
|
+
private fenced;
|
|
160
|
+
private readonly listeners;
|
|
161
|
+
/** Keys whose computed refusal was already reported in shadow mode. */
|
|
162
|
+
private readonly reported;
|
|
163
|
+
closed: boolean;
|
|
164
|
+
constructor(owner: RevisionLeases, plugin: string, sha256: string, inProcess: boolean);
|
|
165
|
+
/** Whether this replica enforces revocation (false until plan task 1.5a). */
|
|
166
|
+
get enforced(): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Whether `key` may be used now. In shadow mode always true and never waiting: a stale lease
|
|
169
|
+
* refreshes in the background, and a computed refusal is reported once per key. When enforcing:
|
|
170
|
+
* {@link wouldAllow} after one coalesced revalidation when the state is not confirmed.
|
|
171
|
+
*/
|
|
172
|
+
check(key: string): boolean | Promise<boolean>;
|
|
173
|
+
/**
|
|
174
|
+
* The computed decision from what is known: {@link leaseAllows} under the last state, and a
|
|
175
|
+
* refusal when the last read failed and the revision has a grant or was never confirmed (fail
|
|
176
|
+
* closed; a revision confirmed without a grant has nothing to revoke).
|
|
177
|
+
*/
|
|
178
|
+
wouldAllow(key: string): boolean;
|
|
179
|
+
/** The keys refused by the last confirmed state. */
|
|
180
|
+
refusedKeys(): string[];
|
|
181
|
+
/** The last confirmed state, if any. */
|
|
182
|
+
current(): LeaseState | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Aborted when `key` is refused or the lease is fenced (enforcing only): the handles that relied
|
|
185
|
+
* on it close. A key restored by a new grant gets a fresh signal.
|
|
186
|
+
*/
|
|
187
|
+
signal(key: string): AbortSignal;
|
|
188
|
+
onRefused(listener: LeaseRefusalListener): () => void;
|
|
189
|
+
close(): void;
|
|
190
|
+
/** Drops the confirmation (a hint or a fence): the next check reads the grant again. */
|
|
191
|
+
invalidate(): void;
|
|
192
|
+
/**
|
|
193
|
+
* The settle deadline or an epoch outage: a lease with a grant that is not confirmed at the
|
|
194
|
+
* current epoch is unconfirmed; when enforcing it also closes its handles, and the next check
|
|
195
|
+
* revalidates (failing closed if it cannot).
|
|
196
|
+
*/
|
|
197
|
+
fenceIfStale(epoch: string | undefined): void;
|
|
198
|
+
/** Revalidates alone, or with a read shared by every lease of a fence or epoch change. */
|
|
199
|
+
revalidate(shared?: Promise<LeaseRead>): Promise<LeaseState | undefined>;
|
|
200
|
+
private valid;
|
|
201
|
+
private apply;
|
|
202
|
+
}
|
|
203
|
+
export interface RevisionLeasesOptions {
|
|
204
|
+
epochs: GrantEpochView;
|
|
205
|
+
/** The lease states of the revisions stored under package sha256s (one query for all). */
|
|
206
|
+
read: (sha256s: readonly string[]) => Promise<Map<string, LeaseState>>;
|
|
207
|
+
/**
|
|
208
|
+
* An in-process generation lost its server full access, or the whole grant was revoked
|
|
209
|
+
* (enforcing only): converge, so the generation is unloaded (and restarted isolated when the
|
|
210
|
+
* remaining grant fits).
|
|
211
|
+
*/
|
|
212
|
+
onUnload: (plugin: string) => void;
|
|
213
|
+
/**
|
|
214
|
+
* A new grant serves withdrawn keys again (enforcing only): reload the instance, since withdrawn
|
|
215
|
+
* registrations come back only with a new setup.
|
|
216
|
+
*/
|
|
217
|
+
onRestored: (plugin: string) => void;
|
|
218
|
+
onFault?: (plugin: string, err: unknown) => void;
|
|
219
|
+
/** A decision computed but not enforced (shadow mode): what enforcement would do. */
|
|
220
|
+
onShadow?: (plugin: string, decision: ShadowRevocation) => void;
|
|
221
|
+
/**
|
|
222
|
+
* Enforce the decisions; defaults to {@link REVOCATION_ENFORCED}. Only the tests of the
|
|
223
|
+
* enforcing branch pass true; task 1.5a removes this option with the shadow branch.
|
|
224
|
+
*/
|
|
225
|
+
enforce?: boolean;
|
|
226
|
+
now?: () => number;
|
|
227
|
+
}
|
|
228
|
+
/** What a lease would enforce, reported while revocation is computed only. */
|
|
229
|
+
export type ShadowRevocation = {
|
|
230
|
+
refusedCall: string;
|
|
231
|
+
} | {
|
|
232
|
+
refused: string[];
|
|
233
|
+
lostServerFullAccess: boolean;
|
|
234
|
+
revoked: boolean;
|
|
235
|
+
state: LeaseState;
|
|
236
|
+
};
|
|
237
|
+
/** The leases of every instance on this replica (one per instance with a package). */
|
|
238
|
+
export declare class RevisionLeases {
|
|
239
|
+
private readonly options;
|
|
240
|
+
private readonly leases;
|
|
241
|
+
readonly epochs: GrantEpochView;
|
|
242
|
+
readonly now: () => number;
|
|
243
|
+
readonly enforced: boolean;
|
|
244
|
+
/** Callbacks run in the context the leases were built in, never a caller's org scope. */
|
|
245
|
+
private readonly inOwnContext;
|
|
246
|
+
constructor(options: RevisionLeasesOptions);
|
|
247
|
+
/** Opens the lease of an instance and starts confirming it; undefined without a package. */
|
|
248
|
+
open({ plugin, sha256, inProcess }: LeaseOptions): PermissionLease | undefined;
|
|
249
|
+
/** The confirmed states of a plugin's leases on this replica (the computed decisions). */
|
|
250
|
+
statesOf(plugin: string): LeaseState[];
|
|
251
|
+
/** The local fence after a commit, or a fan-out hint: revalidate the plugin's leases now. */
|
|
252
|
+
fence(plugin?: string): Promise<void>;
|
|
253
|
+
/** The grant epoch advanced: every lease may be stale; revalidate them all with one read. */
|
|
254
|
+
epochChanged(): Promise<void>;
|
|
255
|
+
/** The settle deadline after an epoch change: close what was not confirmed at the new epoch. */
|
|
256
|
+
fenceStale(): void;
|
|
257
|
+
/** No epoch read succeeded for the whole bound: close every lease that has a grant. */
|
|
258
|
+
fenceAll(): void;
|
|
259
|
+
/** One lease's read (its first confirmation, or a check that found it stale). */
|
|
260
|
+
readOne(sha256: string): Promise<LeaseRead>;
|
|
261
|
+
forget(lease: PermissionLease): void;
|
|
262
|
+
mustUnload(lease: PermissionLease): void;
|
|
263
|
+
restored(lease: PermissionLease): void;
|
|
264
|
+
shadow(lease: PermissionLease, decision: ShadowRevocation): void;
|
|
265
|
+
fault(lease: PermissionLease, err: unknown): void;
|
|
266
|
+
private revalidateAll;
|
|
267
|
+
/**
|
|
268
|
+
* The epoch is captured before the grants are read: a revocation committed after the read's
|
|
269
|
+
* snapshot advances the epoch past this value, so the result never outlives it.
|
|
270
|
+
*/
|
|
271
|
+
private readStates;
|
|
272
|
+
}
|
|
273
|
+
export {};
|