fix(auth): warn on JWKS keys dropped for unapproved algorithms and name the EdDSA removal release

This commit is contained in:
yucheng-berri 2026-10-14 01:57:20 -07:00
parent 80bcabdf83
commit be2c742eef
3 changed files with 96 additions and 3 deletions

View file

@ -119,7 +119,8 @@ _CachedValueT = TypeVar("_CachedValueT", bound=JWKKeyValue | str)
def _log_eddsa_deprecation() -> None:
verbose_proxy_logger.warning(
"JWT Auth: accepted a token signed with EdDSA, which is deprecated and not FIPS 140-3 approved; "
"it is rejected when LITELLM_FIPS_MODE=true. Move the IdP signing key to RS256, PS256 or ES256"
"it is rejected when LITELLM_FIPS_MODE=true. Move the IdP signing key to RS256, PS256 or ES256; "
"EdDSA support will be removed in the next major release"
)
@ -233,6 +234,9 @@ class JWTHandler:
# Supported algos: https://pyjwt.readthedocs.io/en/stable/algorithms.html
# "Warning: Make sure not to mix symmetric and asymmetric algorithms that interpret
# the key in different ways (e.g. HS* and RS*)."
# EdDSA (LEGACY_JWT_ALGORITHMS) is retained here only for unverified-claims decoding;
# the acceptance path uses allowed_algorithms(), which excludes it (refused in FIPS
# mode, accepted with a deprecation warning elsewhere).
SUPPORTED_JWT_ALGORITHMS = [
*APPROVED_JWT_ALGORITHMS,
*LEGACY_JWT_ALGORITHMS,

View file

@ -2,6 +2,7 @@ from collections.abc import Collection, Mapping, Sequence
from types import MappingProxyType
from typing import Final, TypeVar
from litellm._logging import verbose_proxy_logger
from litellm.types.proxy.auth.jwt_algorithms import APPROVED_JWT_ALGORITHMS, LEGACY_JWT_ALGORITHMS
_KEY_TYPE_ALGORITHMS: Final = MappingProxyType(
@ -23,7 +24,27 @@ _JWTMappingT: Final = TypeVar("_JWTMappingT", bound=Mapping[str, object])
def jwks_keys_for(keys: Sequence[_JWTMappingT], algorithms: Collection[str]) -> tuple[_JWTMappingT, ...]:
"""Keep keys whose declared alg is allowed; keys without alg are kept only when their kty can sign with an
allowed algorithm."""
return tuple(key for key in keys if _key_allowed(key, frozenset(algorithms)))
allowed: Final = frozenset(algorithms)
usable_keys: list[_JWTMappingT] = []
for key in keys:
if _key_allowed(key, allowed):
usable_keys.append(key)
else:
_warn_dropped_jwks_key(key)
return tuple(usable_keys)
def _warn_dropped_jwks_key(key: Mapping[str, object]) -> None:
"""Surface why a JWKS key was filtered out. alg/kid/kty are public JWKS header fields, never key material."""
alg: Final = key.get("alg")
verbose_proxy_logger.warning(
"JWT Auth: dropped a JWKS key unusable for token verification: alg=%s, kid=%s, kty=%s; "
"allowed algorithms follow APPROVED_JWT_ALGORITHMS (EdDSA is legacy, allowed only outside FIPS mode) — "
"move the IdP signing key to an approved algorithm such as RS256",
alg if isinstance(alg, str) else "undeclared",
key.get("kid"),
key.get("kty"),
)
def _key_allowed(key: Mapping[str, object], algorithms: frozenset[str]) -> bool:

View file

@ -7649,6 +7649,26 @@ def test_jwks_keys_for_filters_by_declared_or_inferred_algorithm(key, algorithms
assert list(jwks_keys_for([key], algorithms)) == ([key] if expected else [])
def test_jwks_keys_for_warns_when_dropping_key_with_unapproved_algorithm(caplog):
import logging
from litellm.proxy.auth.jwt_algorithms import jwks_keys_for
rsa_key: Final = {"kty": "RSA", "alg": "RS256", "kid": "rsa-key"}
eddsa_key: Final = {"kty": "OKP", "alg": "EdDSA", "kid": "legacy-ed-key"}
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
usable: Final = list(jwks_keys_for([rsa_key, eddsa_key], ("RS256", "ES256")))
assert usable == [rsa_key]
assert "EdDSA" in caplog.text and "legacy-ed-key" in caplog.text
caplog.clear()
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
assert list(jwks_keys_for([rsa_key], ("RS256", "ES256"))) == [rsa_key]
assert "dropped" not in caplog.text
def test_fips_mode_rejects_eddsa_token_but_accepts_rs256():
import jwt
@ -7689,7 +7709,12 @@ def test_eddsa_token_accepted_with_deprecation_log_outside_fips(caplog):
disable_audience_validation=True,
)
assert claims["sub"] == "test-subject"
assert "EdDSA" in caplog.text and "deprecated" in caplog.text and "LITELLM_FIPS_MODE" in caplog.text
assert (
"EdDSA" in caplog.text
and "deprecated" in caplog.text
and "LITELLM_FIPS_MODE" in caplog.text
and "next major release" in caplog.text
)
_log_eddsa_deprecation.cache_clear()
caplog.clear()
@ -7705,6 +7730,49 @@ def test_eddsa_token_accepted_with_deprecation_log_outside_fips(caplog):
_log_eddsa_deprecation.cache_clear()
@pytest.mark.asyncio
async def test_get_public_key_from_jwks_warns_on_eddsa_key_dropped_in_fips_mode(caplog):
"""An operator whose JWKS mixes approved and EdDSA keys must see why the EdDSA key is unusable."""
import logging
_, ed_jwk = _okp_keypair_and_jwk()
ed_jwk = {**ed_jwk, "kid": "legacy-ed-key"}
_, rsa_jwk = _get_rsa_key_and_jwk(kid="rsa-key")
endpoint = _ScriptedJWKSEndpoint(({"keys": [rsa_jwk, ed_jwk]},))
jwt_handler = JWTHandler(fips_mode=lambda: True)
jwt_handler.update_environment(
prisma_client=None,
user_api_key_cache=DualCache(),
litellm_jwtauth=LiteLLM_JWTAuth(),
)
jwt_handler.http_handler = endpoint
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
public_key = await jwt_handler._get_public_key_from_jwks_url(
jwks_url="https://issuer.example.com/keys",
kid="rsa-key",
)
assert public_key == rsa_jwk
assert "EdDSA" in caplog.text and "legacy-ed-key" in caplog.text
caplog.clear()
ed_only_handler = JWTHandler(fips_mode=lambda: True)
ed_only_handler.update_environment(
prisma_client=None,
user_api_key_cache=DualCache(),
litellm_jwtauth=LiteLLM_JWTAuth(),
)
ed_only_handler.http_handler = _ScriptedJWKSEndpoint(({"keys": [ed_jwk]},))
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
with pytest.raises(NoMatchingJWTPublicKeyError):
await ed_only_handler._get_public_key_from_jwks_url(
jwks_url="https://issuer.example.com/keys",
kid="legacy-ed-key",
)
assert "EdDSA" in caplog.text and "legacy-ed-key" in caplog.text
def _rsa_keypair_and_jwk() -> "tuple[object, dict]":
import json