Skip to content

Studio: per-account isolation for shared installs and the desktop app - #10588

Merged
danielhanchen merged 59 commits into
mainfrom
studio-account-isolation
Sep 13, 2026
Merged

danielhanchen merged 59 commits into
mainfrom
studio-account-isolation

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Studio and the desktop app can be shared by several people on one machine. The installation owner (the existing unsloth login) creates accounts from Settings > Accounts. Each account signs in with a one-time setup code, sets a password, and then has its own chats, projects, settings, credentials, uploads, datasets, training runs, outputs, exports, galleries, RAG store, sandboxes and temporary files. Nothing an account does is visible to, or can affect, another account.

A single-account install is unchanged: same paths, same database files, same password-only login, same desktop auto-login, same keyless loopback behaviour, and no extra I/O on the hot paths. Multi-account policy switches on only when a second account exists.

How isolation works

  • Identity is an immutable account_id; usernames are display names only, so re-creating a username never inherits data.
  • Each request is bound to its account through a ContextVar; storage roots, database paths and caches resolve through it at call time. Background work carries the account explicitly, and unbound work resolves to the owner.
  • Managed accounts live under <studio home>/accounts/<account_id>/; the owner stays at the legacy root. The model cache, binaries, the auth database and the Hugging Face cache are shared, and a managed account sees a cached model only when it is provably public or it downloaded it.
  • Every storage module initialises its schema per database path. Paths must resolve inside the account's own roots, including through symlinks.
  • Object routes answer 404 for another account's ids. Deactivating an account invalidates its tokens and API keys; deleting it cancels its jobs, closes its MCP sessions and renames its roots aside, all or nothing.
  • Preview and RAG download links are bound to the minting account. Model load and unload rows in the API monitor are visible only to the owner and the loading account.
  • Installation-wide actions (accounts, updates, installers, shutdown, executables, caches, network settings) are owner-only.

Login, reset, desktop, downgrade

  • /api/auth/status reports login_mode and never lists accounts. With one account the form is unchanged; with more, a username field appears and the setup code is the first password.
  • unsloth studio reset-password keeps its behaviour for one account and requires --username with several.
  • The desktop shell still starts and adopts the backend with its secret and authenticates its ownership probe and quit path with that secret. With one account it auto-signs in; with several it shows the login form.
  • After a downgrade a managed account gets 401 everywhere instead of the owner's data; the next upgrade brings it back. full_access stays off while any managed account record exists.

Sandboxes and the shared GPU

  • Sandboxes are per account. Full tool access is refused server-side whenever more than one account exists. A managed account's python and terminal tool processes are confined at the OS level (Landlock ABI 6 on Linux 6.12 or later, which also keeps signals inside the tool's own process tree, sandbox-exec on macOS): read-only workspace, no link creation, and the install root, other accounts' roots, the shared Hugging Face cache and the per-user temp tree are hidden. Where no mechanism exists, code execution is refused for managed accounts; the owner can opt out with UNSLOTH_STUDIO_ALLOW_UNCONFINED_TOOLS=1.
  • GPU arbitration is ownership-aware: a different model while another account is generating is refused with 409 gpu_busy and Retry-After; an idle swap happens as today. Cancel is scoped to the caller and rechecked under the engine lock. Another account's resident model reports {"loaded": true, "yours": false} (the chat status keeps its list shape: {"loaded": [], "loading": [], "yours": false}).
  • Same model, same settings: a load that matches the resident chat model reuses it instead of evicting and relaunching llama-server, and the account joins its sharers. Every sharer sees and uses the model from Studio and the OpenAI routes; chats, cancels, monitor rows and credentials stay per account. A sharer's unload drops only its share while others remain; the last sharer or the installation owner tears the model down. A replacement load, teardown, idle unload, deactivation or deletion resets the shares.
  • Under --secure, one Cloudflare quick tunnel URL serves every account with Studio's own authentication; keyless access is never admitted on the tunnel and, once a second account exists, not on loopback either.

Kept as design: the installation owner can see and unload a managed account's idle resident model and can browse its private model folder by absolute path, because the owner administers the machine.

Verification

  • Backend suite on this branch merged with main: 42,713 passed; the remaining failures are the same on main (accelerator-dependent tests and one timing test).
  • Frontend: unit tests, tsc, strict locale parity for the Accounts strings, build and bundle budget.
  • Recorded simulations: legacy install upgrade and downgrade; two-account downgrade; password reset; two accounts on one B200 with real llama-server (shared model, refused swap while streaming, idle swap, scoped cancel, delete mid-stream); parallel throughput parity with main; a real quick tunnel run; the account-switch journey on Chromium, Chrome, Edge, Firefox and WebKit; hot-path connection, query and mkdir counts identical to the merge base; a route matrix over every object route with owner, right account, wrong account, unauthenticated and deactivated actors.
  • Rust unit tests for the desktop ownership probe pass locally and in the Tauri CI job.
  • Single-user cost: with accounts off, every owner request runs the same sqlite connections, mkdirs and thread hops as the merge base and fewer statements (the auth schema check is cached per connection), and the counts do not change with 1, 2, 3 or 100 accounts; the account count is never re-read from auth.db on a request, no sharer or fence state is allocated on an owner-only install, and the llama admission queue is the same object for every account. Locked in by tests/multi_account/test_routing_invariance.py. On a B200 with Qwen3-0.6B Q4_K_M, three paired rounds of merge base versus this branch with accounts off: server decode 1768 vs 1774 tokens/s, TTFT 68.2 vs 68.8 ms, status/models/auth/threads p95 within 4 percent, load time no slower. The owner's numbers are unchanged with one idle managed account (created or logged in and polling) and with 100 accounts and 10 idle sessions; the run-to-run spread of the server-reported decode rate on this model is about 8 percent, and every scenario sits inside it.
  • The multi-account browser flow is a Python Playwright driver (tests/studio/playwright_multi_account.py), matching the other tests/studio/playwright_*.py checks, so the frontend lockfile gains no new dependency.

Relation to #10102 and #10250

This is a from-scratch implementation on today's main; #10102 and #10250 were used as references for coverage and no code was taken from them. It differs in keying storage on an immutable account id rather than the username, initialising schemas per database path, binding requests through a ContextVar with an async form, arbitrating the GPU instead of evicting other users' streams, refusing full access server-side, confining tool processes at the OS level, and fencing managed credentials from older builds. The four review P1s on #10250 are addressed here by construction, so #10250 can be closed in favour of this PR.

Screenshots

Each pair is the same scene captured twice: BEFORE is the merge base, AFTER is this branch, driven against two isolated installs.

Turning on multi-user accounts

Nothing changes until the installation owner asks for it. Sign in as the owner, open Settings, and pick the new Accounts tab. Type a username, press Create account, and that first managed account is what switches the install to multi-user. The tab, and everything on it, is owner-only: a managed account never sees it.

Studio shows the new account's setup code once. Copy it and hand it to the person it belongs to. It is their first password, it works once, and it expires in 60 minutes.

Settings, Accounts tab: create an account and copy its setup code

The settings search finds the tab by name, so the owner does not have to know where it lives.

Settings search for Accounts

The account holder's first sign-in

Once a second account exists, the login form grows a Username field and says where the setup code comes from. With a single account it stays the password-only form it has always been.

Login form gains a username field

Signing in with a setup code lands on a forced password change instead of the chat, so a code that was sent over chat or email never becomes a lasting credential.

First sign-in forces a password change

Administering an account

Regenerating a setup code is the password reset path. It replaces the password, signs the account out and revokes its API keys, and the dialog says so before it happens.

Regenerate setup code confirmation

Deactivating keeps the account and its data but invalidates its tokens and API keys, and the row offers Reactivate. Deleting is the destructive one: it cancels the account's jobs, closes its MCP sessions and renames its roots aside.

A deactivated account offers Reactivate

What a managed account cannot do

Full tool access is refused server-side whenever more than one account exists, so the chat permission menu drops the Full access option for a managed account rather than offering something the backend will reject.

Permission menu without Full access

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T02:35:20.905040Z 434a4ee Manual request
🔒 Security Review ✅ Completed 2026-09-10T07:19:00.290244Z c1db692 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54ac9b4294

ℹ️ 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".

"(allow sysctl-read)",
"(allow mach-lookup)",
"(allow ipc-posix-shm)",
"(allow network*)",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Isolate managed tool processes from private networks

For a managed account on macOS this explicitly permits every network operation, while the Linux Landlock rules likewise leave handled_access_net at zero. The command checks are not a security boundary: an account can write a Python/C helper as a file and execute it after approving the tool call, allowing a remote Studio user to connect from the host to loopback, link-local metadata endpoints, or otherwise inaccessible LAN services. Managed tool processes need OS-level private-network isolation or a mediated public-only transport, as is already done for managed MCP connections.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a defect this PR introduces. Tool processes have run in the host network namespace since before this change (tools.py records why CLONE_NEWNET is not applied), and the confinement added here is a filesystem boundary by contract. Landlock rules are per TCP port and sandbox-exec has no address ranges, so neither can express deny-private-allow-public; a filtering proxy plus a network namespace is a separate feature that applies equally to the owner sandbox on main.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ddbd69579

ℹ️ 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".

"/snap",
"/nix",
"/var/lib",
"/proc",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hide sibling process environments from managed tools

On Linux, granting the confined process read access to all of /proc exposes /proc/<pid>/environ for dumpable same-UID sibling processes. For example, model-download workers are launched with the initiating account's HF_TOKEN in their environment, so a managed tool running concurrently can enumerate processes and recover another account's token; hardening only the Studio parent does not protect these workers. Exclude sensitive procfs entries or otherwise isolate process visibility at the OS boundary.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landlock already denies this. /proc//environ is gated by a ptrace access check, not by the /proc read grant, and a confined tool's domain is never a superset of an unconfined worker's, so the read fails with EACCES while cmdline still succeeds. Reproduced on this host: a sibling with HF_TOKEN in its environment, read from a confined managed tool, gives Permission denied. A preexec PR_SET_DUMPABLE is also wiped by the following execve, so the proposed fix would not work.

Comment on lines +348 to +349
target = getattr(importlib.import_module(job_module), job_target)
return target(**kwargs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Confine managed job workers before loading remote code

When a managed account enables trust_remote_code for a model it controls, the training/export worker eventually executes that repository's Python in this child without any filesystem confinement. The selective environment cleanup does not change the process UID, working directory, or HOME, so that code can enumerate and read the owner's workspace, other accounts' roots, saved host credentials, and any unlisted secret environment variables. Run managed job children inside the same account filesystem boundary used for tools, rather than relying only on validated configuration paths.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A managed account cannot enable remote code on any job path: the consent gate refuses it before the scan for every non-owner context, job children are bound to the account through run_account_child, and the only auto-enables require a Hub-verified unsloth or nvidia repo. Confining the training process itself is a separate feature, since it must read the shared cache, write outputs and load CUDA libraries.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

}
// Fence first: peers see it before the tokens, so nothing of the previous account goes out
// under the new credentials while their reload is pending.
if (changed) storage.setItem(BROWSER_ACCOUNT_FENCE_KEY, marker);
if (changed) storage.setItem(BROWSER_ACCOUNT_FENCE_KEY, marker);
commitSession();
if (storage.getItem(BROWSER_ACCOUNT_KEY) !== marker)
storage.setItem(BROWSER_ACCOUNT_KEY, marker);
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3dd3af6d7

ℹ️ 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".

Comment on lines +151 to +153
if urlsplit(url).scheme != "https":
raise ValueError("Managed accounts may only use HTTPS provider endpoints.")
public_provider_address(url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin recipe-provider connections to the validated public address

For a managed account using an attacker-controlled hostname, DNS can return a public address during public_provider_address() and a loopback or LAN address when the Data Designer client later resolves the endpoint. Requiring HTTPS does not enforce public routing: TLS authenticates the hostname, and a private endpoint can present a valid certificate for that same attacker-controlled name; even a failed handshake still initiates a connection to the private service. Route these requests through the pinned public transport used for normal providers/MCP, or otherwise bind the actual connection to the address validated here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 434a4ee. The recipe job subprocess now installs a resolver guard for managed accounts: socket.getaddrinfo and gethostbyname refuse any answer that is not a global address, so a name that rebinds to loopback or the LAN after the endpoint check fails at resolve time and no connection is initiated. It is process-wide in the worker only, which is the process the engine dials from, and the HTTPS plus public-address check at recipe build time stays. Covered by test_managed_recipe_worker_refuses_names_that_resolve_privately.

Comment on lines +315 to +316
for path in _existing((_DEVICE_ROOT,)):
rules.append((path, device))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict device access to the nodes tools actually require

On a shared Linux host, managed tools run under the same Unix identity as Studio, so granting read, write, and ioctl access beneath all of /dev exposes same-UID resources outside the account workspace. For example, a tool can open another Studio/owner terminal through a guessed /dev/pts/<n> path, and it can access known same-UID objects under /dev/shm; root or privileged deployments additionally expose any mounted block and character devices. Grant only required pseudo-devices and explicitly selected accelerator nodes rather than the entire device tree (the macOS profile contains the analogous broad grant).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 434a4ee. The Landlock rules no longer grant /dev; they grant the pseudo-devices (null, zero, full, random, urandom, tty) and the accelerator nodes that exist (nvidia*, nvidiactl, nvidia-uvm, nvidia-caps, dri, kfd). /dev is also treated as protected when the system roots are granted child by child, so the /run/shm link cannot reintroduce /dev/shm. The macOS profile now allows the same pseudo-devices by literal path instead of the /dev subpath. A runtime test confirms a managed tool reads /dev/urandom and writes /dev/null but cannot list /dev/shm.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 434a4ee0cb

ℹ️ 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".

# Conflicts:
#	studio/backend/routes/inference.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants