Skip to content

feat(proxy): add LITELLM_FIPS_MODE for FIPS 140 approved crypto - #38491

Closed
devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fips_mode_lit_5289
Closed

devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fips_mode_lit_5289

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • FIPS-enforced OpenSSL rejects scrypt, so password endpoints crash
  • Default at-rest encryption (XSalsa20-Poly1305) is not FIPS-approved

How it solves it:

  • New LITELLM_FIPS_MODE=true env var opts into FIPS-approved crypto
  • Password hashing and master-key KDFs switch to PBKDF2-HMAC-SHA256
  • At-rest credential encryption is forced to AES-256-GCM
  • Non-approved configs and legacy scrypt hashes fail with actionable errors

Root cause in one sentence: under an enforced OpenSSL FIPS provider, hashlib.scrypt raises ValueError: [digital envelope routines] unsupported, which breaks proxy password hashing, verification, rehash, and MCP key derivation, while the default XSalsa20-Poly1305 at-rest encryption runs but is not a FIPS-approved algorithm

User Flow

Before: an admin running the proxy on a FIPS-enforced host cannot set user passwords

  1. They send POST http://localhost:4000/user/update with {"user_id": "...", "password": "Str0ngPass!123"}
  2. The proxy returns HTTP 400 with "Authentication Error, [digital envelope routines] unsupported" and the password is never stored
  3. Any UI login against a stored password hash fails the same way, so no one can log in to http://localhost:4000/ui

After: the same admin sets LITELLM_FIPS_MODE=true and everything works with FIPS-approved algorithms

  1. They start the proxy with LITELLM_FIPS_MODE=true on the same FIPS-enforced host
  2. They send the same POST http://localhost:4000/user/update and get HTTP 200; the stored hash is PBKDF2-HMAC-SHA256
  3. POST http://localhost:4000/login with that password returns 303 to /ui?login=success, and a wrong password returns 401
  4. POST http://localhost:4000/credentials stores the credential encrypted with AES-256-GCM (v2:gcm: values at rest)
  5. If a user still has an old scrypt hash, login fails closed with a log telling the admin to reset that password

Relevant issues

Related context: #16789, #25861 (prior draft explorations in #28729, #28730)

Linear ticket

Resolves LIT-5289

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/test_litellm/<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
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

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 runs were captured on a live proxy on localhost:4000 with Postgres, running under an enforced OpenSSL 3.0.2 FIPS provider (OPENSSL_CONF with default_properties = fips=yes, self-built fips.so, openssl fipsinstall verified). The control chat completion hits the real OpenAI API. The /user/update fixture is byte-identical across both arms

Before (cd63c7e)

Control: real chat completion succeeds

  1. curl -s http://localhost:4000/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Say FIPS-CONTROL-OK and nothing else"}]}'
  2. {"id":"chatcmpl-EHPog77tVg5k5tTymBBMLzP00vbbq",...,"content":"FIPS-CONTROL-OK",...} (HTTP 200, real tokens billed)

Setting a user password fails

  1. curl -s -w '\nHTTP %{http_code}\n' http://localhost:4000/user/update -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d '{"user_id":"5c416115-a50b-4f31-8816-4bd6e07d962a","password":"Str0ngPass!123"}'
  2. {"error":{"message":"Authentication Error, [digital envelope routines] unsupported","type":"auth_error","param":"None","code":"400"}} with HTTP 400
  3. Proxy log: litellm.proxy.proxy_server.user_update(): Exception occured - [digital envelope routines] unsupported / ValueError: [digital envelope routines] unsupported

After (captured at 08faa586a2, runtime code byte-identical to tip db8ffcb; the only later change is a test expectation string)

Proxy restarted on the fixed code with LITELLM_FIPS_MODE=true, same FIPS OpenSSL env

Control: real chat completion succeeds

  1. Same curl as Before with content "Say FIPS-FIXED-OK and nothing else"
  2. {"id":"chatcmpl-EHPqpLO498yYFHB332ahosMzWWSrP",...,"content":"FIPS-FIXED-OK",...} (HTTP 200)

Setting a user password succeeds and stores PBKDF2

  1. Byte-identical curl ... /user/update as Before
  2. HTTP 200 with the updated user object
  3. select left(password,10) from "LiteLLM_UserTable" where user_email='fips-repro@example.com'; returns pbkdf2:Fys

UI login verifies the PBKDF2 hash

  1. curl -s -o /dev/null -w 'HTTP %{http_code} redirect=%{redirect_url}\n' -X POST http://localhost:4000/login -d "username=fips-repro@example.com&password=Str0ngPass!123" returns HTTP 303 redirect=http://localhost:4000/ui?login=success
  2. The same request with password=WrongPass returns HTTP 401

Credential written at rest with AES-256-GCM

  1. curl -s -w '\nHTTP %{http_code}\n' http://localhost:4000/credentials -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d '{"credential_name":"fips-test-cred","credential_info":{},"credential_values":{"api_key":"sk-fips-demo-123"}}' returns {"success":true,...} with HTTP 200
  2. select credential_name, left(credential_values::text,60) from "LiteLLM_CredentialsTable" ... returns fips-test-cred|{"api_key": "v2:gcm:EDX194oCxoGDwd-2qjuXFMbMGqWxU2R1GPmVzTCi

Legacy scrypt hash fails closed with an actionable error

  1. A user row is given a pre-existing scrypt: hash, then curl ... POST /login with the correct password returns HTTP 401
  2. Proxy log: Cannot verify a scrypt password hash under LITELLM_FIPS_MODE: scrypt is not FIPS-approved. Reset this user's password so it is re-hashed with PBKDF2-HMAC-SHA256.

Type

🆕 New Feature

Caveats (if any)

Medium

  • Existing scrypt: password hashes cannot verify under FIPS mode; admins must reset those passwords (fails closed with a log naming the fix)
  • Toggling LITELLM_FIPS_MODE changes the MCP master-key KDF, invalidating outstanding MCP bridge/session tokens minted under the other mode

Low

  • MCP envelope sealing (_experimental/mcp_server/outbound_credentials/envelope.py) still uses libsodium SecretBox directly; it runs fine under FIPS enforcement but is outside the approved-algorithm boundary, left for a follow-up since changing it alters the envelope wire format
  • Pre-existing XSalsa20 ciphertexts still decrypt under FIPS mode for migration readback; only new writes are forced to AES-256-GCM
  • Scope note: the live proof exercises /user/update (hash), /login (verify), and /credentials (encrypt); /user/new ignores the password field entirely, and invitation onboarding plus the startup plaintext migration reuse the same hash_password chokepoint fixed here

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

Link to Devin session: https://app.devin.ai/sessions/c5c84e8fc1a64efebc61816ad93510a3
Open in Devin Desktop: https://app.devin.ai/desktop/session/c5c84e8fc1a64efebc61816ad93510a3?variant=devin
Requested by: @yassin-berriai

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

No action taken on #38491 — repo and author (devin-ai-integration[bot]) match, but the PR has no labels, so the required enterprise label is absent. No GitHub or Linear mutations made.

@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds an opt-in FIPS mode that uses PBKDF2-HMAC-SHA256 for password and master-key derivation and AES-256-GCM for new encrypted values

  • Adds centralized FIPS mode and key-derivation helpers
  • Updates password hashing, verification, and rehash selection
  • Applies FIPS-aware derivation to MCP bridge and session credentials
  • Adds regression coverage for password, encryption, migration, and MCP behavior

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains

No blocking failure remains

Important Files Changed

Filename Overview
litellm/proxy/common_utils/fips.py Adds environment-driven FIPS selection and shared PBKDF2 or scrypt master-key derivation
litellm/proxy/common_utils/encrypt_decrypt_utils.py Forces AES-256-GCM for new writes in FIPS mode while retaining format-aware decryption
litellm/proxy/utils.py Adds PBKDF2 password hashing and verification while preserving existing hash formats outside FIPS mode
litellm/proxy/auth/login_utils.py Selects the current password-hash prefix according to FIPS mode when deciding whether to rehash
litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py Moves bridge signing and encryption key derivation to the shared FIPS-aware helper
litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py Moves MCP session signing-key derivation to the shared FIPS-aware helper

Reviews (2): Last reviewed commit: "feat(proxy): add LITELLM_FIPS_MODE for F..." | Re-trigger Greptile

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_fips_mode_lit_5289 branch from 08faa58 to db8ffcb Compare August 27, 2026 08:50
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review the new head db8ffcb (squashed, includes a CI test expectation fix)

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...itellm/proxy/common_utils/encrypt_decrypt_utils.py 83.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

The raise is intentional fail-closed behavior: an explicit encryption_algorithm: xsalsa20-poly1305 under LITELLM_FIPS_MODE is an unsupported configuration, and the ticket requires unsupported configs to fail clearly with an actionable error rather than silently write non-approved ciphertext. A failure-as-value return here would have to be mapped back to an error at every write site anyway; raising at the single chokepoint keeps that contract in one place, and the message tells the operator exactly which setting to change.

@codspeed

codspeed Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fips_mode_lit_5289 (db8ffcb) with litellm_internal_staging (8ebcb3e)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (cd63c7e) during the generation of this report, so 8ebcb3e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@yassin-berriai

Copy link
Copy Markdown
Contributor

@yucheng-berri pls update on status for FIPS

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