nulladrift 0.6.2 → 0.7.0
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 +7 -0
- package/dist/index.js +34 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
@@ -1846,7 +1846,7 @@ import { readFile as readFile3 } from "fs/promises";
|
|
|
1846
1846
|
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
1847
1847
|
|
|
1848
1848
|
// src/lib/version.ts
|
|
1849
|
-
var VERSION = "0.
|
|
1849
|
+
var VERSION = "0.7.0";
|
|
1850
1850
|
var USER_AGENT = `nulladrift/${VERSION} (+https://github.com/Nulladrift/nulladrift)`;
|
|
1851
1851
|
|
|
1852
1852
|
// src/lock/provenance.ts
|
|
@@ -4224,6 +4224,9 @@ async function runLogout(options) {
|
|
|
4224
4224
|
return EXIT_CLEAN;
|
|
4225
4225
|
}
|
|
4226
4226
|
|
|
4227
|
+
// src/commands/push.ts
|
|
4228
|
+
import { createHash as createHash6 } from "crypto";
|
|
4229
|
+
|
|
4227
4230
|
// src/report/push-error.ts
|
|
4228
4231
|
function envelope(body) {
|
|
4229
4232
|
try {
|
|
@@ -4268,11 +4271,26 @@ function describeRefusal(status, body) {
|
|
|
4268
4271
|
// src/lib/build-token.ts
|
|
4269
4272
|
var BUILD_TOKEN_HEADER = "nulladrift-build-token";
|
|
4270
4273
|
var DEFAULT_AUDIENCE = "nulladrift";
|
|
4274
|
+
var READING_TOKEN_HEADER = "nulladrift-reading-token";
|
|
4275
|
+
function readingAudience(base, digest2) {
|
|
4276
|
+
return `${base.replace(/\/+$/, "")}#sha256:${digest2}`;
|
|
4277
|
+
}
|
|
4278
|
+
function readingAudienceBase(apiUrl, env = process.env) {
|
|
4279
|
+
return env["NULLADRIFT_BUILD_AUDIENCE"] || new URL(apiUrl).origin;
|
|
4280
|
+
}
|
|
4271
4281
|
async function acquireBuildToken(options = {}) {
|
|
4272
4282
|
const env = options.env ?? process.env;
|
|
4273
4283
|
const explicit = env["NULLADRIFT_ID_TOKEN"];
|
|
4274
4284
|
if (explicit) return { token: explicit, source: "environment" };
|
|
4275
4285
|
if (env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
4286
|
+
return fromGithubActions(env["NULLADRIFT_BUILD_AUDIENCE"] ?? DEFAULT_AUDIENCE, env, options);
|
|
4287
|
+
}
|
|
4288
|
+
async function acquireReadingToken(audience, options = {}) {
|
|
4289
|
+
const env = options.env ?? process.env;
|
|
4290
|
+
if (env["GITHUB_ACTIONS"] !== "true") return void 0;
|
|
4291
|
+
return fromGithubActions(audience, env, options);
|
|
4292
|
+
}
|
|
4293
|
+
async function fromGithubActions(audience, env, options) {
|
|
4276
4294
|
const requestUrl = env["ACTIONS_ID_TOKEN_REQUEST_URL"];
|
|
4277
4295
|
const requestToken = env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
|
|
4278
4296
|
if (!requestUrl || !requestToken) {
|
|
@@ -4280,7 +4298,7 @@ async function acquireBuildToken(options = {}) {
|
|
|
4280
4298
|
}
|
|
4281
4299
|
try {
|
|
4282
4300
|
const url = new URL(requestUrl);
|
|
4283
|
-
url.searchParams.set("audience",
|
|
4301
|
+
url.searchParams.set("audience", audience);
|
|
4284
4302
|
const response = await (options.fetch ?? fetch)(url, {
|
|
4285
4303
|
headers: { authorization: `bearer ${requestToken}`, accept: "application/json" },
|
|
4286
4304
|
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
@@ -4296,9 +4314,11 @@ async function acquireBuildToken(options = {}) {
|
|
|
4296
4314
|
|
|
4297
4315
|
// src/commands/push.ts
|
|
4298
4316
|
function describeIdentity(identity2, hint) {
|
|
4299
|
-
|
|
4317
|
+
const where = `${identity2?.repository ?? ""}${identity2?.ref ? ` @ ${identity2.ref}` : ""}`;
|
|
4318
|
+
const contents = identity2?.boundToReading ? " \xB7 contents signed" : identity2?.bindingRefused ? ` \xB7 contents not signed: ${identity2.bindingRefused}` : "";
|
|
4319
|
+
if (identity2?.trust === "trusted") return `${green("signed")} ${dim(`${where} \xB7 a trusted build${contents}`)}`;
|
|
4300
4320
|
if (identity2?.trust === "verified") {
|
|
4301
|
-
return `${yellow("signed")} ${dim(`${
|
|
4321
|
+
return `${yellow("signed")} ${dim(`${where} \xB7 not a build this organization lists as trusted${contents}`)}`;
|
|
4302
4322
|
}
|
|
4303
4323
|
if (identity2?.rejected) return `${red("build token refused")} ${dim(identity2.rejected)}`;
|
|
4304
4324
|
return hint ? dim(`unsigned: ${hint}`) : void 0;
|
|
@@ -4388,8 +4408,14 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4388
4408
|
// this leaves the machine. The full reason is still printed locally.
|
|
4389
4409
|
unreachable: result.unreachable.map((failure) => ({ server: failure.server, reason: failure.reason.split("\n server stderr:")[0] ?? failure.reason }))
|
|
4390
4410
|
};
|
|
4391
|
-
const
|
|
4411
|
+
const payload = JSON.stringify(body);
|
|
4412
|
+
const digest2 = createHash6("sha256").update(payload).digest("hex");
|
|
4413
|
+
const [build, reading] = await Promise.all([
|
|
4414
|
+
acquireBuildToken(),
|
|
4415
|
+
acquireReadingToken(readingAudience(readingAudienceBase(apiUrl), digest2))
|
|
4416
|
+
]);
|
|
4392
4417
|
const buildToken = build && "token" in build ? build.token : void 0;
|
|
4418
|
+
const readingToken = reading && "token" in reading ? reading.token : void 0;
|
|
4393
4419
|
let response;
|
|
4394
4420
|
try {
|
|
4395
4421
|
response = await fetch(`${apiUrl}/api/v1/ingest`, {
|
|
@@ -4397,9 +4423,10 @@ ${dim(`Looked in: ${looked}`)}
|
|
|
4397
4423
|
headers: {
|
|
4398
4424
|
"content-type": "application/json",
|
|
4399
4425
|
authorization: `Bearer ${token}`,
|
|
4400
|
-
...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {}
|
|
4426
|
+
...buildToken ? { [BUILD_TOKEN_HEADER]: buildToken } : {},
|
|
4427
|
+
...readingToken ? { [READING_TOKEN_HEADER]: readingToken } : {}
|
|
4401
4428
|
},
|
|
4402
|
-
body:
|
|
4429
|
+
body: payload,
|
|
4403
4430
|
// A redirect would carry the reading and the identity token to wherever it points.
|
|
4404
4431
|
redirect: "error",
|
|
4405
4432
|
signal: AbortSignal.timeout(options.timeoutMs)
|