Add a landing page and a read-only cluster dashboard

Pasting the gateway's address into a browser returned 404, which looks like a
broken endpoint rather than one that tells you how to use it.

Two pages, and the split between them is a security boundary rather than a
layout choice. The landing page is served without a key — it has to be,
because the person reading it is the one who does not have one yet — so it
contains no data at all: it says how to connect, not what is here. Model names
stay behind /v1/models. It reconstructs the address from the forwarded headers
so the copy-pasteable example names the address the client actually used
rather than the internal one; those headers are reflected into displayed text
and never used for a decision.

The dashboard shows nodes, models, replicas, placement failures and usage, and
lives on the admin listener only. That listener is loopback-bound and also
serves pprof, which can dump the process heap — where API keys sit in
plaintext — so reaching the page from elsewhere is an SSH tunnel's job. It is
read-only: anything that mints a credential stays in `llmgw keys`, where it
needs a shell rather than a browser session this project has no way to
authenticate.

Mounting the landing page uncovered a hole in the exemption list. An entry
ending in "/" was a prefix rule, and "/" ends in "/", so exempting the landing
page would have exempted every path there is — authentication still installed,
still logging, and letting the whole API through. "/" is now exact, with a
test enumerating what must and must not be exempt.

Server-rendered templates and one stylesheet, embedded. The single-binary goal
rules out a JavaScript toolchain and nothing on either page needs one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-16 08:58:05 +02:00
1 parent 0b93fb2883
commit 1839832b8b
14 files changed
+836 -10

No files matched your search

+24
View File
@@ -380,3 +380,27 @@ func TestLastUsedIsBatchedNotWrittenPerRequest(t *testing.T) {
t.Errorf("wrong key touched: %s", k.ID)
}
}
func TestExemptingTheLandingPageDoesNotExemptEverything(t *testing.T) {
// A near-miss worth a test. "/" ends in a slash, so a prefix rule would
// match every path there is: authentication still installed, still logging,
// and letting the entire API through.
cases := []struct {
path string
want bool
}{
{"/", true},
{"/_static/base.css", true},
{"/health", true},
{"/v1/models", false},
{"/v1/chat/completions", false},
{"/healthz", false}, // not a prefix rule
{"/_staticx", false}, // prefix rules end at the slash
}
exempt := []string{"/health", "/", "/_static/"}
for _, c := range cases {
if got := isExempt(c.path, exempt); got != c.want {
t.Errorf("isExempt(%q) = %v, want %v", c.path, got, c.want)
}
}
}
+12 -3
View File
@@ -40,12 +40,21 @@ func Middleware(a *Authenticator, log *slog.Logger, exempt ...string) func(http.
// isExempt reports whether a path is served without a key.
//
// Health is the only one by default. Metrics live on the admin listener, which
// is a separate port precisely so it can be firewalled rather than
// An entry ending in "/" is a prefix rule, with one exception that matters
// enormously: "/" itself is exact. Treating it as a prefix would match every
// path there is, so exempting the landing page would silently exempt the whole
// API — authentication still installed, still logging, and letting everything
// through.
//
// Metrics and pprof are not in this list because they live on the admin
// listener, a separate port precisely so it can be firewalled rather than
// authenticated.
func isExempt(path string, exempt []string) bool {
for _, e := range exempt {
if path == e || (strings.HasSuffix(e, "/") && strings.HasPrefix(path, e)) {
if path == e {
return true
}
if e != "/" && strings.HasSuffix(e, "/") && strings.HasPrefix(path, e) {
return true
}
}