litellm/.github/workflows/fips-scan.yml
yuneng-jiang 93445e1fc0
build(docker): build the FIPS image from the main Dockerfile with FLAVOR=fips (#54994)
* build(docker): build the FIPS image from the main Dockerfile with FLAVOR=fips

Dockerfile.fips repeated most of the main Dockerfile, so every shared change had to be made twice. The FIPS steps now live in the main Dockerfile as stages that only --build-arg FLAVOR=fips reaches. The default flavor builds exactly what it built before, and it never pulls the Chainguard base or mounts the cgr-token secret.

The FIPS Scan workflow now runs on every Dockerfile change and reads its uv commands from the builder-deps-fips stage. The FIPS owners also own the shared Dockerfile and its dockerignore.

* test(docker): check the user each flavor's image actually ships with

The non-root test took the last USER line in the Dockerfile, which is now the
fips-check stage's USER root. That stage only feeds a report into final-fips,
so the test failed while both shipped images still run as 65532.

The test now follows each flavor's FROM chain from the final stage and checks
the USER it inherits, for both standard and fips.

* build(docker): keep the FIPS scan inputs out of the default build

The shared dockerignore let scan_bundled_crypto.sh and fips_elf_inventory.txt
into every build, so COPY . . put them in the standard builder image. The
dockerignore is back to main's, and fips-check now reads both files from a
fips-scan build context that FIPS builds pass with
--build-context fips-scan=litellm/deploy/docker. Without it, a FIPS build stops
with an error that names the flag, so the scan cannot be skipped by accident.

* build(docker): run the FIPS scan for every runnable FIPS target

EXPOSE and ENTRYPOINT sat in the shared runtime stage, before fips-check, so
FLAVOR=fips with --target runtime or --target final-standard built a runnable
FIPS image that never ran the scan. Dockerfile.fips only set them after its
scan.

The shared stage is now runtime-app, and runtime resolves to runtime-${FLAVOR},
where runtime-fips copies the fips-check report. EXPOSE and ENTRYPOINT move to
runtime, the last stage, so the default target and compose's target: runtime
build exactly what they built before for the default flavor, and every runnable
FLAVOR=fips target runs the scan. test_dockerfile_fips_scan.py checks that every
FLAVOR=fips stage with an ENTRYPOINT depends on fips-check.

* test(docker): count EXPOSE as runnable when checking the FIPS scan gate

The published FIPS image carries both ENTRYPOINT and EXPOSE, so a FLAVOR=fips stage that only adds EXPOSE is also a runnable image and must depend on fips-check.
2026-11-30 09:47:47 -08:00

117 lines
4.2 KiB
YAML

name: FIPS Scan
on:
pull_request:
branches:
- main
- "litellm_**"
- "rc/**"
- "stable/**"
- "lts/**"
workflow_dispatch:
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
plan:
name: fips scan plan
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
relevant: ${{ steps.changes.outputs.relevant }}
steps:
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
persist-credentials: false
fetch-depth: 2
- name: Detect dependency and FIPS image changes
id: changes
run: |
set -euo pipefail
if ! base="$(git rev-parse --verify --quiet HEAD^2 >/dev/null && git rev-parse HEAD^1)"; then
echo "Not a pull request merge commit, running the full scan."
echo "relevant=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if git diff --name-only "$base" HEAD | grep -Eq '^(uv\.lock|pyproject\.toml|litellm/(enterprise|proxy-extras|packaging/litellm-proxy)/pyproject\.toml|litellm/deploy/docker/(Dockerfile|Dockerfile\.dockerignore|fips_elf_inventory\.txt|scan_bundled_crypto\.sh)|\.github/workflows/fips-scan\.yml)$'; then
echo "relevant=true" >> "$GITHUB_OUTPUT"
else
echo "No dependency or FIPS image changes in this pull request, nothing to scan."
echo "relevant=false" >> "$GITHUB_OUTPUT"
fi
scan:
name: fips scan
needs: plan
if: needs.plan.outputs.relevant == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
container:
image: ghcr.io/astral-sh/uv:0.11.7-python3.13-trixie-slim@sha256:74ee1af27961f5fe73f70146808097ea11e03464cecaac33e60e173dc62e9202
env:
DOCKERFILE: litellm/deploy/docker/Dockerfile
UV_PROJECT_ENVIRONMENT: /app/.venv
UV_LINK_MODE: copy
UV_PYTHON_DOWNLOADS: "0"
steps:
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
with:
persist-credentials: false
- name: Install the build toolchain
run: |
apt-get update -qq
apt-get install -y -qq --no-install-recommends binutils gcc g++ libc6-dev
- name: Install the FIPS image's Python dependencies
run: |
set -eu
stage="$(sed -n '/^FROM [^ ]* AS builder-deps-fips$/,/^FROM /p' "$DOCKERFILE")"
venv="$(printf '%s\n' "$stage" | sed -n 's/^RUN \(uv venv .*\)$/\1/p')"
sync="$(printf '%s\n' "$stage" | sed -n '/^RUN uv sync --frozen --no-install-project /,/[^\\]$/p' | sed '1s/^RUN //')"
if [ -z "$venv" ] || [ -z "$sync" ]; then
echo "Could not find the uv venv and first uv sync commands in the builder-deps-fips stage of $DOCKERFILE"
exit 1
fi
printf '%s\n%s\n' "$venv" "$sync"
sh -ec "$venv"
sh -ec "$sync"
- name: Scan the native binaries
id: scan
run: sh litellm/deploy/docker/scan_bundled_crypto.sh /app/.venv
- name: List the binaries missing from the inventory
if: failure() && steps.scan.outcome == 'failure'
run: |
echo "Review each binary below. If it bundles no crypto, add its line to litellm/deploy/docker/fips_elf_inventory.txt"
SCAN_EMIT_INVENTORY=1 sh litellm/deploy/docker/scan_bundled_crypto.sh /app/.venv \
| grep -Fxv -f litellm/deploy/docker/fips_elf_inventory.txt || true
passed:
name: fips scan passed
needs: [plan, scan]
if: always()
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Require the scan to pass, or to be skipped because nothing relevant changed
env:
PLAN_RESULT: ${{ needs.plan.result }}
RELEVANT: ${{ needs.plan.outputs.relevant }}
SCAN_RESULT: ${{ needs.scan.result }}
run: |
echo "plan: $PLAN_RESULT, relevant: $RELEVANT, scan: $SCAN_RESULT"
test "$PLAN_RESULT" = success
if [ "$RELEVANT" = true ]; then
test "$SCAN_RESULT" = success
else
test "$SCAN_RESULT" = skipped
fi