Split the internet upgrades: API-only tunnel, OIDC, authenticator codes, expose-dashboard

install-newt now sets up the tunnel for the API only; the dashboard stays on the LAN.
Dashboard sign-in is its own step: install-oidc (the OIDC flow, split out) or install-otp,
which pairs authenticator apps with a QR code in the terminal (stdlib QR encoder, TOTP per
RFC 6238) so a code also opens the dashboard, with replay and lockout rules.
expose-dashboard walks through publishing the dashboard, only after install-newt, and
warns while it's protected by the API key alone; with codes it offers to switch the key off
for the dashboard. Each install-* has a remove-*.

Also opencode-install.sh: a standalone script, fetched from the repo, that installs opencode
if needed, saves the API key to a 0600 file and adds the provider to opencode.json for new
and existing configs. /v1/models reports whether the model reasons, for that script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-06 15:56:54 -08:00
parent e6ff4ce909
commit c8b70afdbf
20 changed files with 1715 additions and 239 deletions

144
README.md
View file

@ -53,8 +53,11 @@ PYTHONPATH=. python3 -P -m llmhost plan --simulate apple:64 # a 64 GB Mac
| `llmhost logs -f` | follow the model server log (`--web` for the dashboard's, `--newt` for the tunnel's) |
| `llmhost start` / `stop` / `restart` | control the model server (stop frees the GPU) |
| `llmhost key` | print the API key |
| `llmhost install-newt` | optional: reach this server from the internet through a Pangolin tunnel, with OIDC sign-in on the dashboard (see [Reaching it from the internet](#reaching-it-from-the-internet)) |
| `llmhost remove-newt` | undo `install-newt`: back to LAN-only, dashboard back to the API key |
| `llmhost install-newt` | optional: reach the API from the internet through a Pangolin tunnel; the dashboard stays local (see [Reaching it from the internet](#reaching-it-from-the-internet)) |
| `llmhost install-oidc` | optional: sign in to the dashboard through an OIDC provider instead of the API key |
| `llmhost install-otp` | optional: pair authenticator apps; their codes also open the dashboard (`--show` to add another device) |
| `llmhost expose-dashboard` | walk through publishing the dashboard through the tunnel, once it has a sign-in of its own |
| `llmhost remove-newt` / `remove-oidc` / `remove-otp` | undo the matching `install-*` |
| `llmhost opencode-setup` | install opencode here if needed and connect it to this server |
| `llmhost opencode-config` | print what to add to opencode on another machine |
| `llmhost opencode-remove` | take llm-host back out of this machine's opencode config (`--host` for a retired remote server, `--all` for every one) |
@ -71,52 +74,56 @@ whole duration counts as generation.
## Reaching it from the internet
A plain install is LAN-only, and the dashboard asks for the API key. To let people use it from
anywhere, `llmhost install-newt` adds two things on top:
A plain install is LAN-only, and the dashboard asks for the API key. Going further is a few separate,
optional steps, so the API can go online without the dashboard:
- **A tunnel.** [newt](https://github.com/fosrl/newt) dials out to your [Pangolin](https://github.com/fosrl/pangolin)
server, which serves HTTPS on your domain. Nothing on this machine is opened to the internet, and no port is forwarded.
newt runs as a third user service, in userspace (no root). It's a pinned release, checked against its sha256 before it's installed.
- **OIDC sign-in on the dashboard, replacing the API key there.** Whoever holds the key can also stop or
switch the model from the dashboard, which is too much to hand out with the key. The API itself is
unchanged and still takes the key.
| step | what it adds |
|---|---|
| `llmhost install-newt` | the API, online through a tunnel; the dashboard stays on your LAN |
| `llmhost install-oidc` | dashboard sign-in through your OIDC provider, replacing the API key |
| `llmhost install-otp` | dashboard sign-in with codes from an authenticator app, alongside (or instead of) the key |
| `llmhost expose-dashboard` | a walkthrough for putting the dashboard online too, once it has one of those sign-ins |
You need a Pangolin server with a Newt site (Pangolin: *Sites → Add Site → Newt*, which gives an endpoint, ID and
secret) and an OIDC client registered with your identity provider:
### The API: `install-newt`
- a confidential client using `client_secret_basic`
- the authorization-code flow with PKCE (S256)
- scopes `openid profile email groups`
- the redirect URI `https://<dashboard host>/auth/callback`
[newt](https://github.com/fosrl/newt) dials out to your [Pangolin](https://github.com/fosrl/pangolin) server, which
serves HTTPS on your domain. Nothing on this machine is opened to the internet, and no port is forwarded. newt runs as
a third user service, in userspace (no root). It's a pinned release, checked against its sha256 before it's installed.
Then:
Create a Newt site in Pangolin (*Sites → Add Site → Newt*, which gives an endpoint, ID and secret), then:
```bash
llmhost install-newt \
--endpoint https://pangolin.example.com --newt-id <site id> \
--public-url https://llm-dash.example.com \
--issuer https://auth.example.com --client-id llm-host \
llmhost install-newt --endpoint https://pangolin.example.com --newt-id <site id>
```
It asks for the site secret, or reads `$LLMHOST_NEWT_SECRET`; it's never taken as a flag, so it stays out of shell
history. The secret is stored in `~/.config/llm-host/newt_secret` (mode 600) and handed to newt in its environment
at start, never written into a service file or `config.json`. Running it again changes only what you give it.
Then add one HTTP resource in Pangolin, for the API: a host of your choice → `<this machine's LAN IP>:<API port>`,
with Pangolin's own authentication off, since llm-host checks the API key. Point it at the LAN IP, not
`localhost`, which llm-host treats as local. Clients use `https://<API host>/v1` with the key; for opencode, see
[`opencode-install.sh`](#connecting-opencode).
### Dashboard sign-in: `install-oidc` and `install-otp`
Out of the box the dashboard takes the API key, the same key you hand to API users. That's fine on your LAN, but
anyone holding the key could also stop, start or switch the model from the dashboard. Before the dashboard goes
online, give it a sign-in of its own.
**OIDC** (`llmhost install-oidc`) replaces the key with sign-in through your identity provider, limited to the
groups or usernames you allow. Register a confidential client using `client_secret_basic`, the authorization-code
flow with PKCE (S256), scopes `openid profile email groups`, and the redirect URI `https://<dashboard host>/auth/callback`:
```bash
llmhost install-oidc --public-url https://llm-dash.example.com \
--issuer https://auth.example.com --client-id <client id from the provider> \
--allow-group llm-admins # and/or --allow-user <username>; repeatable
```
It asks for anything left out. The two secrets are always prompted for, or read from `$LLMHOST_NEWT_SECRET` and
`$LLMHOST_OIDC_SECRET`, and never taken as flags, so they stay out of shell history. They're stored in
`~/.config/llm-host/` with mode 600 and handed to the services at start; they're never written into a service
file or `config.json`. Running it again changes only what you give it.
It ends by printing the two Pangolin HTTP resources to create, both pointing at this machine's LAN address (not
`localhost`, which llm-host treats as local), and **with Pangolin's own SSO off**:
| resource | target | who checks |
|---|---|---|
| dashboard, at the `--public-url` host | `<LAN IP>:<web port>` | llm-host, through your OIDC provider |
| API, at a host of your choice | `<LAN IP>:<API port>` | llm-host, with the API key |
Clients then use `https://<API host>/v1` with the key from `llmhost key`, or from the dashboard's **Connect** button.
It shows anyone signed in the key, plus the steps to add this server to opencode: type the API's address and it
fills in a key-saving command and the provider block, both with copy buttons.
For Authelia, the client looks like this:
It asks for the client secret (or reads `$LLMHOST_OIDC_SECRET`) and checks the provider's discovery document.
Sign-in happens at the public URL, and visits by any other address are sent there, so the dashboard must be
reachable at that URL; see `expose-dashboard`. For Authelia, the client looks like this:
```yaml
identity_providers:
@ -136,20 +143,38 @@ identity_providers:
token_endpoint_auth_method: client_secret_basic
```
How the dashboard's sign-in behaves:
How OIDC sign-in behaves:
- **Only listed people get in.** A person must be in an allowed group or have an allowed username
(`preferred_username`, falling back to email). Groups come from userinfo.
- **Sessions are HttpOnly, Secure, `SameSite=Lax` cookies.** They last 12 hours and are held in memory, so
restarting the dashboard signs everyone out. State-changing requests must come from the dashboard's own origin.
- **The ID token is checked.** Its issuer, audience, expiry and nonce must match. It arrives directly from the
token endpoint over TLS, which OIDC allows in place of verifying its signature.
- **Other addresses redirect to the public URL.** A visit to any other name for the machine
(`http://<host>.local:11340`) is sent there, because that's the only host the session cookie exists on.
**Authenticator codes** (`llmhost install-otp`) need no provider. It shows a QR code in the terminal; scan it with
any authenticator app, then type the code it shows to confirm. After that, the dashboard's sign-in also accepts a
current 6-digit code. To add another phone later, `llmhost install-otp --show` shows the same pairing again. Each
code works once, and after 5 wrong codes in 5 minutes codes are refused for a while. The limit is global, because
behind a tunnel every request comes from the same address. Codes are TOTP: SHA-1, 6 digits, 30 seconds, the
defaults every app supports. The secret is kept in `~/.config/llm-host/otp_secret` (mode 600). The API key keeps
working on the dashboard too, until `expose-dashboard` offers to turn it off there.
For both, sessions are HttpOnly, `SameSite=Lax` cookies, Secure behind HTTPS. They last 12 hours and are held in
memory, so restarting the dashboard signs everyone out. State-changing requests must come from the dashboard's own
page. While OIDC is on, it's the only way in, and codes come back with `remove-oidc`.
### The dashboard: `expose-dashboard`
`llmhost expose-dashboard` won't start until `install-newt` is done. It then checks the dashboard's sign-in:
- **OIDC:** fine.
- **Authenticator codes:** it offers to stop the API key opening the dashboard.
- **The key alone:** it explains the risk and asks before going on (`--force` skips the question).
Then it describes the Pangolin resource to add (the dashboard's host → `<LAN IP>:<dashboard port>`) and, once you
press Enter, checks the public URL reaches this dashboard.
`llmhost status` shows the tunnel and sign-in settings. `setup` and `update` keep them, and `update` moves newt to
a newly pinned release. `llmhost remove-newt` undoes it all: it removes the service, the binary and both secrets,
and switches the dashboard back to the key.
a newly pinned release. Each step has an undo: `remove-newt`, `remove-oidc`, `remove-otp`.
## Connecting opencode
@ -166,6 +191,23 @@ A config with comments (`.jsonc`) is never rewritten, since that would drop them
that copies the API key over. That block is named **LLMHost (<the server's hostname>)** — e.g. `LLMHost (mybox.local)`
— under the provider id `llmhost-<shorthost>`.
**On any machine, in one step**, run `opencode-install.sh` from this repo. It needs only the API's address and
the key, not the dashboard or llm-host, so you can hand it to people who reach just the API, such as through a
tunnel that exposes the API alone. The dashboard's **Connect** button shows the command with the address filled in:
```bash
/bin/bash -c "$(curl -fsSL https://git.neilbantoc.dev/pub/llm-host/raw/branch/main/opencode-install.sh)" -- --url https://<API host>
```
It checks the server answers with the key, which it asks for without echoing it (or pass `--key` /
`$LLMHOST_API_KEY`, at the cost of the key landing in shell history). Then it installs opencode with the official
installer, unless it's already there, saves the key to `~/.config/opencode/llmhost-<host>.key` (mode 600), and adds
the provider to `opencode.json`. Everything else in that file is kept, and it's backed up as
`opencode.json.before-llmhost` first. It makes the server the default model when you have none; if you do, it asks
first, and `--default` / `--no-default` decide without asking. It also drops any key opencode had cached for that
provider. A `.jsonc` config is never rewritten; the block is printed to paste instead. `--remove` takes the server
back out. It needs `curl` and `python3`.
### One opencode, several servers
The two paths use different provider ids, so a single opencode config can point at a local server and any number
@ -289,7 +331,9 @@ python3 tests/test_opencode.py # or run one directly
| `tests/test_proxy.py` | model names, dropping client reasoning settings, upstream key, streamed-run counting, against a fake server |
| `tests/test_dashboard.py` | KV parsing, per-run summaries, log collapsing |
| `tests/test_dashboard_auth.py` | API-key mode, and OIDC sign-in against a fake provider: PKCE, state/nonce/aud/iss/exp checks, allow list, origin check, sign-out |
| `tests/test_newt.py` | `install-newt`/`remove-newt` against fake services: pinned checksum, secrets kept out of config, output and argv, re-runs, undo |
| `tests/test_opencode_install.py` | `opencode-install.sh` against a fake API in a throwaway HOME: new and existing configs, default-model choice, cached-key cleanup, `--remove`, refusals |
| `tests/test_newt.py` | `install-newt`, `install-oidc`, `install-otp`, `expose-dashboard` and their undos against fake services: pinned checksum, secrets kept out of config, output and argv, re-runs |
| `tests/test_otp.py` | TOTP against RFC 6238, code replay and lockout, the QR encoder against reference matrices, code sign-in on the dashboard |
| `tests/test_reasoning.py` | effort options matching the real chat templates; the setting surviving an update |
## Continuing on an NVIDIA box
@ -334,7 +378,8 @@ suites are hermetic and don't need a GPU), so run that first.
| `~/.local/share/llm-host/` | this repo (`src/`), backend venvs, the assembled CUDA toolkit |
| `~/.config/llm-host/config.json` | the plan: backend, fitting models, active model, ports |
| `~/.config/llm-host/api_key` | API key (mode 600) |
| `~/.config/llm-host/oidc_secret` | dashboard sign-in client secret (mode 600), after `install-newt` |
| `~/.config/llm-host/oidc_secret` | OIDC client secret (mode 600), after `install-oidc` |
| `~/.config/llm-host/otp_secret` | authenticator-app secret (mode 600), after `install-otp` |
| `~/.config/llm-host/newt_secret` | Pangolin site secret (mode 600), after `install-newt` |
| `~/.local/share/llm-host/newt/` | the newt binary, after `install-newt` |
| `~/.cache/huggingface/hub/` | downloaded models |
@ -352,5 +397,6 @@ On macOS the services are launchd agents, so they run while you're logged in.
setting applied instead.
- AMD (ROCm), Intel and CPU-only machines aren't supported yet.
- The API and dashboard use plain HTTP and are meant for a trusted LAN. Don't forward their ports to the internet;
use [`llmhost install-newt`](#reaching-it-from-the-internet), which puts HTTPS in front and OIDC sign-in on the dashboard.
use [`llmhost install-newt`](#reaching-it-from-the-internet), which puts HTTPS in front, and give the dashboard
its own sign-in before `expose-dashboard`.
- Everyone using the API shares one key, with no per-person revocation or rate limits.