Serve the cluster dashboard over the web, without serving pprof with it
CI / test (push) Successful in 1m21s
CI / test (push) Successful in 1m21s
Reaching it meant an SSH tunnel, because the page lived on the admin listener and that listener is bound to loopback. Opening the port was never the way to fix that: it also serves pprof, and pprof can dump the process heap, where every API key sits in plaintext. Exposing the port would have been exposing the key store. So the page moves rather than the port. The same dashboard is now mounted at /admin on the client-facing port, behind the session and CSRF machinery that already guards /profile, gated on a flag on the account. The admin listener keeps pprof and metrics and stays on loopback. One bit, not a role system: it grants looking. Everything that changes the cluster or issues a credential stays on the CLI, where it needs a shell rather than a session — which keeps the worst case of a stolen admin cookie to "saw the cluster" rather than "drained your fleet". Someone without the flag gets 404, not 403. A 403 confirms the page is there and that admin accounts exist here, which is free reconnaissance; 404 is what every other unknown path returns. The profile page does not show a link to a door the visitor cannot open. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
058ee382fa
commit
e519dc587c
12 files changed
+250
-14
No files matched your search
@@ -5,12 +5,14 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
@@ -395,3 +397,74 @@ func TestAWrongCurrentPasswordChangesNothing(t *testing.T) {
|
||||
t.Errorf("a failed change signed the person out: %d", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheClusterPageIsOnlyForAdmins(t *testing.T) {
|
||||
// Serving the dashboard over the web needs an actual answer to "who may see
|
||||
// this", and the answer must not be "anyone with an account".
|
||||
path, _ := provision(t)
|
||||
h := start(t, 2, func(c *config.Server) {
|
||||
c.Auth = config.Auth{Enabled: true, Store: path, SignupOpen: true, CacheTTL: 50 * time.Millisecond}
|
||||
})
|
||||
h.rt.SetClusterView(fakeCluster{}, nil)
|
||||
// Rebuild the handler now that there is a cluster to show.
|
||||
srv := httptest.NewServer(h.rt.Handler())
|
||||
defer srv.Close()
|
||||
|
||||
// A stranger is sent to sign in, which reveals nothing: /login is public.
|
||||
anon := newBrowser(t, srv.URL)
|
||||
if code, _ := anon.get("/admin"); code != http.StatusSeeOther {
|
||||
t.Errorf("an anonymous visit returned %d", code)
|
||||
}
|
||||
|
||||
// An ordinary account gets 404, not 403. 403 would confirm the page exists
|
||||
// and that admin accounts are a thing here.
|
||||
user := newBrowser(t, srv.URL)
|
||||
id := signUpAndApproveAt(t, user, srv.URL, path, "ayse@example.com")
|
||||
code, body := user.get("/admin")
|
||||
if code != http.StatusNotFound {
|
||||
t.Errorf("a non-admin got %d, want 404", code)
|
||||
}
|
||||
if strings.Contains(strings.ToLower(body), "forbidden") ||
|
||||
strings.Contains(strings.ToLower(body), "admin") {
|
||||
t.Error("the refusal admits the page exists")
|
||||
}
|
||||
// And the profile page does not advertise a door they cannot open.
|
||||
if _, profile := user.get("/profile"); strings.Contains(profile, `href="/admin"`) {
|
||||
t.Error("a non-admin is shown a link to the cluster")
|
||||
}
|
||||
|
||||
withStore(t, path, func(s *store.SQLite) {
|
||||
if err := s.SetAdmin(context.Background(), id, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
code, body = user.get("/admin")
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("an admin got %d", code)
|
||||
}
|
||||
if !strings.Contains(body, "llmgw-node01") {
|
||||
t.Error("the page does not show the cluster")
|
||||
}
|
||||
if _, profile := user.get("/profile"); !strings.Contains(profile, `href="/admin"`) {
|
||||
t.Error("an admin is not shown the link")
|
||||
}
|
||||
}
|
||||
|
||||
// signUpAndApproveAt is signUpAndApprove against an explicitly given base URL,
|
||||
// for tests that rebuild the handler.
|
||||
func signUpAndApproveAt(t *testing.T, b *browser, base, path, email string) string {
|
||||
t.Helper()
|
||||
_ = base
|
||||
return signUpAndApprove(t, b, path, email)
|
||||
}
|
||||
|
||||
// fakeCluster is enough of a cluster for the page to render.
|
||||
type fakeCluster struct{}
|
||||
|
||||
func (fakeCluster) Nodes() []adminapi.NodeView {
|
||||
return []adminapi.NodeView{{ID: "llmgw-node01", State: "ready", GPUTotal: 8, GPUFree: 8}}
|
||||
}
|
||||
func (fakeCluster) Models() []adminapi.ModelView { return nil }
|
||||
func (fakeCluster) Replicas(string) []adminapi.ReplicaView { return nil }
|
||||
func (fakeCluster) Explain(string) adminapi.ExplainView { return adminapi.ExplainView{} }
|
||||
Reference in new issue
Block a user