litellm/tests/unit/proxy/rag_endpoints
tavren27 da8c02b9d5
fix(proxy): resolve a team wildcard deployment for a wildcard key on files, batches and RAG routes (#49744)
* fix(proxy): resolve a team wildcard deployment for a wildcard key on files, batches and RAG routes

A key allowed gpt-* in a team whose BYOK deployment is named openai/* fell back to the
environment OPENAI_API_KEY on /v1/files, /v1/batches and /v1/rag, because the key allowlist
check never matched a wildcard against a wildcard. Two wildcards now cover each other when
some model litellm knows for the deployment's provider matches both, so a claude-* key still
never resolves a team openai/* deployment

* test(proxy): type the team wildcard credentials helper's return

* fix(proxy): keep a restricted key on the team wildcard for RAG files and vector store file lists

Every files, RAG and vector store site now authorizes the model the key
reaches the team deployment by. A RAG upload is registered under that
model, so a later retrieve or delete by the same key passes auth, and the
vector store file list skips a team OpenAI model the key cannot call
instead of answering 403 on it

Put auth_checks back as it is on main, dropping the wildcard_pattern_regex
helper that CodeQL flagged

* fix(proxy): check every allowlist before a restricted key gets a team deployment's key

Files and batches give a key with its own allowlist the team deployment's provider key only once the model it reaches passes the key, team, org, and project checks that request auth runs

The vector store file list and the stored deployment check use the same gate for team deployments and keep main's exact-name check for proxy-wide ones, a RAG managed id never records a pattern from the key's own list, and the reverse match is computed once per call

* fix(proxy): try every model a restricted key reaches before picking a team provider key

Files, batches, RAG and vector store files now try each model the key and the team
deployment both cover and use the first one that passes the full key, team, org and
project checks, so a team narrower than the key, or a key whose first exact name the
team blocks, keeps the team's provider key. A deployment the key names directly wins
over one only two wildcards share, so adding a team openai/* model never moves a key
off the exact model it used before. The batch rate limiter and RAG ingest and query
use the same checked lookup as uploads, so the JSONL model check never reads a file
with a key the caller could not use

* fix(proxy): try the key's project allowlist names when resolving a team provider deployment

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-18 10:55:44 +00:00
..
__init__.py
test_rag_endpoints.py fix(proxy): resolve a team wildcard deployment for a wildcard key on files, batches and RAG routes (#49744) 2026-11-18 10:55:44 +00:00
test_upload_security.py