The gateway now authenticates LiteLLM virtual keys as well as the master key. Keys are looked up by sha256 hash in the proxy's LiteLLM_VerificationToken table (general_settings.database_url or DATABASE_URL), honoring expires, blocked, models and allowed_routes, and are read from Authorization: Bearer, x-api-key or api-key The same query LEFT JOINs the key's team. A blocked or missing team refuses the key and the team's models narrow the key's, as in the proxy's can_key_call_model and can_team_access_model. The key's team also stays in its grant: a deployment whose model_info.team_id names a team serves only that team's keys, so routing and retries skip it for any other virtual key, as the proxy's filter_team_based_models does. The master key routes as before Keys with budgets pass without spend tracking: the gateway does not record spend for its own requests, so a key or team gets the proxy's budget-exceeded error only once the spend the Python proxy has stored reaches its max_budget Every other restriction the proxy enforces and this gateway does not yet fails closed. The query also joins the key's team membership, user and budget tables and reduces each restriction column to whether it is set, and a key carrying one (rate limits and max_parallel_requests, including those in a budget table or per model in model_max_budget, a membership's allowed_models, projects, organizations, agents, guardrails, tags, tool allowlists, enforced params and the like, on the key, its team, its membership or its user) gets a 401 saying that kind of key is not supported by this gateway yet Lookups sit behind a moka cache (60 s for found keys, 5 s for unknown ones) with single-flight misses. When the database fails, recently seen keys keep working from a stale copy and store reads pause briefly; the master key never needs the database. Auth failures return the proxy's ProxyException JSON, including 403 key_model_access_denied for a model outside the key's list The load-test README documents running with virtual keys and x-api-key, and key-churn asks for the 4 model groups genconfig creates by default |
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| README.md | ||
Gateway management
This crate scaffolds virtual key creation, retrieval, and revocation with an injected KeyStore. gateway-auth::keys owns the separate read-only KeyLookup interface and credential verification. Neither crate imports a database implementation
The future db key repository should implement both interfaces against the existing LiteLLM database. The gateway composition layer can inject the same repository into management and authentication, sharing its connection pool
Storage contract
create inserts the supplied hash and expiration atomically, returning AlreadyExists without changing an existing record on collision. Management generates a token from 32 bytes of operating-system randomness and returns its plaintext only after storage succeeds. KeyHash uses the existing SHA-256 token hashing function. Storage never receives the plaintext token
get returns the stored status, including revoked keys. revoke returns Revoked for an existing key, including one already revoked, and NotFound for a missing key. Once revocation succeeds, every subsequent lookup must return revoked or missing, including lookups from other gateway instances. Database writes and any cache invalidation must preserve this contract
KeyLookup returns active status with optional expiration, revoked status, or no record. Backend failures remain errors. verify_key checks the current lookup result and expiration on every call, reads its supplied clock after lookup completes, and returns the verified hash. Pass SystemTime::now in production or a fixed clock in tests
Scope
These are backend operations, with no HTTP routes, database adapter, production in-memory store, or gateway CLI wiring. The in-memory repository under tests exercises the shared storage contract. Verification establishes only that a credential is valid; it does not grant permissions. Caller identity, management authorization, and inference policy enforcement belong to the gateway auth integration before these operations are exposed over HTTP
The existing master-key authentication path is unchanged. User, team, model, and budget policies are not represented in this scaffold, so existing database rows carrying those policies require that integration before they can authorize traffic