diff --git a/internal/cli/server.go b/internal/cli/server.go index 51c1c8a8..3210be1f 100644 --- a/internal/cli/server.go +++ b/internal/cli/server.go @@ -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 diff --git a/internal/router/handlers.go b/internal/router/handlers.go index d70f7658..31db5c9a 100644 --- a/internal/router/handlers.go +++ b/internal/router/handlers.go @@ -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) } } diff --git a/internal/web/dashboard.go b/internal/web/dashboard.go index a25fb089..46aac1d5 100644 --- a/internal/web/dashboard.go +++ b/internal/web/dashboard.go @@ -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() diff --git a/internal/web/templates/dashboard.html b/internal/web/templates/dashboard.html index 4f4a5ab8..568dcb7d 100644 --- a/internal/web/templates/dashboard.html +++ b/internal/web/templates/dashboard.html @@ -8,10 +8,15 @@

Cluster

{{.NodeCount}} nodes · {{.ReadyReplicas}} of {{.TotalReplicas}} replicas ready · {{.ModelCount}} models

@@ -100,6 +105,14 @@ written in batches, so the last few seconds may be missing.

Authentication is off, so there is no identity to account against.

{{end}} +{{if not .OnAdminListener}} +

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: +ssh -L 9090:127.0.0.1:9090 <control-plane>

+{{end}} +