diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 76f2226d60..0fd79d030b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -105,8 +105,7 @@ jobs: pattern: hide-package-* path: packages merge-multiple: true - - name: Prepare an exact draft with append-only assets and enforced immutability + - name: Prepare an exact draft with append-only assets env: GH_TOKEN: ${{ github.token }} - HIDE_RELEASE_POLICY_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }} run: node scripts/release-draft.mjs "$GITHUB_REF_NAME" "$GITHUB_SHA" packages diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11184969bc..f7bf8afb55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -175,7 +175,7 @@ A release is a tag on a commit that is already on `main`, never on a branch. Pushing a stable `vX.Y.Z` tag runs `verify-cargo.sh test` and `verify-web.sh` again on macOS, then packages the app with `HIDE_VERSION= pnpm --dir desktop package` on macOS, Windows and Linux runners. The last two use `package.yml`, whose `node desktop/scripts/smoke-package.mjs` unpacks each package, installs the kit, resolves the command in a fresh shell and checks daemon replacement with a second complete package fixture. The [release asset gate](docs/BUILD.md#release-asset-gate) requires that version's `hide-v-macos-arm64.zip`, `hide-v-windows-x64.zip` and `hide-v-linux-x64.tar.gz`, each with its verified `.sha256`, before draft preparation. -Preparation also requires owner-enforced GitHub release immutability and a `RELEASE_POLICY_TOKEN` secret with Administration read access; absent or unverified prerequisites leave the build artifacts available and block release writes. +The operator keeps immutable releases turned on in the repository's Settings; the workflow does not check it. The writer adds only missing assets to its exact verified draft and never deletes, overwrites, or publishes a release; legacy drafts require separate coverage review. A maintainer publishes only after reviewing separate installation, native first-launch and terminal input/output evidence on every supported system. A package checksum or headless daemon smoke check does not provide that native evidence. diff --git a/docs/BUILD.md b/docs/BUILD.md index 0dcc4a56dd..c965aefc16 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -117,24 +117,23 @@ It serializes runs of the same tag and waits for all three packaging jobs before The file-only entrypoint is `node scripts/check-release-assets.mjs [release-pages.json]`. The directory must contain exactly that tag's macOS ARM64 ZIP, Windows x64 ZIP and Linux x64 TAR.GZ, and one SHA-256 sidecar per archive. The gate rejects a missing target, extra or mixed-version files, symbolic links, empty archives, an incorrectly named sidecar, and a mismatched digest; archive hashing streams bytes rather than retaining each package in memory. -Before any release write, the writer requires GitHub's immutable-release policy to report both `enabled: true` and `enforced_by_owner: true`, and checks that the current tag still resolves to the event commit. -The workflow passes its contents-write token as `GH_TOKEN` and a separate `RELEASE_POLICY_TOKEN` repository secret as `HIDE_RELEASE_POLICY_TOKEN`; that credential needs Administration read access for the [policy endpoint](https://docs.github.com/en/rest/repos/repos#check-if-immutable-releases-are-enabled-for-a-repository). -A missing credential, disabled or unenforced policy, moved tag, or failed initial API read blocks preparation before writes; package workflow artifacts remain available. +Before any release write, the writer checks that the current tag still resolves to the event commit; the workflow passes its contents-write token as `GH_TOKEN`. +A missing credential, moved tag, or failed initial API read blocks preparation before writes; package workflow artifacts remain available. An API failure after an append may leave a partial or complete draft, including an upload whose success response was lost. The writer stops further preparation and preserves accepted assets; a retry validates those bytes before skipping them. -Policy setup and credentials are operator work, and must be complete before attempting a release. +The operator keeps immutable releases turned on in the repository's Settings; the workflow does not check it. The authenticated release and asset inventories are fully paginated, with a 100-page and 16 MiB limit; a tag lookup alone cannot establish that a draft is absent. Multiple releases for the same tag, an invalid inventory, or a published release block the run. -A new draft records its event commit and enforced-policy origin in its body; an existing draft must have that exact provenance record. -Legacy drafts are not automatically reused because enabling immutability does not prove coverage of an older release. +A new draft records its event commit in its body; an existing draft must have that exact provenance record. +Legacy drafts are not automatically reused. The provenance record describes this controlled writer's origin; it is not a cryptographic attestation or a defense against administrative bypass. The writer binds to that checked release ID, uploads only missing names, and skips an existing asset only when its uploaded state, size and SHA-256 digest match the local file. It never changes an existing release's metadata, deletes an asset, or overwrites a name. Mismatched assets, incomplete `starter` uploads and duplicate-name races stop for review; a retry resumes a matching partial draft without replacing completed bytes. The final read must still show the complete unpublished draft and matching bytes. -[GitHub immutability](https://docs.github.com/en/code-security/concepts/supply-chain-security/immutable-releases) supplies the server protection if publication happens between a read and upload; a GET alone is not an atomic draft-state condition. +[GitHub immutability](https://docs.github.com/en/code-security/concepts/supply-chain-security/immutable-releases) supplies, once the operator setting is on, the server protection if publication happens between a read and upload; a GET alone is not an atomic draft-state condition. The operational contract excludes concurrent owner-policy disabling, manual changes to the draft, and tag moves during preparation and publication. Repeated tag reads do not make prepublication provenance atomic; the maintainer must confirm that the tag and draft source record still identify the tested commit before publishing. Each request has a 30-second bound, JSON responses are limited to 8 MiB, and the workflow job has a ten-minute bound. @@ -142,4 +141,4 @@ Each request has a 30-second bound, JSON responses are limited to 8 MiB, and the This gate proves the asset set and digests, not installation, terminal input/output, native first launch, signing or notarization. The Windows and Linux package smoke checks cover bundled tools, daemon startup, the embedded shell and daemon shutdown; actual desktop and terminal checks on each supported system still need their own evidence before a maintainer publishes the draft. The release workflow prepares a draft only and never publishes it automatically. -Its source guard does not establish that policy credentials are provisioned or that any current release is immutable; verify those live operational prerequisites before release work. +Its source guard does not establish that the repository setting is on; verify it before release work. diff --git a/scripts/release-draft.mjs b/scripts/release-draft.mjs index dd06bd1904..7d4a9a84c9 100644 --- a/scripts/release-draft.mjs +++ b/scripts/release-draft.mjs @@ -1,5 +1,5 @@ // Never publish, PATCH release metadata, DELETE or overwrite an asset. -// Owner-enforced GitHub immutability protects publication during an upload. +// The repository's immutable releases setting protects publication during an upload. import { createReadStream } from "node:fs"; import path from "node:path"; import { pathToFileURL } from "node:url"; @@ -9,16 +9,16 @@ const MAX_PAGES = 100; const MAX_JSON_BYTES = 8 * 1024 * 1024; const MAX_INVENTORY_BYTES = 16 * 1024 * 1024; -export function createGitHubClient({ repository, writeToken, policyToken, fetchImpl = fetch }) { +export function createGitHubClient({ repository, writeToken, fetchImpl = fetch }) { if (!/^[\w.-]+\/[\w.-]+$/.test(repository)) throw new Error("a GitHub owner/repository is required"); - if (!writeToken || !policyToken) throw new Error("release write and Administration-read policy credentials are required"); + if (!writeToken) throw new Error("a release write credential is required"); const prefix = `/repos/${repository}`; - async function request(method, suffix, { policy = false, body, upload = false, uploadSize } = {}) { + async function request(method, suffix, { body, upload = false, uploadSize } = {}) { const base = upload ? "https://uploads.github.com" : "https://api.github.com"; const response = await fetchImpl(`${base}${prefix}${suffix}`, { method, redirect: "error", signal: AbortSignal.timeout(30_000), headers: { - Authorization: `Bearer ${policy ? policyToken : writeToken}`, + Authorization: `Bearer ${writeToken}`, Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", ...(body ? { "Content-Type": upload ? "application/octet-stream" : "application/json" } : {}), ...(upload ? { "Content-Length": String(uploadSize) } : {}), @@ -56,7 +56,6 @@ export function createGitHubClient({ repository, writeToken, policyToken, fetchI throw new Error("GitHub inventory exceeds 100 pages; preparation stopped"); } return { - policy: () => request("GET", "/immutable-releases", { policy: true }), releases: () => list("/releases"), release: (id) => request("GET", `/releases/${id}`), assets: async (id) => (await list(`/releases/${id}/assets`)).flat(), @@ -82,16 +81,10 @@ export function createGitHubClient({ repository, writeToken, policyToken, fetchI }; } -function requirePolicy(policy) { - if (policy?.enabled !== true || policy?.enforced_by_owner !== true) { - throw new Error("owner-enforced immutable releases are required before any release write"); - } -} - function requireRelease(release, tag, marker, id = release?.id) { if (!Number.isSafeInteger(release?.id) || release.id <= 0 || release.tag_name !== tag || release.id !== id || release.draft !== true || release.prerelease !== false || release.body !== marker) { - throw new Error("release must be the exact unpublished draft created under this source and policy; review legacy drafts separately"); + throw new Error("release must be the exact unpublished draft created under this source; review legacy drafts separately"); } } @@ -112,9 +105,8 @@ function compareAssets(remote, manifest, complete = false) { export async function prepareDraft({ tag, sha, directory, client }) { if (!/^[a-f0-9]{40}$/.test(sha)) throw new Error("the release event must identify an exact commit SHA"); const manifest = await verifyAssets(tag, directory); - const marker = ``; + const marker = ``; async function preflight() { - requirePolicy(await client.policy()); if (await client.tag(tag) !== sha) throw new Error("the current tag no longer identifies the release event commit"); } await preflight(); @@ -147,7 +139,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.ar const [tag, sha, directory] = process.argv.slice(2); try { if (!tag || !sha || !directory || process.argv.length !== 5) throw new Error("usage: node scripts/release-draft.mjs "); - const client = createGitHubClient({ repository: process.env.GITHUB_REPOSITORY, writeToken: process.env.GH_TOKEN, policyToken: process.env.HIDE_RELEASE_POLICY_TOKEN }); + const client = createGitHubClient({ repository: process.env.GITHUB_REPOSITORY, writeToken: process.env.GH_TOKEN }); const result = await prepareDraft({ tag, sha, directory, client }); console.log(`complete unpublished draft verified: ${result.tag}, release ${result.id}, ${result.assets} assets`); } catch (error) { diff --git a/scripts/tests/release-draft.test.mjs b/scripts/tests/release-draft.test.mjs index 132493bc45..9e67385e7c 100644 --- a/scripts/tests/release-draft.test.mjs +++ b/scripts/tests/release-draft.test.mjs @@ -9,7 +9,7 @@ import { createGitHubClient, prepareDraft } from "../release-draft.mjs"; const tag = "v1.2.3"; const sha = "1".repeat(40); -const marker = ``; +const marker = ``; const names = ["macos-arm64.zip", "windows-x64.zip", "linux-x64.tar.gz"].map((s) => `hide-${tag}-${s}`); const digest = (data) => `sha256:${createHash("sha256").update(data).digest("hex")}`; @@ -30,7 +30,6 @@ async function fixture(t, options = {}) { release: options.release ? structuredClone(options.release) : null, assets: options.assets ? structuredClone(options.assets) : [], requests: [], writes: [], assetGets: 0, - policy: options.policy ?? { enabled: true, enforced_by_owner: true }, }; const server = http.createServer(async (req, res) => { const url = new URL(req.url, "http://fixture.invalid"); @@ -42,7 +41,6 @@ async function fixture(t, options = {}) { if (req.method !== "GET") state.writes.push({ method: req.method, route }); const answer = (status, body) => { res.writeHead(status, { "Content-Type": "application/json" }); res.end(JSON.stringify(body)); }; if (options.fail === route) return answer(options.status ?? 500, { message: "fixture failure" }); - if (route === "/immutable-releases") return answer(200, state.policy); if (route === `/git/ref/tags/${tag}`) return answer(200, { object: { type: options.annotated ? "tag" : "commit", sha: options.tagSha ?? sha } }); if (route === `/git/tags/${sha}`) return answer(200, { object: { type: "commit", sha } }); if (route === "/releases" && req.method === "GET") { @@ -66,7 +64,7 @@ async function fixture(t, options = {}) { } if (route === "/releases/7/assets" && req.method === "POST") { if (Number(req.headers["content-length"]) !== bytes.length) return answer(411, { message: "asset byte length is required" }); - // A publication after the client's last GET is blocked by server policy. + // A publication after the client's last GET is blocked by the immutable releases setting. if (options.publishDuringUpload) state.release.draft = false; if (!state.release.draft) return answer(422, { message: "immutable published release" }); const name = url.searchParams.get("name"); @@ -80,7 +78,7 @@ async function fixture(t, options = {}) { await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); t.after(() => new Promise((resolve) => { server.closeAllConnections(); server.close(resolve); })); const base = `http://127.0.0.1:${server.address().port}`; - const client = createGitHubClient({ repository: "example/project", writeToken: "fixture-write", policyToken: "fixture-policy", fetchImpl: (url, opts) => fetch(`${base}${new URL(url).pathname}${new URL(url).search}`, opts) }); + const client = createGitHubClient({ repository: "example/project", writeToken: "fixture-write", fetchImpl: (url, opts) => fetch(`${base}${new URL(url).pathname}${new URL(url).search}`, opts) }); return { state, directory, files, run: () => prepareDraft({ tag, sha, directory, client }) }; } @@ -98,14 +96,6 @@ test("complete fresh draft posts six matching assets without PATCH or DELETE; re assert.deepEqual(f.state.writes, []); }); -test("disabled, unenforced or inaccessible policy stops before any release write", async (t) => { - for (const options of [{ policy: { enabled: false, enforced_by_owner: false } }, { policy: { enabled: true, enforced_by_owner: false } }, { policy: {} }, { fail: "/immutable-releases", status: 403 }]) { - const f = await fixture(t, options); - await assert.rejects(f.run()); - assert.deepEqual(f.state.writes, []); - } -}); - test("published, legacy and ambiguous drafts stop without mutation", async (t) => { for (const options of [{ release: { ...draft(), draft: false } }, { release: { ...draft(), body: "old draft" } }, { pages: [[{ ...draft(), assets: [] }, { ...draft(), assets: [] }]] }]) { const f = await fixture(t, options); @@ -164,7 +154,3 @@ test("moved tag, wrong release ID and incomplete local package fail; annotated t const annotated = await fixture(t, { annotated: true }); assert.equal((await annotated.run()).assets, 6); }); - -test("missing policy credentials are a source-visible blocker", () => { - assert.throws(() => createGitHubClient({ repository: "example/project", writeToken: "fixture-write" }), /Administration-read/); -});