Skip to content

feat(docker): install cryptography, grpcio and libpq from chainguard apks in the fips image - #52997

Merged
yucheng-berri merged 2 commits into
mainfrom
litellm_fips_chainguard_apks
Nov 20, 2026
Merged

yucheng-berri merged 2 commits into
mainfrom
litellm_fips_chainguard_apks

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

How it solves it:

  • Chainguard's apks for all three link the image's FIPS OpenSSL
  • The venv now sees system packages and skips the three PyPI wheels
  • The scan waivers for the bundled copies are gone, so a returning wheel fails the build
  • A build check fails the image if the apk grpc or libpq stops linking the image's FIPS OpenSSL, since the apks are not version-pinned

This covers C2 (LIT-8433) and C4 (LIT-8435), and it replaces #52263's source build for C3 (LIT-8434). Only the FIPS image changes. The regular image is untouched.

User Flow

Before: an operator runs the FIPS image against a Postgres or gRPC server that offers ChaCha20, and those connections use ChaCha20 outside the FIPS module

  1. They start the FIPS image with general_settings.fips_mode: true and a DATABASE_URL with sslmode=require
  2. The Postgres log shows the boot migration login and 4 of 10 litellm-prisma logins on ECDHE-RSA-CHACHA20-POLY1305
  3. A gRPC client in the image (OTel gRPC exporter, control-plane audit sink) completes a handshake with a ChaCha20-only server

After: the same connections use AES-GCM through the FIPS module, and a ChaCha20-only server is refused

  1. They start the FIPS image with the same config
  2. The Postgres log shows the boot migration login and all 10 litellm-prisma logins on ECDHE-RSA-AES256-GCM-SHA384
  3. The gRPC handshake with the ChaCha20-only server fails with no shared cipher

Linear ticket

Resolves LIT-8433
Resolves LIT-8435

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Both images were built on an x86_64 VM from the pinned Chainguard FIPS base in Dockerfile.fips, with the FIPS provider openssl-provider-fips-3.4.0 3.4.0-r5.

Before is #52263 at cc3a0907114. It is main's FIPS image plus the cryptography source build, with the same grpcio and psycopg-binary wheels as main. On main itself, the cryptography wheel also bundles its own OpenSSL and fips_mode: true cannot boot (see #52263).

After was built from 8eec05f37cd (#52263 merged with the merged FIPS image PR) with this PR's Dockerfile.fips and scan change applied. Main has not touched Dockerfile.fips, the scan files, or these three packages in uv.lock since then. The only other difference is the builder's pkgconf, which only the cryptography source build needed.

Head rebuild (4fcd7ccf177, amd64 and arm64)

The PR head was rebuilt on both architectures and run through the same checks below plus a production matrix. On both, psycopg and grpc refuse a ChaCha20-only server, chat works over AES-GCM, and client-certificate login works with PGSSLCERT/PGSSLKEY.

Production matrix: 23 of 23 pass on amd64 and arm64 head, same as the amd64 baseline cc3a0907114
Case amd64 head arm64 head amd64 baseline
Postgres 16: no TLS, TLS 1.3 + SCRAM, verify-full, no sslmode, md5 password pass pass pass
Postgres 16 verify-full, wrong host name is refused pass pass pass
Postgres 13 and 17 over TLS pass pass pass
Restart on an existing DB, two replicas booting at once pass pass pass
Model added via /model/new, survives restart (stored key v2:gcm:) pass pass pass
grpc asyncio over TLS (ChaCha20-only server refused), grpc with public roots pass pass pass
OTel gRPC: TLS, plaintext, TLS with 4 workers (14 spans each) pass pass pass
Arize over real gRPC pass pass pass
License RSA verify, JWT RS256 auth (tampered token gets 401) pass pass pass
Vertex service-account token signed by cryptography pass pass pass
Read-only root filesystem, OpenShift random UID pass pass pass
fips_mode off pass pass pass

Shared setup, on one docker network, with server names prefixed by <prefix> (<prefix>pg is pgmix below):

  • pgmix: Postgres 16, TLS 1.2, ssl_ciphers=ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384, ssl_prefer_server_ciphers=on, so it picks ChaCha20 whenever the client offers it
  • pgchacha: the same, with ssl_ciphers=ECDHE-RSA-CHACHA20-POLY1305 only
  • raw:4443 and raw:4444: TLS 1.2 servers with the same two cipher lists that log the cipher each handshake picked
  • grpc:50051: a TLS gRPC echo server
  • The client below runs inside the image under test with GRPC_SSL_CIPHER_SUITES=ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384, so gRPC offers ChaCha20 first. A FIPS OpenSSL drops it, a bundled BoringSSL keeps it
  • The proxy runs with the config below, DATABASE_URL=postgresql://postgres:pw@pgmix:5432/litellm?sslmode=require and LITELLM_LOCAL_MODEL_COST_MAP=True, with an OpenAI-compatible TLS upstream that logs the cipher
Postgres, servers, client and proxy config
docker run -d --name pgmix --network fips -v $PWD/c:/c:ro -e POSTGRES_PASSWORD=pw -e POSTGRES_DB=litellm --entrypoint bash postgres:16 -c \
  'cp /c/srv.key /tmp/k && chown postgres /tmp/k && chmod 600 /tmp/k && exec docker-entrypoint.sh postgres -c ssl=on \
   -c ssl_cert_file=/c/srv.pem -c ssl_key_file=/tmp/k -c ssl_max_protocol_version=TLSv1.2 \
   -c ssl_ciphers=ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384 -c ssl_prefer_server_ciphers=on -c log_connections=on'
docker run --rm --network fips -v $PWD/c:/c:ro --entrypoint /app/.venv/bin/python <image> /c/client.py <prefix>
# tlsraw.py <port> <ciphers>
import socket, ssl, sys, threading
port, ciphers = int(sys.argv[1]), sys.argv[2]
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.minimum_version = ctx.maximum_version = ssl.TLSVersion.TLSv1_2
ctx.set_ciphers(ciphers)
ctx.options |= ssl.OP_CIPHER_SERVER_PREFERENCE
ctx.set_alpn_protocols(["h2", "http/1.1"])
ctx.load_cert_chain("/c/srv.pem", "/c/srv.key")
ls = socket.create_server(("0.0.0.0", port))
def serve(c):
    try:
        s = ctx.wrap_socket(c, server_side=True)
        print(f"HANDSHAKE {s.version()} cipher={s.cipher()[0]} alpn={s.selected_alpn_protocol()}", flush=True)
        s.close()
    except Exception as e:
        print(f"HANDSHAKE-FAIL {type(e).__name__}: {str(e)[:120]}", flush=True)
while True:
    c, _ = ls.accept(); threading.Thread(target=serve, args=(c,), daemon=True).start()
# grpcecho.py
import sys, time, grpc
from concurrent import futures
def say(request, context):
    print(f"RPC from {context.peer()} transport={dict(context.auth_context()).get('transport_security_type')}", flush=True)
    return b"echo:" + request
handler = grpc.method_handlers_generic_handler("capk.Echo", {"Say": grpc.unary_unary_rpc_method_handler(say)})
srv = grpc.server(futures.ThreadPoolExecutor(4))
srv.add_generic_rpc_handlers((handler,))
creds = grpc.ssl_server_credentials([(open("/c/srv.key", "rb").read(), open("/c/srv.pem", "rb").read())])
srv.add_secure_port("0.0.0.0:50051", creds)
srv.start(); print("listening", flush=True)
while True: time.sleep(3600)
# client.py <prefix>, run inside the image under test
import importlib, importlib.metadata as md, importlib.util, os, sys
# Same client cipher list for every image: offer ChaCha20 first. A FIPS OpenSSL drops it, a bundled BoringSSL keeps it.
os.environ["GRPC_SSL_CIPHER_SUITES"] = "ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384"
pfx = sys.argv[1]
def section(t): print(f"== {t}", flush=True)
section("where each package comes from")
for mod, dist in (("cryptography", "cryptography"), ("grpc", "grpcio"), ("psycopg", "psycopg")):
    m = importlib.import_module(mod)
    print(f"  {mod:13s} {md.version(dist):10s} {m.__file__}")
print("  psycopg_binary installed:", importlib.util.find_spec("psycopg_binary") is not None)
import psycopg
print("  psycopg implementation:", psycopg.pq.__impl__, "| libpq version:", psycopg.pq.version())
from cryptography.hazmat.bindings._rust import openssl as o
print("  cryptography links:", o.openssl_version_text(), "| fips_enabled:", o.is_fips_enabled())
section("cryptography: what the loaded OpenSSL allows")
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.ciphers.aead import AESGCM, ChaCha20Poly1305
from cryptography.hazmat.primitives.asymmetric import x25519
def attempt(label, fn):
    try:
        fn(); print(f"  {label}: ALLOWED")
    except Exception as e:
        print(f"  {label}: REFUSED ({type(e).__name__})")
attempt("MD5 hash", lambda: hashes.Hash(hashes.MD5()).finalize())
attempt("ChaCha20-Poly1305 encrypt", lambda: ChaCha20Poly1305(ChaCha20Poly1305.generate_key()).encrypt(b"\0" * 12, b"x", None))
attempt("X25519 keygen", lambda: x25519.X25519PrivateKey.generate())
attempt("AES-256-GCM encrypt", lambda: AESGCM(AESGCM.generate_key(256)).encrypt(b"\0" * 12, b"x", None))
attempt("SHA-256 hash", lambda: hashes.Hash(hashes.SHA256()).finalize())
section("grpc over TLS")
import grpc
creds = grpc.ssl_channel_credentials(open("/c/ca.pem", "rb").read())
try:
    ch = grpc.secure_channel(f"{pfx}grpc:50051", creds, options=(("grpc.ssl_target_name_override", f"{pfx}pg"),))
    print("  echo RPC ->", ch.unary_unary("/capk.Echo/Say")(b"hello", timeout=15))
    ch.close()
except Exception as e:
    print("  echo RPC FAILED:", type(e).__name__, str(e)[:200])
opts = (("grpc.ssl_target_name_override", f"{pfx}pg"),)
for name, port in (("rawmix (prefers ChaCha20, also offers AES-GCM)", 4443), ("rawchacha (ChaCha20 only)", 4444)):
    ch = grpc.secure_channel(f"{pfx}raw:{port}", creds, options=opts)
    try:
        grpc.channel_ready_future(ch).result(timeout=4)
    except Exception:
        pass
    ch.close()
    print(f"  handshake attempted with {name}; see server log")
section("psycopg over TLS")
for name, host in (("pgmix (prefers ChaCha20, also offers AES-GCM)", f"{pfx}pg"), ("pgchacha (ChaCha20 only)", f"{pfx}pgchacha")):
    try:
        with psycopg.connect(f"host={host} dbname=litellm user=postgres password=pw sslmode=require", connect_timeout=10) as c:
            print(f"  {name}: connected,", c.execute("select version, cipher from pg_stat_ssl where pid = pg_backend_pid()").fetchone())
    except Exception as e:
        print(f"  {name}: FAILED {type(e).__name__}: {str(e).strip().splitlines()[0][:160]}")
section("crypto libraries mapped into this process")
seen = sorted({l.split()[-1] for l in open("/proc/self/maps") if any(k in l for k in ("ssl", "crypto", "fips", "ossl-modules", "libpq", "cygrpc", "sodium", "psycopg"))})
for p in seen: print("  ", p)
model_list:
  - model_name: gpt
    litellm_params: {model: openai/gpt-4.1-mini, api_base: "https://up:4433/v1", api_key: sk-dummy}
general_settings:
  fips_mode: true

Before (cc3a0907114)

  1. Client in the image
== where each package comes from
  cryptography  50.0.0     /app/.venv/lib/python3.13/site-packages/cryptography/__init__.py
  grpc          1.84.1     /app/.venv/lib/python3.13/site-packages/grpc/__init__.py
  psycopg       3.3.6      /app/.venv/lib/python3.13/site-packages/psycopg/__init__.py
  psycopg_binary installed: True
  psycopg implementation: binary | libpq version: 180006
  cryptography links: OpenSSL 4.0.3 29 Sep 2026 | fips_enabled: True
== cryptography: what the loaded OpenSSL allows
  MD5 hash: ALLOWED
  ChaCha20-Poly1305 encrypt: REFUSED (UnsupportedAlgorithm)
  X25519 keygen: REFUSED (UnsupportedAlgorithm)
  AES-256-GCM encrypt: ALLOWED
  SHA-256 hash: ALLOWED
== grpc over TLS
  echo RPC -> b'echo:hello'
  handshake attempted with rawmix (prefers ChaCha20, also offers AES-GCM); see server log
  handshake attempted with rawchacha (ChaCha20 only); see server log
== psycopg over TLS
  pgmix (prefers ChaCha20, also offers AES-GCM): connected, ('TLSv1.2', 'ECDHE-RSA-CHACHA20-POLY1305')
  pgchacha (ChaCha20 only): connected, ('TLSv1.2', 'ECDHE-RSA-CHACHA20-POLY1305')
  1. raw server log for the gRPC handshakes (4443 then 4444, gRPC retries each)
HANDSHAKE TLSv1.2 cipher=ECDHE-RSA-CHACHA20-POLY1305 alpn=h2   (x6)
  1. Proxy with fips_mode: true. /key/generate, then POST /v1/chat/completions with the new key returns 200. Postgres logins during boot and traffic, by application_name and cipher
1 (no app name)  ECDHE-RSA-CHACHA20-POLY1305
1 litellm-native ECDHE-RSA-CHACHA20-POLY1305
6 litellm-prisma ECDHE-RSA-AES256-GCM-SHA384
4 litellm-prisma ECDHE-RSA-CHACHA20-POLY1305

After (8eec05f37cd + this change)

  1. Client in the image
== where each package comes from
  cryptography  50.0.2     /usr/lib/python3.13/site-packages/cryptography/__init__.py
  grpc          1.84.3     /usr/lib/python3.13/site-packages/grpc/__init__.py
  psycopg       3.3.6      /app/.venv/lib/python3.13/site-packages/psycopg/__init__.py
  psycopg_binary installed: False
  psycopg implementation: python | libpq version: 180007
  cryptography links: OpenSSL 4.0.3 29 Sep 2026 | fips_enabled: True
== cryptography: what the loaded OpenSSL allows
  MD5 hash: ALLOWED
  ChaCha20-Poly1305 encrypt: REFUSED (UnsupportedAlgorithm)
  X25519 keygen: REFUSED (UnsupportedAlgorithm)
  AES-256-GCM encrypt: ALLOWED
  SHA-256 hash: ALLOWED
== grpc over TLS
  echo RPC -> b'echo:hello'
  handshake attempted with rawmix (prefers ChaCha20, also offers AES-GCM); see server log
I1120 00:45:23.078885      24 ssl_transport_security.cc:2544] Handshake failed with error SSL_ERROR_SSL: error:0A000410:SSL routines::tls alert handshake failure
I1120 00:45:23.945689      14 ssl_transport_security.cc:2544] Handshake failed with error SSL_ERROR_SSL: error:0A000410:SSL routines::tls alert handshake failure
I1120 00:45:25.573502      11 ssl_transport_security.cc:2544] Handshake failed with error SSL_ERROR_SSL: error:0A000410:SSL routines::tls alert handshake failure
  handshake attempted with rawchacha (ChaCha20 only); see server log
== psycopg over TLS
  pgmix (prefers ChaCha20, also offers AES-GCM): connected, ('TLSv1.2', 'ECDHE-RSA-AES256-GCM-SHA384')
  pgchacha (ChaCha20 only): FAILED OperationalError: connection failed: connection to server at "172.19.0.5", port 5432 failed: SSL error: tls alert handshake failure
  1. raw server log for the gRPC handshakes
HANDSHAKE TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 alpn=h2   (x3, port 4443)
HANDSHAKE-FAIL SSLError: [SSL: NO_SHARED_CIPHER] no shared cipher (_ssl.c:1082)   (x3, port 4444)
  1. Proxy with fips_mode: true. /key/generate, then POST /v1/chat/completions with the new key returns 200, and the upstream saw ECDHE-RSA-AES256-GCM-SHA384. The proxy worker maps /usr/lib/libpq.so.5.18, /usr/lib/ossl-modules/fips.so and the apk's cryptography _rust.abi3.so. Postgres logins
 1 (no app name)  ECDHE-RSA-AES256-GCM-SHA384
 1 litellm-native ECDHE-RSA-CHACHA20-POLY1305
10 litellm-prisma ECDHE-RSA-AES256-GCM-SHA384
  1. Build-time checks in the fips-check stage: openssl-fips-test passes, the cryptography is_fips_enabled() assert passes, and the scan prints PASS: all 113 ELF binaries accounted for with the grpc and psycopg waivers removed. At cf808c19f0c the amd64 image builds again with the new grpc and libpq check passing (#57 DONE 0.8s)

    The new check needs libssl.so.4 in the library's NEEDED list and no defined SSL_, EVP_ or BIO_ symbols. It finds grpc's cygrpc module by import and libpq by what psycopg loads. Run against each library on its own:

    Library libssl it needs Check
    apk grpc cygrpc, amd64 and arm64 libssl.so.4 pass
    apk libpq.so.5.18, amd64 and arm64 libssl.so.4 pass
    PyPI grpcio 1.84.1 cygrpc (BoringSSL linked in) none fail
    PyPI psycopg-binary 3.3.9 libpq its own libssl-6a9b88ec.so.3 fail

    The arm64 rows ran on the arm64 head image's libraries. The arm64 image was not rebuilt for this commit

  2. tests/code_coverage_tests/test_scan_bundled_crypto.py passes locally (52 tests). The new cases fail the scan for a PyPI grpcio or psycopg-binary binary that bundles TLS

Type

🚄 Infrastructure
✅ Test

Behavior changes

Removed / renamed

  • FIPS image only. The PyPI grpcio and psycopg-binary wheels and the source-built cryptography are no longer installed

Silent regressions to watch

  • FIPS image versions move off uv.lock. grpcio is 1.84.3 (pyproject pins 1.84.1), cryptography is 50.0.2 (lock has 50.0.0)
  • psycopg uses its pure-Python implementation on the system libpq 18. It is only used by the boot migration step
  • gRPC and Postgres servers that only offer ChaCha20 or other non-FIPS ciphers are now refused. That is the point of the image

Migration for existing customers

  • None. The FIPS image has not been published

Regression tests

  • test_pypi_grpcio_and_psycopg_binary_tls_fails pins that the bundled copies fail the scan
  • The fips-check stage fails the build if the apk grpc or libpq stops linking libssl.so.4 or brings its own TLS

Caveats (if any)

High

Medium

  • The three apks are not version-pinned
    • The Chainguard repo keeps every version, and apk installs the newest one at build time
    • Tested with py3.13-cryptography 50.0.2-r6, py3.13-grpcio-1.84 1.84.3-r0 and libpq-18 18.7-r0
  • A pip-style metadata check reports grpcio==1.84.1 unmet and psycopg-binary missing. Nothing checks this at runtime

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Devin Review


Note

High Risk
Changes how the FIPS image supplies TLS for Postgres, gRPC, and cryptography; misconfiguration could break DB/OTel connectivity or weaken FIPS guarantees.

Overview
The FIPS Docker image no longer installs PyPI cryptography, grpcio, or psycopg-binary. The builder creates a venv with system site packages and uv sync skips those three packages; the runtime stage pulls py3.13-cryptography, py3.13-grpcio-1.84, and libpq-18 from Chainguard so TLS uses the image’s FIPS OpenSSL instead of bundled wheels.

Build-time enforcement is tightened: the fips-check stage asserts cryptography reports FIPS enabled, fips_elf_inventory.txt drops grpc/psycopg wheel binaries, and scan_bundled_crypto.sh removes waivers for cryptography, grpcio, and psycopg-binary—so any returning bundled-TLS wheels fail the build. Tests add cases that those PyPI artifacts are violations, not waived paths.

Reviewed by Cursor Bugbot for commit 4fcd7cc. Bugbot is set up for automated code reviews on this repo. Configure here.

…apks in the fips image

The PyPI grpcio and psycopg-binary wheels carry their own TLS, so their
connections never reach the FIPS provider. Chainguard builds all three
packages against its FIPS OpenSSL, so the venv now sees system packages,
skips the three wheels, and the runtime stage installs the apks. The
scan waivers for the bundled copies are gone, so a wheel that slips back
in fails the build.
@veria-ai

veria-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous library-check gap addressed.

Summary

The FIPS image replaces PyPI TLS libraries with Chainguard packages.

  • The FIPS image loads crypto and database packages from Chainguard.
  • FIPS image builds reject bundled TLS libraries and check package links.

No new actionable issues were found in the changes since the previous review.

Reviews (2) · Last reviewed commit: "fix(docker): check that the apk grpc and..." · Reviewed by Greptile

Comment thread litellm/deploy/docker/Dockerfile.fips Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4fcd7cc. Configure here.

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri
yucheng-berri merged commit 75f71a8 into main Nov 20, 2026
48 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_fips_chainguard_apks branch November 20, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants