Stop the dashboard linking to pages that are not where it is
Clicking "metrics" on the web dashboard answered "no api key was provided". The page is served twice and its navigation assumed one of them. Metrics, pprof and the management API exist on the admin listener; account administration, the profile and the chat exist on the client-facing port. The nav offered the first set in both places, so on the public port those links fell through to the API-key middleware — which is a far more confusing way to say "that is not here" than a 404 would have been. Each page now offers what is actually reachable from it, and the public one says where the rest lives rather than pretending it does not exist, including why that port is not exposed: pprof can dump the process heap, and the heap holds every API key in plaintext. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f68fbf7c49
commit
3b67b1fe42
5 files changed
+78
-18
No files matched your search
@@ -127,7 +127,7 @@ func newServerCmd() *cobra.Command {
|
||||
usage = st
|
||||
}
|
||||
adminMux.HandleFunc("GET /", web.Dashboard(
|
||||
api, usage, version.Version, 5*time.Second, log))
|
||||
api, usage, version.Version, 5*time.Second, true, log))
|
||||
adminMux.Handle("GET /_static/", web.Static())
|
||||
|
||||
// The same page on the client-facing port at /admin, behind a
|
||||
|
||||
@@ -115,7 +115,7 @@ func (r *Router) Handler() http.Handler {
|
||||
// the admin listener — which also carries pprof, and pprof can dump
|
||||
// the heap that holds every API key in plaintext.
|
||||
mux.HandleFunc("GET /admin", pages.AdminPage(web.Dashboard(
|
||||
r.clusterView, r.clusterUsage, version.Version, 5*time.Second, r.log)))
|
||||
r.clusterView, r.clusterUsage, version.Version, 5*time.Second, false, r.log)))
|
||||
pages.RegisterAdminUsers(mux, r.store)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,18 @@ type DashboardData struct {
|
||||
TotalReplicas int
|
||||
|
||||
AuthEnabled bool
|
||||
RefreshSec int
|
||||
Version string
|
||||
Now string
|
||||
// OnAdminListener decides which links the page offers.
|
||||
//
|
||||
// The same page is served twice, and the two have different neighbours:
|
||||
// metrics, pprof and the management API exist only on the admin listener,
|
||||
// while account administration and the profile exist only on the
|
||||
// client-facing one. A nav that assumes one of them sends every visitor to
|
||||
// the other into a 404 — or, on the public port, into "no api key was
|
||||
// provided", which is a far more confusing way to say the same thing.
|
||||
OnAdminListener bool
|
||||
RefreshSec int
|
||||
Version string
|
||||
Now string
|
||||
}
|
||||
|
||||
// Source is what the dashboard reads. An interface so the page can be rendered
|
||||
@@ -65,7 +74,7 @@ type UsageSource interface {
|
||||
// where it needs a shell on the machine rather than a browser session this
|
||||
// project has no way to authenticate.
|
||||
func Dashboard(src Source, usage UsageSource, version string, refresh time.Duration,
|
||||
log *slog.Logger,
|
||||
onAdminListener bool, log *slog.Logger,
|
||||
) http.HandlerFunc {
|
||||
if log == nil {
|
||||
log = slog.Default()
|
||||
@@ -75,10 +84,11 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
|
||||
}
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
d := DashboardData{
|
||||
RefreshSec: int(refresh.Seconds()),
|
||||
Version: version,
|
||||
Now: time.Now().UTC().Format(time.RFC3339),
|
||||
AuthEnabled: usage != nil,
|
||||
OnAdminListener: onAdminListener,
|
||||
RefreshSec: int(refresh.Seconds()),
|
||||
Version: version,
|
||||
Now: time.Now().UTC().Format(time.RFC3339),
|
||||
AuthEnabled: usage != nil,
|
||||
}
|
||||
if src != nil {
|
||||
d.Nodes = src.Nodes()
|
||||
|
||||
@@ -8,10 +8,15 @@
|
||||
<h1>Cluster</h1>
|
||||
<p class="sub">{{.NodeCount}} nodes · {{.ReadyReplicas}} of {{.TotalReplicas}} replicas ready · {{.ModelCount}} models</p>
|
||||
<nav>
|
||||
<a href="/admin/users">accounts</a>
|
||||
{{if .OnAdminListener}}
|
||||
<a href="/metrics">metrics</a>
|
||||
<a href="/debug/pprof/">pprof</a>
|
||||
<a href="/api/v1/nodes">api</a>
|
||||
{{else}}
|
||||
<a href="/admin/users">accounts</a>
|
||||
<a href="/profile">your keys</a>
|
||||
<a href="/chat">chat</a>
|
||||
{{end}}
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@@ -100,6 +105,14 @@ written in batches, so the last few seconds may be missing.</p>
|
||||
<p class="empty">Authentication is off, so there is no identity to account against.</p>
|
||||
{{end}}
|
||||
|
||||
{{if not .OnAdminListener}}
|
||||
<p class="note">Metrics, pprof and the management API are on the admin listener,
|
||||
which is bound to loopback and not reachable from here. pprof can dump the
|
||||
process heap, where API keys sit in plaintext, which is why that port is not
|
||||
exposed:
|
||||
<code>ssh -L 9090:127.0.0.1:9090 <control-plane></code></p>
|
||||
{{end}}
|
||||
|
||||
<footer>
|
||||
<span>llmgw {{.Version}} · refreshes every {{.RefreshSec}}s</span>
|
||||
<span>{{.Now}}</span>
|
||||
|
||||
@@ -156,7 +156,7 @@ func (f fakeUsage) UsageSince(context.Context, time.Time) ([]store.KeyUsage, err
|
||||
}
|
||||
|
||||
func TestDashboardShowsTheCluster(t *testing.T) {
|
||||
h := Dashboard(fakeSource{}, fakeUsage{}, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, fakeUsage{}, "v1", time.Second, true, nil)
|
||||
code, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("status %d", code)
|
||||
@@ -174,7 +174,7 @@ func TestDashboardShowsTheCluster(t *testing.T) {
|
||||
func TestDashboardExplainsOnlyWhatIsUnplaced(t *testing.T) {
|
||||
// Asking why a satisfied model was not placed gives an empty answer, and a
|
||||
// page full of empty answers hides the one that matters.
|
||||
h := Dashboard(fakeSource{}, nil, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, nil, "v1", time.Second, true, nil)
|
||||
_, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
|
||||
if !strings.Contains(body, "needs 8") {
|
||||
@@ -188,7 +188,7 @@ func TestDashboardExplainsOnlyWhatIsUnplaced(t *testing.T) {
|
||||
func TestDashboardSurvivesAFailingUsageQuery(t *testing.T) {
|
||||
// A reporting query failing must not take the page with it: the cluster
|
||||
// state is what someone is most likely here for.
|
||||
h := Dashboard(fakeSource{}, fakeUsage{err: context.DeadlineExceeded}, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, fakeUsage{err: context.DeadlineExceeded}, "v1", time.Second, true, nil)
|
||||
code, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("status %d", code)
|
||||
@@ -199,7 +199,7 @@ func TestDashboardSurvivesAFailingUsageQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDashboardSaysWhenThereIsNothingToAccount(t *testing.T) {
|
||||
h := Dashboard(fakeSource{}, nil, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, nil, "v1", time.Second, true, nil)
|
||||
_, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
if !strings.Contains(body, "Authentication is off") {
|
||||
t.Error("the page does not explain the empty usage section")
|
||||
@@ -209,7 +209,7 @@ func TestDashboardSaysWhenThereIsNothingToAccount(t *testing.T) {
|
||||
func TestDashboardRendersAnEmptyCluster(t *testing.T) {
|
||||
// The state a fresh install is in, and the one most likely to be looked at
|
||||
// with a template that has never seen it.
|
||||
h := Dashboard(emptySource{}, nil, "v1", time.Second, nil)
|
||||
h := Dashboard(emptySource{}, nil, "v1", time.Second, true, nil)
|
||||
code, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("status %d", code)
|
||||
@@ -338,7 +338,7 @@ func TestTheDashboardDrawsTrafficWhenThereIsSome(t *testing.T) {
|
||||
{Start: now.Add(-time.Hour)},
|
||||
{Start: now, Requests: 95, Prompt: 9000, Completion: 2100, LatencyMs: 310},
|
||||
}}
|
||||
h := Dashboard(fakeSource{}, usage, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, usage, "v1", time.Second, true, nil)
|
||||
_, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
|
||||
if !strings.Contains(body, "<svg") {
|
||||
@@ -355,9 +355,46 @@ func TestTheDashboardDrawsTrafficWhenThereIsSome(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTheDashboardSaysWhenThereIsNoTrafficYet(t *testing.T) {
|
||||
h := Dashboard(fakeSource{}, fakeUsage{}, "v1", time.Second, nil)
|
||||
h := Dashboard(fakeSource{}, fakeUsage{}, "v1", time.Second, true, nil)
|
||||
_, body := get(t, h, "http://127.0.0.1:9090/", nil)
|
||||
if !strings.Contains(body, "No traffic recorded yet") {
|
||||
t.Error("an empty history renders nothing at all")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheDashboardOffersOnlyLinksThatExistWhereItIsServed(t *testing.T) {
|
||||
// The same page is served twice with different neighbours. Metrics, pprof
|
||||
// and the management API exist only on the admin listener; account
|
||||
// administration and the profile only on the client-facing one.
|
||||
//
|
||||
// Getting this wrong was not a 404: on the public port those paths fall
|
||||
// through to the API-key middleware, so a visitor clicking "metrics" was
|
||||
// told "no api key was provided", which is a far more confusing way to say
|
||||
// the link does not belong there.
|
||||
_, admin := get(t, Dashboard(fakeSource{}, nil, "v1", time.Second, true, nil),
|
||||
"http://127.0.0.1:9090/", nil)
|
||||
for _, want := range []string{`href="/metrics"`, `href="/debug/pprof/"`, `href="/api/v1/nodes"`} {
|
||||
if !strings.Contains(admin, want) {
|
||||
t.Errorf("the admin listener's page is missing %s", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(admin, `href="/admin/users"`) {
|
||||
t.Error("the admin listener's page links to a page only the public port serves")
|
||||
}
|
||||
|
||||
_, public := get(t, Dashboard(fakeSource{}, nil, "v1", time.Second, false, nil),
|
||||
"https://llmgw.example/admin", nil)
|
||||
for _, unwanted := range []string{`href="/metrics"`, `href="/debug/pprof/"`, `href="/api/v1/nodes"`} {
|
||||
if strings.Contains(public, unwanted) {
|
||||
t.Errorf("the public page links to %s, which is not served there", unwanted)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(public, `href="/admin/users"`) {
|
||||
t.Error("the public page does not link to account administration")
|
||||
}
|
||||
// And it says where the missing ones are, rather than pretending they do
|
||||
// not exist.
|
||||
if !strings.Contains(public, "admin listener") {
|
||||
t.Error("the public page does not say where metrics and pprof live")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user