Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Require proxy admin for permissioned endpoints
rcourtman422271d10349
diff --git a/internal/api/auth.go b/internal/api/auth.goindex 1884c1c7f7..07f45e94ba 100644--- a/internal/api/auth.go+++ b/internal/api/auth.go@@ -691,6 +691,32 @@ func RequirePermission(cfg *config.Config, authorizer auth.Authorizer, action, rreturn}+ // Check if using proxy auth and if so, verify admin status+ if cfg.ProxyAuthSecret != "" {+ if valid, username, isAdmin := CheckProxyAuth(cfg, r); valid {+ if !isAdmin {+ // User is authenticated but not an admin+ log.Warn().+ Str("ip", r.RemoteAddr).+ Str("path", r.URL.Path).+ Str("action", action).+ Str("resource", resource).+ Str("username", username).+ Msg("Non-admin user attempted to access permissioned endpoint")++ // Return forbidden error+ if strings.HasPrefix(r.URL.Path, "/api/") || strings.Contains(r.Header.Get("Accept"), "application/json") {+ w.Header().Set("Content-Type", "application/json")+ w.WriteHeader(http.StatusForbidden)+ w.Write([]byte(`{"error":"Admin privileges required"}`))+ } else {+ http.Error(w, "Admin privileges required", http.StatusForbidden)+ }+ return+ }+ }+ }+// Extract user from header (set by CheckAuth) and inject into contextusername := w.Header().Get("X-Authenticated-User")ctx := r.Context()diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.goindex c85f2cf877..8ad3764b12 100644--- a/internal/api/security_regression_test.go+++ b/internal/api/security_regression_test.go@@ -2063,6 +2063,8 @@ func TestProxyAuthNonAdminDeniedAdminEndpoints(t *testing.T) {{method: http.MethodPost, path: "/api/system/settings/update", body: `{}`},{method: http.MethodPost, path: "/api/security/reset-lockout", body: `{}`},{method: http.MethodPost, path: "/api/security/apply-restart", body: `{}`},+ {method: http.MethodGet, path: "/api/security/tokens", body: ``},+ {method: http.MethodDelete, path: "/api/security/tokens/token-1", body: ``},{method: http.MethodPost, path: "/api/security/regenerate-token", body: `{}`},{method: http.MethodPost, path: "/api/security/validate-token", body: `{"token":"abc"}`},{method: http.MethodPost, path: "/api/security/oidc", body: `{}`},@@ -2813,6 +2815,33 @@ func TestPermissionProtectedEndpointsDenyWhenAuthorizerBlocks(t *testing.T) {}}+func TestPermissionEndpointsRejectProxyNonAdmin(t *testing.T) {+ prevAuthorizer := auth.GetAuthorizer()+ auth.SetAuthorizer(&auth.DefaultAuthorizer{})+ defer auth.SetAuthorizer(prevAuthorizer)++ cfg := newTestConfigWithTokens(t)+ cfg.ProxyAuthSecret = "proxy-secret"+ cfg.ProxyAuthUserHeader = "X-Remote-User"+ cfg.ProxyAuthRoleHeader = "X-Remote-Roles"+ cfg.ProxyAuthAdminRole = "admin"++ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")++ req := httptest.NewRequest(http.MethodGet, "/api/security/tokens", nil)+ req.Header.Set("X-Proxy-Secret", cfg.ProxyAuthSecret)+ req.Header.Set("X-Remote-User", "viewer-user")+ req.Header.Set("X-Remote-Roles", "viewer")+ rec := httptest.NewRecorder()+ router.Handler().ServeHTTP(rec, req)+ if rec.Code != http.StatusForbidden {+ t.Fatalf("expected 403 for non-admin proxy on permissioned endpoint, got %d", rec.Code)+ }+ if !strings.Contains(rec.Body.String(), "Admin privileges required") {+ t.Fatalf("expected admin privilege error, got %q", rec.Body.String())+ }+}+func TestApplyRestartRequiresAuthInAPIMode(t *testing.T) {record := newTokenRecord(t, "apply-restart-token-123.12345678", []string{config.ScopeSettingsWrite}, nil)cfg := newTestConfigWithTokens(t, record)