Repository navigation
fix(proxy): gate disable_global_guardrails on keys and teams to proxy admins #42699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yucheng-berri
merged 12 commits into
main
from
litellm_gate_disable_global_guardrails_admin
Sep 24, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d311fe4
fix(proxy): gate disable_global_guardrails on keys and teams to proxy…
yucheng-berri 8bddfae
test: cover metadata smuggle with explicit false and UI toggle gating
yucheng-berri aac2128
test(proxy): satisfy PT017 in resend-stored guardrail flag test
yucheng-berri a0f4d6e
refactor(proxy): keep regenerate_key_fn under the C901 ceiling via a …
yucheng-berri c3a0cab
chore(ui): regenerate schema.d.ts for guardrail opt-out docstrings
yucheng-berri b2c3fad
fix(proxy): gate disable_global_guardrails on caller-sent metadata, n…
yucheng-berri c0e3a40
test(integration): audit cells for disable_global_guardrails admin gate
yucheng-berri ab1fe4a
test(integration): restore contracts.json formatting
yucheng-berri 2cfb50e
test(integration): share guardrail opt-out helpers
yucheng-berri 80ba786
merge: origin/main into litellm_gate_disable_global_guardrails_admin
yucheng-berri 486a0c6
fix(ui): hide the team disable_global_guardrails switch from non prox…
yucheng-berri 0ce0fdb
test(integration): drop covers markers and bound the slow sink check …
yucheng-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import json | ||
| import uuid | ||
| from hashlib import sha256 | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| import httpx | ||
| import yaml | ||
| from pydantic import JsonValue | ||
|
|
||
| from integration._support.client import Gateway, Scenario, object_value | ||
| from integration._support.database import read_rows | ||
| from integration._support.wire import Reply, Request | ||
|
|
||
| MANAGEMENT_ROUTES: Final = ["/key/*", "/team/new", "/team/update", "/v1/chat/completions"] | ||
|
|
||
|
|
||
| def denying_guardrail(request: Request) -> Reply: | ||
| assert request.target == "/beta/litellm_basic_guardrail_api" | ||
| return Reply(body=json.dumps({"action": "BLOCKED", "blocked_reason": "synthetic policy denial"}).encode()) | ||
|
|
||
|
|
||
| def guardrail_config(policy_url: str, path: Path) -> Path: | ||
| config: Final = yaml.safe_load(Path("tests/integration/proxy_config.yaml").read_text()) | ||
| config["guardrails"] = [ | ||
| { | ||
| "guardrail_name": "guardrail" + uuid.uuid4().hex, | ||
| "litellm_params": { | ||
| "guardrail": "generic_guardrail_api", | ||
| "mode": "pre_call", | ||
| "default_on": True, | ||
| "api_base": policy_url, | ||
| "api_key": "synthetic-guardrail-key", | ||
| }, | ||
| } | ||
| ] | ||
| path.write_text(yaml.safe_dump(config)) | ||
| return path | ||
|
|
||
|
|
||
| def stored_metadata(token: str) -> dict[str, object]: | ||
| rows: Final = read_rows( | ||
| 'SELECT metadata FROM "LiteLLM_VerificationToken" WHERE token = %s', (sha256(token.encode()).hexdigest(),) | ||
| ) | ||
| assert len(rows) == 1, rows | ||
| return rows[0]["metadata"] | ||
|
|
||
|
|
||
| def non_admin_caller(scenario: Scenario, member: str, team: str, model: str) -> str: | ||
| return scenario.key(user_id=member, team_id=team, models=[model], allowed_routes=MANAGEMENT_ROUTES) | ||
|
|
||
|
|
||
| def chat(candidate: Gateway, model: str, key: str, marker: str, *, stream: bool = False) -> httpx.Response: | ||
| return candidate.request( | ||
| "POST", | ||
| "/v1/chat/completions", | ||
| {"model": model, "messages": [{"role": "user", "content": marker}], "stream": stream}, | ||
| key=key, | ||
| ) | ||
|
|
||
|
|
||
| def upstream_observations(gateway: Gateway) -> tuple[dict[str, JsonValue], ...]: | ||
| with httpx.Client(timeout=5, trust_env=False) as client: | ||
| drained: Final = object_value(client.get(f"{gateway.upstream_url}/__observations").json()) | ||
| requests: Final = drained["requests"] | ||
| assert isinstance(requests, list) | ||
| return tuple(object_value(entry) for entry in requests) | ||
|
|
||
|
|
||
| def upstream_hits(gateway: Gateway, marker: str) -> int: | ||
| return sum(1 for entry in upstream_observations(gateway) if marker in json.dumps(entry.get("body"))) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.