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
Cover apply-restart auth guards
rcourtman06df067cd74c
diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.goindex 02ad0f9a89..c25c449510 100644--- a/internal/api/security_regression_test.go+++ b/internal/api/security_regression_test.go@@ -2302,3 +2302,58 @@ func TestPermissionProtectedEndpointsDenyWhenAuthorizerBlocks(t *testing.T) {}}}++func TestApplyRestartRequiresAuthInAPIMode(t *testing.T) {+ record := newTokenRecord(t, "apply-restart-token-123.12345678", []string{config.ScopeSettingsWrite}, nil)+ cfg := newTestConfigWithTokens(t, record)+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")++ req := httptest.NewRequest(http.MethodPost, "/api/security/apply-restart", nil)+ rec := httptest.NewRecorder()+ router.Handler().ServeHTTP(rec, req)+ if rec.Code != http.StatusUnauthorized {+ t.Fatalf("expected 401 without auth, got %d", rec.Code)+ }+}++func TestApplyRestartRequiresSettingsWriteScope(t *testing.T) {+ rawToken := "apply-restart-scope-token-123.12345678"+ record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)+ cfg := newTestConfigWithTokens(t, record)+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")++ req := httptest.NewRequest(http.MethodPost, "/api/security/apply-restart", nil)+ req.Header.Set("X-API-Token", rawToken)+ rec := httptest.NewRecorder()+ router.Handler().ServeHTTP(rec, req)+ if rec.Code != http.StatusForbidden {+ t.Fatalf("expected 403 for missing settings:write scope, got %d", rec.Code)+ }+ if !strings.Contains(rec.Body.String(), config.ScopeSettingsWrite) {+ t.Fatalf("expected missing scope response to mention %q, got %q", config.ScopeSettingsWrite, rec.Body.String())+ }+}++func TestApplyRestartRequiresProxyAdmin(t *testing.T) {+ record := newTokenRecord(t, "apply-restart-proxy-token-123.12345678", []string{config.ScopeSettingsWrite}, nil)+ cfg := newTestConfigWithTokens(t, record)+ 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.MethodPost, "/api/security/apply-restart", 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 user, got %d", rec.Code)+ }+ if !strings.Contains(rec.Body.String(), "Admin privileges required") {+ t.Fatalf("expected admin privilege error, got %q", rec.Body.String())+ }+}