Skip to content

feat(proxy): encrypt stored secrets with AES-256-GCM in fips_mode - #51828

Open
yucheng-berri wants to merge 5 commits into
mainfrom
litellm_fips_at_rest_aes_gcm_cryptography
Open

yucheng-berri wants to merge 5 commits into
mainfrom
litellm_fips_at_rest_aes_gcm_cryptography

Conversation

@yucheng-berri

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

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

<make-me-human-readable>
With general_settings.fips_mode: true, the proxy still encrypted every stored secret (model keys, credentials, MCP tokens) with XSalsa20-Poly1305 from libsodium, which is not a FIPS algorithm and runs outside the validated OpenSSL module. In fips_mode those secrets are now written with AES-256-GCM through the cryptography library, under a key the FIPS provider derives from LITELLM_SALT_KEY, and values in any other format are refused on read. Without fips_mode nothing changes
</make-me-human-readable>

Details

Replaces #51429: same change, with the seal done by cryptography instead of ctypes.

Stacked on #52099, which makes a fips_mode proxy refuse to start when the salt key is under 112 bits (14 bytes). Rebased onto its head 75a29d1. _fips_at_rest_key now turns the key into bytes through #52099's key_derivation_key, the same function MCP keys and plugin claims use. A key of 32+ bytes of hex derives the same at-rest key as 33f8446. Any other key of 14+ bytes, which 33f8446 refused, is used as its UTF-8 bytes.

TLDR

Problem this solves:

How it solves it:

  • In fips_mode the write algorithm is always AES-256-GCM
  • The seal is cryptography's AESGCM, the same call main's opt-in path uses
  • The 12-byte nonce comes from os.urandom, as on main's opt-in path
  • The key comes from the existing KBKDF helper under its own label
  • Stored format is unchanged, v2:gcm: + base64url(nonce + ciphertext + tag)
  • In fips_mode a value without the v2:gcm: prefix is refused

User Flow

Before: a fips_mode proxy stores a model key with libsodium

  1. The proxy admin runs the FIPS image with general_settings.fips_mode: true
  2. The admin sends POST https://litellm-domain/model/new with an api_key, and gets 200
  3. The stored key has no prefix and was encrypted with XSalsa20-Poly1305, outside the FIPS module

After: the same request stores the key with AES-256-GCM from the FIPS provider

  1. Same image, same config, same request, and the same 200
  2. The stored key starts with v2:gcm: and was encrypted by the FIPS provider's AES-256-GCM
  3. After a restart, POST https://litellm-domain/v1/chat/completions on that model returns 200 and the upstream receives the original key

Linear ticket

Resolves LIT-8427

Behavior changes

Removed / renamed

  • None

Silent regressions to watch

  • None without fips_mode. The default write is still PyNaCl, encryption_algorithm: aes-256-gcm still writes the same v2:gcm: values with the same key, and both are read as before
  • With fips_mode: true, all of these are the same as in feat(fips): encrypt stored secrets with the FIPS provider's AES-256-GCM in fips_mode #51429
    • LITELLM_SALT_KEY (or the master key, when no salt key is set) must be at least 112 bits (14 bytes), such as sk-$(openssl rand -hex 32). Otherwise every write of a stored secret raises. POST /credentials returns 500 with that message and POST /model/new returns 500 Failed to add model to db. Main accepted those writes and stored them with libsodium. Unreachable once feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 lands: the proxy refuses to start
    • A key of 32+ bytes of hex, optionally prefixed with sk-, is decoded, and any other key is used as its UTF-8 bytes, the same way feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 reads it for MCP keys and plugin claims
    • Team and key callback settings, guardrail params and search tool params used to be stored as written when encryption failed. In fips_mode that write now fails with the same salt key message, so a secret is never stored in plaintext because of a bad key. With a bad key at startup this is unreachable once feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 lands: the proxy refuses to start
    • encryption_algorithm: xsalsa20-poly1305 is ignored
    • Values written outside fips_mode (PyNaCl values, and v2:gcm: values written in standard mode) are not decrypted. The models and credentials behind them do not load, and the log says why. Main read them
    • Values written in fips_mode cannot be read after fips_mode is turned off, because the key differs
    • Tokens that go through the same helper change shape the way they already do under encryption_algorithm: aes-256-gcm, so a response id becomes resp_v2:gcm:...
    • fips_mode is only in v1.110.0 dev and rc tags, no stable release

What differs from #51429

  • The nonce is made by the application (os.urandom(12)) and passed to the module. feat(fips): encrypt stored secrets with the FIPS provider's AES-256-GCM in fips_mode #51429 passed no nonce, so the FIPS provider drew it
    • On the Chainguard FIPS provider (CMVP Include optional parameters in the request payload when using the Hugging Face REST API. #5132) this makes the provider report iv-generated=0 for each encryption. Its security policy (page 22 Table 8, and page 53 section 2.7.9) lists "AES-GCM encryption with external IV" as a non-approved service. feat(fips): encrypt stored secrets with the FIPS provider's AES-256-GCM in fips_mode #51429 produced iv-generated=1
    • The cipher itself is still AES-256-GCM served by the FIPS provider, and the key is still derived by the provider's KBKDF with fips-indicator=1. Both are measured below at this head
    • This is what peer FIPS builds ship. A study of 20 open source projects with FIPS builds found that every one calls AES-GCM through its language's mainstream crypto library, none wrote its own binding, and 11 of the 15 that use AES-GCM pass an application-made nonce. Previously measured with gdb on FIPS builds, not rerun for this PR: Vault's FIPS 140-3 build, the FIPS kube-apiserver and GitLab's FIPS image each hand the provider a caller-made IV, and Chainguard's own litellm-fips image does the same through cryptography with os.urandom(12)
  • No ctypes in the seal. _fips_seal_aes_gcm and its "OpenSSL could not run AES-256-GCM" error are gone. The key derivation still reaches OpenSSL through main's existing ctypes KBKDF helper, which this PR does not touch, so on an OpenSSL without a FIPS provider a fips_mode write still fails with "OpenSSL could not run KBKDF"
  • _KBKDF_PROPERTIES keeps its name, and derive_key_from_salt_key is not edited

Migration for existing customers

  • None for deployments that leave fips_mode off
  • fips_mode is for new deployments. A database with secrets written before fips_mode was on has to be re-created or have those secrets entered again

Regression tests

  • tests/unit/proxy/common_utils/test_encrypt_decrypt_utils.py
    • test_fips_mode_writes_aes_gcm_under_the_kbkdf_key: the value is v2:gcm: + 12 + n + 16 bytes, plain cryptography opens it under the SP 800-108 key computed by hand, two writes of the same plaintext differ, and an xsalsa20-poly1305 setting does not change it
    • test_fips_mode_reads_a_value_sealed_by_cryptography_under_the_kbkdf_key
    • test_fips_mode_refuses_a_value_changed_after_it_was_written: one flipped bit in the nonce, ciphertext or tag
    • test_fips_mode_refuses_values_it_did_not_write
    • test_values_written_in_fips_mode_are_not_read_in_standard_mode
    • test_fips_mode_encrypts_under_an_explicit_new_key: a hex and a non-hex new key
    • test_fips_mode_reads_known_answer_values_written_under_a_hex_salt_key: two v2:gcm: values written by 33f8446 still decrypt
    • test_fips_mode_writes_under_the_kbkdf_key_of_the_utf8_bytes_of_a_salt_key_that_is_not_hex: 14 ASCII bytes, 14 UTF-8 bytes in 7 characters, and a hex key with a trailing newline
    • test_fips_mode_refuses_to_encrypt_under_a_salt_key_under_112_bits: 13 ASCII bytes and 13 UTF-8 bytes, with the key absent from the message
    • test_fips_mode_leaves_bearer_tokens_as_they_are
    • test_fips_mode_never_stores_a_secret_as_written_when_it_cannot_be_encrypted: callback vars, guardrail params and search tool params
  • The standard-mode tests in that file are untouched and pass
  • test_fips_mode_merge_user_env_vars_takes_its_lock_without_blake2b used a salt key that is not hex. It now sets a hex one
  • 17 mutations of the new and changed lines at 3401bdb each turn one of these tests red (17 of 17 killed). 7 more of the rebased _fips_at_rest_key at 1fb6388 do too (7 of 7 killed): hex taken as text, the key stripped, the 112-bit refusal skipped, the message going back to the hex rule or printing the key, and the label or context changed

Screenshots / Proof of Fix

Real proxies on the real Chainguard FIPS image (Python 3.13, OpenSSL 4.0.3, Chainguard FIPS Provider 3.4.0-r5), with each tree's litellm/ mounted over the installed package, real Postgres 16, and a local upstream that records the Authorization header. CHAINGUARD_LEGACY_ALLOWED=0, fips_mode: true, a 64-hex salt key.

Rebase onto #52099's 112-bit floor: 33f8446 (Before) vs 1fb6388 (After)

Same image, real Postgres 16, real OpenAI gpt-4.1-mini behind a recorder, throwaway keys deleted after the run, 0 of them in any proxy log.

Before (33f8446)

  1. Hex salt key, 32 bytes: POST /model/new and POST /credentials return 200, both rows start with v2:gcm:, chat through both returns 200
  2. Salt key that is not hex, 20 bytes: the proxy exits with code 3, LITELLM_SALT_KEY is not at least 32 bytes of hex
  3. Master key that is not hex, 32 bytes, and no salt key: exits with code 3, same message
  4. POST /key/regenerate with a 20-byte non-hex new_master_key: 500 LITELLM_SALT_KEY must be at least 32 bytes of hex

After (1fb6388)

  1. Hex salt key, 32 bytes: the new proxy starts on the database 33f8446 wrote, and chat through the stored model and the stored credential returns 200. Its at-rest key fingerprint (first 16 hex of SHA-256) is fee3a84c7b82021e, the same as 33f8446's
  2. Salt key that is not hex, 20 bytes: the proxy starts, both rows start with v2:gcm:, chat through both returns 200
  3. Master key that is not hex, 32 bytes, and no salt key: starts, rows are v2:gcm:, chat 200
  4. POST /key/regenerate with a 20-byte non-hex new_master_key: 200, rows stay v2:gcm:. With a 13-byte one: 500 the key that encrypts stored secrets (LITELLM_SALT_KEY, or the master key when LITELLM_SALT_KEY is not set) must be at least 112 bits (14 bytes). Main returns 200 for both
  5. Salt key under 112 bits (13 bytes, and 12 characters that are 13 UTF-8 bytes): exits with code 3 at startup, from feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099

Before (3ad1643)

  1. POST /credentials and two POST /model/new return 200
  2. Stored keys:
    b3-model-1         no prefix, 63 bytes = 24 nonce + 16 mac + 23 ciphertext (nacl SecretBox)
    b3-cred-1          no prefix, 62 bytes = 24 nonce + 16 mac + 22 ciphertext (nacl SecretBox)
    
  3. After a restart, GET /v1/models 200 lists both models, chat 200, and the upstream received Bearer sk-b3-MODEL-PLAINTEXT-1 and Bearer sk-b3-CRED-PLAINTEXT-1
  4. In the proxy process: _sodium mapped=True, libcrypto mapped=True, fips.so mapped=True
  5. gdb on encrypt_value_helper and decrypt_value_helper: crypto_secretbox_easy and crypto_secretbox_open_easy are hit, and no libcrypto cipher call is made

After (3401bdb)

  1. POST /credentials and two POST /model/new return 200
  2. Stored keys, with 0 rows holding the plaintext:
    b3-model-1         v2:gcm: + 51 bytes = 12 nonce + 23 ciphertext + 16 tag
    b3-cred-1          v2:gcm: + 50 bytes = 12 nonce + 22 ciphertext + 16 tag
    
    The same with encryption_algorithm: xsalsa20-poly1305 in the config
  3. After a restart, GET /v1/models 200 lists both models, chat 200, and the upstream received Bearer sk-b3-MODEL-PLAINTEXT-1 and Bearer sk-b3-CRED-PLAINTEXT-1. POST /v1/responses 200 with an id of resp_v2:gcm:..., and the follow-up with previous_response_id 200 with the upstream's own id passed on. POST /v2/login 200. 0 "Error decrypting" lines in the log
  4. In the proxy process: _sodium mapped=False, libcrypto mapped=True, fips.so mapped=True
  5. gdb on encrypt_value_helper in fips_mode (shortened, the provider string is the same on every line):
    EVP_KDF_fetch(algorithm=KBKDF, properties=fips=yes) returned provider=fips ("Chainguard FIPS Provider for OpenSSL" 3.4.0-r5)
    EVP_KDF_derive returned 1; fips-indicator=1
    no RAND_bytes, RAND_bytes_ex or EVP_RAND_generate call (the nonce is os.urandom, not the module's DRBG)
    EVP_CIPHER_fetch(algorithm=id-aes256-GCM) returned EVP_CIPHER=AES-256-GCM provider=fips
    EVP_EncryptInit_ex(key=NULL, iv=set), called from cryptography's _rust.abi3.so, returned 1; provider=fips | iv-generated=0
    EVP_CipherUpdate returned 1; provider=fips | iv-generated=0
    EVP_CipherFinal returned 1; provider=fips | iv-generated=0
    libsodium breakpoint hits: 0 (10 armed)
    
    The read runs KBKDF again and EVP_DecryptFinal_ex returns 1 on the FIPS provider's AES-256-GCM, with 0 libsodium hits. A PyNaCl value and a standard-mode v2:gcm: value both come back as None, and 'nacl' in sys.modules stays False

GET /ui/ returns 500 on both sides with CHAINGUARD_LEGACY_ALLOWED=0, as it did for #51429. It is not part of this change.

The other cells in #51429 (rows written in standard mode and then fips_mode on, fips_mode rows read with fips_mode off, base and head on one Postgres in standard mode, cost per call) were measured there at 1ee6ac4 and were not rerun here. The code they exercise is the same in this PR except for the seal.

Tests and gates

At 52ce5d1, on a Linux VM with Python 3.12.3, whose OpenSSL is a shared library, so no fips_mode test skipped:

  • pytest tests/unit/proxy/common_utils tests/unit/llms/custom_httpx/test_http_handler.py tests/unit/proxy/test_proxy_server_endpoints_and_startup.py tests/unit/proxy/mcp_server/outbound_credentials tests/unit/proxy/test_plugin_routes.py tests/unit/proxy/auth tests/unit/proxy/mcp_server/test_mcp_env_vars.py tests/unit/proxy/guardrails tests/unit/proxy/search_endpoints -n 16 --timeout=300: 16124 passed, 8 skipped, 1 xfailed. The 8 skips are unrelated optional guardrail packages
  • ruff_strict_gate.py, type_discipline_gate.py, test_quality_gate.py and type_check_gate.py with --base 75a29d1ec46 (this PR's base, feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099's head): all four print OK
  • 7 mutations of the rebased _fips_at_rest_key: 7 of 7 killed

The live run in the Before (3ad1643) and After (3401bdb) sections above and these numbers are from 3401bdb, before the rebase. The rebase changes only how _fips_at_rest_key turns the key into bytes, and the hex case above shows it derives the same key:

  • pytest tests/unit/proxy -n 14 on 3401bdb and on its merge base
    • head: 7 failed, 55482 passed, 88 skipped, 1 xfailed
    • base: 7 failed, 55461 passed, 88 skipped, 1 xfailed
    • The 7 failures are the same tests on both sides (2 in mcp_server/test_operations.py, 5 in spend_tracking/test_input_tokens.py), none touched by this PR
Proxy command, config, env vars and client calls

The image is the FIPS image built from docker/Dockerfile.fips in #50330 (tagged litellm-fips below), with this branch's litellm/ mounted over the installed package. Use main's litellm/ for the Before steps.

docker network create b3
docker run -d --name b3-pg --network b3 -e POSTGRES_PASSWORD=pw postgres:16
# upstream double: any OpenAI-compatible server that logs the Authorization header, listening on b3-up:8080

cat > cfg.yaml <<'EOF'
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  store_model_in_db: true
  fips_mode: true
EOF

export LITELLM_MASTER_KEY=sk-$(openssl rand -hex 16)
export LITELLM_SALT_KEY=sk-$(openssl rand -hex 32)
SP=/app/.venv/lib/python3.13/site-packages

docker run -d --name b3-proxy --network b3 -p 127.0.0.1:4000:4000 \
  -e CHAINGUARD_LEGACY_ALLOWED=0 -e LITELLM_MASTER_KEY -e LITELLM_SALT_KEY \
  -e DATABASE_URL=postgresql://postgres:pw@b3-pg:5432/postgres \
  -v $PWD/litellm:$SP/litellm:ro -v $PWD/cfg.yaml:/cfg.yaml:ro \
  --entrypoint /app/.venv/bin/litellm litellm-fips --config /cfg.yaml --port 4000
H="Authorization: Bearer $LITELLM_MASTER_KEY"
curl -s localhost:4000/credentials -H "$H" -H content-type:application/json -d '{
  "credential_name": "b3-cred-1", "credential_info": {"custom_llm_provider": "openai"},
  "credential_values": {"api_key": "sk-b3-CRED-PLAINTEXT-1", "api_base": "http://b3-up:8080/v1"}}'
curl -s localhost:4000/model/new -H "$H" -H content-type:application/json -d '{
  "model_name": "b3-model-1",
  "litellm_params": {"model": "openai/fake-gpt", "api_base": "http://b3-up:8080/v1", "api_key": "sk-b3-MODEL-PLAINTEXT-1"}}'

# what is stored
docker exec b3-pg psql -U postgres -At -c \
  "select model_name, litellm_params->>'api_key' from \"LiteLLM_ProxyModelTable\""
docker exec b3-pg psql -U postgres -At -c \
  "select credential_name, credential_values->>'api_key' from \"LiteLLM_CredentialsTable\""

# read path: restart, then call through the stored model and check the upstream log
docker restart b3-proxy
curl -s localhost:4000/v1/chat/completions -H "$H" -H content-type:application/json \
  -d '{"model": "b3-model-1", "messages": [{"role": "user", "content": "ping"}]}'

# is libsodium loaded in the proxy
docker exec b3-proxy sh -c 'grep -l _sodium /proc/[0-9]*/maps'

The gdb lines come from host gdb attached to a Python process in the same image that calls enforce_fips_mode({"fips_mode": True}) and then encrypt_value_helper("...") and decrypt_value_helper(...), with breakpoints on EVP_KDF_fetch, EVP_KDF_derive, EVP_CIPHER_fetch, the EVP_EncryptInit_ex* and EVP_CipherInit_ex* family, update and final, EVP_DecryptFinal_ex, the getrandom syscall and libsodium's crypto_secretbox_*, reading the iv-generated parameter with EVP_CIPHER_CTX_get_params after each call.

Type

🆕 New Feature

Caveats (if any)

Severe

High

Found by an adversarial review of #51429, present here too, fips_mode only, not fixed in this PR:

  • A key under 112 bits also breaks per-request paths. Unreachable once feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 lands: the proxy refuses to start
    • /v1/responses returns 500, and a stream ends with response.failed
    • Realtime client_secrets and transcription_sessions return 500 after the upstream call
    • MCP /authorize returns 500
  • Rows without v2:gcm: can reach callers as ciphertext
    • Callers that pass return_original_value=True (DB env vars in proxy_server.py) and credential_hydration.py get the stored ciphertext back and use it as the secret
    • SSO settings return ciphertext, and a re-save or /key/regenerate wraps old ciphertext in v2:gcm:
    • LITELLM_MIGRATE_FROM_MASTER_KEY reports nothing to migrate
    • An old previous_response_id returns 403

Found by a live base-versus-head run at 3b436a2 on the Chainguard FIPS base image, fips_mode only, not fixed in this PR:

  • Rows that main wrote with fips_mode already on are refused too, not only rows written before it was on. That includes rows main wrote with encryption_algorithm: aes-256-gcm, which use the SHA-256 key
  • Over such rows, a guardrail call sends the stored ciphertext to the guardrail vendor as its API key, and a search call returns 500 with the ciphertext in the error text
  • Rolling back to a build without this PR while fips_mode stays on loses every row this PR wrote, the same way turning fips_mode off does
  • With a key under 112 bits, /key/generate with callback vars fails and leaves one orphan budget row. /team/new and /team/update fail with no partial write. Unreachable once feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 lands: the proxy refuses to start
  • /key/regenerate with a new_master_key under 112 bits returns 500 while a valid salt key is set, and the error names LITELLM_SALT_KEY. Main returns 200. A new_master_key that is not hex but is 14+ bytes now returns 200

Medium

  • Every /v1/responses answer in fips_mode runs one KBKDF with no cache
  • The KBKDF helper still uses ctypes, so a Python with statically linked OpenSSL cannot derive the key. The tests that derive it skip there. A separate PR is replacing that helper

Low

  • MCP grant envelopes (envelope.py) still call SecretBox directly in fips_mode
  • UI session tokens (encrypt_bearer_token) keep the SHA-256 key in fips_mode
  • No boot check for the salt key length in this PR alone, so a short key fails on the first write. Unreachable once feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode #52099 lands: the proxy refuses to start
  • POST /model/new hides the reason when encryption fails
  • encryption_algorithm: xsalsa20-poly1305 is ignored in fips_mode, not refused at boot
  • credential_migration.py reads the raw setting and does not know fips_mode
  • pynacl is still installed in the FIPS image

Devin Review


Note

High Risk
Changes core secret encryption and decrypt compatibility in fips_mode; existing non-v2:gcm DB secrets stop decrypting, and failed encrypt paths now error instead of storing plaintext.

Overview
When general_settings.fips_mode is on, new at-rest secret writes always use AES-256-GCM (v2:gcm:) via cryptography, with keys derived through KBKDF (_fips_at_rest_key) instead of libsodium or plain SHA-256. encryption_algorithm is ignored for writes in FIPS mode.

Decrypt in FIPS mode accepts only v2:gcm: ciphertext; legacy nacl and standard-mode GCM values are refused (_unreadable_in_fips_mode). Callback vars, guardrail params, and search tool params no longer fall back to plaintext when encryption fails—FIPS mode re-raises instead.

Bearer tokens keep the existing SHA-256 key path. Unit tests add broad FIPS round-trip, tamper rejection, key-length, and store-path coverage.

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

@veria-ai

veria-ai Bot commented Nov 14, 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 found 1 potential issue.

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

Devin Review

def _encrypt_aes_gcm(value: str, signing_key: str) -> str:
"""Encrypt under AES-256-GCM and return the versioned ``v2:gcm:`` string."""
sealed: Final = _seal_aes_gcm(value=value, signing_key=signing_key, aad=None)
sealed: Final = _seal_aes_gcm(value=value, key=_at_rest_key(signing_key), aad=None)

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.

🟨 Non-approved encryption in FIPS mode

With fips_mode enabled, _encrypt_aes_gcm uses an application-generated nonce through the shared seal. The documented provider classifies external-IV GCM encryption as non-approved. Stored secrets therefore use a non-approved service despite FIPS mode.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Declared in the PR body under What differs from #51429. The maintainer chose the library call that peer FIPS builds ship, knowing the indicator reads 0.

@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 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge within its stated FIPS deployment and migration limits.

Summary

Stored secrets now use AES-256-GCM with a KBKDF-derived key when fips_mode is enabled. Callback, guardrail, and search-tool writes stop when encryption fails. Standard-mode encryption and bearer-token keys stay unchanged.

No new actionable issues were found. The earlier error-pattern finding was withdrawn. The earlier test finding is fixed by using real missing-key failures instead of replacing encryption.

This assessment preserves yucheng-berri's stated tradeoffs. These include refusing older secrets, requiring secrets to be entered again when changing modes, externally supplied nonces, ciphertext reaching some older callers, short explicit rotation keys failing, uncached key derivation, static-OpenSSL limits, and remaining encryption paths outside this change.

  • FIPS mode stores shared secrets with AES-GCM.
  • Sensitive settings fail to save when FIPS encryption fails.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  W[Write stored secret] --> F{FIPS mode active?}
  F -->|Yes| K[Derive key with KBKDF]
  K --> A[Encrypt with AES-256-GCM]
  F -->|No| C[Use configured algorithm]
  A --> V[Store v2:gcm value]
  C --> S[Store standard-mode value]
  R[Read stored secret] --> G{FIPS mode active?}
  G -->|Yes| P{Has v2:gcm prefix?}
  P -->|Yes| D[Decrypt with KBKDF-derived key]
  P -->|No| E[Return existing read-failure result]
  G -->|No| N[Use existing format detection]
Loading

Reviews (6) · Last reviewed commit: "test: use a real missing-key failure in ..." · Reviewed by Greptile

@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.

Stale Bugbot comment from a previous run.

@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 45 untouched benchmarks


Comparing litellm_fips_at_rest_aes_gcm_cryptography (33f8446) with litellm_fips_mode_require_hex_salt_key (0a5d611)

Open in CodSpeed

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@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.

Stale Bugbot comment from a previous run.

With general_settings.fips_mode on, the proxy now refuses to start unless
the key it encrypts stored secrets with (LITELLM_SALT_KEY, or the master
key when LITELLM_SALT_KEY is not set) is at least 32 bytes of hex. The
fips_mode key derivations already need that shape, so a deployment with
any other key used to boot and then fail on its first secret write.

The hex pattern moves to fips.py so the boot gate and the KBKDF helper
share one definition. Standard mode is unchanged.
@yucheng-berri
yucheng-berri force-pushed the litellm_fips_at_rest_aes_gcm_cryptography branch from 3b436a2 to 33f8446 Compare November 16, 2026 20:23
@yucheng-berri
yucheng-berri changed the base branch from main to litellm_fips_mode_require_hex_salt_key November 16, 2026 20:23
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@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.

Stale Bugbot comment from a previous run.

…n-hex keys

The fips_mode boot gate, derive_key_from_salt_key and their tests now share
key_derivation_key: a salt key of 32+ bytes of hex (optionally sk-) is decoded
as before, any other key is taken as its UTF-8 bytes, and a key under 14 bytes
is refused. The refusal names the master key when LITELLM_SALT_KEY is not set.
@yucheng-berri
yucheng-berri force-pushed the litellm_fips_at_rest_aes_gcm_cryptography branch from 33f8446 to 1fb6388 Compare November 16, 2026 23:46
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@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.

Stale Bugbot comment from a previous run.

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…ode refusals

derive_key_from_salt_key no longer binds LITELLM_SALT_KEY to a local before
refusing it, and enforce_fips_mode now takes get_salt_key instead of the key
itself, so only fips_mode_refusal sees the key and it returns before the raise.
An error reporter that captures frame locals can no longer pick up the key from
a refused boot or a refused key derivation.
@yucheng-berri
yucheng-berri force-pushed the litellm_fips_at_rest_aes_gcm_cryptography branch from 1fb6388 to 52ce5d1 Compare November 17, 2026 02:04
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@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 52ce5d1. Configure here.

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

Base automatically changed from litellm_fips_mode_require_hex_salt_key to main November 17, 2026 20:59

This branch has not been deployed

No deployments
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.

1 participant