@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.
Files changed (51) hide show
  1. package/dist/agents/admin-agents.d.ts +20 -3
  2. package/dist/agents/admin-agents.js +38 -7
  3. package/dist/catalog/marketplace-fetch.d.ts +2 -0
  4. package/dist/catalog/marketplace-fetch.js +7 -2
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/provenance.d.ts +69 -0
  7. package/dist/catalog/provenance.js +108 -0
  8. package/dist/ctx/create-ctx.d.ts +16 -0
  9. package/dist/ctx/create-ctx.js +269 -34
  10. package/dist/errors.d.ts +1 -1
  11. package/dist/errors.js +2 -2
  12. package/dist/extensions/execution-realm.d.ts +96 -0
  13. package/dist/extensions/execution-realm.js +141 -0
  14. package/dist/extensions/extensions.module.js +3 -0
  15. package/dist/extensions/grant-epoch.d.ts +4 -2
  16. package/dist/extensions/grant-epoch.js +4 -2
  17. package/dist/extensions/host.d.ts +26 -3
  18. package/dist/extensions/host.js +135 -10
  19. package/dist/extensions/instance.d.ts +2 -0
  20. package/dist/extensions/instance.js +1 -0
  21. package/dist/extensions/isolated/admission.d.ts +6 -0
  22. package/dist/extensions/isolated/admission.js +17 -0
  23. package/dist/extensions/isolated/tier.d.ts +14 -0
  24. package/dist/extensions/isolated/tier.js +27 -0
  25. package/dist/extensions/ledger.d.ts +5 -0
  26. package/dist/extensions/ledger.js +16 -0
  27. package/dist/extensions/permission-view.d.ts +2 -2
  28. package/dist/extensions/publisher-proof.job.d.ts +39 -0
  29. package/dist/extensions/publisher-proof.job.js +160 -0
  30. package/dist/extensions/registry.d.ts +6 -0
  31. package/dist/extensions/registry.js +8 -0
  32. package/dist/extensions/review-hash.d.ts +114 -0
  33. package/dist/extensions/review-hash.js +145 -0
  34. package/dist/extensions/revision-grants.d.ts +10 -0
  35. package/dist/extensions/revocation-leases.d.ts +273 -0
  36. package/dist/extensions/revocation-leases.js +533 -0
  37. package/dist/extensions/revocation.d.ts +78 -0
  38. package/dist/extensions/revocation.js +202 -0
  39. package/dist/index.d.ts +6 -2
  40. package/dist/index.js +6 -2
  41. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  42. package/dist/lifecycle/kernel-lifecycle.js +24 -18
  43. package/dist/overrides.d.ts +5 -1
  44. package/dist/overrides.js +2 -0
  45. package/dist/packages/official-publisher.d.ts +44 -0
  46. package/dist/packages/official-publisher.js +147 -48
  47. package/dist/packages/provenance.d.ts +6 -0
  48. package/dist/packages/provenance.js +26 -9
  49. package/dist/platform/ops/admin-items.ops.js +1 -1
  50. package/dist/roles/worker.module.js +3 -0
  51. package/package.json +2 -2
@@ -5,7 +5,7 @@ import { toSignedEntity, toTrustMaterial, Verifier } from "@sigstore/verify";
5
5
  import { z } from "zod";
6
6
  import { canonicalJson } from "../tools/canonical-json.js";
7
7
  import npmPublishKeys from "./npm-publish-keys.json" with { type: "json" };
8
- import { fetchNpmAttestations, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
8
+ import { fetchNpmAttestations, isTransientAttestationsFailure, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
9
9
  import trustedRoot from "./sigstore-trusted-root.json" with { type: "json" };
10
10
  const NPM_PUBLISH = "https://github.com/npm/attestation/tree/main/specs/publish/v0.1";
11
11
  const REGISTRY = "https://registry.npmjs.org";
@@ -33,27 +33,6 @@ const statementSchema = z.object({
33
33
  .length(1),
34
34
  predicate: z.unknown(),
35
35
  });
36
- const buildSchema = z.object({
37
- buildDefinition: z.object({
38
- buildType: z.literal(BUILD_TYPE),
39
- externalParameters: z.object({
40
- workflow: z.object({
41
- repository: z.literal(REPOSITORY),
42
- path: z.literal(WORKFLOW),
43
- ref: z.literal(MAIN_REF),
44
- }),
45
- }),
46
- internalParameters: z.object({
47
- github: z.object({
48
- repository_id: z.literal(REPOSITORY_ID),
49
- repository_owner_id: z.literal(OWNER_ID),
50
- }),
51
- }),
52
- resolvedDependencies: z
53
- .array(z.object({ digest: z.object({ gitCommit: z.string().regex(/^[0-9a-f]{40}$/) }) }))
54
- .min(1),
55
- }),
56
- });
57
36
  const publishSchema = z.object({
58
37
  name: z.string(),
59
38
  version: z.string(),
@@ -82,7 +61,7 @@ function checkEnvelope(raw, type, revision) {
82
61
  }
83
62
  return { entity, predicate: statement.predicate };
84
63
  }
85
- function verifyBuildSigner(entity) {
64
+ function readBuildCertificate(entity) {
86
65
  if (entity.key.$case !== "certificate") {
87
66
  throw new Error("The build attestation has no signing certificate");
88
67
  }
@@ -90,23 +69,67 @@ function verifyBuildSigner(entity) {
90
69
  const signer = verifier.verify(entity, { extensions: { issuer: GITHUB_ISSUER } });
91
70
  // Fulcio extensions sign these GitHub OIDC claims independently of the predicate.
92
71
  const claim = (oid) => cert.extension(`1.3.6.1.4.1.57264.1.${oid}`)?.valueObj.subs[0]?.value.toString("utf8");
93
- if (claim(14) !== MAIN_REF || !claim(9)?.endsWith(`/${WORKFLOW}@${MAIN_REF}`)) {
94
- throw new Error("The signing certificate does not match the official release workflow or main ref");
72
+ const identity = signer.identity?.subjectAlternativeName;
73
+ const buildSigner = claim(9);
74
+ const repository = claim(12);
75
+ const ref = claim(14);
76
+ const repositoryId = claim(15);
77
+ const ownerId = claim(17);
78
+ const commit = claim(13);
79
+ if (!identity ||
80
+ !buildSigner ||
81
+ !repository ||
82
+ !ref ||
83
+ !repositoryId ||
84
+ !ownerId ||
85
+ !commit ||
86
+ identity !== buildSigner) {
87
+ throw new Error("The signing certificate does not carry a complete GitHub Actions identity");
95
88
  }
96
- if (signer.identity?.subjectAlternativeName !== WORKFLOW_IDENTITY ||
97
- claim(9) !== WORKFLOW_IDENTITY ||
98
- claim(12) !== REPOSITORY ||
99
- claim(15) !== REPOSITORY_ID ||
100
- claim(17) !== OWNER_ID) {
101
- throw new Error("The signing certificate does not match the official repository identity");
89
+ // A reusable workflow signs with its own file (the SAN and build signer name the called
90
+ // workflow, possibly in another repository at another ref), not the source repository's
91
+ // workflow. Such a signer is refused: the identity reviewers approve and continuity compares is
92
+ // `<repository>/<workflow>`, and a called workflow outside the repository would let whoever owns
93
+ // it publish under that repository's name, so the workflow must live in the source repository at
94
+ // the built ref.
95
+ const prefix = `${repository}/`;
96
+ const suffix = `@${ref}`;
97
+ if (!buildSigner.startsWith(prefix) || !buildSigner.endsWith(suffix)) {
98
+ throw new Error("The signing certificate's workflow is not in its source repository and ref");
102
99
  }
103
- const commit = claim(13);
104
- if (!commit)
105
- throw new Error("The signing certificate names no source commit");
106
- return commit;
100
+ const workflow = buildSigner.slice(prefix.length, buildSigner.length - suffix.length);
101
+ return {
102
+ issuer: GITHUB_ISSUER,
103
+ identity,
104
+ repository,
105
+ repositoryId,
106
+ ownerId,
107
+ workflow,
108
+ ref,
109
+ commit,
110
+ };
107
111
  }
108
- /** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
109
- export function verifyOfficialPublisher(body, revision) {
112
+ const genericBuildSchema = z.object({
113
+ buildDefinition: z.object({
114
+ buildType: z.string(),
115
+ externalParameters: z.object({
116
+ workflow: z.object({ repository: z.string(), path: z.string(), ref: z.string() }),
117
+ }),
118
+ internalParameters: z.object({
119
+ github: z.object({ repository_id: z.string(), repository_owner_id: z.string() }),
120
+ }),
121
+ resolvedDependencies: z
122
+ .array(z.object({ digest: z.object({ gitCommit: z.string().regex(/^[0-9a-f]{40}$/) }) }))
123
+ .min(1),
124
+ }),
125
+ });
126
+ /**
127
+ * Checks both signatures and the transparency evidence of an npm package revision built by GitHub
128
+ * Actions, with the bundled roots: the registry's publish attestation (an npm registry key) and the
129
+ * SLSA build attestation (a Fulcio certificate from the GitHub OIDC issuer). Returns the signing
130
+ * certificate's identity and the build predicate, still to be checked by the caller.
131
+ */
132
+ function attested(body, revision) {
110
133
  const { attestations } = attestationsSchema.parse(body);
111
134
  const [publish, ...duplicatePublish] = attestations.filter((a) => a.predicateType === NPM_PUBLISH);
112
135
  const [build, ...duplicateBuild] = attestations.filter((a) => a.predicateType === SLSA_PROVENANCE_V1);
@@ -123,30 +146,106 @@ export function verifyOfficialPublisher(body, revision) {
123
146
  }
124
147
  verifier.verify(published.entity);
125
148
  const built = checkEnvelope(build.bundle, SLSA_PROVENANCE_V1, revision);
126
- const commit = verifyBuildSigner(built.entity);
127
- const [source] = buildSchema.parse(built.predicate).buildDefinition.resolvedDependencies;
128
- if (source?.digest.gitCommit !== commit) {
149
+ return {
150
+ certificate: readBuildCertificate(built.entity),
151
+ predicate: built.predicate,
152
+ evidenceDigest: createHash("sha256")
153
+ .update(canonicalJson([publish.bundle, build.bundle]))
154
+ .digest("hex"),
155
+ };
156
+ }
157
+ /**
158
+ * Any GitHub Actions publisher (publisher evidence for review and continuity, plan task 1.2e):
159
+ * both attestations verified, and the build predicate in agreement with the certificate. The
160
+ * identity is returned as signed; `catalog/provenance.ts` normalizes it.
161
+ */
162
+ export function verifyPublisher(body, revision) {
163
+ const { certificate, predicate, evidenceDigest } = attested(body, revision);
164
+ const def = genericBuildSchema.parse(predicate).buildDefinition;
165
+ const workflow = def.externalParameters.workflow;
166
+ const [source] = def.resolvedDependencies;
167
+ if (workflow.repository !== certificate.repository ||
168
+ workflow.path !== certificate.workflow ||
169
+ workflow.ref !== certificate.ref ||
170
+ def.internalParameters.github.repository_id !== certificate.repositoryId ||
171
+ def.internalParameters.github.repository_owner_id !== certificate.ownerId) {
172
+ throw new Error("The build definition does not match the signing certificate");
173
+ }
174
+ if (source?.digest.gitCommit !== certificate.commit) {
129
175
  throw new Error("The signing certificate does not match the build's source commit");
130
176
  }
131
- if (!/^@capybara-hq\/plugin-[a-z0-9][a-z0-9-]*$/.test(revision.name)) {
132
- throw new Error("An official plugin must belong to the Capybara npm namespace");
177
+ return { revision, certificate, buildType: def.buildType, evidenceDigest };
178
+ }
179
+ const OFFICIAL_NAME = /^@capybara-hq\/plugin-[a-z0-9][a-z0-9-]*$/;
180
+ /**
181
+ * The one definition of official proof, shared by the official marketplace's admission
182
+ * ({@link verifyOfficialPublisher}) and publisher evidence (`classifyPublisherEvidence`): a revision
183
+ * whose attestations verified ({@link verifyPublisher}: the build predicate agrees with the
184
+ * certificate and its source commit) is official when the certificate is the official release
185
+ * workflow on the official repository's main ref, the build type is the GitHub Actions workflow
186
+ * build, and the package is in the Capybara plugin namespace. Returns why it is not, or undefined.
187
+ */
188
+ export function officialPublisherProblem(verified) {
189
+ const cert = verified.certificate;
190
+ if (cert.ref !== MAIN_REF || cert.workflow !== WORKFLOW) {
191
+ return "The signing certificate does not match the official release workflow or main ref";
192
+ }
193
+ if (cert.issuer !== GITHUB_ISSUER ||
194
+ cert.identity !== WORKFLOW_IDENTITY ||
195
+ cert.repository !== REPOSITORY ||
196
+ cert.repositoryId !== REPOSITORY_ID ||
197
+ cert.ownerId !== OWNER_ID) {
198
+ return "The signing certificate does not match the official repository identity";
133
199
  }
200
+ if (verified.buildType !== BUILD_TYPE) {
201
+ return "The build attestation is not a GitHub Actions workflow build";
202
+ }
203
+ if (!OFFICIAL_NAME.test(verified.revision.name)) {
204
+ return "An official plugin must belong to the Capybara npm namespace";
205
+ }
206
+ return undefined;
207
+ }
208
+ /** Checks both signatures, transparency evidence and publisher identity with the bundled roots. */
209
+ export function verifyOfficialPublisher(body, revision) {
210
+ const verified = verifyPublisher(body, revision);
211
+ const problem = officialPublisherProblem(verified);
212
+ if (problem)
213
+ throw new Error(problem);
134
214
  return {
135
215
  checked: true,
136
216
  revision,
137
217
  repository: REPOSITORY,
138
- commit,
218
+ commit: verified.certificate.commit,
139
219
  workflow: WORKFLOW,
140
220
  buildType: BUILD_TYPE,
141
- evidenceDigest: createHash("sha256")
142
- .update(canonicalJson([publish.bundle, build.bundle]))
143
- .digest("hex"),
221
+ evidenceDigest: verified.evidenceDigest,
144
222
  policyVersion: POLICY_VERSION,
145
223
  };
146
224
  }
147
225
  /** Uses the same bounded registry client as the review's display-only provenance. */
148
226
  export async function fetchOfficialPublisher(cfg, revision, signal) {
149
227
  const timeout = AbortSignal.timeout(PROVENANCE_TIMEOUT_MS);
150
- const attestations = await fetchNpmAttestations(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout);
151
- return verifyOfficialPublisher(attestations, revision);
228
+ let attestations;
229
+ try {
230
+ attestations = await fetchNpmAttestations(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout);
231
+ }
232
+ catch (e) {
233
+ throw new OfficialPublisherError(e, isTransientAttestationsFailure(e));
234
+ }
235
+ try {
236
+ return verifyOfficialPublisher(attestations, revision);
237
+ }
238
+ catch (e) {
239
+ // Verification is deterministic for the fetched evidence: another signer, digest or name.
240
+ throw new OfficialPublisherError(e, false);
241
+ }
242
+ }
243
+ /** A failed publisher check; `transient` failures (network, timeout, 5xx) may pass on a retry soon. */
244
+ export class OfficialPublisherError extends Error {
245
+ transient;
246
+ constructor(cause, transient) {
247
+ super(cause instanceof Error ? cause.message : String(cause), { cause });
248
+ this.transient = transient;
249
+ this.name = "OfficialPublisherError";
250
+ }
152
251
  }
@@ -35,6 +35,12 @@ export type ProvenanceResult = Provenance | ProvenanceNotChecked;
35
35
  export declare const SLSA_PROVENANCE_V1 = "https://slsa.dev/provenance/v1";
36
36
  /** Provenance must not hold up an import: a slow registry gives "not checked". */
37
37
  export declare const PROVENANCE_TIMEOUT_MS = 15000;
38
+ /**
39
+ * Whether a {@link fetchNpmAttestations} failure may pass on a retry soon (timeouts, network
40
+ * errors, other HTTP statuses than 404) rather than being the registry's answer (no provenance, an
41
+ * invalid name, a malformed or oversized body).
42
+ */
43
+ export declare function isTransientAttestationsFailure(e: unknown): boolean;
38
44
  /** The hex sha512 of a `sha512-<base64>` integrity (undefined for anything else). */
39
45
  export declare function sha512Hex(integrity: string): string | undefined;
40
46
  /**
@@ -11,6 +11,25 @@ const NPM_NAME_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
11
11
  const SEMVER_RE = /^[0-9A-Za-z.+-]{1,256}$/;
12
12
  const COMMIT_RE = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
13
13
  class NpmAttestationsError extends Error {
14
+ transient;
15
+ constructor(message,
16
+ /** A network or registry hiccup worth retrying soon; false for the registry's definite answers. */
17
+ transient, options) {
18
+ super(message, options);
19
+ this.transient = transient;
20
+ }
21
+ }
22
+ class AttestationsTooLarge extends Error {
23
+ }
24
+ /**
25
+ * Whether a {@link fetchNpmAttestations} failure may pass on a retry soon (timeouts, network
26
+ * errors, other HTTP statuses than 404) rather than being the registry's answer (no provenance, an
27
+ * invalid name, a malformed or oversized body).
28
+ */
29
+ export function isTransientAttestationsFailure(e) {
30
+ if (e instanceof NpmAttestationsError)
31
+ return e.transient;
32
+ return !(e instanceof SyntaxError || e instanceof AttestationsTooLarge);
14
33
  }
15
34
  const notChecked = (reason) => ({ checked: false, reason });
16
35
  const errMsg = (e) => (e instanceof Error ? e.message : String(e));
@@ -44,7 +63,7 @@ export async function fetchProvenance(cfg, name, version, signal, opts = {}) {
44
63
  /** Fetches bounded attestation evidence without accepting it as publisher proof. */
45
64
  export async function fetchNpmAttestations(cfg, name, version, signal) {
46
65
  if (!NPM_NAME_RE.test(name) || name.length > 214 || !SEMVER_RE.test(version)) {
47
- throw new NpmAttestationsError("not a valid npm package name and version");
66
+ throw new NpmAttestationsError("not a valid npm package name and version", false);
48
67
  }
49
68
  try {
50
69
  const registry = new URL(cfg.registry.endsWith("/") ? cfg.registry : `${cfg.registry}/`);
@@ -58,20 +77,18 @@ export async function fetchNpmAttestations(cfg, name, version, signal) {
58
77
  }, cfg.net, cfg.lookup !== undefined ? { lookup: cfg.lookup } : {});
59
78
  if (!res.ok) {
60
79
  await res.body?.cancel().catch(() => { });
61
- throw new NpmAttestationsError(res.status === 404
62
- ? "the registry has no provenance for this version"
63
- : `the registry answered HTTP ${res.status} for the attestations`);
80
+ throw res.status === 404
81
+ ? new NpmAttestationsError("the registry has no provenance for this version", false)
82
+ : new NpmAttestationsError(`the registry answered HTTP ${res.status} for the attestations`, true);
64
83
  }
65
- const raw = await readCapped(res, MAX_ATTESTATION_BYTES, () => new Error("the attestations are too large"));
84
+ const raw = await readCapped(res, MAX_ATTESTATION_BYTES, () => new AttestationsTooLarge("the attestations are too large"));
66
85
  return JSON.parse(raw.toString("utf8"));
67
86
  }
68
87
  catch (e) {
69
88
  if (signal.aborted)
70
- throw new NpmAttestationsError("the registry did not answer in time", { cause: e });
89
+ throw new NpmAttestationsError("the registry did not answer in time", true, { cause: e });
71
90
  if (e instanceof NetDeniedError) {
72
- throw new NpmAttestationsError(`the network rules refused the attestations: ${e.message}`, {
73
- cause: e,
74
- });
91
+ throw new NpmAttestationsError(`the network rules refused the attestations: ${e.message}`, true, { cause: e });
75
92
  }
76
93
  throw e;
77
94
  }
@@ -96,7 +96,7 @@ let AdminItemsOperations = class AdminItemsOperations {
96
96
  }),
97
97
  defineOperation({
98
98
  id: "admin.agent-get",
99
- description: "Read one agent of this org as the admin console shows it (super admin): its definition with the instructions in full, members, profile with quick action labels, versions count, the skills and connectors it has by name, and how many of the org's skills it turns off (skillsOff). Never its conversations or credentials.",
99
+ description: "Read one agent of this org as the admin console shows it (super admin): its definition with the instructions in full, members, profile with quick action labels, versions count, the skills it has by name and the connectors with their status, setup state and icon, and how many of the org's skills it turns off (skillsOff). Never its conversations or credentials.",
100
100
  input: AgentIdInput,
101
101
  example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
102
102
  authz: { superAdmin: true },
@@ -36,6 +36,7 @@ import { ExtensionsModule } from "../extensions/extensions.module.js";
36
36
  import { PluginsReconcileJob } from "../extensions/lifecycle.js";
37
37
  import { LifecycleHookWorkersModule } from "../extensions/lifecycle-hooks.js";
38
38
  import { PackageDigestBackfillJob } from "../extensions/package-digest.job.js";
39
+ import { PublisherProofRecheckJob } from "../extensions/publisher-proof.job.js";
39
40
  import { BlobSweepModule } from "../files/blob-sweep.job.js";
40
41
  import { FileDraftCleanupJob } from "../files/draft-cleanup.job.js";
41
42
  import { FileLibraryKickoffJob } from "../files/hash-job.js";
@@ -168,6 +169,8 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
168
169
  CatalogJobs,
169
170
  // sha512 of packages stored before migration 0235 (extension permission model plan 1.2b)
170
171
  PackageDigestBackfillJob,
172
+ // publisher proofs of official revisions imported before they were recorded (rc.165)
173
+ PublisherProofRecheckJob,
171
174
  DirectoryScanJob,
172
175
  PluginsReconcileJob,
173
176
  GatewayCheckJob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.144",
3
+ "version": "0.1.0-rc.146",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "yaml": "^2.9.1",
71
71
  "yauzl": "3.4.0",
72
72
  "zod": "^4.6.7",
73
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.102"
73
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.103"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",