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

ci: reuse native builds across package and container checks (#1130)

mldangelo-oai3f1b6732fdb5
diff --git a/.github/workflows/container-ci.yml b/.github/workflows/container-ci.yml
index 011bb1f7c..057432030 100644
--- a/.github/workflows/container-ci.yml
+++ b/.github/workflows/container-ci.yml
@@ -1,167 +1,15 @@
name: container-ci
on:
- push:
- branches: [main]
- paths:
- - .dockerignore
- - .github/workflows/native-*.yml
- - .github/actions/download-native/**
- - .github/workflows/container-ci.yml
- - Dockerfile
- - Dockerfile.dockerignore
- - compose.yaml
- - compose.apparmor.yaml
- - compose.findings.yaml
- - compose.runner.yaml
- - docker/**
- - plugins/codex-security/**
- - sdk/typescript/**
- workflow_call:
- inputs:
- native-artifacts-ready:
- description: Use the native artifacts already built by the caller in this run.
- type: boolean
- default: false
workflow_dispatch:
permissions:
contents: read
-concurrency:
- group: container-ci-${{ github.event.pull_request.number || github.run_id }}
- cancel-in-progress: ${{ github.event_name == 'pull_request' }}
-
jobs:
native:
- if: ${{ !inputs.native-artifacts-ready }}
uses: ./.github/workflows/native-artifacts.yml
container:
needs: native
- if: ${{ !cancelled() && (inputs.native-artifacts-ready || needs.native.result == 'success') }}
- name: linux-amd64
- runs-on: ubuntu-latest
- timeout-minutes: 30
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- - name: Prepare native runtime
- uses: ./.github/actions/download-native
-
- - 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 customer container
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
- env:
- DOCKER_BUILD_RECORD_UPLOAD: "false"
- with:
- context: .
- load: true
- platforms: linux/amd64
- push: false
- tags: codex-security:ci
- cache-from: type=gha,scope=codex-security-amd64
- cache-to: ${{ github.event_name != 'pull_request' && 'type=gha,mode=max,scope=codex-security-amd64' || '' }}
-
- - name: Verify bundled scanner
- run: |
- docker run --rm codex-security:ci --version
- docker run --rm codex-security:ci bulk-scan --help
- docker run --rm codex-security:ci info --json
-
- - name: Set up Bun for findings service smoke test
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- with:
- bun-version: "1.3.14"
-
- - name: Verify findings service and persistent SQLite storage
- run: bun sdk/typescript/scripts/smoke-findings-service.ts codex-security:ci
-
- - name: Validate hardened customer Compose configuration
- env:
- CODEX_SECURITY_IMAGE: codex-security:ci
- run: |
- 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
-
- - 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
- run: bash docker/verify-container-sandbox.sh codex-security:ci
-
- - name: Reject interactive repository discovery
- shell: bash
- run: |
- set -euo pipefail
- if output="$(docker run --rm -t codex-security:ci 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 noninteractive Git credentials
- shell: bash
- run: |
- set -euo pipefail
- docker run --rm \
- --entrypoint /bin/sh \
- --env GH_TOKEN=SYNTHETIC_GITHUB_TOKEN \
- codex-security:ci \
- -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)"'
+ uses: ./.github/workflows/container-validate.yml
diff --git a/.github/workflows/container-validate.yml b/.github/workflows/container-validate.yml
index 8580c830e..f2a040fba 100644
--- a/.github/workflows/container-validate.yml
+++ b/.github/workflows/container-validate.yml
@@ -8,7 +8,6 @@ permissions:
jobs:
validate:
- if: github.repository == 'openai/codex-security'
name: validate-linux-${{ matrix.architecture }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
@@ -29,6 +28,40 @@ jobs:
- name: Prepare native runtime
uses: ./.github/actions/download-native
+ - 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
@@ -83,6 +116,26 @@ jobs:
- 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: |
diff --git a/.github/workflows/native-windows.yml b/.github/workflows/native-windows.yml
index dcb1d7758..be806bd93 100644
--- a/.github/workflows/native-windows.yml
+++ b/.github/workflows/native-windows.yml
@@ -36,6 +36,8 @@ jobs:
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
package_json_file: package.json
+ cache: true
+ cache_dependency_path: sdk/typescript/pnpm-lock.yaml
- name: Set up Node.js 22
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml
index 659528234..6058d93e6 100644
--- a/.github/workflows/node-ci.yml
+++ b/.github/workflows/node-ci.yml
@@ -20,7 +20,6 @@ jobs:
timeout-minutes: 10
outputs:
ci-mode: ${{ steps.scope.outputs.ci-mode }}
- container-ci: ${{ steps.scope.outputs.container-ci }}
container-validate: ${{ steps.scope.outputs.container-validate }}
test-quality: ${{ steps.scope.outputs.test-quality }}
@@ -42,11 +41,12 @@ jobs:
set -euo pipefail
ci_mode=full
check_markdown=false
- container_ci=false
container_validate=false
+ if [[ "$EVENT_NAME" == "push" ]]; then
+ container_validate=true
+ fi
test_quality=false
if [[ "$EVENT_NAME" == "pull_request" && "$BASE_CHANGED" == "true" ]]; then
- container_ci=true
container_validate=true
test_quality=true
fi
@@ -74,17 +74,13 @@ jobs:
Dockerfile.dockerignore | compose.yaml | compose.apparmor.yaml | \
compose.findings.yaml | compose.runner.yaml | docker/* | \
plugins/codex-security/* | sdk/typescript/*)
- container_ci=true
container_validate=true
;;
- .github/workflows/container-ci.yml)
- container_ci=true
- ;;
- .github/workflows/container-release.yml | .github/workflows/container-validate.yml)
+ .github/workflows/container-ci.yml | .github/workflows/container-release.yml | \
+ .github/workflows/container-validate.yml)
container_validate=true
;;
.github/workflows/node-ci.yml)
- container_ci=true
container_validate=true
test_quality=true
;;
@@ -102,7 +98,6 @@ jobs:
fi
printf 'ci-mode=%s\n' "$ci_mode" >> "$GITHUB_OUTPUT"
printf 'check-markdown=%s\n' "$check_markdown" >> "$GITHUB_OUTPUT"
- printf 'container-ci=%s\n' "$container_ci" >> "$GITHUB_OUTPUT"
printf 'container-validate=%s\n' "$container_validate" >> "$GITHUB_OUTPUT"
printf 'test-quality=%s\n' "$test_quality" >> "$GITHUB_OUTPUT"
@@ -199,16 +194,9 @@ jobs:
native:
needs: validate-title
- if: needs.validate-title.outputs.ci-mode == 'full' || needs.validate-title.outputs.container-ci == 'true' || needs.validate-title.outputs.container-validate == 'true' || needs.validate-title.outputs.test-quality == 'true'
+ if: needs.validate-title.outputs.ci-mode == 'full' || needs.validate-title.outputs.container-validate == 'true' || needs.validate-title.outputs.test-quality == 'true'
uses: ./.github/workflows/native-artifacts.yml
- container-ci:
- needs: [validate-title, native]
- if: needs.validate-title.outputs.container-ci == 'true'
- uses: ./.github/workflows/container-ci.yml
- with:
- native-artifacts-ready: true
-
container-validate:
needs: [validate-title, native]
if: needs.validate-title.outputs.container-validate == 'true'
@@ -527,6 +515,7 @@ jobs:
mcp,
plugin-host,
plugin-source,
+ container-validate,
]
if: always()
runs-on: ubuntu-latest
@@ -538,6 +527,9 @@ jobs:
- name: Require every Unix coverage job
if: needs.validate-title.result != 'success' || (needs.validate-title.outputs.ci-mode == 'full' && (needs.static-checks.result != 'success' || needs.package.result != 'success' || needs.test.result != 'success' || needs.compatibility.result != 'success' || needs.mcp.result != 'success' || needs.plugin-host.result != 'success' || needs.plugin-source.result != 'success')) || (needs.validate-title.outputs.ci-mode != 'full' && needs.validate-title.outputs.ci-mode != 'markdown')
run: exit 1
+ - name: Require selected container coverage
+ if: needs.validate-title.outputs.container-validate == 'true' && needs.container-validate.result != 'success'
+ run: exit 1
windows-test:
name: windows-latest / node-22 / tests-${{ matrix.shard }}
diff --git a/sdk/typescript/tests-ts/container-ci-workflow.test.ts b/sdk/typescript/tests-ts/container-ci-workflow.test.ts
new file mode 100644
index 000000000..6d286a050
--- /dev/null
+++ b/sdk/typescript/tests-ts/container-ci-workflow.test.ts
@@ -0,0 +1,158 @@
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { expect, test } from "bun:test";
+import { bashCommand } from "./support/shell.js";
+
+type Step = { name?: string; uses?: string; run?: string; if?: string };
+type Job = {
+ uses?: string;
+ needs?: string | string[];
+ if?: string;
+ steps?: Step[];
+ strategy?: { matrix: { include: Array<{ architecture: string }> } };
+};
+
+function workflow(name: string) {
+ return Bun.YAML.parse(
+ readFileSync(
+ new URL(`../../../.github/workflows/${name}.yml`, import.meta.url),
+ "utf8",
+ ),
+ ) as { on: Record<string, unknown>; jobs: Record<string, Job> };
+}
+
+const ci = workflow("node-ci");
+const bash = bashCommand();
+
+test("shares one native build and container matrix in automatic CI", () => {
+ const container = workflow("container-ci");
+ const validation = workflow("container-validate");
+ expect(Object.keys(container.on)).toEqual(["workflow_dispatch"]);
+ expect(
+ Object.values(ci.jobs).filter(
+ (job) => job.uses === "./.github/workflows/native-artifacts.yml",
+ ),
+ ).toHaveLength(1);
+ expect(
+ Object.values(ci.jobs).filter((job) =>
+ job.uses?.startsWith("./.github/workflows/container-"),
+ ),
+ ).toEqual([ci.jobs["container-validate"]!]);
+ expect(ci.jobs["container-validate"]).toMatchObject({
+ needs: ["validate-title", "native"],
+ uses: "./.github/workflows/container-validate.yml",
+ });
+ expect(container.jobs["container"]).toMatchObject({
+ needs: "native",
+ uses: "./.github/workflows/container-validate.yml",
+ });
+ expect(
+ validation.jobs["validate"]?.strategy?.matrix.include.map(
+ ({ architecture }) => architecture,
+ ),
+ ).toEqual(["amd64", "arm64"]);
+ const steps = validation.jobs["validate"]!.steps!;
+ for (const name of [
+ "Verify customer build excludes secrets and scan data",
+ "Reject interactive repository discovery",
+ "Verify hardened Codex command sandbox",
+ "Verify host-scoped Git credentials",
+ "Verify findings API and persistent storage through consumer Compose",
+ ]) {
+ expect(steps.filter((step) => step.name === name)).toHaveLength(1);
+ }
+});
+
+test("keeps container validation available to forks and publication upstream-only", () => {
+ const container = workflow("container-ci");
+ const validation = workflow("container-validate");
+ const release = workflow("container-release");
+ expect(container.jobs["native"]).not.toHaveProperty("if");
+ expect(container.jobs["container"]).not.toHaveProperty("if");
+ expect(validation.jobs["validate"]).not.toHaveProperty("if");
+ for (const name of ["native", "validate", "authorize"]) {
+ expect(release.jobs[name]?.if).toBe(
+ "github.repository == 'openai/codex-security'",
+ );
+ }
+ expect(release.jobs["publish-platform"]?.needs).toBe("authorize");
+});
+
+test.each([
+ ["push", false, "README.md", true],
+ ["pull_request", true, "README.md", true],
+ ["pull_request", false, "README.md", false],
+ ["pull_request", false, "Dockerfile", true],
+ ["pull_request", false, ".github/workflows/container-ci.yml", true],
+ ["pull_request", false, ".github/workflows/container-validate.yml", true],
+ ["pull_request", false, ".github/workflows/container-release.yml", true],
+ ["pull_request", false, ".github/workflows/native-windows.yml", true],
+ ["pull_request", false, ".github/workflows/node-ci.yml", true],
+ ["pull_request", false, "sdk/typescript/src/index.ts", true],
+ [
+ "pull_request",
+ false,
+ "plugins/codex-security/skills/example/SKILL.md",
+ true,
+ ],
+] as const)(
+ "selects container validation for %s / retarget=%p / %s",
+ (eventName, baseChanged, path, selected) => {
+ const directory = mkdtempSync(join(tmpdir(), "container-ci-scope-"));
+ const output = join(directory, "outputs");
+ const script = ci.jobs["validate-title"]!.steps!.find(
+ (step) => step.name === "Decide CI mode",
+ )!.run!;
+ try {
+ const result = spawnSync(
+ bash,
+ ["-c", `git() { printf '%s\\0' "$CHANGED_PATH"; }\n${script}`],
+ {
+ env: {
+ ...process.env,
+ EVENT_NAME: eventName,
+ BASE_CHANGED: String(baseChanged),
+ CHANGED_PATH: path,
+ GITHUB_OUTPUT: output,
+ },
+ },
+ );
+ expect(result.status).toBe(0);
+ const outputs = Object.fromEntries(
+ readFileSync(output, "utf8")
+ .trim()
+ .split("\n")
+ .map((line) => line.split("=")),
+ );
+ expect(outputs["container-validate"]).toBe(String(selected));
+ } finally {
+ rmSync(directory, { recursive: true, force: true });
+ }
+ },
+);
+
+test("required CI rejects failed, cancelled, or skipped selected container checks", () => {
+ const gate = ci.jobs["required-test"]!;
+ expect(gate.needs).toContain("container-validate");
+ expect(gate.if).toBe("always()");
+ const step = gate.steps!.find(
+ (step) => step.name === "Require selected container coverage",
+ )!;
+ expect(step.run).toBe("exit 1");
+ for (const selected of ["true", "false"]) {
+ for (const result of ["success", "failure", "cancelled", "skipped"]) {
+ const condition = step
+ .if!.replaceAll(
+ "needs.validate-title.outputs.container-validate",
+ `'${selected}'`,
+ )
+ .replaceAll("needs.container-validate.result", `'${result}'`);
+ const evaluation = spawnSync(bash, ["-c", `[[ ${condition} ]]`]);
+ expect(evaluation.status, `${selected}/${result}`).toBe(
+ selected === "true" && result !== "success" ? 0 : 1,
+ );
+ }
+ }
+});
diff --git a/sdk/typescript/tests-ts/skeleton.test.ts b/sdk/typescript/tests-ts/skeleton.test.ts
index b5439c3cf..aa514d74e 100644
--- a/sdk/typescript/tests-ts/skeleton.test.ts
+++ b/sdk/typescript/tests-ts/skeleton.test.ts
@@ -198,6 +198,7 @@ describe("TypeScript package skeleton", () => {
"mcp",
"plugin-host",
"plugin-source",
+ "container-validate",
]);
expect(jobs["windows"]?.needs).toEqual([
"validate-title",