Repository navigation
Studio: keep managed accounts off owner files and device nodes - #12661
Conversation
Multi-account mode only. llama-server runs as the installation's OS user, and account model access is checked for the model being loaded, not for pass-through paths. A managed account could already not name a custom --mmproj; it could still name --chat-template-file, --grammar-file, -jf, --lora*, --control-vector*, -md / --spec-draft-model, -lcs / -lcd or --log-prompts-dir, either as llama_extra_args or in a custom llama.cpp config it sent itself, and point them at the owner's files. Those flags are now refused (403) for managed accounts on both routes. The owner, and a managed load that inherits the owner's saved override, are unchanged. The Landlock rights on a managed tool's writable roots dropped only symlink creation. They now also drop character and block device node creation and device ioctls, so a root-run Studio cannot hand a tool a raw disk through its own workspace. GPU and /dev access still come from the explicit device rules.
Codex Review SummaryThis 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. |
…mpeg-dir A managed account's load built from the owner's saved per-model override (API auto-switch, including through an alias) or resending the resident same-model settings (UI reload / Apply) was refused, because those values reach /load as an explicit list. Path flag values the owner already chose for the same model now pass; any new path is still refused. A custom INI identical to the owner's saved or resident one passes the same way. --video-ffmpeg-dir makes llama-server run <dir>/ffmpeg, so it is owner only too. /estimate-memory sizes the files these flags name, so a refused path is answered unsizable instead of being opened.
Argument inheritance treats an HF cache snapshot path and its repo id as one model, so a managed reload naming the repo id resent the owner's inherited paths and was refused. Only snapshot paths are mapped; other local paths still compare case-sensitively.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd2e582cb5
ℹ️ 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".
| _refuse_managed_custom_projector( | ||
| extra_llama_args, request.model_path, request._override_alias_id, request.gguf_variant | ||
| ) |
There was a problem hiding this comment.
Resolve the variant before checking owner-approved paths
When a managed caller reloads a model with echoed path arguments but omits gguf_variant, this check runs before ModelConfig resolves the actual quant and passes None as the variant. _owner_chosen_launch consequently cannot find an owner override saved under a variant-qualified key such as org/model:Q4_K_M, and it also rejects a resident intent whose hf_variant is Q4_K_M, returning 403 for an otherwise owner-approved path. Defer this check or repeat it after resolution using config.gguf_variant so the supported omitted-variant reload flow continues to work.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8075503: when the reload names no variant, the resident same-model load matches, since the load resolves the quant the resident one used; a different named variant is still refused.
| and _same_loaded_identifier( | ||
| _snapshot_repo_or_self(getattr(intent, "model_identifier", None)), | ||
| _snapshot_repo_or_self(identifier), | ||
| ) |
There was a problem hiding this comment.
Verify cache paths before granting resident owner paths
A managed account can place an accessible GGUF under its own workspace using a syntactic path such as .../models--private--repo/snapshots/x/model.gguf; model_visible explicitly permits files under the account's workspace, while hf_cache_repo_id recognizes this shape without verifying that it is inside a configured Hugging Face cache. These two calls therefore reduce both that attacker-controlled path and a resident private/repo snapshot to the same repo ID, causing the resident model's owner-only argument pairs or custom config to be accepted for an unrelated managed-account model. Only canonicalize a path here after confirming it is actually beneath a known HF cache root.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8075503: a caller's snapshot-shaped path maps to a repo id only when it sits under a known Hugging Face hub cache; a look-alike path in an account workspace no longer matches the resident repo (new test).
| for i, raw in enumerate(tokens): | ||
| flag = _flag_name(raw) | ||
| if flag in OWNER_ONLY_PATH_FLAGS: | ||
| _, eq, inline = raw.partition("=") | ||
| found.append((flag, inline if eq else (tokens[i + 1] if i + 1 < len(tokens) else ""))) |
There was a problem hiding this comment.
Distinguish option values from owner-only flags
For a managed caller whose legitimate string-valued option begins with a flag-shaped value, such as ['--reverse-prompt', '--lora'], this scans --lora as a separate path option and returns 403 even though llama.cpp consumes the next argv token unconditionally as --reverse-prompt's value (std::string val = argv[++i] in the upstream parser). Track valued-option boundaries using the selected server's option catalog instead of interpreting every token beginning with - as an active path flag.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it only fails closed (a 403 for a managed account) when a string option's value itself looks like a path flag, which no Studio flow sends. Owners are unaffected.
…nt follows the resident load
|
@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: 807550396d
ℹ️ 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".
| and _same_loaded_identifier( | ||
| _snapshot_repo_or_self(getattr(intent, "model_identifier", None)), | ||
| _snapshot_repo_or_self(identifier, require_cache = True), |
There was a problem hiding this comment.
Verify resident snapshot paths before canonicalizing
When the owner has loaded a local model from a snapshot-shaped path outside the Hugging Face cache (for example, /owner/models--org--public/snapshots/x/model.gguf) and a managed caller can access the real org/public repo, the resident side is unconditionally reduced to org/public while only the caller side requires cache membership. The models therefore compare equal, and the caller can resend the owner-only paths exposed in the runtime settings to have them accepted for an unrelated model. Fresh evidence beyond the prior thread is that this updated line still invokes _snapshot_repo_or_self for the resident intent without require_cache=True; require real-cache membership on both sides before granting the resident exemption.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 045d538: the resident side now also maps a snapshot-shaped path to a repo id only when it is inside a known Hugging Face hub cache (new test case).
| _refuse_managed_custom_projector( | ||
| extra_llama_args, request.model_path, request._override_alias_id, request.gguf_variant |
There was a problem hiding this comment.
Recheck path flags after inheriting resident arguments
When a managed request omits llama_extra_args, as the settings Apply flow does, this check receives None and returns, but _resolve_inherited_extra_args later populates the list from the resident backend without another owner-only-path check. Its same-model predicate canonicalizes any snapshot-shaped path through _canonical_model_identity, so an accessible workspace path such as models--private--repo/snapshots/x/model.gguf can inherit the owner resident's --lora, template, or executable-directory arguments automatically. Fresh evidence beyond the earlier fixed thread is that the unsafe arguments are added at line 18329 after the new check has already run; recheck the resolved list or require real cache membership in the inheritance predicate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 045d538: extras inherited from the resident load go through the same owner-only path check as a sent list, so a look-alike path cannot pick up the owner's path options (new test test_inherited_owner_paths_get_the_same_managed_check).
| """Rights on a writable root. No symlink creation: the server follows links, so a tool must not | ||
| plant an escaping one. No device nodes or device ioctls either: a root-run Studio would otherwise | ||
| let a tool mknod a disk in its workspace; real devices come only from the explicit device rules.""" | ||
| return handled & ~(_FS_MAKE_SYM | _FS_MAKE_CHAR | _FS_MAKE_BLOCK | _FS_IOCTL_DEV) |
There was a problem hiding this comment.
Reject device nodes already present in writable roots
On a root-run Studio without a device cgroup, a managed workspace may already contain a character or block node—for example, one left by a tool before this upgrade or supplied through a persistent volume. This mask still grants READ_FILE and WRITE_FILE to every entry beneath the writable root; removing MAKE_CHAR/MAKE_BLOCK only prevents creating another node, and removing IOCTL_DEV does not prevent ordinary reads or writes to a raw disk node. Scan and reject/remove existing device nodes before granting the writable-root rule so upgrading actually closes the device-access path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs a root-run Studio without a device cgroup plus a device node already sitting inside a managed workspace. Studio never puts device nodes there, and removing MAKE_CHAR/MAKE_BLOCK stops tools from creating them from now on.
…k inherited extras
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
)" (#12725) This reverts commit 864fec4. Conflicts with later commits were resolved by keeping their changes and removing only the custom llama.cpp config parts. The custom config handling #12661 added to _owner_chosen_launch and _refuse_managed_custom_projector is removed too; the owner-only path check for llama_extra_args stays.
Summary
Two confinement gaps that only apply in multi-account Studio (an owner plus managed accounts in one Studio process). Owner and single-user behaviour is unchanged.
Managed accounts could point llama-server at the owner's files.
validate_extra_argsblocks llama-server flags that write files, but flags that read a path (--chat-template-file,--grammar-file,--json-schema-file,--lora,--lora-scaled,--control-vector*,--model-draft,--model-vocoder,--lookup-cache-*,--mmproj,--video-ffmpeg-dir) were accepted from a managed caller'sllama_extra_argson/load, and from a custom INI config the managed caller sends itself. llama-server runs as the owner's OS user, so those paths were read with the owner's access. Managed accounts now get a 403 for these flags (the message does not echo the path);--log-prompts-dir, a write flag that was not blocked, is included. Only custom--mmprojwas refused before.--video-ffmpeg-dirmatters most: llama-server runs<dir>/ffmpegto decode a video, so a managed tool could stage an executable and have it run as the owner.Values the owner already chose for the same model still pass, so no managed flow changes: the owner's saved per-model override (written only through owner routes; this covers API auto-switch loads, including through an alias) and the currently loaded same-model instance (so the UI resending inherited or echoed settings on a reload or Apply keeps working). A custom INI identical to the owner's saved or resident one passes the same way. Only a new path value is refused. This also stops the existing 403 a managed auto-switch got when the owner had saved a custom
--mmproj./estimate-memorysizes the files these flags name, so for a managed caller it answersunsizable(the panel's normal "cannot size" state, not an error) for a path the load would refuse, instead of opening it.The managed-account tool sandbox allowed creating device nodes. The Landlock rules for a managed account's writable tool workspace removed only symlink creation, leaving MAKE_CHAR, MAKE_BLOCK and IOCTL_DEV. On a Studio running as root without a device cgroup, a tool could
mknoda block device in its workspace and read or write the disk._writable_access()now also drops those rights, computed from the ABI-handled mask so rights an older Landlock ABI does not know are never touched. GPU and/devaccess come from the explicit device rules and are unaffected.Testing
test_llama_server_args.py,test_llama_custom_routes.py,test_mmproj_placement_policy.py,test_account_tool_confinement.py): 581 passed, 1 skipped; on main the same files fail exactly the 21 new or updated tests.os.mknod(S_IFCHR)in its workspace returns EPERM on main (Landlock allowed it; only the capability check stopped it, which a root-run Studio passes) and EACCES on this branch (Landlock refuses it). Normal file writes work on both./estimate-memoryanswersunsizablefor a refused path without opening it (fails without the gate).tests/multi_account957 passed; touched and route suites (test_mmproj_placement_policy.py,test_llama_custom_routes.py,test_llama_server_args.py,test_account_tool_confinement.py,test_openai_auto_switch.py, memory-estimate suites): all pass except twotest_openai_auto_switch.pyfixture-hygiene checks that fail identically without this change.tests/multi_accountplus confinement, sandbox,test_account_*, extra-args and custom-config suites (82 files): 3629 passed, 10 skipped, 0 failed on this branch; main fails exactly the 10 new tests.Not covered: an end-to-end multi-account load through a real llama-server (the routes were tested at the helper level), and a root-run Studio demonstrating the original device-node escalation.