Skip to content

Commit 7bbd2e9

Browse files
authored
fix(docker): bound attestation registry inspection (#109325)
1 parent f1fc40f commit 7bbd2e9

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎scripts/verify-docker-attestations.d.mts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export function parsePlatform(value: unknown): {
1515
* Collects missing/mismatched attestation errors for required image platforms.
1616
*/
1717
export function collectDockerAttestationErrors(params: unknown): string[];
18+
export function inspectRaw(
19+
imageRef: unknown,
20+
params?: {
21+
execFileSyncImpl?: (command: string, args: string[], options: unknown) => string;
22+
},
23+
): string;
1824
export function parseArgs(argv: unknown): {
1925
help: boolean;
2026
imageRefs: unknown[];

‎scripts/verify-docker-attestations.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import process from "node:process";
77
const ATTESTATION_REFERENCE_TYPE = "attestation-manifest";
88
const EXPECTED_ATTESTATION_ARTIFACT_TYPE = "application/vnd.docker.attestation.manifest.v1+json";
99
const REQUIRED_PREDICATES = ["https://spdx.dev/Document", "https://slsa.dev/provenance/v1"];
10+
const DOCKER_INSPECT_TIMEOUT_MS = 120_000;
1011

1112
/**
1213
* Rewrites an image reference to use the provided digest.
@@ -124,11 +125,14 @@ export function collectDockerAttestationErrors(params) {
124125
return errors;
125126
}
126127

127-
function inspectRaw(imageRef) {
128-
return execFileSync("docker", ["buildx", "imagetools", "inspect", "--raw", imageRef], {
128+
export function inspectRaw(imageRef, params = {}) {
129+
const execFileSyncImpl = params.execFileSyncImpl ?? execFileSync;
130+
return execFileSyncImpl("docker", ["buildx", "imagetools", "inspect", "--raw", imageRef], {
129131
encoding: "utf8",
132+
killSignal: "SIGKILL",
130133
maxBuffer: 20 * 1024 * 1024,
131134
stdio: ["ignore", "pipe", "pipe"],
135+
timeout: DOCKER_INSPECT_TIMEOUT_MS,
132136
});
133137
}
134138

‎test/scripts/verify-docker-attestations.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
33
import {
44
collectDockerAttestationErrors,
55
imageRefForDigest,
6+
inspectRaw,
67
parseArgs,
78
parsePlatform,
89
} from "../../scripts/verify-docker-attestations.mjs";
@@ -54,6 +55,32 @@ function createAttestation(
5455
}
5556

5657
describe("verify-docker-attestations", () => {
58+
it("bounds docker manifest inspection calls", () => {
59+
const calls: unknown[] = [];
60+
const imageRef = "ghcr.io/openclaw/openclaw:test";
61+
const output = inspectRaw(imageRef, {
62+
execFileSyncImpl(command: string, args: string[], options: unknown) {
63+
calls.push({ args, command, options });
64+
return "{}";
65+
},
66+
});
67+
68+
expect(output).toBe("{}");
69+
expect(calls).toStrictEqual([
70+
{
71+
args: ["buildx", "imagetools", "inspect", "--raw", imageRef],
72+
command: "docker",
73+
options: {
74+
encoding: "utf8",
75+
killSignal: "SIGKILL",
76+
maxBuffer: 20 * 1024 * 1024,
77+
stdio: ["ignore", "pipe", "pipe"],
78+
timeout: 120_000,
79+
},
80+
},
81+
]);
82+
});
83+
5784
it("parses required platforms and image refs", () => {
5885
expect(
5986
parseArgs(["--platform", "linux/amd64", "--platform", "linux/arm64", "ghcr.io/openclaw/app"]),

0 commit comments

Comments
 (0)