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
feat(container): publish a versioned Wolfi amd64 scanner (#2091)
andy-tang-oai5094179a10cc
diff --git a/.github/workflows/publish-wolfi.yml b/.github/workflows/publish-wolfi.ymlnew file mode 100644index 000000000..ad8e5e2c1--- /dev/null+++ b/.github/workflows/publish-wolfi.yml@@ -0,0 +1,171 @@+name: Publish Wolfi scanner++on:+ workflow_dispatch:+ pull_request:+ paths:+ - .github/workflows/publish-wolfi.yml+ - docker/wolfi/**+ - LICENSE+ - docker/entrypoint.sh+ - docker/git-credential.sh+ - docker/codex-security.apparmor+ - docker/codex-security-seccomp.json+ - github-action/scripts/setup-ubuntu-sandbox.sh+ - sdk/typescript/scripts/is-main.mjs+ - sdk/typescript/scripts/package-provenance.mjs+ - sdk/typescript/scripts/release-automation.mjs++permissions: {}++env:+ IMAGE: ghcr.io/openai/codex-security++jobs:+ build:+ name: Build and smoke-test Linux amd64+ runs-on: ubuntu-24.04+ timeout-minutes: 60+ permissions:+ contents: read+ outputs:+ artifact: ${{ steps.upload.outputs.artifact-id }}+ digest: ${{ steps.prepare.outputs.digest }}+ tag: ${{ steps.prepare.outputs.tag }}+ sbom-sha: ${{ steps.prepare.outputs.sbom-sha }}+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ fetch-depth: 0+ persist-credentials: false+ - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0+ with:+ node-version: "24.15.0"+ package-manager-cache: false+ - name: Build and test on native Linux+ run: bash docker/wolfi/ci-build.sh "$RUNNER_TEMP/wolfi"+ - name: Prepare the tested digest for publication+ id: prepare+ shell: bash+ run: |+ set -euo pipefail+ out=$RUNNER_TEMP/wolfi+ candidate=$RUNNER_TEMP/candidate+ mkdir "$candidate"+ digest=$(python3 docker/wolfi/to-oci.py "$out/image.tar" "$out/verification.json" "$candidate/layout")+ skopeo inspect --raw "oci:$candidate/layout:wolfi" | sha256sum | cut -d' ' -f1 | grep -Fxq "${digest#sha256:}"+ version=$(jq -er '.installed_npm[] | select(.path == "node_modules/@openai/codex-security") | .version' "$out/public-components.json")+ [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]+ release_sha=$(git rev-parse --verify "refs/tags/npm-v$version^{commit}")+ bash docker/wolfi/verify-npm-release.sh "$out/public-components.json" "$version" "$release_sha"+ recorded_source=$(docker run --rm --network=none --pull=never --entrypoint /usr/bin/node \+ codex-security:wolfi-amd64 -p 'require("/usr/share/licenses/codex-security/SOURCES.json").scanner_source')+ [[ $recorded_source == "https://github.com/openai/codex-security/tree/$release_sha" ]]+ python3 docker/wolfi/release-sbom.py "$out/sbom/sbom-x86_64.spdx.json" "$out/public-components.json" "$candidate/sbom.spdx.json"+ pdfjs=$(jq -er '.installed_npm[] | select(.path == "node_modules/pdfjs-dist") | .version' "$out/public-components.json")+ jq -e --arg purl "pkg:npm/pdfjs-dist@$pdfjs" 'any(.packages[].externalRefs[]?; .referenceLocator == $purl)' \+ "$candidate/sbom.spdx.json" > /dev/null+ sbom_sha=$(sha256sum "$candidate/sbom.spdx.json" | cut -d' ' -f1)+ revision=$(jq -er '.image_revision | numbers | select(. >= 0 and . == floor)' "$out/build-inputs.json")+ tag=$version-wolfi-amd64+ if [[ $revision != 0 ]]; then tag+=-r$revision; fi+ printf 'digest=%s\ntag=%s\nsbom-sha=%s\n' "$digest" "$tag" "$sbom_sha" >> "$GITHUB_OUTPUT"+ printf 'Scanner source: %s\n\nRecipe commit: %s\n\nTested digest: %s\n' "$release_sha" "$GITHUB_SHA" "$digest" >> "$GITHUB_STEP_SUMMARY"+ - name: Retain the tested image and SBOM for the protected job+ if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && github.ref_protected+ id: upload+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2+ with:+ name: wolfi-amd64-${{ github.run_attempt }}+ path: ${{ runner.temp }}/candidate+ if-no-files-found: error+ compression-level: 0+ retention-days: 7++ publish:+ name: Approve and publish the Wolfi variant+ needs: build+ if: github.event_name == 'workflow_dispatch' && github.repository == 'openai/codex-security' && github.ref == 'refs/heads/main' && github.ref_protected+ runs-on: ubuntu-24.04+ timeout-minutes: 30+ environment: container+ concurrency:+ group: publish-wolfi-amd64+ cancel-in-progress: false+ permissions:+ contents: read+ packages: write+ attestations: write+ id-token: write+ artifact-metadata: write+ env:+ DIGEST: ${{ needs.build.outputs.digest }}+ TAG: ${{ needs.build.outputs.tag }}+ SBOM_SHA: ${{ needs.build.outputs.sbom-sha }}+ steps:+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2+ with:+ artifact-ids: ${{ needs.build.outputs.artifact }}+ merge-multiple: true+ path: ${{ runner.temp }}/candidate+ - name: Check the public package, immutable tag and local artifacts+ shell: bash+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ set -euo pipefail+ [[ $TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+-wolfi-amd64(-r[1-9][0-9]*)?$ && $DIGEST =~ ^sha256:[0-9a-f]{64}$ ]]+ printf '%s %s\n' "$SBOM_SHA" "$RUNNER_TEMP/candidate/sbom.spdx.json" | sha256sum -c -+ skopeo inspect --raw "oci:$RUNNER_TEMP/candidate/layout:wolfi" | sha256sum | cut -d' ' -f1 | grep -Fxq "${DIGEST#sha256:}"+ package=orgs/openai/packages/container/codex-security+ gh api "$package" | jq -e '.visibility == "public"' > /dev/null+ existing=$(gh api --paginate --slurp "$package/versions?per_page=100" |+ jq -r --arg tag "$TAG" '.[][] | select(any(.metadata.container.tags[]?; . == $tag)) | .name')+ if [[ -n $existing && $existing != "$DIGEST" ]]; then+ echo "::error::Refusing to replace $TAG ($existing) with $DIGEST"+ exit 1+ fi+ - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0+ with:+ registry: ghcr.io+ username: ${{ github.actor }}+ password: ${{ github.token }}+ - name: Upload by digest and verify an anonymous pull+ shell: bash+ run: |+ set -euo pipefail+ skopeo copy --preserve-digests "oci:$RUNNER_TEMP/candidate/layout:wolfi" "docker://$IMAGE@$DIGEST"+ skopeo copy --src-no-creds --preserve-digests --digestfile "$RUNNER_TEMP/pulled.digest" \+ "docker://$IMAGE@$DIGEST" "oci:$RUNNER_TEMP/pulled:wolfi"+ [[ $(cat "$RUNNER_TEMP/pulled.digest") == "$DIGEST" ]]+ - name: Attest build provenance+ uses: actions/attest@508db95dd578ae2727ebd6217d5ba78e4fbda05d # v4.2.1+ with:+ subject-name: ${{ env.IMAGE }}+ subject-digest: ${{ env.DIGEST }}+ push-to-registry: true+ - name: Attest the SPDX inventory+ uses: actions/attest@508db95dd578ae2727ebd6217d5ba78e4fbda05d # v4.2.1+ with:+ subject-name: ${{ env.IMAGE }}+ subject-digest: ${{ env.DIGEST }}+ sbom-path: ${{ runner.temp }}/candidate/sbom.spdx.json+ push-to-registry: true+ - name: Promote only the verified Wolfi tag+ shell: bash+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ set -euo pipefail+ for predicate in https://slsa.dev/provenance/v1 https://spdx.dev/Document/v2.3; do+ gh attestation verify "oci://$IMAGE@$DIGEST" --repo "$GITHUB_REPOSITORY" --predicate-type "$predicate" \+ --signer-workflow "$GITHUB_REPOSITORY/.github/workflows/publish-wolfi.yml" \+ --source-ref refs/heads/main --source-digest "$GITHUB_SHA"+ done+ skopeo list-tags --no-creds "docker://$IMAGE" > "$RUNNER_TEMP/tags.json"+ count=$(jq -er --arg tag "$TAG" '[.Tags[] | select(. == $tag)] | length' "$RUNNER_TEMP/tags.json")+ if [[ $count == 0 ]]; then+ skopeo copy --preserve-digests --src-no-creds "docker://$IMAGE@$DIGEST" "docker://$IMAGE:$TAG"+ fi+ skopeo inspect --no-creds --raw "docker://$IMAGE:$TAG" | sha256sum | cut -d' ' -f1 | grep -Fxq "${DIGEST#sha256:}"+ printf 'Published \x60%s:%s\x60 at \x60%s\x60.\n' "$IMAGE" "$TAG" "$DIGEST" >> "$GITHUB_STEP_SUMMARY"diff --git a/docker/wolfi/README.md b/docker/wolfi/README.mdindex 26975726a..1c028591d 100644--- a/docker/wolfi/README.md+++ b/docker/wolfi/README.md@@ -5,9 +5,9 @@ Linux amd64. [melange](https://github.com/chainguard-dev/melange) createsthe scanner APK; [apko](https://github.com/chainguard-dev/apko) assembles itwith packages from the [public Wolfi repository](https://github.com/wolfi-dev/os).The image uses the same entrypoint, UID/GID 10001, and `/input`, `/output`, and-`/state` directories as the [published scanner](../README.md). It is a local-alternative to that image. It does not build unreleased changes in this checkout-or publish tags to a registry.+`/state` directories as the [published scanner](../README.md). The local build+packages the pinned npm release. To publish it, use the separate+[amd64 release workflow](#publish-the-amd64-variant).## Build and inspect@@ -67,6 +67,35 @@ fixture. It also checks that a sandboxed child can read the test repository butcannot modify it. A real scan needs a compatible model endpoint; the imagedoes not include a model.+## Publish the amd64 variant++Pull requests that change this recipe or its shared inputs run the native build+and smoke test. The build also verifies that the scanner archive in the image's+npm inventory matches the signed provenance for its upstream release tag.+Publishing is a separate manual run. After the workflow is on protected+`main`, a maintainer can start it with:++```sh+gh workflow run publish-wolfi.yml --repo openai/codex-security --ref main+```++Approve the pending `container` deployment in GitHub Actions after the build+and smoke test pass. The workflow publishes the tested platform digest, checks+an anonymous pull, and attaches build provenance and an SPDX inventory covering+OS packages, installed npm packages, and bundled native components. The run+summary includes the digest for a pinned pull.++The first Wolfi image for a scanner version uses a tag such as+`ghcr.io/openai/codex-security:0.7.0-wolfi-amd64`. To ship a Wolfi OS fix+without changing the scanner version, update the OS pins and increment+`image_revision` in [build-inputs.json](build-inputs.json) in the same PR.+Revision 1 publishes `0.7.0-wolfi-amd64-r1` and leaves the first tag in place.+Reset the revision to 0 for a new scanner version.++Retries cannot replace a versioned tag with a different digest. To retry a+failed publication using the same build, rerun the failed job within the+seven-day artifact retention period.+## Inputs and updates[builder.yaml](builder.yaml) and [apko.yaml](apko.yaml) list the exact builderdiff --git a/docker/wolfi/build-inputs.json b/docker/wolfi/build-inputs.jsonindex 865216d49..7aed7b519 100644--- a/docker/wolfi/build-inputs.json+++ b/docker/wolfi/build-inputs.json@@ -3,6 +3,7 @@"wolfi_key_sha256": "f0031424cf46f7db780ce63a45f0fd6aa6f85f601e6bb3b7a91fe3d4d5b7d2cc","repository": "https://packages.wolfi.dev/os","local_package": "codex-security=0.7.0-r1",+ "image_revision": 0,"snapshots": {"builder": {"lock_identity_sha256": "77cd79a5f9b66efc5d0f03dee78f2e24b66dc1a5acfc2454ba33e124aeb758a0"diff --git a/docker/wolfi/ci-build.sh b/docker/wolfi/ci-build.shnew file mode 100755index 000000000..cb49ef04b--- /dev/null+++ b/docker/wolfi/ci-build.sh@@ -0,0 +1,77 @@+#!/usr/bin/env bash+# Build and smoke-test one archive on a fresh GitHub-hosted ubuntu-24.04 VM.+# The workflow supplies Node 24.15.0 (npm 11) and an absolute, new output directory.+set -euo pipefail+die() { echo "$*" >&2; exit 1; }+[[ $# == 1 && $1 == /* && ! -e $1 ]] || die 'Usage: ci-build.sh NEW_ABSOLUTE_OUTPUT_DIRECTORY'+[[ ${RUNNER_ENVIRONMENT:-} == github-hosted && $(uname -s -m) == 'Linux x86_64' ]] ||+ die 'Use a disposable GitHub-hosted Ubuntu 24.04 amd64 VM'+[[ $(id -u) != 0 && $(npm --version) == 11.* ]] || die 'Run as the runner user with npm 11 on PATH'++recipe=$(cd "$(dirname "$0")" && pwd -P)+out=$1+tools=$(mktemp -d "${RUNNER_TEMP:?}/wolfi-tools.XXXXXXXX")+profile=$recipe/../codex-security.apparmor+added_profile=false+cleanup() {+ if "$added_profile"; then sudo -n apparmor_parser --skip-cache --remove "$profile"; fi+ rm -rf -- "$tools"+}+trap cleanup EXIT++# Reuse the repository's Ubuntu Bubblewrap setup. Its packaged AppArmor profile+# grants user namespaces to bwrap without changing any host security sysctl.+bash "$recipe/../../github-action/scripts/setup-ubuntu-sandbox.sh"+bwrap --unshare-user --unshare-net --uid 1000 --gid 1000 --ro-bind / / --dev /dev --proc /proc -- /usr/bin/true++# SHA-256 pins from each tagged upstream release's checksums.txt. Extract only+# the binary after verification; no installer or downloaded source is executed.+install_tool() {+ local name=$1 version=$2 sha=$3 base+ base="${name}_${version}_linux_amd64"+ curl --proto '=https' --proto-redir '=https' --fail --location --silent --show-error --retry 3 \+ "https://github.com/chainguard-dev/$name/releases/download/v$version/$base.tar.gz" \+ --output "$tools/$base.tar.gz"+ printf '%s %s\n' "$sha" "$tools/$base.tar.gz" | sha256sum --check --strict+ tar -xOzf "$tools/$base.tar.gz" "$base/$name" > "$tools/$name"+ chmod 0755 "$tools/$name"+}+install_tool apko 1.4.13 2377cd4a2efed58905da580f835fbdf2a6ed4ad0f10ff541827153a42d491cee+install_tool melange 0.61.1 4f2d104f1149e4bcf63c7f7a71deeae385d453c3bdf0f987c9c2d16a2efdd7da++# Stage and resolve the public inputs normally. For the guest build alone,+# unshare needs CAP_SYS_ADMIN: create its network namespace, then drop back+# to the runner UID before starting melange. The APK snapshot is its only source.+export REAL_MELANGE="$tools/melange"+cat > "$tools/offline-melange" <<'EOF'+#!/usr/bin/env bash+set -euo pipefail+if [[ $1 == build ]]; then+ exec sudo -n /usr/bin/unshare --net -- /usr/bin/setpriv \+ --reuid "$(id -u)" --regid "$(id -g)" --clear-groups --reset-env -- "$REAL_MELANGE" "$@"+fi+exec "$REAL_MELANGE" "$@"+EOF+chmod 0755 "$tools/offline-melange"+APKO="$tools/apko" MELANGE="$tools/offline-melange" "$recipe/build.sh" "$out"++# build.sh has verified the package locks, original archive and signed checksums.+# Bind the smoke test to the verified config, including its rootfs diff IDs.+tag=$(jq -er .tag "$out/verification.json")+config_digest=$(jq -er .config_digest "$out/verification.json")+if docker image inspect "$tag" >/dev/null 2>&1; then die "Test image tag already exists: $tag"; fi+docker load --input "$out/image.tar"+image_id=$(docker image inspect --format '{{.Id}}' "$tag")+if [[ $image_id != "$config_digest" ]]; then+ # The containerd image store returns a manifest digest as the ID; the+ # classic store returns the config digest itself. Inspect the same local ID.+ loaded_config=$(skopeo inspect --raw "docker-daemon:$image_id" | jq -er .config.digest)+ [[ $loaded_config == "$config_digest" ]] || die "Docker's loaded config differs from the verified archive"+fi++# Fail if AppArmor cannot enforce the repository's profile. The smoke script+# also applies the committed seccomp policy and disables container networking.+sudo -n apparmor_parser --skip-cache --add "$profile"+added_profile=true+sudo -n grep -Fxq 'codex-security-container (enforce)' /sys/kernel/security/apparmor/profiles+"$recipe/tests/smoke.sh" "$image_id"diff --git a/docker/wolfi/release-sbom.py b/docker/wolfi/release-sbom.pynew file mode 100644index 000000000..9010007d3--- /dev/null+++ b/docker/wolfi/release-sbom.py@@ -0,0 +1,65 @@+#!/usr/bin/env python3+"""Add the verified scanner payload to apko's single-platform SPDX document."""+import argparse+import base64+import hashlib+import json+from pathlib import Path, PurePosixPath+from urllib.parse import quote+++def enrich(sbom, components):+ packages = sbom["packages"]+ image, = (p for p in packages if p["SPDXID"] in sbom["documentDescribes"])+ if image["name"] != components["image_manifest"]:+ raise ValueError("apko SBOM and payload inventory describe different images")+ apk, = (p for p in packages if p["name"] == "codex-security")+ install = PurePosixPath("/usr/lib/codex-security")++ def add(parent_id, package):+ packages.append(package)+ sbom["relationships"].append({"spdxElementId": parent_id, "relationshipType": "CONTAINS",+ "relatedSpdxElement": package["SPDXID"]})++ # Use the manifest name for npm aliases, but keep each installed path distinct.+ npm_ids = {}+ for i, item in enumerate(components["installed_npm"]):+ path = PurePosixPath(item["path"])+ npm_ids[path] = f"SPDXRef-npm-{i}"+ name, version = item["name"], item["version"]+ purl = f"pkg:npm/{quote(name)}@{quote(version, safe='')}"+ checksum = base64.b64decode(item["integrity"].removeprefix("sha512-"), validate=True).hex()+ add(apk["SPDXID"], {+ "SPDXID": npm_ids[path], "name": name, "versionInfo": version,+ "downloadLocation": item["source"], "licenseDeclared": item["license"],+ "filesAnalyzed": False, "sourceInfo": f"Installed at {install / path}; SHA512 identifies the source archive.",+ "checksums": [{"algorithm": "SHA512", "checksumValue": checksum}],+ "externalRefs": [{"referenceCategory": "PACKAGE-MANAGER", "referenceType": "purl",+ "referenceLocator": purl}],+ })++ for i, item in enumerate(components["bundled_native"]):+ path = PurePosixPath(item["path"])+ owner = next(npm_ids[p] for p in path.parents if p in npm_ids)+ add(owner, {+ "SPDXID": f"SPDXRef-native-{i}", "name": path.name, "primaryPackagePurpose": "FILE",+ "packageFileName": str(install / path), "downloadLocation": "NOASSERTION",+ "filesAnalyzed": False, "sourceInfo": item["source"],+ "checksums": [{"algorithm": "SHA256", "checksumValue": item["sha256"]}],+ })++ # A changed SPDX document needs its own namespace, distinct from apko's original.+ sbom["creationInfo"]["creators"].append("Tool: codex-security/release-sbom.py")+ digest = hashlib.sha256(json.dumps(sbom, sort_keys=True).encode()).hexdigest()+ sbom["documentNamespace"] = f"https://github.com/openai/codex-security/spdx/wolfi-{digest}"+ return sbom+++if __name__ == "__main__":+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("sbom", type=Path)+ parser.add_argument("components", type=Path)+ parser.add_argument("destination", type=Path)+ args = parser.parse_args()+ result = enrich(json.loads(args.sbom.read_bytes()), json.loads(args.components.read_bytes()))+ args.destination.write_text(json.dumps(result, indent=2) + "\n")diff --git a/docker/wolfi/to-oci.py b/docker/wolfi/to-oci.pynew file mode 100644index 000000000..1d7ad00ba--- /dev/null+++ b/docker/wolfi/to-oci.py@@ -0,0 +1,94 @@+#!/usr/bin/env python3+"""Copy a verified single-platform apko archive into a new OCI image layout.++Verify the build's signed SHA256SUMS before using its image.tar and verification.json.+The layout names its single image 'wolfi'. The OCI manifest, config and compressed+layer bytes remain identical. No registry access is needed.+"""+import argparse+import hashlib+import json+import re+import tarfile+import tempfile+from pathlib import Path+++def convert(archive, verification, destination):+ if destination.exists() or destination.is_symlink():+ raise ValueError(f"Destination already exists: {destination}")+ expected = json.loads(verification.read_bytes())+ with tempfile.TemporaryDirectory(dir=destination.parent) as tmp, tarfile.open(archive, "r:") as tar:+ layout = Path(tmp) / "layout"+ blobs = layout / "blobs" / "sha256"+ blobs.mkdir(parents=True)+ members = tar.getmembers()+ entries = {m.name: m for m in members}+ if len(entries) != len(members):+ raise ValueError("Archive contains duplicate member names")++ def member(name):+ m = entries[name]+ if not m.isfile():+ raise ValueError(f"Expected a regular archive member: {name}")+ return m++ def copy_blob(name, desc):+ digest = desc["digest"]+ if not re.fullmatch(r"sha256:[0-9a-f]{64}", digest):+ raise ValueError(f"Invalid blob digest: {digest}")+ m = member(name)+ if type(desc["size"]) is not int or m.size != desc["size"]:+ raise ValueError(f"Size mismatch: {name}")+ path = blobs / digest.split(":")[1]+ h = hashlib.sha256()+ total = 0+ with tar.extractfile(m) as source, path.open("wb") as dest:+ for chunk in iter(lambda: source.read(1 << 20), b""):+ dest.write(chunk)+ total += len(chunk)+ h.update(chunk)+ if total != desc["size"] or "sha256:" + h.hexdigest() != digest:+ raise ValueError(f"Blob does not match its descriptor: {name}")+ return path++ with tar.extractfile(member("index.json")) as f:+ index = json.load(f)+ descriptor, = index["manifests"]+ if (index["schemaVersion"] != 2 or index["mediaType"] != "application/vnd.oci.image.index.v1+json"+ or descriptor["mediaType"] != "application/vnd.oci.image.manifest.v1+json"+ or descriptor["digest"] != expected["oci_manifest"]):+ raise ValueError("OCI manifest does not match verification.json")+ platform = descriptor["platform"]+ if f"{platform['os']}/{platform['architecture']}" != expected["platform"]:+ raise ValueError("OCI platform does not match verification.json")+ manifest = json.loads(copy_blob(descriptor["digest"], descriptor).read_bytes())+ if (manifest["schemaVersion"] != 2 or manifest["mediaType"] != descriptor["mediaType"]+ or manifest["config"]["digest"] != expected["config_digest"]):+ raise ValueError("Unexpected OCI manifest or configuration digest")+ with tar.extractfile(member("manifest.json")) as f:+ docker, = json.load(f)+ config = json.loads(copy_blob(docker["Config"], manifest["config"]).read_bytes())+ if any(config[k] != platform[k] for k in ("os", "architecture")):+ raise ValueError("OCI config and platform descriptor disagree")+ if len(docker["Layers"]) != len(manifest["layers"]):+ raise ValueError("Docker and OCI layer counts disagree")+ for name, desc in zip(docker["Layers"], manifest["layers"]):+ copy_blob(name, desc)+ (layout / "oci-layout").write_bytes(b'{"imageLayoutVersion":"1.0.0"}\n')+ descriptor.setdefault("annotations", {})["org.opencontainers.image.ref.name"] = "wolfi"+ (layout / "index.json").write_text(json.dumps(index, separators=(",", ":")) + "\n")+ layout.rename(destination)+ return descriptor["digest"]+++if __name__ == "__main__":+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("archive", type=Path, help="Verified apko image.tar")+ parser.add_argument("verification", type=Path, help="Build's verification.json")+ parser.add_argument("destination", type=Path, help="New layout directory (parent must exist)")+ args = parser.parse_args()+ try:+ print(convert(args.archive, args.verification, args.destination))+ except (KeyError, OSError, ValueError, tarfile.TarError) as exc:+ parser.exit(1, f"Failed to convert archive: {exc}\n")diff --git a/docker/wolfi/verify-npm-release.sh b/docker/wolfi/verify-npm-release.shnew file mode 100644index 000000000..2dd2863c6--- /dev/null+++ b/docker/wolfi/verify-npm-release.sh@@ -0,0 +1,21 @@+#!/usr/bin/env bash+# Run from the repo root with the verified image inventory, scanner version and tagged commit.+set -euo pipefail+inventory=$1 version=$2 release_sha=$3+verifier=$PWD/sdk/typescript/scripts/release-automation.mjs+work=$(mktemp -d)+trap 'rm -rf -- "$work"' EXIT+export npm_config_registry=https://registry.npmjs.org/++# npm ci checked this lock integrity while staging the image. Verify the very+# same archive against the signed provenance of the upstream scanner release.+integrity=$(jq -er --arg version "$version" '.installed_npm[] |+ select(.path == "node_modules/@openai/codex-security" and .version == $version) | .integrity' "$inventory")+cp docker/wolfi/payload/{package.json,package-lock.json} "$work/"+cd "$work"+npm ci --omit=optional --ignore-scripts --no-audit --no-fund+archive=$(npm pack --ignore-scripts --json "@openai/codex-security@$version" |+ jq -er --arg integrity "$integrity" '.[0] | if .integrity == $integrity then .filename+ else error("npm archive SHA-512 differs from the verified image inventory") end')+npm audit signatures --json --include-attestations |+ node "$verifier" verify-recovered-provenance "$archive" "$version" "$release_sha" openai/codex-security