Repository navigation
Studio: auto-generate an admin password for headless public launches - #7392
Conversation
|
@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: 2bdc68ecce
ℹ️ 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".
| # Same-tab URL may carry the one-time token; the shared link never does. | ||
| same_tab_url = _append_link_token(url, same_tab_link_token) |
There was a problem hiding this comment.
Complete the enabled link-token handoff
With start(link_token=True) or the environment opt-in, this appends a bearer token to the iframe URL but no frontend source consumes link_token or calls /api/auth/link-exchange (the TODO immediately above confirms this). Consequently users still get the normal login page, while the unused credential remains in the page URL/history until expiry instead of being exchanged and scrubbed; either wire the frontend exchange/scrub before exposing the option or do not mint/append the token.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
link_token is an explicit opt-in, default OFF (start(link_token=True) or UNSLOTH_STUDIO_COLAB_LINK_TOKEN=1); the frontend TODO is documented in _show_and_embed and the start() docstring. On the default path nothing is minted or appended, so there is no leak for a normal user. When opted in, the token rides only the same-tab proxy URL in the operator's own browser (never the shared Cloudflare link) and is single-use with a short TTL. Keeping this as the tracked TODO rather than changing behavior: the frontend exchange + history scrub lands with the same opt-in.
|
Codex Review: Didn't find any major issues. Bravo. 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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6757025f35
ℹ️ 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 _is_colab_runtime(): | ||
| if _embed_kernel_port_iframe(port): | ||
| return | ||
| _embed_html_iframe(url, port) | ||
| _embed_html_iframe(url, port, same_tab_url = same_tab_url) |
There was a problem hiding this comment.
Attach the link token on the normal Colab path
When start(link_token=True) runs on real Colab, the token-bearing URL is passed only to this HTML fallback. The default Cloudflare flow returns earlier at line 760, while cloudflare=False normally returns after serve_kernel_port_as_iframe() succeeds, so the documented opt-in never loads or displays a URL containing the token in either normal Colab flow; it works only when the kernel helper fails or outside Colab. Provide a token-capable same-tab navigation path rather than discarding it on the standard embed paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not a defect, this is the documented opt-in TODO. link_token defaults to OFF and the docstring in _show_and_embed states plainly that the built UI does not yet read ?link_token, POST it to /api/auth/link-exchange, store the JWT and scrub the query with history.replaceState, so the token is emitted but unused everywhere today, not just on the kernel-helper and Cloudflare paths. The backend half (mint, single-use exchange, expiry, rate limit, secret binding) landed first deliberately; wiring the frontend handoff is the follow-up that will consume it. Adding a token-capable same-tab navigation path now would put a bearer credential on a URL for a UI that ignores it, which is exposure without benefit. serve_kernel_port_as_iframe takes only a port and cannot carry a query string, and the shared Cloudflare link must never carry the token by design.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6dd73e4f8f
ℹ️ 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".
| headers = {"Retry-After": str(blocked_for)}, | ||
| ) | ||
|
|
||
| exchanged = exchange_link_token_with_secret(payload.link_token) |
There was a problem hiding this comment.
Commit token consumption together with session issuance
When a valid exchange encounters a transient failure after this call—such as create_refresh_token() timing out on the auth database or the final password-state lookup raising—the JTI deletion has already been committed by consume_link_token(). The endpoint therefore returns 500 while permanently destroying the one-time credential, and retrying the same link receives 401 even though no session was delivered. Consume the link token and persist the issued refresh token in one transaction so either the complete exchange commits or the token remains retryable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining this one. Burning the jti on a partial failure is the intended direction for a single-use credential: after consume_link_token commits, the only safe assumption is that the token may have been used, so leaving it retryable would reopen exactly the replay window the route documents (consume-before-rotation, cf. Keycloak CVE-2026-1035). The user is not stranded either, the same-tab login page still works and the token expires in 10 minutes. The proposed remedy also conflicts with the security property already in place: issuance is deliberately performed AFTER the consume and is then rechecked against the JWT secret the token validated with, revoking the just-minted refresh token if a password change rotated it. Folding consume plus refresh-token insert into one transaction would require threading a shared connection through consume_link_token, save_refresh_token and the rotation recheck, which is a redesign of the auth storage layer for a nicety on a path that only triggers when the auth DB is already failing, and it would trade a fail-closed error for a fail-open one.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f23a1acaea
ℹ️ 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".
| exchanged = exchange_link_token_with_secret(payload.link_token) | ||
| if exchanged is None: | ||
| _record_login_failure(ip_key) | ||
| raise HTTPException( | ||
| status_code = status.HTTP_401_UNAUTHORIZED, | ||
| detail = "Invalid, expired, or already-used link token", | ||
| ) | ||
| username, secret_at_exchange = exchanged | ||
| access_token = create_access_token(subject = username) | ||
| refresh_token = create_refresh_token(subject = username) |
There was a problem hiding this comment.
Consume the link token only after session issuance succeeds
exchange_link_token_with_secret() deletes and commits the one-time nonce before this route creates either session token. If the subsequent JWT-secret lookup or save_refresh_token() encounters a transient SQLite error, the endpoint returns a 500 but the link token has already been irreversibly consumed; retrying the same URL then returns 401, leaving the user without the promised session. Make nonce consumption and refresh-token insertion atomic, or otherwise preserve a safe retry path when issuance fails.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining again, same rationale as the earlier round on this endpoint.
Burning the jti before issuance is the intended direction for a single-use credential. The token is the whole credential here (the endpoint is unauthenticated), so the failure we optimise for is replay, not retry: on any doubt the nonce must be gone. A 500 after consumption costs the user one re-login through the normal form, which is always available; leaving the nonce live so a 500 can be retried would also leave it live for anyone who captured the URL out of a shell history, a proxy log or a saved notebook.
Making consumption and refresh-token insertion one transaction is also not compatible with the binding this route deliberately keeps: exchange_link_token_with_secret returns the JWT secret the token validated against, and issuance is only accepted if storage.get_jwt_secret still matches after the consume. That consume-then-recheck ordering is what stops a pre-change link token from minting a session that survives a concurrent password change (update_password rotates the secret and deletes link_tokens in its own transaction). Folding the consume into the issuance transaction would either hold a write lock across token minting or reorder the recheck ahead of the consume, reopening that TOCTOU. No change.
|
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". |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
Summary
Rebased onto current
mainand scoped to the headless auto-password path only. The opt-in one-time link token that this branch used to carry is split into its own branch, per review.A public launch (
--secure,--cloudflareproducing a public tunnel, or Colabstart(cloudflare=True)) that supplies no password used to depend on the seeded bootstrap credential staying live behind a 1 hour shutdown deadline, and refused outright where that deadline could not arm. When such a launch has no supplied password (no--password/UNSLOTH_STUDIO_PASSWORD/ stdin) and the admin still holds the seeded must-change credential, it now:secrets.token_urlsafe(24)password,update_password, which clearsmust_change_password, rotates the JWT secret, revokes refresh tokens and deletes.bootstrap_password,Because
must_change_passwordbecomes0,run.py's terminal gate returns without prompting and Colab's pending check passes, so the tunnel proceeds headlessly instead of failing closed. Theunsloth_clistudio parent gate mirrors the same behaviour before re-exec so the two stay in sync. An interactive terminal still gets the masked prompt, and a supplied--passwordis respected and never overwritten. On--securewith a provably unavailable tunnel the launch still refuses early, since there is no point rotating a recovery credential for a launch that cannot start.What this also removes
On
maintoday,colab.py_finalize_colab_admin_passwordpromotes the plaintext bootstrap password to the real admin password and caches it to disk at.colab_notebook_login(_store_colab_login_credentials). This branch replaces that path and explicitly purges the legacy cache. That is a bigger change than the original description claimed, so calling it out directly.storage.update_password
maingrewexpect_password_hash(compare-and-set on the verified credential, #9102) and now returns the rotated JWT secret rather than a bool. This branch addsrequire_must_changeand composes both guards into the same UPDATE rather than branching per guard: SQLite applies the wholeWHEREatomically, so exactly one of two racing writers seesrowcount > 0no matter which guard the loser tripped. A rejected guard now rolls back rather than committing, so a failed compare-and-set commits nothing at all.The desktop secret joins that transaction, gated on
preserve_desktop_secret. It authenticates as the user without the password and is keyed off the secret being rotated, so a post-commitclear_desktop_secret()on a second connection can raise on a busy database and leave a pre-change desktop credential live against the new password.require_must_changeis technically subsumed byexpect_password_hash(every write rehashes with a fresh salt). They are kept separate because they state different policies, and because the auto-generate callers hold no credential to pass; collapsing them is noted in the docstring as follow-up. Routing this throughcredential_generation_guard()would not work: it holds its ownBEGIN IMMEDIATEacross the yield, so a nested SQLite write blocks on the RESERVED lock and raisesdatabase is locked.Scope of the claims, stated precisely
must_change_passwordalready false and will not generate or print again. Recovery isunsloth studio reset-password. Documenting this as the intended model rather than leaving it unstated.Behaviour change worth flagging
--secure --api-onlyis no longer refused. That refusal existed because api-only has no login page, so the bootstrap shutdown deadline never armed and the seeded default would have stayed live on a public URL indefinitely. Auto-generation removes the premise rather than working around it: the gate rotates the seeded credential and prints the new one before any re-exec.Rebase notes
Reconstructed as one commit on current
mainrather than replaying 23 commits of merges and fixups. Six files conflicted on the old branch; splitting the link token out removed two of them entirely, including a 162-line collision with #9102's keyless-auth block. Several test doubles had drifted and were repaired rather than papered over:_stub_update_passwordreturned a bool. Sinceupdate_passwordnow returnsOptional[str],False is not None, so the lost-race test passed while the gate displayed a password that would not authenticate. The stub now returns the secret orNone.start_studio_tunnelstubs werelambda port:;mainaddedmanaged_by/admissionafter the fork.reset_passwordtests encoded the pre-Studio: reset-password rotates the credential in place instead of deleting auth.db #7573 "delete auth.db" contract thatmainreplaced with in-place rotation. Removed;main's seven replacements cover it.STUDIO_HOMEand fails closed under CliRunner's non-tty streams. The gate is stubbed in those helpers; it has its own suite.Tests
studio/backend/tests/test_colab_secure_autopassword.py: auto-generate sets and clears must-change, no-op when a password is already set, compare-and-set guard, post-commit-cleanup and commit-failure boundaries,start_cloudflare_tunnelauto-generates then proceeds, and never finalizes or caches credentials.studio/backend/tests/test_password_prompt_backstop.pyandunsloth_cli/tests/test_studio_password_prompt.pyupdated to the headless auto-generate contract, including the console tty preflight and the fail-closed no-console path.test_cli_update_password_compare_and_set_guardnow also asserts no collateralapi_keysrevocation on a rejected write. That DELETE has no WHERE clause, so running it past a failed compare-and-set would wipe every key for every user while leaving the password as the winner set it.Local run against the Backend CI invocation: no new failures versus the same command on
main(identical 175-failure baseline, all from optional CI extras absent locally).