mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-30 01:36:07 +00:00
Add the require-checksums input (#1139)
Adds `require-checksums`, which enforces the "intrinsic or explicitly provided checksum" idea. See #1032. <details> <summary>Automated notes</summary> Add the opt-in input `require-checksums`. When enabled, setup-uv verifies the archive against the workflow's `checksum` input or the digest bundled for the resolved uv version, architecture, and platform. If neither is available, setup fails before downloading the archive. By default, setup-uv continues to accept manifest checksums as it does today. The setting also applies to custom manifests, which can still supply download URLs. On persistent runners, strict mode keys tool-cache entries by the expected archive digest so a previous manifest-verified installation cannot bypass the check. Closes #1032. Builds on #1033. ## Validation - `npm ci --ignore-scripts` and `npm run all` passed under Node 24 (182 tests). - The packaged-action regression test installs a custom build into a temporary runner tool cache. It checks that strict mode rejects a manifest-only version even with a warm cache, reuses a verified installation for the same digest, and rejects a changed digest or a custom build that conflicts with the bundled digest. </details> --------- Signed-off-by: William Woodruff <william@yossarian.net>
This commit is contained in:
1 parent
fc0acc2d6f
commit
de938e707d
16 files changed
+235
-43
No files matched your search
@@ -56,7 +56,7 @@ test("manifest checksums are used when no known checksum exists", async () => {
|
||||
).rejects.toThrow("did not match");
|
||||
});
|
||||
|
||||
test("empty manifest checksums are rejected", async () => {
|
||||
test.each(["", undefined])("rejects missing checksums (%s)", async (hash) => {
|
||||
await expect(
|
||||
validateChecksum(
|
||||
undefined,
|
||||
@@ -64,7 +64,7 @@ test("empty manifest checksums are rejected", async () => {
|
||||
"aarch64",
|
||||
"pc-windows-msvc",
|
||||
"1.2.3",
|
||||
"",
|
||||
hash,
|
||||
),
|
||||
).rejects.toThrow("No checksum found");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { execFile, execFileSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import { createServer } from "node:http";
|
||||
import type { AddressInfo } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { expect, test } from "@jest/globals";
|
||||
import { getArch, getPlatform } from "../../src/utils/platforms";
|
||||
|
||||
test("enforces intrinsic checksums on downloads and tool-cache hits", async () => {
|
||||
const platform = await getPlatform();
|
||||
const target = `${getArch()}-${platform}`;
|
||||
const windows = platform === "pc-windows-msvc";
|
||||
const dir = fs.mkdtempSync(path.join(tmpdir(), "setup-uv-checksums-"));
|
||||
const server = createServer();
|
||||
try {
|
||||
const member = windows ? "uv.exe" : `uv-${target}/uv`;
|
||||
const archiveName = windows ? "uv.zip" : "uv.tar.gz";
|
||||
fs.mkdirSync(path.dirname(path.join(dir, member)), { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, member), "test build");
|
||||
execFileSync("tar", ["-acf", archiveName, member], { cwd: dir });
|
||||
const archive = fs.readFileSync(path.join(dir, archiveName));
|
||||
const digest = createHash("sha256").update(archive).digest("hex");
|
||||
let downloads = 0;
|
||||
server.on("request", (_req, res) => {
|
||||
downloads++;
|
||||
res.end(archive);
|
||||
});
|
||||
await new Promise<void>((resolve) =>
|
||||
server.listen(0, "127.0.0.1", resolve),
|
||||
);
|
||||
const address = server.address() as AddressInfo;
|
||||
|
||||
function install(version: string, strict: boolean, checksum = "") {
|
||||
const manifest = JSON.stringify({
|
||||
artifacts: [
|
||||
{
|
||||
archive_format: windows ? "zip" : "tar.gz",
|
||||
platform: target,
|
||||
sha256: digest,
|
||||
url: `http://127.0.0.1:${address.port}/${archiveName}`,
|
||||
},
|
||||
],
|
||||
version,
|
||||
});
|
||||
return promisify(execFile)(process.execPath, ["dist/setup/index.cjs"], {
|
||||
env: {
|
||||
"INPUT_ACTIVATE-ENVIRONMENT": "false",
|
||||
INPUT_CHECKSUM: checksum,
|
||||
"INPUT_MANIFEST-FILE": `data:application/json,${encodeURIComponent(manifest)}`,
|
||||
"INPUT_NO-PROJECT": "false",
|
||||
"INPUT_PYTHON-VERSION": "3.13",
|
||||
"INPUT_REQUIRE-CHECKSUMS": String(strict),
|
||||
INPUT_VERSION: version,
|
||||
"INPUT_WORKING-DIRECTORY": dir,
|
||||
PATH: process.env.PATH,
|
||||
RUNNER_TEMP: dir,
|
||||
RUNNER_TOOL_CACHE: path.join(dir, "cache"),
|
||||
SystemRoot: process.env.SystemRoot,
|
||||
},
|
||||
timeout: 10_000,
|
||||
});
|
||||
}
|
||||
|
||||
const version = "99.0.0";
|
||||
await install(version, false);
|
||||
await expect(install(version, true)).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining(
|
||||
`No bundled checksum for ${target}-${version}`,
|
||||
),
|
||||
});
|
||||
expect(downloads).toBe(1);
|
||||
await install(version, true, digest);
|
||||
expect(downloads).toBe(2);
|
||||
await install(version, true, digest);
|
||||
expect(downloads).toBe(2);
|
||||
await expect(install(version, true, "0".repeat(64))).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("did not match"),
|
||||
});
|
||||
// The custom manifest also offers these bytes under a known release version.
|
||||
await expect(install("0.9.26", true)).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("did not match"),
|
||||
});
|
||||
await expect(install(version, true, "../uv")).rejects.toMatchObject({
|
||||
stdout: expect.stringContaining("Expected a SHA-256 checksum"),
|
||||
});
|
||||
} finally {
|
||||
server.close();
|
||||
fs.rmSync(dir, { force: true, recursive: true });
|
||||
}
|
||||
}, 30_000);
|
||||
@@ -26,6 +26,7 @@ export function createSetupInputs(
|
||||
pythonDir: "/tmp/uv-python-dir",
|
||||
pythonVersion: "",
|
||||
quiet: false,
|
||||
requireChecksums: false,
|
||||
resolutionStrategy: "highest",
|
||||
restoreCache: false,
|
||||
saveCache: true,
|
||||
|
||||
@@ -109,9 +109,15 @@ describe("loadInputs", () => {
|
||||
expect(inputs.exportPythonArch).toBe(false);
|
||||
expect(inputs.venvPath).toBe("/workspace/.venv");
|
||||
expect(inputs.manifestFile).toBeUndefined();
|
||||
expect(inputs.requireChecksums).toBe(false);
|
||||
expect(inputs.resolutionStrategy).toBe("highest");
|
||||
});
|
||||
|
||||
it("loads require-checksums", () => {
|
||||
mockInputs["require-checksums"] = "true";
|
||||
expect(loadInputs().requireChecksums).toBe(true);
|
||||
});
|
||||
|
||||
it("uses the Python version from an explicitly selected .tool-versions file", () => {
|
||||
mockInputs["working-directory"] = createTempProject({
|
||||
".tool-versions": "uv 0.12.3\npython 3.13.1t\n",
|
||||
|
||||
Reference in new issue
Block a user