Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

release: publish protected multi-architecture Codex Security images (#17)

David Chouinardbf8c36529aea
diff --git a/.github/workflows/container-ci.yml b/.github/workflows/container-ci.yml
index 8d4dc10f3..76599fd43 100644
--- a/.github/workflows/container-ci.yml
+++ b/.github/workflows/container-ci.yml
@@ -9,6 +9,7 @@ on:
- Dockerfile
- Dockerfile.dockerignore
- compose.yaml
+ - compose.apparmor.yaml
- docker/**
- sdk/typescript/**
pull_request:
@@ -18,6 +19,7 @@ on:
- Dockerfile
- Dockerfile.dockerignore
- compose.yaml
+ - compose.apparmor.yaml
- docker/**
- sdk/typescript/**
workflow_dispatch:
@@ -105,6 +107,11 @@ jobs:
docker compose config --quiet
docker compose run --rm codex-security --version
+ - name: Validate optional AppArmor Compose configuration
+ env:
+ CODEX_SECURITY_IMAGE: codex-security:ci
+ run: docker compose -f compose.yaml -f compose.apparmor.yaml config --quiet
+
- name: Verify hardened Codex command sandbox
shell: bash
run: |
diff --git a/.github/workflows/container-release.yml b/.github/workflows/container-release.yml
new file mode 100644
index 000000000..4609c5bf9
--- /dev/null
+++ b/.github/workflows/container-release.yml
@@ -0,0 +1,608 @@
+name: container-release
+
+on:
+ pull_request:
+ paths:
+ - .dockerignore
+ - .github/workflows/container-release.yml
+ - Dockerfile
+ - Dockerfile.dockerignore
+ - compose.yaml
+ - compose.apparmor.yaml
+ - docker/**
+ - sdk/typescript/**
+ push:
+ tags:
+ - "container-v*"
+ workflow_dispatch:
+
+concurrency:
+ group: container-release-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'publish' }}
+ cancel-in-progress: false
+
+permissions:
+ contents: read
+
+jobs:
+ validate:
+ if: github.repository == 'openai/codex-security'
+ name: validate-linux-${{ matrix.architecture }}
+ runs-on: ${{ matrix.runner }}
+ timeout-minutes: 45
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - architecture: amd64
+ runner: ubuntu-24.04
+ - architecture: arm64
+ runner: ubuntu-24.04-arm
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
+
+ - name: Build native customer image
+ uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
+ with:
+ context: .
+ load: true
+ platforms: linux/${{ matrix.architecture }}
+ push: false
+ tags: codex-security:release-candidate
+
+ - name: Verify native image and bundled scanner
+ env:
+ EXPECTED_ARCHITECTURE: ${{ matrix.architecture }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ actual_architecture="$(docker image inspect --format '{{.Architecture}}' codex-security:release-candidate)"
+ if [[ "$actual_architecture" != "$EXPECTED_ARCHITECTURE" ]]; then
+ echo "Expected a native $EXPECTED_ARCHITECTURE image; found $actual_architecture." >&2
+ exit 1
+ fi
+ docker run --rm codex-security:release-candidate --version
+ docker run --rm codex-security:release-candidate bulk-scan --help
+ docker run --rm codex-security:release-candidate info --json
+ [[ "$(docker run --rm --entrypoint id codex-security:release-candidate -u)" == 10001 ]]
+
+ - name: Verify host-aware AppArmor sandbox selection
+ shell: bash
+ run: |
+ set -euo pipefail
+ docker run --rm --entrypoint /bin/sh codex-security:release-candidate -ec '
+ command_directory="$(mktemp -d)"
+ trap '\''rm -rf "$command_directory"'\'' EXIT
+ printf "%s\\n" "#!/bin/sh" '\''printf "%s\\n" "$@"'\'' > "$command_directory/codex-security"
+ chmod 755 "$command_directory/codex-security"
+
+ actual="$(
+ PATH="$command_directory:$PATH" \
+ /usr/local/bin/codex-security-entrypoint \
+ bulk-scan /input/repositories.csv --output-dir /output
+ )"
+ restricted_user_namespaces=
+ if [ -r /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
+ IFS= read -r restricted_user_namespaces \
+ < /proc/sys/kernel/apparmor_restrict_unprivileged_userns || true
+ fi
+
+ apparmor_profile=
+ if [ -r /proc/self/attr/current ]; then
+ IFS= read -r apparmor_profile < /proc/self/attr/current || true
+ fi
+
+ if [ "$restricted_user_namespaces" = 1 ] &&
+ [ "$apparmor_profile" != "codex-security-container (enforce)" ]; then
+ printf "%s\\n" "$actual" | grep -Fxq features.use_legacy_landlock=true
+ elif printf "%s\\n" "$actual" | grep -Fxq features.use_legacy_landlock=true; then
+ printf "%s\\n" "Landlock must not be forced when the preferred sandbox is available." >&2
+ exit 1
+ fi
+ '
+
+ - name: Verify hardened Codex command sandbox
+ shell: bash
+ run: |
+ set -euo pipefail
+ command=(
+ docker run --rm
+ --cap-drop ALL
+ --security-opt no-new-privileges
+ --security-opt "seccomp=$GITHUB_WORKSPACE/docker/codex-security-seccomp.json"
+ --entrypoint node
+ codex-security:release-candidate
+ /usr/local/lib/node_modules/@openai/codex-security/node_modules/@openai/codex/bin/codex.js
+ )
+
+ if output="$("${command[@]}" sandbox /usr/bin/true 2>&1)"; then
+ printf '%s\n' "$output"
+ elif grep -Eq 'bwrap: (Failed to make / slave: Permission denied|loopback: Failed RTM_NEW(ADDR|LINK): Operation not permitted|setting up uid map: Permission denied|No permissions to create a new namespace)' <<< "$output"; then
+ echo '::warning::This Docker host blocks nested Bubblewrap namespaces; verifying the supported Landlock fallback.'
+ "${command[@]}" sandbox --enable use_legacy_landlock /usr/bin/true
+ else
+ printf 'The hardened Codex sandbox failed unexpectedly:\n%s\n' "$output" >&2
+ exit 1
+ fi
+
+ - name: Verify host-scoped Git credentials
+ shell: bash
+ run: |
+ set -euo pipefail
+ docker run --rm \
+ --entrypoint /bin/sh \
+ --env GH_TOKEN=SYNTHETIC_GITHUB_TOKEN \
+ codex-security:release-candidate \
+ -ec 'actual="$(printf "protocol=https\nhost=github.com\n\n" | /usr/local/bin/codex-security-git-credential get)"; test "$actual" = "$(printf "username=x-access-token\npassword=SYNTHETIC_GITHUB_TOKEN")"; test -z "$(printf "protocol=https\nhost=untrusted.example\n\n" | /usr/local/bin/codex-security-git-credential get)"'
+
+ - name: Verify hardened customer Compose configuration
+ env:
+ CODEX_SECURITY_IMAGE: codex-security:release-candidate
+ shell: bash
+ run: |
+ set -euo pipefail
+ mkdir -p results state
+ chmod 700 results state
+ printf 'id,repository,revision\n' > repositories.csv
+ CODEX_SECURITY_USER="$(id -u):$(id -g)"
+ export CODEX_SECURITY_USER
+ docker compose config --quiet
+ docker compose run --rm codex-security --version
+ if output="$(docker compose run --rm codex-security 2>&1)"; then
+ echo 'An empty repository CSV must not start a security scan.' >&2
+ exit 1
+ else
+ status=$?
+ fi
+ if [[ "$status" -ne 2 ]] || ! grep -Fq 'Multiscan CSV must contain at least one repository.' <<< "$output"; then
+ printf 'Unexpected empty-repository scan behavior:\n%s\n' "$output" >&2
+ exit 1
+ fi
+
+ - name: Verify optional hardened AppArmor Compose override
+ env:
+ CODEX_SECURITY_IMAGE: codex-security:release-candidate
+ shell: bash
+ run: |
+ set -euo pipefail
+ CODEX_SECURITY_USER="$(id -u):$(id -g)"
+ export CODEX_SECURITY_USER
+ compose=(docker compose -f compose.yaml -f compose.apparmor.yaml)
+
+ "${compose[@]}" config --format json |
+ jq --exit-status '
+ .services["codex-security"].security_opt as $options |
+ ($options | index("apparmor=codex-security-container")) != null and
+ ($options | index("no-new-privileges:true")) != null and
+ any($options[]; startswith("seccomp="))
+ ' > /dev/null
+
+ if ! docker info --format '{{json .SecurityOptions}}' |
+ grep -Fq '"name=apparmor"'; then
+ echo '::notice::This Docker host does not expose AppArmor; the default customer workflow remains available.'
+ exit 0
+ fi
+
+ sudo install -m 0644 docker/codex-security.apparmor \
+ /etc/apparmor.d/codex-security-container
+ sudo apparmor_parser -r -W /etc/apparmor.d/codex-security-container
+ sudo grep -Fxq 'codex-security-container (enforce)' \
+ /sys/kernel/security/apparmor/profiles
+
+ # The single-quoted program is evaluated inside the customer container.
+ # shellcheck disable=SC2016
+ "${compose[@]}" run --rm --entrypoint /bin/sh codex-security -ec '
+ test "$(cat /proc/self/attr/current)" = "codex-security-container (enforce)"
+ command_directory="$(mktemp -d)"
+ trap '\''rm -rf "$command_directory"'\'' EXIT
+ printf "%s\\n" "#!/bin/sh" '\''printf "%s\\n" "$@"'\'' \
+ > "$command_directory/codex-security"
+ chmod 755 "$command_directory/codex-security"
+ actual="$(
+ PATH="$command_directory:$PATH" \
+ /usr/local/bin/codex-security-entrypoint \
+ bulk-scan /input/repositories.csv --output-dir /output
+ )"
+ if printf "%s\\n" "$actual" |
+ grep -Fxq features.use_legacy_landlock=true; then
+ printf "%s\\n" "The AppArmor profile must retain the preferred Codex sandbox." >&2
+ exit 1
+ fi
+ '
+
+ "${compose[@]}" run --rm --entrypoint node codex-security \
+ /usr/local/lib/node_modules/@openai/codex-security/node_modules/@openai/codex/bin/codex.js \
+ sandbox /usr/bin/true
+
+ authorize:
+ if: github.event_name != 'pull_request'
+ name: authorize-container-publication
+ needs: validate
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ environment: container
+ permissions:
+ contents: read
+ packages: read
+ outputs:
+ image: ${{ steps.release.outputs.image }}
+ version: ${{ steps.release.outputs.version }}
+
+ steps:
+ - name: Checkout release source
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+
+ - name: Validate protected release source and version
+ id: release
+ shell: bash
+ run: |
+ set -euo pipefail
+ package_version="$(node -p 'require("./sdk/typescript/package.json").version')"
+
+ if [[ "$GITHUB_EVENT_NAME" == workflow_dispatch ]]; then
+ if [[ "$GITHUB_REF" != refs/heads/main ]]; then
+ echo 'Manual image releases must use the protected main branch.' >&2
+ exit 1
+ fi
+ version="$package_version"
+ elif [[ "$GITHUB_REF_NAME" =~ ^container-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
+ version="${GITHUB_REF_NAME#container-v}"
+ else
+ echo 'Container release tags must identify a stable version such as container-v0.1.0.' >&2
+ exit 1
+ fi
+
+ if [[ "$version" != "$package_version" ]]; then
+ echo "Container version $version must match the CLI package version $package_version." >&2
+ exit 1
+ fi
+
+ git fetch --no-tags origin +refs/heads/main:refs/remotes/origin/main
+ if ! git merge-base --is-ancestor "$GITHUB_SHA" refs/remotes/origin/main; then
+ echo 'Container releases must be built from a commit on the protected main branch.' >&2
+ exit 1
+ fi
+
+ printf 'image=ghcr.io/%s\n' "${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
+ printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"
+
+ - name: Preflight public package and immutable release version
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ VERSION: ${{ steps.release.outputs.version }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ owner="${GITHUB_REPOSITORY_OWNER,,}"
+ package="${GITHUB_REPOSITORY#*/}"
+ endpoint="orgs/$owner/packages/container/$package"
+
+ if ! metadata="$(gh api "$endpoint" 2>/dev/null)"; then
+ echo "::error::A repository administrator must bootstrap ghcr.io/$owner/$package, make the package public, and grant this repository package access before approving publication."
+ exit 1
+ fi
+
+ if [[ "$(jq -r '.visibility' <<< "$metadata")" != public ]]; then
+ echo "::error::ghcr.io/$owner/$package must be public before any release image is pushed."
+ exit 1
+ fi
+
+ sh docker/verify-container-release-version.sh "$endpoint" "$VERSION"
+
+ publish-platform:
+ name: publish-linux-${{ matrix.architecture }}
+ needs: authorize
+ runs-on: ${{ matrix.runner }}
+ timeout-minutes: 60
+ permissions:
+ contents: read
+ packages: write
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - architecture: amd64
+ runner: ubuntu-24.04
+ - architecture: arm64
+ runner: ubuntu-24.04-arm
+
+ steps:
+ - name: Checkout approved release source
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
+
+ - name: Sign in to GitHub Container Registry
+ uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Publish native image by immutable digest
+ id: build
+ uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
+ with:
+ context: .
+ platforms: linux/${{ matrix.architecture }}
+ outputs: type=image,name=${{ needs.authorize.outputs.image }},push-by-digest=true,name-canonical=true,push=true
+ provenance: mode=max
+ sbom: true
+ labels: |
+ org.opencontainers.image.source=https://github.com/${{ github.repository }}
+ org.opencontainers.image.version=${{ needs.authorize.outputs.version }}
+ org.opencontainers.image.revision=${{ github.sha }}
+
+ - name: Verify the exact published native image
+ env:
+ EXPECTED_ARCHITECTURE: ${{ matrix.architecture }}
+ IMAGE: ${{ needs.authorize.outputs.image }}
+ IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ if [[ ! "$IMAGE_DIGEST" =~ ^sha256:[[:xdigit:]]{64}$ ]]; then
+ echo 'The registry did not return a valid immutable platform digest.' >&2
+ exit 1
+ fi
+
+ reference="$IMAGE@$IMAGE_DIGEST"
+ docker logout ghcr.io
+ docker pull "$reference"
+
+ actual_architecture="$(docker image inspect --format '{{.Architecture}}' "$reference")"
+ if [[ "$actual_architecture" != "$EXPECTED_ARCHITECTURE" ]]; then
+ echo "Expected a native $EXPECTED_ARCHITECTURE image; found $actual_architecture." >&2
+ exit 1
+ fi
+
+ docker run --rm "$reference" --version
+ docker run --rm "$reference" bulk-scan --help
+ docker run --rm "$reference" info --json
+ [[ "$(docker run --rm --entrypoint id "$reference" -u)" == 10001 ]]
+
+ - name: Record verified platform digest
+ env:
+ IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ if [[ ! "$IMAGE_DIGEST" =~ ^sha256:[[:xdigit:]]{64}$ ]]; then
+ echo 'The registry did not return a valid immutable platform digest.' >&2
+ exit 1
+ fi
+ mkdir -p "$RUNNER_TEMP/codex-security-platform-digests"
+ touch "$RUNNER_TEMP/codex-security-platform-digests/${IMAGE_DIGEST#sha256:}"
+
+ - name: Upload platform digest
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: codex-security-image-digest-${{ matrix.architecture }}
+ path: ${{ runner.temp }}/codex-security-platform-digests/*
+ if-no-files-found: error
+ retention-days: 7
+ compression-level: 0
+
+ manifest:
+ name: publish-and-verify-multiarchitecture-candidate
+ needs:
+ - authorize
+ - publish-platform
+ runs-on: ubuntu-24.04
+ timeout-minutes: 30
+ permissions:
+ contents: read
+ packages: write
+ outputs:
+ digest: ${{ steps.manifest.outputs.digest }}
+ candidate: ${{ steps.manifest.outputs.candidate }}
+
+ steps:
+ - name: Checkout approved customer configuration
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
+
+ - name: Download verified platform digests
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
+ with:
+ path: ${{ runner.temp }}/codex-security-platform-digests
+ pattern: codex-security-image-digest-*
+ merge-multiple: true
+
+ - name: Sign in to GitHub Container Registry
+ uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Publish provisional multiarchitecture candidate
+ id: manifest
+ env:
+ IMAGE: ${{ needs.authorize.outputs.image }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ mapfile -t digest_files < <(
+ find "$RUNNER_TEMP/codex-security-platform-digests" \
+ -maxdepth 1 -type f -printf '%f\n' | sort
+ )
+
+ if [[ "${#digest_files[@]}" -ne 2 ]]; then
+ echo 'A release must contain exactly one verified amd64 and arm64 image.' >&2
+ exit 1
+ fi
+
+ references=()
+ for digest in "${digest_files[@]}"; do
+ if [[ ! "$digest" =~ ^[[:xdigit:]]{64}$ ]]; then
+ echo 'The release contains an invalid platform digest.' >&2
+ exit 1
+ fi
+ references+=("$IMAGE@sha256:$digest")
+ done
+
+ candidate="$IMAGE:release-candidate-$GITHUB_SHA"
+ docker buildx imagetools create \
+ --tag "$candidate" \
+ "${references[@]}"
+
+ manifest_digest="$(docker buildx imagetools inspect "$candidate" | awk '/^Digest:/{print $2; exit}')"
+ if [[ ! "$manifest_digest" =~ ^sha256:[[:xdigit:]]{64}$ ]]; then
+ echo 'The registry did not return a valid multiarchitecture image digest.' >&2
+ exit 1
+ fi
+ printf 'digest=%s\n' "$manifest_digest" >> "$GITHUB_OUTPUT"
+ printf 'candidate=%s\n' "$candidate" >> "$GITHUB_OUTPUT"
+
+ docker buildx imagetools inspect "$candidate" --raw |
+ jq --exit-status '
+ [.manifests[] | select(.platform.os == "linux") | .platform.architecture]
+ | (index("amd64") != null and index("arm64") != null)
+ ' > /dev/null
+
+ - name: Verify customers can pull the candidate without GitHub credentials
+ env:
+ CANDIDATE: ${{ steps.manifest.outputs.candidate }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ docker logout ghcr.io
+ if ! docker pull "$CANDIDATE"; then
+ echo '::error::The verified candidate cannot be pulled anonymously; no stable release tags have been published.'
+ exit 1
+ fi
+ docker run --rm "$CANDIDATE" --version
+ docker run --rm "$CANDIDATE" bulk-scan --help
+ docker run --rm "$CANDIDATE" info --json
+
+ - name: Verify hardened customer Compose against the public candidate
+ env:
+ CODEX_SECURITY_IMAGE: ${{ steps.manifest.outputs.candidate }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ mkdir -p results state
+ chmod 700 results state
+ printf 'id,repository,revision\n' > repositories.csv
+ CODEX_SECURITY_USER="$(id -u):$(id -g)"
+ export CODEX_SECURITY_USER
+ docker compose config --quiet
+ docker compose run --rm codex-security --version
+ if output="$(docker compose run --rm codex-security 2>&1)"; then
+ echo 'An empty repository CSV must not start a security scan.' >&2
+ exit 1
+ else
+ status=$?
+ fi
+ if [[ "$status" -ne 2 ]] || ! grep -Fq 'Multiscan CSV must contain at least one repository.' <<< "$output"; then
+ printf 'Unexpected empty-repository scan behavior:\n%s\n' "$output" >&2
+ exit 1
+ fi
+
+ attest:
+ name: attest-verified-multiarchitecture-candidate
+ needs:
+ - authorize
+ - manifest
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ permissions:
+ attestations: write
+ contents: read
+ id-token: write
+ packages: write
+
+ steps:
+ - name: Sign verified multiarchitecture candidate provenance
+ uses: actions/attest-build-provenance@96b4a1ef7235a096b17240c259729fdd70c83d45 # v2
+ with:
+ push-to-registry: true
+ subject-name: ${{ needs.authorize.outputs.image }}
+ subject-digest: ${{ needs.manifest.outputs.digest }}
+
+ promote:
+ name: promote-verified-and-attested-release
+ needs:
+ - authorize
+ - manifest
+ - attest
+ runs-on: ubuntu-24.04
+ timeout-minutes: 15
+ permissions:
+ contents: read
+ packages: write
+
+ steps:
+ - name: Checkout approved immutable-version verifier
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ persist-credentials: false
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
+
+ - name: Sign in to GitHub Container Registry
+ uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Promote the verified, attested, immutable image digest
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ IMAGE: ${{ needs.authorize.outputs.image }}
+ VERSION: ${{ needs.authorize.outputs.version }}
+ MANIFEST_DIGEST: ${{ needs.manifest.outputs.digest }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ if [[ ! "$MANIFEST_DIGEST" =~ ^sha256:[[:xdigit:]]{64}$ ]]; then
+ echo 'The verified release did not provide a valid immutable digest.' >&2
+ exit 1
+ fi
+
+ owner="${GITHUB_REPOSITORY_OWNER,,}"
+ package="${GITHUB_REPOSITORY#*/}"
+ endpoint="orgs/$owner/packages/container/$package"
+ sh docker/verify-container-release-version.sh "$endpoint" "$VERSION"
+
+ docker buildx imagetools create \
+ --tag "$IMAGE:$VERSION" \
+ --tag "$IMAGE:sha-$GITHUB_SHA" \
+ --tag "$IMAGE:latest" \
+ "$IMAGE@$MANIFEST_DIGEST"
+
+ actual_digest="$(docker buildx imagetools inspect "$IMAGE:$VERSION" | awk '/^Digest:/{print $2; exit}')"
+ if [[ "$actual_digest" != "$MANIFEST_DIGEST" ]]; then
+ echo '::error::The promoted stable tag does not reference the verified and attested candidate digest.'
+ exit 1
+ fi
+
+ - name: Verify the stable release is publicly pullable
+ env:
+ IMAGE: ${{ needs.authorize.outputs.image }}
+ VERSION: ${{ needs.authorize.outputs.version }}
+ shell: bash
+ run: |
+ set -euo pipefail
+ docker logout ghcr.io
+ docker pull "$IMAGE:$VERSION"
+ docker run --rm "$IMAGE:$VERSION" --version
diff --git a/README.md b/README.md
index 293ae1ebf..e0344acf5 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,14 @@ console.log(result.reportPath);
await security.close();
```
+## Containerized bulk scans
+
+Use the official image and included Docker Compose configuration for
+noninteractive, resumable scans of repositories pinned to immutable Git
+revisions. See the [container quick start](sdk/typescript/README.md#containerized-bulk-scans)
+for authentication, private result storage, and optional Ubuntu AppArmor
+hardening.
+
For complete command help, runtime defaults, native multi-agent worker limits,
environment variables, deep-scan configuration, and SDK options, see the
[package README](sdk/typescript/README.md) and the
diff --git a/compose.apparmor.yaml b/compose.apparmor.yaml
new file mode 100644
index 000000000..464e8969d
--- /dev/null
+++ b/compose.apparmor.yaml
@@ -0,0 +1,4 @@
+services:
+ codex-security:
+ security_opt:
+ - apparmor=codex-security-container
diff --git a/docker/codex-security.apparmor b/docker/codex-security.apparmor
new file mode 100644
index 000000000..3513cf7df
--- /dev/null
+++ b/docker/codex-security.apparmor
@@ -0,0 +1,42 @@
+abi <abi/4.0>,
+
+include <tunables/global>
+
+profile codex-security-container flags=(attach_disconnected,mediate_deleted) {
+ include <abstractions/base>
+
+ network,
+ unix,
+ deny network alg,
+ capability,
+ file,
+
+ mount,
+ umount,
+ pivot_root,
+ userns,
+
+ signal (receive) peer=unconfined,
+ signal (receive) peer=runc,
+ signal (receive) peer=crun,
+ signal (receive) peer=docker-default,
+ signal (send,receive) peer=codex-security-container,
+
+ deny @{PROC}/* w,
+ deny @{PROC}/{[^1-9/],[^1-9/][^0-9/],[^1-9s/][^0-9y/][^0-9s/],[^1-9/][^0-9/][^0-9/][^0-9/]*}/** w,
+ deny @{PROC}/sys/[^k]** w,
+ deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w,
+ deny @{PROC}/sysrq-trigger rwklx,
+ deny @{PROC}/kcore rwklx,
+
+ deny /sys/[^f]*/** wklx,
+ deny /sys/f[^s]*/** wklx,
+ deny /sys/fs/[^c]*/** wklx,
+ deny /sys/fs/c[^g]*/** wklx,
+ deny /sys/fs/cg[^r]*/** wklx,
+ deny /sys/firmware/** rwklx,
+ deny /sys/devices/virtual/powercap/** rwklx,
+ deny /sys/kernel/security/** rwklx,
+
+ ptrace (trace,tracedby,read,readby) peer=codex-security-container,
+}
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 4eb562990..83dc3be84 100644
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -10,6 +10,53 @@ if [ "${1:-}" = bulk-scan ]; then
printf '%s\n' 'codex-security: bulk-scan requires a repository CSV; interactive discovery is not supported in this image.' >&2
exit 2
;;
+ *)
+ if [ -r /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
+ restricted_user_namespaces=
+ IFS= read -r restricted_user_namespaces < /proc/sys/kernel/apparmor_restrict_unprivileged_userns ||
+ true
+ if [ "$restricted_user_namespaces" = 1 ]; then
+ apparmor_profile=
+ if [ -r /proc/self/attr/current ]; then
+ IFS= read -r apparmor_profile < /proc/self/attr/current || true
+ fi
+ if [ "$apparmor_profile" != 'codex-security-container (enforce)' ]; then
+ landlock_override=
+ expects_codex_override=
+ for argument do
+ if [ "$expects_codex_override" = yes ]; then
+ case "$argument" in
+ features.use_legacy_landlock=true)
+ landlock_override=enabled
+ ;;
+ features.use_legacy_landlock=*)
+ printf '%s\n' 'codex-security: restricted Ubuntu hosts require --codex features.use_legacy_landlock=true.' >&2
+ exit 2
+ ;;
+ esac
+ expects_codex_override=
+ elif [ "$argument" = --codex ]; then
+ expects_codex_override=yes
+ else
+ case "$argument" in
+ --codex=features.use_legacy_landlock=true)
+ landlock_override=enabled
+ ;;
+ --codex=features.use_legacy_landlock=*)
+ printf '%s\n' 'codex-security: restricted Ubuntu hosts require --codex features.use_legacy_landlock=true.' >&2
+ exit 2
+ ;;
+ esac
+ fi
+ done
+
+ if [ "$landlock_override" != enabled ]; then
+ set -- "$@" --codex features.use_legacy_landlock=true
+ fi
+ fi
+ fi
+ fi
+ ;;
esac
fi
diff --git a/docker/verify-container-release-version.sh b/docker/verify-container-release-version.sh
new file mode 100644
index 000000000..ec0b71855
--- /dev/null
+++ b/docker/verify-container-release-version.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+set -eu
+
+if [ "$#" -ne 2 ]; then
+ printf '%s\n' 'Usage: verify-container-release-version.sh PACKAGE_ENDPOINT VERSION' >&2
+ exit 2
+fi
+
+endpoint=$1
+version=$2
+
+if ! versions="$(gh api --paginate "$endpoint/versions?per_page=100")"; then
+ printf '%s\n' "::error::Unable to verify whether container version $version already exists; refusing to publish." >&2
+ exit 1
+fi
+
+if ! already_published="$(
+ printf '%s\n' "$versions" |
+ jq --slurp --arg version "$version" '
+ if length == 0 or any(.[]; type != "array") then
+ error("Container package versions must contain at least one JSON array.")
+ else
+ any(.[]; any(.[]; any(.metadata.container.tags[]?; . == $version)))
+ end
+ '
+)"; then
+ printf '%s\n' "::error::Unable to validate existing container versions for $version; refusing to publish." >&2
+ exit 1
+fi
+
+case "$already_published" in
+ false)
+ exit 0
+ ;;
+ true)
+ printf '%s\n' "::error::Container version $version already exists; stable version tags cannot be overwritten." >&2
+ exit 1
+ ;;
+ *)
+ printf '%s\n' "::error::Invalid container version lookup result for $version; refusing to publish." >&2
+ exit 1
+ ;;
+esac
diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md
index 9e1f4a512..961325085 100644
--- a/sdk/typescript/README.md
+++ b/sdk/typescript/README.md
@@ -514,6 +514,47 @@ Progress remains on stderr so JSON output stays machine readable. Network
failures and rate limits remain retryable; definitive authentication and model
authorization failures stop immediately.
+## Containerized bulk scans
+
+Create `repositories.csv` with one full, immutable Git commit per repository:
+
+```csv
+id,repository,revision
+payments,https://github.com/example/payments.git,0123456789abcdef0123456789abcdef01234567
+```
+
+Once the approved image has been published, prepare private results and
+authentication directories, sign in, and run the Docker Compose configuration
+from the root of the Codex Security repository:
+
+```bash
+mkdir -p results state
+chmod 700 results state
+export CODEX_SECURITY_USER="$(id -u):$(id -g)"
+export CODEX_SECURITY_IMAGE=ghcr.io/openai/codex-security:0.1.4
+docker compose pull codex-security
+docker compose run --rm codex-security login --device-auth
+docker compose run --rm codex-security
+```
+
+Reports and resumable scan results are written to `results/`; the reusable
+device login remains in `state/`. For unattended scans, set `OPENAI_API_KEY`
+or `CODEX_API_KEY` instead. Set `GH_TOKEN` or `GITHUB_TOKEN` for private
+GitHub repositories.
+
+On Ubuntu hosts that restrict unprivileged user namespaces, an administrator
+can install the optional, narrowly scoped AppArmor profile once:
+
+```bash
+sudo install -m 0644 docker/codex-security.apparmor /etc/apparmor.d/codex-security-container
+sudo apparmor_parser -r -W /etc/apparmor.d/codex-security-container
+docker compose -f compose.yaml -f compose.apparmor.yaml run --rm codex-security
+```
+
+The override preserves the nonroot user, dropped capabilities,
+no-new-privileges, and hardened seccomp policy. Other Docker hosts do not need
+the profile or override.
+
## Local security model
Codex Security runs with your local operating-system permissions. Scan only
diff --git a/sdk/typescript/tests-ts/container-entrypoint.test.ts b/sdk/typescript/tests-ts/container-entrypoint.test.ts
new file mode 100644
index 000000000..990655fee
--- /dev/null
+++ b/sdk/typescript/tests-ts/container-entrypoint.test.ts
@@ -0,0 +1,291 @@
+import { spawnSync, type SpawnSyncReturns } from "node:child_process";
+import { existsSync, readFileSync } from "node:fs";
+import { mkdtemp, 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";
+
+const testPosix = process.platform === "win32" ? test.skip : test;
+const publicEntrypoint = join(
+ import.meta.dir,
+ "..",
+ "..",
+ "..",
+ "docker",
+ "entrypoint.sh",
+);
+const entrypoint = existsSync(publicEntrypoint)
+ ? publicEntrypoint
+ : join(import.meta.dir, "..", "public-repo", "docker", "entrypoint.sh");
+const publicVersionVerifier = join(
+ import.meta.dir,
+ "..",
+ "..",
+ "..",
+ "docker",
+ "verify-container-release-version.sh",
+);
+const versionVerifier = existsSync(publicVersionVerifier)
+ ? publicVersionVerifier
+ : join(
+ import.meta.dir,
+ "..",
+ "public-repo",
+ "docker",
+ "verify-container-release-version.sh",
+ );
+const appArmorRestrictsUserNamespaces = (() => {
+ try {
+ return (
+ readFileSync(
+ "/proc/sys/kernel/apparmor_restrict_unprivileged_userns",
+ "utf8",
+ ).trim() === "1"
+ );
+ } catch {
+ return false;
+ }
+})();
+const usesCodexSecurityAppArmorProfile = (() => {
+ try {
+ return (
+ readFileSync("/proc/self/attr/current", "utf8").trim() ===
+ "codex-security-container (enforce)"
+ );
+ } catch {
+ return false;
+ }
+})();
+
+async function runEntrypoint(
+ args: readonly string[],
+ overrides: Record<string, string> = {},
+): Promise<SpawnSyncReturns<string>> {
+ const root = await realpath(
+ await mkdtemp(join(tmpdir(), "codex-security-container-entrypoint-")),
+ );
+
+ try {
+ await writeFile(
+ join(root, "codex-security"),
+ "#!/bin/sh\nprintf '%s\\n' \"$@\"\n",
+ { mode: 0o755 },
+ );
+
+ return spawnSync("sh", [entrypoint, ...args], {
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ GH_TOKEN: "",
+ GITHUB_TOKEN: "",
+ PATH: `${root}${delimiter}${process.env["PATH"] ?? ""}`,
+ ...overrides,
+ },
+ timeout: 10_000,
+ });
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+}
+
+async function runVersionVerifier(
+ response: string,
+ failure = false,
+): Promise<SpawnSyncReturns<string>> {
+ const root = await realpath(
+ await mkdtemp(join(tmpdir(), "codex-security-container-version-")),
+ );
+
+ try {
+ await writeFile(
+ join(root, "gh"),
+ [
+ "#!/bin/sh",
+ 'if [ "$1" != api ] || [ "$2" != --paginate ] ||',
+ ' [ "$3" != "$EXPECTED_ENDPOINT/versions?per_page=100" ]; then',
+ ' printf "%s\\n" "Unexpected GitHub API request." >&2',
+ " exit 64",
+ "fi",
+ 'if [ "$GH_FIXTURE_FAILURE" = 1 ]; then',
+ ' printf "%s\\n" "Synthetic package lookup failed." >&2',
+ " exit 1",
+ "fi",
+ 'printf "%s\\n" "$GH_FIXTURE_RESPONSE"',
+ "",
+ ].join("\n"),
+ { mode: 0o755 },
+ );
+
+ const endpoint = "orgs/openai/packages/container/codex-security";
+ return spawnSync("sh", [versionVerifier, endpoint, "0.1.4"], {
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ EXPECTED_ENDPOINT: endpoint,
+ GH_FIXTURE_FAILURE: failure ? "1" : "0",
+ GH_FIXTURE_RESPONSE: response,
+ PATH: `${root}${delimiter}${process.env["PATH"] ?? ""}`,
+ },
+ timeout: 10_000,
+ });
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+}
+
+describe("customer container entrypoint", () => {
+ testPosix(
+ "preserves CSV scan arguments and selects Landlock only without the AppArmor profile",
+ async () => {
+ const result = await runEntrypoint([
+ "bulk-scan",
+ "/input/repositories.csv",
+ "--output-dir",
+ "/output",
+ "--workers",
+ "2",
+ ]);
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ expect(result.stdout).toBe(
+ [
+ "bulk-scan",
+ "/input/repositories.csv",
+ "--output-dir",
+ "/output",
+ "--workers",
+ "2",
+ ...(appArmorRestrictsUserNamespaces &&
+ !usesCodexSecurityAppArmorProfile
+ ? ["--codex", "features.use_legacy_landlock=true"]
+ : []),
+ "",
+ ].join("\n"),
+ );
+ },
+ );
+
+ testPosix(
+ "preserves bulk-scan help without injecting scan configuration",
+ async () => {
+ const result = await runEntrypoint(["bulk-scan", "--help"]);
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ expect(result.stdout).toBe("bulk-scan\n--help\n");
+ },
+ );
+
+ testPosix(
+ "preserves an explicit Landlock override without duplicating it",
+ async () => {
+ const arguments_ = [
+ "bulk-scan",
+ "/input/repositories.csv",
+ "--output-dir",
+ "/output",
+ "--codex",
+ "features.use_legacy_landlock=true",
+ ];
+ const result = await runEntrypoint(arguments_);
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ expect(result.stdout).toBe(`${arguments_.join("\n")}\n`);
+ },
+ );
+
+ testPosix(
+ "rejects incompatible Landlock overrides only on restricted hosts",
+ async () => {
+ const arguments_ = [
+ "bulk-scan",
+ "/input/repositories.csv",
+ "--output-dir",
+ "/output",
+ "--codex",
+ "features.use_legacy_landlock=false",
+ ];
+ const result = await runEntrypoint(arguments_);
+
+ if (
+ appArmorRestrictsUserNamespaces &&
+ !usesCodexSecurityAppArmorProfile
+ ) {
+ expect(result.status).toBe(2);
+ expect(result.stdout).toBe("");
+ expect(result.stderr).toBe(
+ "codex-security: restricted Ubuntu hosts require --codex features.use_legacy_landlock=true.\n",
+ );
+ } else {
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ expect(result.stdout).toBe(`${arguments_.join("\n")}\n`);
+ }
+ },
+ );
+
+ testPosix(
+ "rejects interactive discovery before starting the CLI",
+ async () => {
+ const result = await runEntrypoint(["bulk-scan"]);
+
+ expect(result.status).toBe(2);
+ expect(result.stdout).toBe("");
+ expect(result.stderr).toBe(
+ "codex-security: bulk-scan requires a repository CSV; interactive discovery is not supported in this image.\n",
+ );
+ },
+ );
+
+ testPosix("does not change non-scan commands", async () => {
+ const result = await runEntrypoint(["--version"]);
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ expect(result.stdout).toBe("--version\n");
+ });
+});
+
+describe("immutable customer container releases", () => {
+ testPosix("fails closed when package versions cannot be read", async () => {
+ const result = await runVersionVerifier("", true);
+
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain("Synthetic package lookup failed.");
+ expect(result.stderr).toContain("refusing to publish");
+ });
+
+ testPosix("rejects an existing immutable release version", async () => {
+ const result = await runVersionVerifier(
+ JSON.stringify([
+ { metadata: { container: { tags: ["0.1.4", "latest"] } } },
+ ]),
+ );
+
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain("Container version 0.1.4 already exists");
+ });
+
+ testPosix(
+ "accepts an unpublished version across paginated results",
+ async () => {
+ const result = await runVersionVerifier(
+ `${JSON.stringify([
+ { metadata: { container: { tags: ["0.1.3", "latest"] } } },
+ ])}\n[]`,
+ );
+
+ expect(result.status).toBe(0);
+ expect(result.stderr).toBe("");
+ },
+ );
+
+ testPosix("fails closed when the version response is malformed", async () => {
+ const result = await runVersionVerifier("{not-json");
+
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain("refusing to publish");
+ });
+});