Repository navigation
fix(mcp): derive MCP bridge and session keys with the FIPS provider's KBKDF - #50032
Conversation
… KBKDF With OpenSSL enforcing FIPS, hashlib.scrypt raises, so every MCP session token and bridge envelope request failed with a 500. Under FIPS the keys now come from LITELLM_SALT_KEY through SP 800-108r1 KBKDF run by the provider's EVP_KDF. Without FIPS the scrypt keys are unchanged
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Pass the master key as the KBKDF context, so rotating it changes the three FIPS-mode keys as it changes the scrypt keys
|
bugbot run |
[Medium impact] The PR appears safe to merge, with no new actionable issues established. SummaryThis PR derives MCP session and bridge keys through OpenSSL KBKDF when
Reviews (8) · Last reviewed commit: "Pin the MCP key KBKDF fetch to the FIPS ..." · Reviewed by Greptile |
|
bugbot run |
…de is on On a FIPS OpenSSL 1.1.1 host (RHEL 8) scrypt still works, so keying the switch on openssl_enforces_fips() sent those hosts to the OpenSSL 3 only KBKDF and broke MCP sessions and bridge envelopes that worked on main. fips_mode_active() is the same reader B1 adds, set by enforce_fips_mode at startup.
|
bugbot run |
# Conflicts: # litellm/proxy/common_utils/fips.py
|
bugbot run |
# Conflicts: # tests/unit/proxy/common_utils/test_fips.py
|
bugbot run |
#49874 landed fips_mode_active, so this branch drops its copy and its test fixtures now build on the shared fips_openssl and fips_mode ones.
|
bugbot run |
The KBKDF helper derives keys from LITELLM_SALT_KEY, so it now sits next to the other salt key helpers, and fips.py goes back to main's version.
|
bugbot run |
Fetch KBKDF with the property query fips=yes, so a change to the process's default properties after boot can't move the derivation to a non-FIPS provider. The shared fips_openssl test fixture drops the pin, since the test OpenSSL has no FIPS provider.
|
bugbot run |
There was a problem hiding this comment.
✅ 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 21abe3c. Configure here.
Handwritten 1-3 sentence description
<make-me-human-readable>With
general_settings.fips_mode: true, every MCP gateway sign-in and every bridged MCP call failed with a 500, because the keys that sign those tokens were derived with scrypt, which a FIPS OpenSSL 3 refuses. Withfips_modeon, those keys now come from the salt key through the FIPS provider's own key derivation, so MCP sign-in and bridged calls work. Withoutfips_modenothing changes, on any OpenSSL, and tokens already issued keep working</make-me-human-readable>Details
TLDR
Problem this solves:
fips_modeon, MCP session sign-in and bridge tokens always return 500How it solves it:
general_settings.fips_mode: true, derive the three MCP keys fromLITELLM_SALT_KEYfips_mode_active(), B1's reader from feat(proxy): hash UI passwords with PBKDF2 in FIPS mode #49874, set when the boot gate acceptsfips_modeEVP_KDF, fetched withfips=yes, from a helper inencrypt_decrypt_utils.pynext to the other salt key helpersLITELLM_SALT_KEYmust then be hex of at least 32 bytesfips_mode, the scrypt keys are byte-identical on any OpenSSL, pinned by test vectorsWhy the salt key and not the master key:
openssl rand -hex 32run in the FIPS image, where every random generator comes from thefipsproviderfipsprovider also refuses KBKDF keys under 112 bits (SP 800-131Ar2 §8), so a short master key such assk-1234can't be a KDK at all. In the Chainguard image,openssl kdf ... KBKDFwith it returnsKDF parameter errorUser Flow
Before: on a FIPS deployment, a user connecting an MCP client to the gateway can't sign in or call tools
general_settings.fips_mode: trueon a FIPS host500 Internal server errorinstead of a session tokenAfter: the same deployment signs the user in and serves tool calls
general_settings.fips_mode: trueandLITELLM_SALT_KEY=sk-$(openssl rand -hex 32)llm_session_...token pair, and POST https://litellm-domain/mcp tool calls answerllm_env_...token, and POST https://litellm-domain/mcp/ tool calls answerLinear ticket
Resolves LIT-8426
Behavior changes
Removed / renamed
Silent regressions to watch
fips_mode: the scrypt keys are unchanged on any OpenSSL, so issued tokens keep openingfips_mode: true, MCP session and bridge tokens are signed with keys fromLITELLM_SALT_KEY, notmaster_keyfips_modeon exists to breakfips_modestops opening once it is turned on (401, was 500)master_keystill invalidates them, since it is the KBKDF contextfips=yes, so if code in the process repoints OpenSSL's default provider after boot, these requests return 500 instead of using a non-FIPS keyMigration for existing customers
fips_mode. Deployments withfips_mode: truesetLITELLM_SALT_KEYtosk-$(openssl rand -hex 32)or longer hexRegression tests
test_envelope_keys_without_fips_stay_the_scrypt_keys_of_the_master_keyandtest_session_key_without_fips_stays_the_scrypt_key_of_the_master_keypin today's keystest_envelope_keys_on_a_fips_openssl_without_fips_mode_stay_the_scrypt_keysandtest_session_key_on_a_fips_openssl_without_fips_mode_stays_the_scrypt_keypin today's keys on a FIPS OpenSSL withfips_modeofftest_keys_under_fips_come_from_the_salt_key_are_distinct_and_the_same_on_every_callpins the three FIPS keystest_keys_under_fips_all_change_when_the_master_key_rotatespins master key rotation under FIPStest_envelope_keys_under_fips_refuse_a_salt_key_that_is_not_32_bytes_of_hexandtest_session_key_under_fips_refuses_an_unset_salt_keypin the refusaltest_derive_key_from_salt_key_is_sp800_108_counter_mode_hmac_sha256checks the KDF against the SP 800-108 formula computed by handtest_derive_key_from_salt_key_refuses_an_openssl_without_a_fips_providerpins thefips=yesfetchMutations, each run on the four test files (141 tests) at 4842d13, red then restored green:
openssl_enforces_fips(): 1 failed (FIPS OpenSSL withoutfips_mode)openssl_enforces_fips(): 1 failed (same, envelope)fips_mode: 8 failedPin mutations at 21abe3c, each run on
test_encrypt_decrypt_utils.pyandtests/unit/proxy/mcp_server/outbound_credentials(882 tests), red then restored green:fips=yesquery dropped: 1 failed (no-FIPS-provider test)fips=no: 1 failed (same)fips_opensslfixture keeps the pin: 4 failed, so the FIPS-mode tests run the real fetchPre-Submission checklist
uv run pytest tests/unit/<your_test_file>.py -vScreenshots / Proof of Fix
Rig: a UBI 9 container with OpenSSL 3.5.8 and Red Hat's FIPS provider, CPython 3.13.14 and
cryptography50 built from source against that OpenSSL, plus Postgres 16. FIPS host meansOPENSSL_CONF=/etc/ssl/openssl-fips.cnf, standard host means it is unset. All 225 migrations were applied withpsqland the proxy ran withDISABLE_SCHEMA_UPDATE=true, because psycopg-binary breaks real migrations underOPENSSL_CONF. One worker, no Redis, so the QA recipe's two workers and shared Redis were dropped here. A scripted OAuth server and a local MCP server with anaddtool sit behind the proxy. The Chainguard FIPS image results are in their own section at the endSession sign-in is
POST /register,GET /authorizewith a UI session cookie,POST /authorize/complete, thenPOST /tokenwith the code. The bridge serverw5bridgeisoauth_delegatewithdcr_bridge: true. Tokens below are cut to their prefixesBefore (527d882)
fips_mode on, FIPS host
POST /register,GET /authorize,POST /authorize/complete-> 201, 303, 303 withcode=llm_gcode_...POST /tokengrantauthorization_code->500 {"error":{"message":"Internal server error","type":"internal_server_error"}}POST /introspectwith any session token, real or garbage -> the same 500POST /mcpwithBearer llm_session_...->500 {"error":"MCP request failed","details":"[digital envelope routines] unsupported"}POST /w5bridge/token-> 500, andPOST /mcp/w5bridgewithBearer llm_env_...-> the same/mcp500ValueError: [digital envelope routines] unsupportedraised byhashlib.scryptFIPS host, fips_mode unset
Standard host
POST /token-> 200llm_session_...pair,POST /mcptools/calladd(20, 22)-> 20042POST /w5bridge/token-> 200llm_env_...pair,POST /mcp/w5bridgetools/call -> 20042After (c63dc85)
The tip 3a3b8d3 only merges main: 5e24d9b drops the
enforce_fips_modedocstring, 02d65fe takes #50305, whose OpenSSL check probes scrypt instead of MD5, so the test fakes refuse scrypt now, and 3a3b8d3 takes #49874, which landsfips_mode_active()and the sharedfips_opensslandfips_modetest fixtures, so this branch drops its copies. None touches the key code, and withfips_modeunset the gate never runs that check. 4842d13 then moves the KBKDF helper fromfips.pyintoencrypt_decrypt_utils.py, and its test intotest_encrypt_decrypt_utils.py, with the code unchanged, sofips.pymatches main again. 21abe3c then fetches KBKDF withfips=yes, so the derivation can't leave the FIPS provider, with the same key bytesfips_mode on, FIPS host
POST /register,GET /authorize,POST /authorize/complete-> 201, 303, 303 withcode=llm_gcode_...POST /tokengrantauthorization_code->200 {"token_type":"Bearer","expires_in":3600,"access_token":"llm_session_...","refresh_token":"llm_srefresh_..."}POST /introspectaccess and refresh -> 200active: true, kindssessionandsession_refreshPOST /mcpinitialize, tools/list, tools/calladd(20, 22)-> 200,['w5bridge-add', 'w5math-add'],42POST /tokengrantrefresh_token-> 200 new pair, thenPOST /revoke-> 200, and the revoked token's refresh ->400 invalid_grant "the refresh token was revoked"POST /w5bridge/token-> 200llm_env_...pair,POST /mcp/w5bridgetools/call -> 20042, and the MCP server gotAuthorization: Bearer up-access-...42llm_session_not.a.tokenon/mcpandllm_env_not.an.envelopeon/mcp/w5bridge-> 401 withWWW-Authenticate: Bearer error="invalid_token", and introspect ->active: falseValueError,scryptordigital envelopelineFIPS host, fips_mode unset
POST /token,POST /introspect,POST /w5bridge/token->500 Internal server errorPOST /mcpandPOST /mcp/w5bridge->500 {"error":"MCP request failed","details":"[digital envelope routines] unsupported"}fips_modeon fixes these, as in the case aboveRHEL 8 FIPS host (OpenSSL 1.1.1k), fips_mode unset, base vs head
UBI 8 with
openssl-libs-1.1.1k-18.el8_6, system Python 3.12, FIPS forced withOPENSSL_FORCE_FIPS_MODE=1, Postgres 16. OpenSSL 1.1.1 FIPS still allows scrypt, so MCP worked here on mainPOST /token200 pair, introspectactive: true,/mcpinitialize 200, refresh 200, garbage introspectactive: false, garbage/mcp401active: true,/mcpinitialize 200, base's refresh 200ValueErrororLITELLM_SALT_KEYlineLITELLM_SALT_KEYunset, base and head give the same results againsession_keys_from_master_keyandenvelope_keys_from_master_keyreturn the same keys on base and head, with the salt key set or unsetfips_mode: truecan't boot there on main or head: the gate needscryptography's OpenSSL in FIPS mode, andcryptography47+ requires OpenSSL 3POST /v1/mcp/serverreturns 500 ('digest_size' is an invalid keyword argument for openssl_blake2b()), an existing main issueStandard host, tokens minted on base open on head
POST /introspectbase access and refresh -> 200active: truePOST /mcptools/call with base's access token -> 20042, and the refresh grant with base's refresh token -> 200POST /mcp/w5bridgetools/call with base'sllm_env_-> 20042, and the bridge refresh with base'sllm_refresh_-> 20042A standard host's token presented under FIPS
llm_env_tokens sent to the fips_mode on proxy -> introspectactive: false,/mcp401invalid_token, refresh grants400 invalid_grantfips_mode on with
LITELLM_SALT_KEY=sk-1234POST /token,POST /introspect,POST /w5bridge/token->500 Internal server error, and the OAuth server gets no requestPOST /mcp->500 {"error":"MCP request failed","details":"With general_settings.fips_mode on, LITELLM_SALT_KEY must be at least 32 bytes of hex, such as sk-$(openssl rand -hex 32)"}fips_mode on, master key rotated
LITELLM_MASTER_KEY, same salt key and DBactive: false,/mcp401invalid_token, refresh400 invalid_grantllm_env_->/mcp/w5bridge401, oldllm_refresh_->400 invalid_grant, and the OAuth server gets no request/token200,/mcptools/call 20042, bridge tools/call 20042fips_mode on with RS256
mcp_session_token_signing/mcptools/call, refresh -> all 200 on the RS256 key as on main42The key derivation runs in the FIPS provider
Chainguard FIPS image
litellm-fips-b2cg:head, built from #50330'sdocker/Dockerfile.fips: OpenSSL 4.0.3 with the Chainguard FIPS Provider 3.4.0 (CMVP #5132), CPython 3.13.18. This branch's four files at 21abe3c are mounted over the image's copies, and 4842d13's files are the comparison. Same results under the image defaults andCHAINGUARD_LEGACY_ALLOWED=0In-process probe after
enforce_fips_mode(fips_mode: true), with code in the process then changing OpenSSL's default properties:Live proxy through the image's own entrypoint, with Postgres 16, a scripted OAuth server and a local MCP server:
/register201,/login303,/authorize/complete303,/token200,/mcptools/calladd(20, 22)-> 20042, refresh 200 then3/mcp/w2bridgetools/call -> 20042, bridge refresh 200 then11, garbage tokens -> 401invalid_tokenllm_env_envelope opens only under the KBKDF keysLITELLM_SALT_KEYunset:/tokenand bridge mint -> 500 with no upstream request,/mcp-> 500 with the salt key message[digital envelope routines] unsupported500sUnit at 21abe3c:
test_encrypt_decrypt_utils.pyplustests/unit/proxy/mcp_server/outbound_credentialspass, 882 tests, on Python 3.12 with OpenSSL 3.0.13, andtests/unit/proxy/common_utils,tests/unit/proxy/mcp_serverand the seven other test files that use the shared FIPS fixtures give 10592 passed and 1 skipped. The ruff strict, type discipline, test quality and type check gates are OK against a94118c. The fulltests/unit/proxysweep ran at 3a3b8d3, before the move, and gave 50908 passed and 7 failed. 5 of those 7 fail on base a94118c too (test_input_tokens.py), and the other 2 (test_lifecycle.py) pass on head and base when run aloneType
🐛 Bug Fix
Caveats (if any)
Severe
fips_modeon for an existing deployment signs out its MCP clientsinvalid_grant, so they sign in againfips_modeon those requests returned 500 on mainMedium
LITELLM_SALT_KEYwithfips_modeon fails on the first MCP token request, not at boot/tokenand bridge mint return a plain 500,/mcpshows the format messageLow
fips_modestill returns 500 on MCP token routes, as on mainfips_modeon fixes itEVP_KDFfips_modeon returns 500Final Attestation
Note
High Risk
Changes authentication/signing key derivation for MCP tokens under FIPS mode and introduces ctypes/OpenSSL FIPS-provider dependency; invalid or missing salt keys surface as runtime 500s on MCP token routes.
Overview
When
general_settings.fips_modeis enabled, MCP bridge envelope and session signing keys no longer usehashlib.scrypt(blocked on FIPS OpenSSL 3). They are derived via a newderive_key_from_salt_keyhelper inencrypt_decrypt_utils, which runs SP 800-108 counter-mode KBKDF (HMAC-SHA256) through OpenSSL’s FIPSEVP_KDFwithfips=yes, usingLITELLM_SALT_KEYas the KDF key and the master key as context.envelope_keys_from_master_keyandsession_keys_from_master_keybranch onfips_mode_active(): FIPS path uses KBKDF with domain-specific labels; otherwise behavior and scrypt test vectors are unchanged. With FIPS on,LITELLM_SALT_KEYmust be at least 32 bytes of hex (optionalsk-prefix) or derivation raisesValueError.Tests add KBKDF correctness and FIPS-provider requirements, pin scrypt vs FIPS key material, and extend shared FIPS fixtures (including cache clearing for
lru_cachekey helpers).Reviewed by Cursor Bugbot for commit 21abe3c. Bugbot is set up for automated code reviews on this repo. Configure here.