site: a release's attestations are asked of GitHub once, not once a file (ArcticLampyrid on X)

wrangler tail of the 04:05 run: "API rate limit exceeded for 172.71.158.37",
so v0.1.3982, v0.1.3981 and v0.1.3978 got no attestations.jsonl. The worker
has no GITHUB_TOKEN secret, and unsigned the API allows 60 requests an hour
to an IP the worker shares with other workers; asking once per file (15 a
release, every five minutes until whole) spent that fast. Release CI signs
every file in one statement, so the cron now reads the subjects of the
bundles it got and asks only for a file none of them names: one request a
release. A GITHUB_TOKEN secret (read-only, public repos) would lift the
shared limit; that is the owner's to add.

Checked on the real v0.1.3979 bundle from R2: subjects() lists all 17 files,
the CLI's digest among them.
Run (mote): node --test site/*.test.mjs 120/120.
New test: one statement signing every file is asked for once.
Broken by hand: not adding the subjects to the covered set turns it red.
This commit is contained in:
yetone
2026-11-13 12:10:01 +08:00
parent 70f4593e62
commit 5e51e241c2
2 changed files with 34 additions and 2 deletions
+19 -2
View File
@@ -170,8 +170,12 @@ export async function mirror(env, rels, open, now = Date.now, attest = null) {
// the next run asks again rather than keep a list with holes in it.
async function keepBundles(env, tag, rel, attest) {
const lines = new Set();
// release CI signs every file in one statement, so the first answer
// covers the rest: GitHub's API is asked once a release, not once a file
// (unsigned, it allows 60 an hour to an IP the worker shares)
const covered = new Set();
for (const [name, a] of Object.entries(rel.assets)) {
if (!a.sha256) continue;
if (!a.sha256 || covered.has(a.sha256)) continue;
let got = null;
try {
got = await attest(a.sha256);
@@ -182,7 +186,10 @@ async function keepBundles(env, tag, rel, attest) {
console.log("r2 attest: none for", tag, name);
return false;
}
for (const b of got) lines.add(JSON.stringify(b));
for (const b of got) {
lines.add(JSON.stringify(b));
for (const h of subjects(b)) covered.add(h);
}
}
if (!lines.size) return false;
try {
@@ -196,6 +203,16 @@ async function keepBundles(env, tag, rel, attest) {
}
}
// subjects is the sha256 of each file a Sigstore bundle's statement names.
export function subjects(b) {
try {
const st = JSON.parse(atob(b.dsseEnvelope.payload));
return (st.subject || []).map((x) => x.digest && x.digest.sha256).filter(Boolean);
} catch {
return [];
}
}
async function copy(env, tag, name, a, open) {
let res = null;
try {
+15
View File
@@ -203,6 +203,21 @@ test("mirror: a kept release the feeds no longer name still gets its bundles, fo
assert.deepEqual(asked, []);
});
test("mirror: one statement signing every file is asked for once a release, not once a file", async () => {
const env = { RELEASES: bucket() };
const names = ["a", "b", "c"];
const rel = { version: "0.1.3982", assets: Object.fromEntries(names.map((n) => [n, { sha256: sha(n) }])) };
const statement = { subject: names.map((n) => ({ name: n, digest: { sha256: sha(n) } })) };
const bundle = { dsseEnvelope: { payload: btoa(JSON.stringify(statement)) } };
const asked = [];
const attest = async (h) => (asked.push(h), [bundle]);
const done = await mirror(env, [rel], async (n) => new Response(n), Date.now, attest);
assert.ok(done.copied.includes("v0.1.3982/attestations.jsonl"));
assert.equal(asked.length, 1);
const res = await ask(env, "/files/v0.1.3982/attestations.jsonl");
assert.deepEqual((await res.text()).trimEnd().split("\n").map((l) => JSON.parse(l)), [bundle]);
});
test("mirror: a release from before the attestations is not asked for any", async () => {
const env = { RELEASES: bucket() };
const rel = { version: "0.1.3890", assets: { a: { sha256: sha("A") } } };