Files
codex-security/.github/workflows/container-release.yml
T
Michael D'Angelo 5ee36bc4c4 fix(release): queue container publishes and pin release helpers (#1806)
fix(release): preserve queued publications and artifact metadata
2026-10-20 20:52:08 +08:00

564 lines
22 KiB
YAML

name: container-release
on:
push:
tags:
- "container-v*"
workflow_dispatch:
workflow_call:
inputs:
release-sha:
description: Verified npm release source commit.
required: true
type: string
release-version:
description: Verified stable npm version.
required: true
type: string
concurrency:
group: container-release-publish
queue: max
permissions:
contents: read
jobs:
source:
if: github.repository == 'openai/codex-security'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: read
attestations: read
outputs:
sha: ${{ steps.release.outputs.sha }}
image: ${{ steps.release.outputs.image }}
version: ${{ steps.release.outputs.version }}
existing-digest: ${{ steps.existing.outputs.digest }}
steps:
- name: Checkout release history
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Validate protected release source and version
id: release
env:
RELEASE_SHA: ${{ inputs.release-sha }}
RELEASE_VERSION: ${{ inputs.release-version }}
shell: bash
run: |
set -euo pipefail
source_sha="$GITHUB_SHA"
if [[ -n "$RELEASE_SHA" ]]; then
if [[ "$GITHUB_REF" != refs/heads/main || ! "$RELEASE_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo 'Coordinated image releases must run on main with an exact release commit.' >&2
exit 1
fi
source_sha="$RELEASE_SHA"
version="$RELEASE_VERSION"
if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] ||
[[ "$(git rev-parse "refs/tags/npm-v$version^{commit}")" != "$source_sha" ]]; then
echo 'The container source must match the immutable npm release tag.' >&2
exit 1
fi
elif [[ "$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="$(git show "$source_sha:sdk/typescript/package.json" | jq -r .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
package_version="$(git show "$source_sha:sdk/typescript/package.json" | jq -r .version)"
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 "$source_sha" refs/remotes/origin/main; then
echo 'Container releases must be built from a commit on the protected main branch.' >&2
exit 1
fi
owner="$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')"
printf 'image=ghcr.io/%s/codex-security\n' "$owner" >> "$GITHUB_OUTPUT"
printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"
printf 'sha=%s\n' "$source_sha" >> "$GITHUB_OUTPUT"
- &set-up-docker-buildx
name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Verify an existing immutable container release
id: existing
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE: ${{ steps.release.outputs.image }}
VERSION: ${{ steps.release.outputs.version }}
RELEASE_SHA: ${{ steps.release.outputs.sha }}
shell: bash
run: |
set -euo pipefail
owner="$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')"
endpoint="orgs/$owner/packages/container/codex-security"
versions="$(gh api --paginate "$endpoint/versions?per_page=100")"
digest="$(jq -r -s --arg version "$VERSION" '
[.[][] | select(any(.metadata.container.tags[]?; . == $version)) | .name]
| unique | .[]
' <<< "$versions")"
if [[ -z "$digest" ]]; then
exit 0
fi
if [[ ! "$digest" =~ ^sha256:[a-f0-9]{64}$ ]]; then
echo 'The existing container version must resolve to one immutable digest.' >&2
exit 1
fi
jq --exit-status --slurp --arg tag "sha-$RELEASE_SHA" --arg digest "$digest" '
[.[][] | select(any(.metadata.container.tags[]?; . == $tag)) | .name]
| unique == [$digest]
' <<< "$versions" > /dev/null
reference="$IMAGE@$digest"
docker buildx imagetools inspect "$reference" --raw |
jq --exit-status --arg version "$VERSION" --arg sha "$RELEASE_SHA" '
.annotations["org.opencontainers.image.version"] == $version
and .annotations["org.opencontainers.image.revision"] == $sha
and (
[.manifests[] | select(.platform.os == "linux") | .platform.architecture]
| (index("amd64") != null and index("arm64") != null)
)
' > /dev/null
gh attestation verify "oci://$reference" --repo "$GITHUB_REPOSITORY"
docker pull "$reference"
docker run --rm "$reference" --version
sh docker/verify-container-release-version.sh "$endpoint" "$VERSION" "$digest"
printf 'digest=%s\n' "$digest" >> "$GITHUB_OUTPUT"
native:
needs: source
if: github.repository == 'openai/codex-security' && needs.source.outputs.existing-digest == ''
uses: ./.github/workflows/native-artifacts.yml
with:
ref: ${{ needs.source.outputs.sha }}
validate:
needs: [source, native]
if: github.repository == 'openai/codex-security'
uses: ./.github/workflows/container-validate.yml
with:
ref: ${{ needs.source.outputs.sha }}
authorize:
if: github.repository == 'openai/codex-security'
name: authorize-container-publication
needs: [source, validate]
runs-on: ubuntu-24.04
timeout-minutes: 10
environment: container
permissions:
contents: read
packages: read
outputs:
sha: ${{ needs.source.outputs.sha }}
image: ${{ needs.source.outputs.image }}
version: ${{ needs.source.outputs.version }}
labels: ${{ steps.metadata.outputs.labels }}
metadata: ${{ steps.metadata.outputs.json }}
steps:
- name: Checkout release automation
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Preflight public package and immutable release version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.source.outputs.version }}
shell: bash
run: |
set -euo pipefail
owner="${GITHUB_REPOSITORY_OWNER,,}"
endpoint="orgs/$owner/packages/container/codex-security"
if ! metadata="$(gh api "$endpoint" 2>/dev/null)"; then
echo "::error::A repository administrator must bootstrap ghcr.io/$owner/codex-security, 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/codex-security must be public before any release image is pushed."
exit 1
fi
sh docker/verify-container-release-version.sh "$endpoint" "$VERSION"
- name: Generate release image metadata
id: metadata
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ needs.source.outputs.image }}
# Use the release version for metadata; only promote publishes stable tags.
tags: type=raw,value=${{ needs.source.outputs.version }}
labels: |
org.opencontainers.image.title=Codex Security
org.opencontainers.image.description=Codex Security scanner.
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.vendor=OpenAI
org.opencontainers.image.revision=${{ needs.source.outputs.sha }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}/releases/tag/npm-v${{ needs.source.outputs.version }}
org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/blob/${{ needs.source.outputs.sha }}/docker/README.md
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.authorize.outputs.sha }}
persist-credentials: false
- name: Prepare native runtime
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-universal-${{ needs.authorize.outputs.sha }}
path: plugins/codex-security/native/prebuilt
- *set-up-docker-buildx
- &sign-in-to-github-container-registry
name: Sign in to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
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@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
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
cache-from: type=gha,scope=codex-security-${{ matrix.architecture }}
cache-to: type=gha,mode=max,scope=codex-security-${{ matrix.architecture }}
labels: ${{ needs.authorize.outputs.labels }}
- name: Verify the exact published native image
env:
EXPECTED_ARCHITECTURE: ${{ matrix.architecture }}
IMAGE: ${{ needs.authorize.outputs.image }}
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
IMAGE_METADATA: ${{ needs.authorize.outputs.metadata }}
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 image inspect --format '{{json .Config.Labels}}' "$reference" |
jq --exit-status --argjson metadata "$IMAGE_METADATA" '
. as $labels
| all($metadata.labels | to_entries[]; $labels[.key] == .value)
' > /dev/null
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
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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.authorize.outputs.sha }}
persist-credentials: false
- *set-up-docker-buildx
- name: Download verified platform digests
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: ${{ runner.temp }}/codex-security-platform-digests
pattern: codex-security-image-digest-*
merge-multiple: true
- *sign-in-to-github-container-registry
- name: Publish provisional multiarchitecture candidate
id: manifest
env:
IMAGE: ${{ needs.authorize.outputs.image }}
IMAGE_LABELS: ${{ needs.authorize.outputs.labels }}
IMAGE_METADATA: ${{ needs.authorize.outputs.metadata }}
RELEASE_SHA: ${{ needs.authorize.outputs.sha }}
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
annotations=()
while IFS= read -r label; do
annotations+=(--annotation "index:$label")
done <<< "$IMAGE_LABELS"
candidate="$IMAGE:release-candidate-$RELEASE_SHA"
docker buildx imagetools create \
"${annotations[@]}" \
--tag "$candidate" \
"${references[@]}"
manifest_digest="$(docker buildx imagetools inspect --format '{{.Manifest.Digest}}' "$candidate")"
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 --argjson metadata "$IMAGE_METADATA" '
. as $index
| all($metadata.labels | to_entries[]; $index.annotations[.key] == .value)
and (
[.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: source docker/verify-container-compose.sh
attest:
name: attest-verified-multiarchitecture-candidate
needs:
- authorize
- manifest
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
attestations: write
artifact-metadata: write
contents: read
id-token: write
packages: write
steps:
- *sign-in-to-github-container-registry
- name: Sign verified multiarchitecture candidate provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- *set-up-docker-buildx
- *sign-in-to-github-container-registry
- name: Recheck immutable version and select the latest tag
id: version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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,,}"
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 }}
RELEASE_SHA: ${{ needs.authorize.outputs.sha }}
shell: bash
run: |
set -euo pipefail
tags=(--tag "$IMAGE:$VERSION" --tag "$IMAGE:sha-$RELEASE_SHA")
if [[ "$PUBLISH_LATEST" == true ]]; then
tags+=(--tag "$IMAGE:latest")
fi
docker buildx imagetools create \
"${tags[@]}" \
"$IMAGE@$MANIFEST_DIGEST"
actual_digest="$(docker buildx imagetools inspect --format '{{.Manifest.Digest}}' "$IMAGE:$VERSION")"
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 --entrypoint codex-security "$IMAGE:$VERSION" --version
- name: Summarize published container release
continue-on-error: true
env:
IMAGE: ${{ needs.authorize.outputs.image }}
VERSION: ${{ needs.authorize.outputs.version }}
MANIFEST_DIGEST: ${{ needs.manifest.outputs.digest }}
RELEASE_URL: ${{ fromJSON(needs.authorize.outputs.metadata).labels['org.opencontainers.image.url'] }}
DOCUMENTATION_URL: ${{ fromJSON(needs.authorize.outputs.metadata).labels['org.opencontainers.image.documentation'] }}
RELEASE_SHA: ${{ needs.authorize.outputs.sha }}
shell: bash
run: |
{
printf '## Codex Security container %s\n\n' "$VERSION"
printf 'Platforms: linux/amd64, linux/arm64.\n\n'
printf 'Source: [%s](%s/%s/commit/%s)\n\n' \
"$RELEASE_SHA" "$GITHUB_SERVER_URL" "$GITHUB_REPOSITORY" "$RELEASE_SHA"
printf '[Container guide](%s) | [Release notes](%s)\n\n' \
"$DOCUMENTATION_URL" "$RELEASE_URL"
printf '```bash\n'
printf 'docker pull %s:%s@%s\n' "$IMAGE" "$VERSION" "$MANIFEST_DIGEST"
printf 'gh attestation verify oci://%s@%s --repo %s\n' \
"$IMAGE" "$MANIFEST_DIGEST" "$GITHUB_REPOSITORY"
printf '```\n'
} >> "$GITHUB_STEP_SUMMARY"