nulladrift 0.6.2 → 0.7.1

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/README.md CHANGED
@@ -210,6 +210,13 @@ any branch as clean. `push` can send your CI provider's signed identity token as
210
210
  control plane then records the repository, ref and commit as the provider stated them. An
211
211
  organization can list the builds it trusts and require every reading to come from one.
212
212
 
213
+ On GitHub Actions the signature also covers what the reading says. `push` asks for a second
214
+ token, minted for the sha256 of the exact bytes it sends and for the control plane it sends them
215
+ to, so it vouches for one reading at one place and nothing else. An organization can require
216
+ that too: a trusted build's reading whose contents nothing signed then fails. GitLab mints its
217
+ token before the job runs, for an audience fixed in the pipeline file, so a GitLab reading proves
218
+ its build and not its contents.
219
+
213
220
  GitHub Actions needs one permission, and `push` does the rest:
214
221
 
215
222
  ```yaml
package/dist/index.js CHANGED
@@ -758,8 +758,9 @@ function collectFacts(schema) {
758
758
  const properties = asObject(object["properties"]);
759
759
  if (properties) {
760
760
  const requiredList = Array.isArray(object["required"]) ? object["required"].filter((entry) => typeof entry === "string") : [];
761
+ const requiredSet = new Set(requiredList);
761
762
  for (const [name, child] of Object.entries(properties)) {
762
- visit(child, path === "" ? name : `${path}.${name}`, requiredList.includes(name), depth + 1);
763
+ visit(child, path === "" ? name : `${path}.${name}`, requiredSet.has(name), depth + 1);
763
764
  }
764
765
  }
765
766
  const items = object["items"];
@@ -772,7 +773,8 @@ function collectFacts(schema) {
772
773
  return facts;
773
774
  }
774
775
  function isSuperset(next, previous) {
775
- return previous.every((entry) => next.includes(entry));
776
+ const members = new Set(next);
777
+ return previous.every((entry) => members.has(entry));
776
778
  }
777
779
  function classifySchemaChange(before, after) {
778
780
  if (stableKey(before) === stableKey(after)) return "same";
@@ -1846,7 +1848,7 @@ import { readFile as readFile3 } from "fs/promises";
1846
1848
  import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
1847
1849
 
1848
1850
  // src/lib/version.ts
1849
- var VERSION = "0.6.2";
1851
+ var VERSION = "0.7.1";
1850
1852
  var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
1851
1853
 
1852
1854
  // src/lock/provenance.ts
@@ -4224,6 +4226,9 @@ async function runLogout(options) {
4224
4226
  return EXIT_CLEAN;
4225
4227
  }
4226
4228
 
4229
+ // src/commands/push.ts
4230
+ import { createHash as createHash6 } from "crypto";
4231
+
4227
4232
  // src/report/push-error.ts
4228
4233
  function envelope(body) {
4229
4234
  try {
@@ -4268,11 +4273,26 @@ function describeRefusal(status, body) {
4268
4273
  // src/lib/build-token.ts
4269
4274
  var BUILD_TOKEN_HEADER = "nulladrift-build-token";
4270
4275
  var DEFAULT_AUDIENCE = "nulladrift";
4276
+ var READING_TOKEN_HEADER = "nulladrift-reading-token";
4277
+ function readingAudience(base, digest2) {
4278
+ return `${base.replace(/\/+$/, "")}#sha256:${digest2}`;
4279
+ }
4280
+ function readingAudienceBase(apiUrl, env = process.env) {
4281
+ return env["NULLADRIFT_BUILD_AUDIENCE"] || new URL(apiUrl).origin;
4282
+ }
4271
4283
  async function acquireBuildToken(options = {}) {
4272
4284
  const env = options.env ?? process.env;
4273
4285
  const explicit = env["NULLADRIFT_ID_TOKEN"];
4274
4286
  if (explicit) return { token: explicit, source: "environment" };
4275
4287
  if (env["GITHUB_ACTIONS"] !== "true") return void 0;
4288
+ return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"] ?? DEFAULT_AUDIENCE, env, options);
4289
+ }
4290
+ async function acquireReadingToken(audience, options = {}) {
4291
+ const env = options.env ?? process.env;
4292
+ if (env["GITHUB_ACTIONS"] !== "true") return void 0;
4293
+ return fromGithubActions(audience, env, options);
4294
+ }
4295
+ async function fromGithubActions(audience, env, options) {
4276
4296
  const requestUrl = env["ACTIONS_ID_TOKEN_REQUEST_URL"];
4277
4297
  const requestToken = env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
4278
4298
  if (!requestUrl || !requestToken) {
@@ -4280,7 +4300,7 @@ async function acquireBuildToken(options = {}) {
4280
4300
  }
4281
4301
  try {
4282
4302
  const url = new URL(requestUrl);
4283
- url.searchParams.set("audience", env["NULLADRIFT_BUILD_AUDIENCE"] ?? DEFAULT_AUDIENCE);
4303
+ url.searchParams.set("audience", audience);
4284
4304
  const response = await (options.fetch ?? fetch)(url, {
4285
4305
  headers: { authorization: `bearer ${requestToken}`, accept: "application/json" },
4286
4306
  signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
@@ -4296,9 +4316,11 @@ async function acquireBuildToken(options = {}) {
4296
4316
 
4297
4317
  // src/commands/push.ts
4298
4318
  function describeIdentity(identity2, hint) {
4299
- if (identity2?.trust === "trusted") return `${green("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 a trusted build`)}`;
4319
+ const where = `${identity2?.repository ?? ""}${identity2?.ref ? ` @ ${identity2.ref}` : ""}`;
4320
+ const contents = identity2?.boundToReading ? " \xB7 contents signed" : identity2?.bindingRefused ? ` \xB7 contents not signed: ${identity2.bindingRefused}` : "";
4321
+ if (identity2?.trust === "trusted") return `${green("signed")} ${dim(`${where} \xB7 a trusted build${contents}`)}`;
4300
4322
  if (identity2?.trust === "verified") {
4301
- return `${yellow("signed")} ${dim(`${identity2.repository ?? ""}${identity2.ref ? ` @ ${identity2.ref}` : ""} \xB7 not a build this organization lists as trusted`)}`;
4323
+ return `${yellow("signed")} ${dim(`${where} \xB7 not a build this organization lists as trusted${contents}`)}`;
4302
4324
  }
4303
4325
  if (identity2?.rejected) return `${red("build token refused")} ${dim(identity2.rejected)}`;
4304
4326
  return hint ? dim(`unsigned: ${hint}`) : void 0;
@@ -4388,8 +4410,14 @@ ${dim(`Looked in: ${looked}`)}
4388
4410
  // this leaves the machine. The full reason is still printed locally.
4389
4411
  unreachable: result.unreachable.map((failure) => ({ server: failure.server, reason: failure.reason.split("\n server stderr:")[0] ?? failure.reason }))
4390
4412
  };
4391
- const build = await acquireBuildToken();
4413
+ const payload = JSON.stringify(body);
4414
+ const digest2 = createHash6("sha256").update(payload).digest("hex");
4415
+ const [build, reading] = await Promise.all([
4416
+ acquireBuildToken(),
4417
+ acquireReadingToken(readingAudience(readingAudienceBase(apiUrl), digest2))
4418
+ ]);
4392
4419
  const buildToken = build && "token" in build ? build.token : void 0;
4420
+ const readingToken = reading && "token" in reading ? reading.token : void 0;
4393
4421
  let response;
4394
4422
  try {
4395
4423
  response = await fetch(`${apiUrl}/api/v1/ingest`, {
@@ -4397,9 +4425,10 @@ ${dim(`Looked in: ${looked}`)}
4397
4425
  headers: {
4398
4426
  "content-type": "application/json",
4399
4427
  authorization: `Bearer ${token}`,
4400
- ...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {}
4428
+ ...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {},
4429
+ ...readingToken ? { [READING_TOKEN_HEADER]: readingToken } : {}
4401
4430
  },
4402
- body: JSON.stringify(body),
4431
+ body: payload,
4403
4432
  // A redirect would carry the reading and the identity token to wherever it points.
4404
4433
  redirect: "error",
4405
4434
  signal: AbortSignal.timeout(options.timeoutMs)