Files
codex-security/.github/workflows/container-validate.yml
Michael D'Angelo 4d83ce9195 refactor: share workbench arguments and simplify SDK and eval workflows (#2325)
* Simplify workbench dispatch, SDK helpers, and their test fixtures

* test(sdk): keep distinct progress matrix helpers

* test(sdk): expect canceled lifecycle for aborted component scans
2026-11-05 01:28:44 -08:00

278 lines
12 KiB
YAML

name: container-validate
on:
workflow_call:
inputs:
ref:
description: Source commit to validate; defaults to the calling workflow commit.
type: string
default: ""
release-version:
type: string
release-integrity:
type: string
release-tarball-artifact:
type: string
runtime-lock-artifact:
type: string
labels:
description: Release metadata for the OCI candidate. Omit for source validation.
type: string
permissions:
contents: read
jobs:
validate:
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref || github.sha }}
persist-credentials: false
- name: Prepare native runtime
if: inputs.release-tarball-artifact == ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-universal-${{ inputs.ref || github.sha }}
path: plugins/codex-security/native/prebuilt
- name: Download the verified scanner and its runtime lock
if: inputs.release-tarball-artifact != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ inputs.runtime-lock-artifact && format('{0},{1}', inputs.release-tarball-artifact, inputs.runtime-lock-artifact) || inputs.release-tarball-artifact }}
merge-multiple: true
path: ${{ runner.temp }}/scanner-artifacts
- name: Prepare the locked scanner package
if: inputs.release-tarball-artifact != ''
env:
RELEASE_VERSION: ${{ inputs.release-version }}
RELEASE_INTEGRITY: ${{ inputs.release-integrity }}
run: |
lock=$RUNNER_TEMP/scanner-artifacts/package-lock.json
jq -e --arg version "$RELEASE_VERSION" --arg integrity "$RELEASE_INTEGRITY" '
.packages["node_modules/@openai/codex-security"] |
.version == $version and .integrity == $integrity
' "$lock" > /dev/null
mkdir "$RUNNER_TEMP/release-inputs"
node docker/prepare-release-package.mjs "$RUNNER_TEMP"/scanner-artifacts/*.tgz "$lock" "$RUNNER_TEMP/release-inputs"
- name: Verify customer build excludes secrets and scan data
shell: bash
run: |
set -euo pipefail
ignore_file=.dockerignore
if [[ -f Dockerfile.dockerignore ]]; then
ignore_file=Dockerfile.dockerignore
if ! cmp -s .dockerignore "$ignore_file"; then
echo "Dockerfile-specific ignore rules must match the approved customer baseline." >&2
exit 1
fi
fi
if grep -Fq '!' "$ignore_file"; then
echo "Customer Docker ignore rules must not re-include excluded files: $ignore_file" >&2
exit 1
fi
for pattern in \
'**/.env' \
'**/.env.*' \
'**/.npmrc' \
'**/node_modules' \
'**/*.csv' \
'**/repositories.csv' \
'**/results' \
'**/security-scans' \
'**/state'; do
if ! grep -Fxq -- "$pattern" "$ignore_file"; then
echo "Missing customer Docker build exclusion in $ignore_file: $pattern" >&2
exit 1
fi
done
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
driver-opts: ${{ !inputs.labels && 'provenance-add-gha=false' || '' }}
- name: Test release index assembly
if: matrix.architecture == 'amd64' && inputs.ref == '' && inputs.release-tarball-artifact == ''
run: bash docker/test-container-index.sh
- name: Build native customer image
if: inputs.labels == ''
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
env:
DOCKER_BUILD_RECORD_UPLOAD: "false"
with:
context: .
target: &target ${{ inputs.release-tarball-artifact && 'scanner-release' || '' }}
build-contexts: &release-inputs ${{ inputs.release-tarball-artifact && format('release-inputs={0}/release-inputs', runner.temp) || '' }}
load: true
platforms: linux/${{ matrix.architecture }}
push: false
tags: codex-security:release-candidate
cache-from: &cache-from type=gha,scope=${{ inputs.release-tarball-artifact && 'codex-security-release' || 'codex-security' }}-${{ matrix.architecture }}
cache-to: ${{ github.event_name != 'pull_request' && format('type=gha,mode=max,scope=codex-security-{0}', matrix.architecture) || '' }}
- name: Build the release candidate with provenance and SBOM
id: candidate
if: inputs.labels != ''
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
target: *target
build-contexts: *release-inputs
platforms: linux/${{ matrix.architecture }}
labels: ${{ inputs.labels }}
outputs: type=oci,dest=${{ runner.temp }}/image.tar,name=ghcr.io/${{ github.repository }}:${{ inputs.release-version }}
provenance: mode=max
sbom: true
cache-from: *cache-from
cache-to: type=gha,mode=max,scope=${{ inputs.release-tarball-artifact && 'codex-security-release' || 'codex-security' }}-${{ matrix.architecture }}
- name: Load the native image from the release artifact
if: inputs.labels != ''
env:
DIGEST: ${{ steps.candidate.outputs.digest }}
run: |
archive="oci-archive:$RUNNER_TEMP/image.tar"
skopeo inspect --raw "$archive" | sha256sum | cut -d' ' -f1 | grep -Fxq "${DIGEST#sha256:}"
skopeo copy "$archive" docker-daemon:codex-security:release-candidate
printf '%s\n' "$DIGEST" > "$RUNNER_TEMP/digest"
- name: Verify native image
env:
EXPECTED_ARCHITECTURE: ${{ matrix.architecture }}
EXPECTED_VERSION: ${{ inputs.release-version }}
EXPECTED_LABELS: ${{ inputs.labels }}
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
if [[ -n "$EXPECTED_LABELS" ]]; then
docker image inspect --format '{{json .Config.Labels}}' codex-security:release-candidate |
jq -e --arg labels "$EXPECTED_LABELS" '
. as $actual | all($labels | split("\n")[] | select(length > 0) |
capture("^(?<key>[^=]+)=(?<value>.*)$"); $actual[.key] == .value)
' > /dev/null
fi
version=$(docker run --rm codex-security:release-candidate --version)
if [[ -n "$EXPECTED_VERSION" ]]; then test "$version" = "$EXPECTED_VERSION"; fi
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 entrypoint preserves Codex sandbox settings
run: docker run --rm -i --entrypoint /bin/sh codex-security:release-candidate -s < docker/verify-container-entrypoint.sh
- name: Verify hardened Codex command sandbox
run: bash docker/verify-container-sandbox.sh codex-security:release-candidate
- name: Reject interactive repository discovery
shell: bash
run: |
set -euo pipefail
if output="$(docker run --rm -t codex-security:release-candidate bulk-scan 2>&1)"; then
echo "The customer container must require a repository CSV." >&2
exit 1
else
status=$?
fi
if [[ "$status" -ne 2 ]]; then
printf 'The customer container returned unexpected exit status %s:\n%s\n' "$status" "$output" >&2
exit 1
fi
expected='codex-security: bulk-scan requires a repository CSV; interactive discovery is not supported in this image.'
if [[ "${output//$'\r'/}" != "$expected" ]]; then
printf 'The customer container returned an unexpected repository discovery error:\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: source docker/verify-container-compose.sh
- name: Verify 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 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 -T --entrypoint /bin/sh codex-security -ec '
test "$(cat /proc/self/attr/current)" = "codex-security-container (enforce)"
exec /bin/sh
' < docker/verify-container-entrypoint.sh
"${compose[@]}" run --rm --entrypoint /bin/sh codex-security -ec '
cd "$(dirname "$(readlink -f /usr/local/bin/codex-security)")"
exec npm exec --offline -- codex sandbox /usr/bin/true
'
- name: Retain the tested release candidate
if: inputs.labels != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: codex-security-oci-${{ matrix.architecture }}
path: |
${{ runner.temp }}/image.tar
${{ runner.temp }}/digest
if-no-files-found: error
retention-days: 7
compression-level: 0
overwrite: true