mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(proxy): reject incompatible forwarding trust configuration
This commit is contained in:
parent
48997c340c
commit
d0e1bebce0
2 changed files with 21 additions and 0 deletions
|
|
@ -18,6 +18,10 @@ def gateway_binary() -> str | None:
|
|||
return shutil.which(name, path=sysconfig.get_path("scripts")) or shutil.which(name)
|
||||
|
||||
|
||||
def unsupported_proxy_trust(value: str | None) -> bool:
|
||||
return any(host.strip() not in ("", "127.0.0.1") for host in (value or "").split(","))
|
||||
|
||||
|
||||
def startup_error(binary: str | None, unsupported: Mapping[str, object]) -> str | None:
|
||||
flag: Final = next((name for name, value in unsupported.items() if value), None)
|
||||
if flag is not None:
|
||||
|
|
@ -26,6 +30,8 @@ def startup_error(binary: str | None, unsupported: Mapping[str, object]) -> str
|
|||
return "--rust_gateway requires POSIX inherited sockets and process signals"
|
||||
if binary is None:
|
||||
return "--rust_gateway requires the litellm-gateway binary. Install litellm[proxy] in this environment"
|
||||
if unsupported_proxy_trust(os.environ.get("FORWARDED_ALLOW_IPS")):
|
||||
return "--rust_gateway does not support non-loopback FORWARDED_ALLOW_IPS; disable Rust forwarding for this deployment"
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,20 @@ def test_missing_binary_gives_install_instruction() -> None:
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("trusted", [None, "", "127.0.0.1", "192.0.2.1", "*", "127.0.0.1,192.0.2.1"])
|
||||
def test_configured_proxy_trust_is_not_silently_discarded(trusted: str | None, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
if trusted is None:
|
||||
monkeypatch.delenv("FORWARDED_ALLOW_IPS", raising=False)
|
||||
else:
|
||||
monkeypatch.setenv("FORWARDED_ALLOW_IPS", trusted)
|
||||
expected: Final = (
|
||||
None
|
||||
if trusted in (None, "", "127.0.0.1")
|
||||
else "--rust_gateway does not support non-loopback FORWARDED_ALLOW_IPS; disable Rust forwarding for this deployment"
|
||||
)
|
||||
assert startup_error("gateway", {}) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("supervised", [False, True])
|
||||
@pytest.mark.parametrize("host", ["0.0.0.0", "192.0.2.1", "::"])
|
||||
def test_metrics_keep_configured_host_separate_from_private_listener(
|
||||
|
|
@ -158,6 +172,7 @@ def test_supervisor_drains_before_stopping_python_and_reaps_both_children(
|
|||
patch("asyncio.create_subprocess_exec", side_effect=spawn) as launch,
|
||||
patch("socket.socket", return_value=listener),
|
||||
patch("os.killpg", side_effect=kill_group) as kill,
|
||||
patch.dict("os.environ", {"FORWARDED_ALLOW_IPS": "*"}),
|
||||
):
|
||||
assert supervise("gateway", ("python", "--rust_gateway"), "0.0.0.0", 4000) == expected
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue