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
@@ -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