mirror of
https://github.com/openai/codex-security.git
synced 2026-11-25 02:58:16 +08:00
215 lines
8.6 KiB
YAML
215 lines
8.6 KiB
YAML
name: container-validate
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
ref:
|
|
description: Source commit to validate; defaults to the calling workflow commit.
|
|
type: string
|
|
default: ""
|
|
|
|
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
|
|
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
with:
|
|
name: native-universal-${{ inputs.ref || github.sha }}
|
|
path: plugins/codex-security/native/prebuilt
|
|
|
|
- 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
|
|
|
|
- name: Build native customer image
|
|
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
|
|
env:
|
|
DOCKER_BUILD_RECORD_UPLOAD: "false"
|
|
with:
|
|
context: .
|
|
load: true
|
|
platforms: linux/${{ matrix.architecture }}
|
|
push: false
|
|
tags: codex-security:release-candidate
|
|
cache-from: type=gha,scope=codex-security-${{ matrix.architecture }}
|
|
cache-to: ${{ github.event_name != 'pull_request' && format('type=gha,mode=max,scope=codex-security-{0}', matrix.architecture) || '' }}
|
|
|
|
- name: Verify native image
|
|
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 entrypoint preserves Codex sandbox settings
|
|
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
|
|
)"
|
|
expected="$(printf "%s\\n" bulk-scan /input/repositories.csv --output-dir /output)"
|
|
test "$actual" = "$expected"
|
|
'
|
|
|
|
- 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 --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
|