OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(release): retry container releases without replacing a newer latest tag (#1046)
mldangelo-oai2323bfd4193e
diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.ymlindex 7eead71e6..598078847 100644--- a/.github/workflows/container-release.yml+++ b/.github/workflows/container-release.yml@@ -384,10 +384,10 @@ jobs:- *sign-in-to-github-container-registry- - name: Promote the verified, attested, immutable image digest+ - name: Recheck immutable version and select the latest tag+ id: versionenv:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}- IMAGE: ${{ needs.authorize.outputs.image }}VERSION: ${{ needs.authorize.outputs.version }}MANIFEST_DIGEST: ${{ needs.manifest.outputs.digest }}shell: bash@@ -402,10 +402,22 @@ jobs:endpoint="orgs/$owner/packages/container/codex-security"sh docker/verify-container-release-version.sh "$endpoint" "$VERSION" "$MANIFEST_DIGEST"+ - name: Promote the verified, attested, immutable image digest+ env:+ IMAGE: ${{ needs.authorize.outputs.image }}+ VERSION: ${{ needs.authorize.outputs.version }}+ PUBLISH_LATEST: ${{ steps.version.outputs.publish_latest }}+ MANIFEST_DIGEST: ${{ needs.manifest.outputs.digest }}+ shell: bash+ run: |+ set -euo pipefail+ tags=(--tag "$IMAGE:$VERSION" --tag "$IMAGE:sha-$GITHUB_SHA")+ if [[ "$PUBLISH_LATEST" == true ]]; then+ tags+=(--tag "$IMAGE:latest")+ fi+docker buildx imagetools create \- --tag "$IMAGE:$VERSION" \- --tag "$IMAGE:sha-$GITHUB_SHA" \- --tag "$IMAGE:latest" \+ "${tags[@]}" \"$IMAGE@$MANIFEST_DIGEST"actual_digest="$(docker buildx imagetools inspect --format '{{.Manifest.Digest}}' "$IMAGE:$VERSION")"diff --git a/docker/README.md b/docker/README.mdindex cbe053932..5f5bf0fb1 100644--- a/docker/README.md+++ b/docker/README.md@@ -88,9 +88,10 @@ After merging to `main`, push `container-v<version>` matching the SDK packageversion or run `container-release` manually on `main`. Releases require a commiton protected `main`; pull requests only build and test.-If a release fails, fix the cause and rerun only failed jobs; do not overwrite-an existing stable version. Promotion retries accept an existing version only-when it already points to the same verified image digest. `bootstrap` and+If a release fails, fix the cause and rerun only failed jobs. Promotion retries+require the existing stable version to reference the verified digest. If a newer+stable version exists, promotion leaves `latest` untouched; otherwise a retry+also requires `latest` to reference that digest. `bootstrap` and`release-candidate-<commit>` tags are not consumer releases.See the [findings service guide](../sdk/typescript/README.md#findings-service-preview)diff --git a/docker/verify-container-release-version.sh b/docker/verify-container-release-version.shindex 86d0faf25..ac12fc134 100644--- a/docker/verify-container-release-version.sh+++ b/docker/verify-container-release-version.sh@@ -16,19 +16,28 @@ if ! versions="$(gh api --paginate "$endpoint/versions?per_page=100")"; thenexit 1fi-if ! already_published="$(+if ! version_status="$(printf '%s\n' "$versions" |- jq --slurp --arg version "$version" --arg digest "$verified_digest" '+ jq --raw-output --slurp --arg version "$version" --arg digest "$verified_digest" '+ def stable_version:+ select(test("^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$")) |+ split(".") | map(tonumber);if length == 0 or any(.[]; type != "array") thenerror("Container package versions must contain at least one JSON array.")else[.[][] | select(any(.metadata.container.tags[]?; . == $version))] as $existing |- if ($existing | length) == 0 then false- elif ($digest | test("^sha256:[a-fA-F0-9]{64}$")) then- [.[][] | select(any(.metadata.container.tags[]?; . == "latest"))] as $latest |+ [.[][] | select(any(.metadata.container.tags[]?; . == "latest"))] as $latest |+ any(.[][]; any(.metadata.container.tags[]?;+ stable_version > ($version | stable_version))) as $backfill |+ if ($existing | length) > 0 and (+ ($digest | test("^sha256:[a-fA-F0-9]{64}$") | not) orany($existing[]; .name != $digest) or- ($latest | length) == 0 or any($latest[]; .name != $digest)- else true+ ($backfill | not) and (+ ($latest | length) == 0 or any($latest[]; .name != $digest)+ )+ ) then "published"+ elif $backfill then "backfill"+ else "latest"endend'@@ -37,12 +46,19 @@ if ! already_published="$(exit 1fi-case "$already_published" in- false)+case "$version_status" in+ latest|backfill)+ if [ -n "${GITHUB_OUTPUT:-}" ]; then+ publish_latest=false+ if [ "$version_status" = latest ]; then+ publish_latest=true+ fi+ printf 'publish_latest=%s\n' "$publish_latest" >> "$GITHUB_OUTPUT"+ fiexit 0;;- true)- printf '%s\n' "::error::Container version $version already exists; retries require both that version and latest to match the verified digest." >&2+ published)+ printf '%s\n' "::error::Container version $version already exists; retries require a matching verified digest and, unless a newer stable version exists, a matching latest tag." >&2exit 1;;*)diff --git a/sdk/typescript/tests-ts/container-entrypoint.test.ts b/sdk/typescript/tests-ts/container-entrypoint.test.tsindex 6534afb78..dfc82e2c3 100644--- a/sdk/typescript/tests-ts/container-entrypoint.test.ts+++ b/sdk/typescript/tests-ts/container-entrypoint.test.ts@@ -1,6 +1,6 @@import { spawnSync, type SpawnSyncReturns } from "node:child_process";import { existsSync } from "node:fs";-import { mkdtemp, realpath, rm, writeFile } from "node:fs/promises";+import { mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { delimiter, join } from "node:path";import { describe, expect, test } from "bun:test";@@ -48,8 +48,8 @@ async function runEntrypoint(async function runVersionVerifier(response: string,failure = false,- digest?: string,-): Promise<SpawnSyncReturns<string>> {+ expectedDigest?: string,+): Promise<SpawnSyncReturns<string> & { workflowOutput: string }> {const root = await realpath(await mkdtemp(join(tmpdir(), "codex-security-container-version-")),);@@ -75,13 +75,15 @@ async function runVersionVerifier();const endpoint = "orgs/openai/packages/container/codex-security";- return spawnSync(+ const output = join(root, "output");+ await writeFile(output, "");+ const result = spawnSync("sh",[versionVerifier,endpoint,"0.1.4",- ...(digest === undefined ? [] : [digest]),+ ...(expectedDigest === undefined ? [] : [expectedDigest]),],{encoding: "utf8",@@ -90,11 +92,13 @@ async function runVersionVerifier(EXPECTED_ENDPOINT: endpoint,GH_FIXTURE_FAILURE: failure ? "1" : "0",GH_FIXTURE_RESPONSE: response,+ GITHUB_OUTPUT: output,PATH: `${root}${delimiter}${process.env["PATH"] ?? ""}`,},timeout: 10_000,},);+ return { ...result, workflowOutput: await readFile(output, "utf8") };} finally {await rm(root, { recursive: true, force: true });}@@ -237,19 +241,99 @@ describe("immutable customer container releases", () => {expect(result.status).toBe(1);expect(result.stderr).toContain("Synthetic package lookup failed.");expect(result.stderr).toContain("refusing to publish");+ expect(result.workflowOutput).toBe("");});testPosix("rejects an existing immutable release version", async () => {const result = await runVersionVerifier(JSON.stringify([- { metadata: { container: { tags: ["0.1.4", "latest"] } } },+ {+ name: `sha256:${"a".repeat(64)}`,+ metadata: { container: { tags: ["0.1.4", "latest"] } },+ },]),);expect(result.status).toBe(1);expect(result.stderr).toContain("Container version 0.1.4 already exists");+ expect(result.workflowOutput).toBe("");});+ testPosix(+ "retries the verified digest without moving latest backwards",+ async () => {+ const digest = `sha256:${"a".repeat(64)}`;+ for (const newer of [false, true]) {+ for (const latest of ["same", "different", "missing"]) {+ const versions = [+ {+ name: digest,+ metadata: {+ container: {+ tags: ["0.1.4", ...(latest === "same" ? ["latest"] : [])],+ },+ },+ },+ {+ name: `sha256:${"b".repeat(64)}`,+ metadata: {+ container: {+ tags: [+ ...(newer ? ["0.2.0"] : []),+ ...(latest === "different" ? ["latest"] : []),+ ],+ },+ },+ },+ ];+ const result = await runVersionVerifier(+ `[]\n${JSON.stringify(versions)}`,+ false,+ digest,+ );+ const allowed = newer || latest === "same";+ expect(result.status, JSON.stringify({ newer, latest })).toBe(+ allowed ? 0 : 1,+ );+ expect(result.workflowOutput).toBe(+ allowed ? `publish_latest=${!newer}\n` : "",+ );+ if (allowed) expect(result.stderr).toBe("");+ }+ }+ },+ );++ testPosix(+ "requires every existing version tag to match a valid verified digest",+ async () => {+ const digest = `sha256:${"a".repeat(64)}`;+ for (const [name, verified] of [+ [`sha256:${"b".repeat(64)}`, digest],+ [undefined, digest],+ ["invalid", "invalid"],+ ] as const) {+ const result = await runVersionVerifier(+ JSON.stringify([+ {+ name: verified,+ metadata: { container: { tags: ["0.1.4", "latest"] } },+ },+ { name, metadata: { container: { tags: ["0.1.4"] } } },+ { metadata: { container: { tags: ["0.2.0"] } } },+ ]),+ false,+ verified,+ );+ expect(result.status).toBe(1);+ expect(result.stderr).toContain(+ "Container version 0.1.4 already exists",+ );+ expect(result.workflowOutput).toBe("");+ }+ },+ );+testPosix("accepts an unpublished version across paginated results",async () => {@@ -261,6 +345,27 @@ describe("immutable customer container releases", () => {expect(result.status).toBe(0);expect(result.stderr).toBe("");+ expect(result.stdout).toBe("");+ expect(result.workflowOutput).toBe("publish_latest=true\n");+ },+ );++ testPosix(+ "publishes older stable versions without moving latest backwards",+ async () => {+ for (const tags of [+ ["0.1.5", "latest"],+ ["0.1.10"],+ ["0.10.0"],+ ["1.0.0"],+ ]) {+ const result = await runVersionVerifier(+ `[]\n${JSON.stringify([{ metadata: { container: { tags } } }])}`,+ );+ expect(result.status).toBe(0);+ expect(result.stdout).toBe("");+ expect(result.workflowOutput).toBe("publish_latest=false\n");+ }},);@@ -269,43 +374,6 @@ describe("immutable customer container releases", () => {expect(result.status).toBe(1);expect(result.stderr).toContain("refusing to publish");+ expect(result.workflowOutput).toBe("");});});--testPosix(- "retries promotion only for the same verified manifest digest",- async () => {- const digest = `sha256:${"a".repeat(64)}`;- const response = JSON.stringify([- { name: digest, metadata: { container: { tags: ["0.1.4", "latest"] } } },- ]);- expect((await runVersionVerifier(response, false, digest)).status).toBe(0);- expect(- (await runVersionVerifier(response, false, `sha256:${"b".repeat(64)}`))- .status,- ).toBe(1);- expect((await runVersionVerifier(response, false, "invalid")).status).toBe(- 1,- );- expect((await runVersionVerifier(response, true, digest)).status).toBe(1);- const older = JSON.stringify([- { name: digest, metadata: { container: { tags: ["0.1.4"] } } },- {- name: `sha256:${"b".repeat(64)}`,- metadata: { container: { tags: ["0.1.5", "latest"] } },- },- ]);- expect((await runVersionVerifier(older, false, digest)).status).toBe(1);- expect(- (- await runVersionVerifier(- JSON.stringify([- { name: digest, metadata: { container: { tags: ["0.1.4"] } } },- ]),- false,- digest,- )- ).status,- ).toBe(1);- },-);