Repository navigation
Studio: add inference only API keys - #17833
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…nference [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d4ffe1fe1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _inference_key_may_call(credentials: HTTPAuthorizationCredentials) -> bool: | ||
| from utils.keyless_api_access import KEYLESS_SCOPE_INFERENCE, scope_covers | ||
| route = getattr(credentials, "route", None) | ||
| return route is not None and scope_covers(KEYLESS_SCOPE_INFERENCE, *route) |
There was a problem hiding this comment.
Enforce the no-load policy on Decision API routes
When the Decision API is enabled, an inference-only key belonging to the owner can still download and switch models through POST /v1/systemone (also admitted through /mcp/decisions). Reusing the keyless allowlist admits these endpoints, but routes/systemone.py::system_one restricts checkpoint selection using request_admitted_without_credential and is_owner_context, not LoadPolicy.NEVER: this key is authenticated and retains the owner's context, so both checks permit it. _decide then reaches laya_runtime._ensure_loading, which starts a model loader without checking the load policy; its loaders can fetch uncached checkpoints. Apply the inference-only no-load restriction to this execution path, or exclude these routes until they enforce it, so a restricted key cannot bypass the model-management prohibition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 677d983: an inference only key now gets 403 on any Decision API model other than the configured one, as a keyless caller does; test added.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 677d983f57
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if record.get("key_access") == API_KEY_ACCESS_INFERENCE and not _inference_key_may_call( | ||
| credentials | ||
| ): |
There was a problem hiding this comment.
Restrict state-changing chat tools for inference-only keys
When the owner has skill-creator enabled and server-side tools are available, an inference-only key can send /v1/chat/completions with enable_tools: true and have the model call create_skill. routes/inference.py::_select_request_tools still offers that tool, and core/inference/tools.py calls skills.create_skill directly, permanently installing an enabled skill in the owner's ~/.agents/skills. Neither the route allowlist nor LoadPolicy.NEVER restricts this execution path; narrowing the key minted for Studio MCP only protects forwarded MCP calls, not built-in tools. This lets a supposedly inference-only caller change the owner's persistent agent configuration and influence subsequent chats. Apply the restricted authority to built-in tool selection/execution as well, excluding state-changing tools.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 89e9e17: an inference only key now runs with server-side tools hard-disabled (the same tools_force_disabled switch keyless access uses), so it cannot call python, terminal, create_skill or any other built-in tool; test added.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…(rest red on main) (#17956) ## Summary `(Python 3.13, rest)` is red on main (seen on the staging run of #17933): ``` studio/backend/tests/multi_account/test_alice_bob_matrix.py::test_object_route_factory_completeness E AssertionError: ['routes.auth:PATCH:/api-keys/{key_id}'] ``` #17833 added `PATCH /api/auth/api-keys/{key_id}` (switch a key between full and inference access). The account isolation matrix requires every object route to have a factory, so it is exercised as owner / right user / wrong user / unauthenticated / deactivated, or to be listed as skipped with a reason. The new route had neither. The route itself is scoped correctly (`set_api_key_access` filters by the caller's key scope); it was only missing from the matrix. ## Change Test only: `studio/backend/tests/multi_account/factories.py` adds a factory for the route next to the existing `DELETE /api-keys/{key_id}` one: seed one of alice's keys, PATCH it to `{"access": "inference"}`, and expect the response to show `inference` for alice and a 404 for everyone else, with alice's data unchanged on every rejected call. ## Testing - The matrix rows for both api-key routes plus the completeness / skipped / factory checks: 15 passed. On main the completeness check fails as above. - Sabotage: with the key scope removed from `set_api_key_access` (any user can change any key), the new `[owner]` and `[wrong]` rows fail.
Fixes #17819
An
sk-unsloth-key acts as its account on the whole Unsloth API. Someone exposing Unsloth on a LAN or behind a reverse proxy so a remote client can chat found that the same key can also load, unload and download models, flip Model auto-switch back on, and mint more keys. Turning Model auto-switch off does not stop any of that: it only decides whether a chat request naming an unloaded model loads it. There was no way to hand out a key that can only chat.This PR lets a key be Full access (the default, exactly what every key does today) or Inference only. The create form is unchanged; the choice sits on the new token card, next to "Copy now - this won't be shown again.", and an inference only key is labelled Inference in the token list.
An inference only key:
_INFERENCE_ROUTES):/v1/chat/completions,/v1/completions,/v1/embeddings,/v1/messages,/v1/responses, the token counters,GET /v1/models,GET /api/inference/loaded-modelsand the llama.cpp discovery probes;403with a message naming the reason on everything else (/api/inference/loadand its/v1/loadalias, unload, downloads, settings, training, key management);LoadPolicy.NEVER, so even with Model auto-switch and auto download on, a chat request naming an unloaded model is refused instead of loading or downloading it;API:
POST /api/auth/api-keystakes an optionalaccess(fulldefault, orinference); list and create responses report it.PATCH /api/auth/api-keys/{id}with{"access": "full" | "inference"}changes it on an active, non-internal key of the caller's own account (the new token card uses this). It takes effect on the key's next request, and repeating it is a no-op. An inference only key cannot call it, so it cannot widen itself.What does not change:
unsloth startand the desktop key are full access, as before. The newaccesscolumn is NULL for every existing row and NULL reads as full.account_api_keys) carries the access too, so a key restored from it after an older build's bulk delete stays inference only.fullreads as inference only, never wider. The check runs where the key is validated, on the route the bearer was sent to; credentials built anywhere else carry no route and refuse an inference only key.Checked on a real backend (base
a21e6b7vs this branch, same install, Model auto-switch off, offline HF cache):GET /v1/modelsPOST /v1/chat/completions(no model loaded)POST /api/inference/loadPOST /v1/loadPOST /api/inference/unloadPUT /api/settings/openai-auto-switchPOST /api/auth/api-keysTests:
studio/backend/tests/multi_account/test_decision_api_fine_tunes.py: an inference only key keeps the configured Decision API model and gets 403 on any other.studio/backend/tests/test_inference_only_api_key.py(33 cases): full keys keep every route; inference keys keep the chat routes with the never-load policy and are refused model management; legacy databases keep their keys full; unknown stored values read as inference only; create, list and PATCH round-trip the access (narrow, widen, repeat, an inference key cannot widen itself, internal and revoked keys untouched); the MCP gate refuses; the chat tools key inherits it; a managed key restored from its copy keeps it. With the auth check disabled, the route tests fail.studio/frontend/tests/api-key-access.test.ts,npm run i18n:check:strict(every locale has the new strings),scripts/typecheck.mjs.Settings > API before and after (merge base
a21e6b7vs this branch):The create form is unchanged.
After Create token, the access choice sits next to the copy-now note; the key starts as Full access and Inference only switches it.
An inference only key is labelled Inference in the list (the API reports
access: inference).