Repository navigation
Conversation
Closes unslothai#5177. uvicorn terminates TLS in-process via --ssl-certfile / --ssl-keyfile, plus a --ssl-self-signed convenience flag that auto-generates and reuses a cert in ~/.unsloth/studio/ssl/. Off by default to preserve parity with the existing HTTP behavior. Configuration is layered (CLI > env vars > app_secrets > default) and surfaced in a new "Server" settings tab that supports save + in-place restart. The restart re-execs the Python process and confirms success via a per-instance ID exposed on /api/health, with a global gate so authFetch parks (rather than detonating) every request that races the restart window. --no-ssl is the documented escape hatch when SSL is misconfigured via the UI. Tauri preflight now probes both schemes and threads the discovered scheme through the desktop auth flow with self-signed certs accepted. Anchor the Python build-artifact `lib/` / `lib64/` rules in .gitignore to the project root so they stop shadowing legitimate frontend src/**/lib/ source directories. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request introduces SSL/TLS support for Unsloth Studio, allowing users to configure HTTPS through CLI arguments, environment variables, or a new 'Server' tab in the settings UI. The changes include a backend resolver for SSL settings, automated self-signed certificate generation using the cryptography library, and a self-restart feature to apply configuration changes without manual server restarts. The frontend and Tauri components were also updated to handle scheme transitions and HTTPS health checks. Review feedback highlights opportunities to improve error logging in the SSL configuration logic and to remove unused imports in the settings route.
- ssl_config: log at debug level when auth.storage import or app_secrets read fails, instead of swallowing silently. Uses the project's `loggers.get_logger` for consistency. - routes/settings: drop unused `os` / `sys` imports. - server tab: add a green "Note:" callout flagging that flipping HTTP↔HTTPS changes the browser origin, so chat history (IndexedDB), theme, and the login session live with whichever scheme they were saved on. Nothing is deleted, but users will re-sign in on the new scheme. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces SSL/TLS support for the Unsloth Studio backend and frontend, enabling HTTPS configuration via CLI flags, environment variables, or a new 'Server' settings tab. Key changes include a centralized SSL configuration resolver, automated self-signed certificate generation using the cryptography library, and a self-restart mechanism to apply settings. The frontend now includes a request gate and polling logic to handle server restarts gracefully. Feedback suggests decoupling the settings routes from the runner script to maintain a cleaner separation of concerns.
|
@ctsstc for your case , use the following options:
then open http://localhost:8888 with your local computerNo TLS needed. The tunnel is the encryption, and localhost never triggers a cert warning. Bind Studio to 127.0.0.1 so port 8888 isn't open to the outside.
B - Public (available to others as well):
This should solve your problem |
|
Thanks for leaving the follow up here. I was initially hoping for something baked-in, without extra config/software/etc, but realistically you bring up good points on the options you've proposed. Especially given my use case is likely not your normal use case. I do wonder if only local connections should be accepted to remove the footgun that this provides, but then that would block off the tunnel option. This PR should be good to go if you change your mind. I realize the expense to bring in code debt if the use case is minor. This also introduces a nice server restart flow if you want to rip that out at some point, as well as cleaning up the gitignore to not be so broad that they target working directories. |
|
@ctsstc i'll close it for now but i'll keep it in mind might reopen and integrate at a later stage. thank you for the contribution. |
Closes #5177.
Why
HTTP is still the default to preserve parity. Existing setups — scripts, integrations, ops runbooks pointing at
http://localhost:8888— keep working unchanged after pulling this. Worth raising as a follow-up though: should HTTPS-via-self-signed become the recommended default for new installs, given the surface handles passwords, HF tokens, and API keys? The one-time cert warning is real first-time-user friction that doesn't exist today, so I left it opt-in for this PR — happy to flip the default if maintainers prefer the safer posture.Tauri wasn't tested end-to-end. The Rust changes compile clean (
cargo check --testspasses locally) and the preflight/scheme-probe/health paths all have unit tests, but a full desktop-app build round trip was more time and disk than I had to spare. Would appreciate a maintainer spot-check that (a) the desktop app still attaches to a running backend over both schemes, and (b) the desktop-secret auth flow works against an HTTPS backend with the self-signed cert (danger_accept_invalid_certs(true)is wired up indesktop_auth.rs).Future: shared preference storage (out of scope here). Today theme, sidebar state, chat history (IndexedDB via Dexie), and the auth token all live in the browser, and browsers partition that data by full origin (
scheme + host + port). So flipping HTTP↔HTTPS hides everything until the user switches back. The Server settings tab now calls this caveat out explicitly, but the proper fix is to migrate the high-pain keys (theme, sidebar, eventually chat threads) to a/api/preferencesendpoint and per-user table on the backend.That's a meaningful trade-off, not an obvious win:
Worth flagging as the natural next step, ideally with an opt-in/opt-out toggle so users who depend on per-browser isolation keep it. Maybe consider a migration if anyone wants to keep their current local storage settings and transfer them to a persistent DB storage. I imagine going this route may introduce more tangible user accounts across the persistence layer (for the backend).
Summary
--ssl-certfile/--ssl-keyfile, plus a--ssl-self-signedconvenience flag that auto-generates and reuses a cert in~/.unsloth/studio/ssl/. Off by default to preserve parity with current HTTP behavior.app_secrets> default) is surfaced in a new Settings → Server tab with save + in-place restart. Restart re-execs the Python process and confirms success via a per-instance ID exposed on/api/health.authFetchparks (rather than detonates) every request that races the restart window — modal stays open, no toast spam, no/loginredirect cascade.--no-sslis the documented escape hatch when SSL is misconfigured via the UI.lib//lib64/rules in.gitignoreto the project root so they stop shadowing legitimate frontendsrc/**/lib/source directories.Why no ngrok / reverse proxy
uvicorn natively supports
ssl_keyfile/ssl_certfile, so TLS terminates in-process. No ngrok, no nginx, no extra hop. Self-signed certs trigger the standard one-time browser warning that the user clicks through.Configuration precedence
--no-sslflag (escape hatch — overrides everything)--ssl-certfile/--ssl-keyfile/--ssl-self-signedCLI flagsUNSLOTH_SSL_CERTFILE/UNSLOTH_SSL_KEYFILE/UNSLOTH_SSL_SELF_SIGNEDenv varsapp_secretsrows written by the Settings UIThe Settings tab calls out which layer is currently in effect (e.g. "TLS is forced on by --ssl-self-signed; saved settings take over when the flag is dropped") so users can tell why "Active" can diverge from the saved toggle.
Test Points to Consider
unsloth studio(default) → access banner showshttp://, frontend loads, login works (regression)unsloth studio --ssl-self-signed→ cert generated at~/.unsloth/studio/ssl/, banner showshttps://, browser shows one-time self-signed warning that can be clicked through, UI loads, login works, SSE training progress and/v1/chat/completionsstreaming both workopenssl req -x509 -newkey rsa:2048 -nodes -keyout /tmp/k.pem -out /tmp/c.pem -days 1 -subj "/CN=localhost", thenunsloth studio --ssl-certfile /tmp/c.pem --ssl-keyfile /tmp/k.pem→ HTTPS bound, no regeneration of stored certUNSLOTH_SSL_SELF_SIGNED=1 unsloth studio→ equivalent to--ssl-self-signedunsloth studio --no-sslafter enabling SSL via UI → server starts on HTTP, banner reflects scheme, UI is reachable to fix misconfigPOST /api/settings/server/testwith bad path → returns{ ok: false, error: "..." }without crashing; valid pair →{ ok: true }scheme: "https", frontend connects viahttps://127.0.0.1:<port>Note: I did not test the Tauri flow since I knew building out could take a while and I'm limited on resources. I'm hoping someone else can spot check it 🤞
Out of scope (intentional)
--ssl-acme-domainsource slots in as another precedence layer in a follow-up. Wanted to avoid extra dependencies, and likely use case for users hosting their own domain to expose this is low, meanwhile there's still a method for them to provide their own certs.🤖 Generated with Claude Code