install-newt: optional internet access via a Pangolin tunnel, with OIDC sign-in on the dashboard

A plain install is unchanged: LAN-only, dashboard behind the API key. `llmhost install-newt`
is the upgrade path. It installs a pinned, sha256-checked newt as a third user service and
switches the dashboard to an OIDC authorization-code + PKCE sign-in limited to allowed groups
or users. The API still takes the key. Secrets live in 0600 files, never in config.json, a
service file or argv. `llmhost remove-newt` undoes it; setup/update keep it; `logs --newt`
shows the tunnel (and `logs -f` now follows the service it was asked for).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-05 21:44:09 -08:00
parent d07a92e5b5
commit e814a2359d
11 changed files with 1155 additions and 26 deletions

View file

@ -76,13 +76,14 @@ button.small { font-size: 12px; padding: 4px 10px; }
}
.effort select:disabled { color: var(--muted); }
.effort .s { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.45; }
button {
button, a.btn {
font: inherit; font-size: 13px; font-weight: 550; padding: 7px 13px; border-radius: 8px; cursor: pointer;
border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.btn { display: inline-block; text-decoration: none; }
button.primary, a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
.profiles { display: flex; flex-direction: column; gap: 8px; }
@ -169,6 +170,7 @@ pre {
<span id="phase" class="pill">…</span>
<span class="spacer"></span>
<span class="meta" id="uptime"></span>
<span class="meta" id="whoami" hidden></span>
<button id="logout" title="Forget API key">Sign out</button>
</header>
@ -268,6 +270,11 @@ pre {
<div class="err" id="auth-err"></div>
<button class="primary" type="submit">Continue</button>
</form>
<div class="dialog" id="auth-oidc" hidden>
<h3>Sign in</h3>
<p id="auth-oidc-text">This dashboard signs in through your identity provider.</p>
<a class="btn primary" href="/auth/login" id="auth-oidc-go">Sign in</a>
</div>
</div>
<div class="toast" id="toast"></div>
@ -275,6 +282,9 @@ pre {
const $ = (id) => document.getElementById(id);
let KEY = null;
try { KEY = localStorage.getItem("llmhost-key"); } catch (e) {}
// "key": the API key, typed in and kept in this browser. "oidc": a session cookie set by
// signing in at the provider (/auth/login); the key isn't accepted then.
let AUTH = { mode: "key" };
let state = null;
let logTimer = null;
@ -287,14 +297,23 @@ function toast(msg) {
}
async function api(path, opts = {}) {
const r = await fetch(path, { ...opts, headers: { "Authorization": "Bearer " + KEY, "Content-Type": "application/json" } });
if (r.status === 401) { showAuth("That key was rejected."); throw new Error("unauthorized"); }
const headers = { "Content-Type": "application/json" };
if (AUTH.mode === "key") headers["Authorization"] = "Bearer " + KEY;
const r = await fetch(path, { ...opts, headers, credentials: "same-origin" });
if (r.status === 401) { showAuth(AUTH.mode === "key" ? "That key was rejected." : ""); throw new Error("unauthorized"); }
const body = await r.json();
if (!r.ok) throw new Error(body.error || r.statusText);
return body;
}
function showAuth(err = "") { $("auth-err").textContent = err; $("auth").classList.add("show"); $("auth-key").focus(); }
function showAuth(err = "") {
if (AUTH.mode === "oidc") {
$("auth-form").hidden = true; $("auth-oidc").hidden = false;
$("auth").classList.add("show"); $("auth-oidc-go").focus();
return;
}
$("auth-err").textContent = err; $("auth").classList.add("show"); $("auth-key").focus();
}
$("auth-form").addEventListener("submit", (e) => {
e.preventDefault();
KEY = $("auth-key").value.trim();
@ -302,7 +321,14 @@ $("auth-form").addEventListener("submit", (e) => {
$("auth").classList.remove("show");
poll();
});
$("logout").onclick = () => { try { localStorage.removeItem("llmhost-key"); } catch (e) {} KEY = null; showAuth(); };
$("logout").onclick = async () => {
if (AUTH.mode === "oidc") {
try { await fetch("/auth/logout", { method: "POST", credentials: "same-origin" }); } catch (e) {}
AUTH.user = null; $("whoami").hidden = true; clearTimeout(pollTimer); showAuth();
return;
}
try { localStorage.removeItem("llmhost-key"); } catch (e) {} KEY = null; showAuth();
};
const fmt = {
n: (v, d = 0) => v == null ? "—" : v.toLocaleString(undefined, { maximumFractionDigits: d, minimumFractionDigits: d }),
@ -692,12 +718,26 @@ $("logs").addEventListener("toggle", () => {
let pollTimer = null;
async function poll() {
clearTimeout(pollTimer);
if (!KEY) { showAuth(); return; }
if (AUTH.mode === "key" ? !KEY : !AUTH.user) { showAuth(); return; }
try { render(await api("/api/status")); }
catch (e) { if (e.message !== "unauthorized") { $("phase").textContent = "Dashboard unreachable"; $("phase").className = "pill failed"; } }
catch (e) {
if (e.message === "unauthorized" && AUTH.mode === "oidc") return; // session over; wait for sign-in
if (e.message !== "unauthorized") { $("phase").textContent = "Dashboard unreachable"; $("phase").className = "pill failed"; }
}
pollTimer = setTimeout(poll, 2000);
}
poll();
(async () => {
try {
const r = await fetch("/auth/config", { credentials: "same-origin" });
if (r.ok) AUTH = await r.json();
} catch (e) {}
if (AUTH.mode === "oidc") {
$("logout").title = "Sign out of this dashboard";
if (AUTH.user) { $("whoami").textContent = AUTH.name || AUTH.user; $("whoami").hidden = false; }
}
poll();
})();
</script>
</body>
</html>