Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Reject damaged RBAC integrity organisation selections

pulse-triage[bot]3230e5aad7fb
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index aa77c03986..1cb1db1d81 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -10591,3 +10591,13 @@ settings, certificate trust or authentication. The adjacent
correct audit verdicts and unchanged saved secrets/local administrator recovery.
Existing XML-parser failures keep their original categories; this evidence
check only runs after that parser succeeds.
+
+### RBAC integrity query admission does not change agent authority
+
+The public integrity-check fallback rejects damaged or repeated `org_id`
+selections (`400 invalid_query`) and explicit blank identifiers
+(`400 invalid_org_id`) before verification. Omitted selection and existing
+org/authentication/licence boundaries remain. This changes no agent token,
+enrolment, credential or runtime operation. The API contract and
+`TestContractRBACIntegrityQueryAdmission` cover the registered fallback;
+`rbac_integrity_query_test.go` covers rejected and supported selections.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 3a31da0796..e0cfabff18 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -13022,3 +13022,24 @@ files, saved secrets and local administrator recovery. Existing fetch/parse
categories, metadata-source precedence, limits, rate checks and outbound/TLS
policy remain unchanged. Browser proof consumes those actual synthetic wire
results through the existing Settings editor at desktop and narrow viewports.
+
+### RBAC integrity checks require an unambiguous organisation selection
+
+The public `GET /api/admin/rbac/integrity` fallback parses the complete query.
+Malformed encoding anywhere or repeated decoded `org_id` keys return
+`400 invalid_query`; an explicitly blank/whitespace-only or invalid identifier
+returns `400 invalid_org_id`. No integrity verdict or manager initialization
+may follow rejected admission. Omission retains the request organisation
+(including the existing default-context compatibility); a valid singleton
+retains percent decoding and whitespace normalization. A valid different
+organisation still returns `403 access_denied`. Well-formed unrelated query
+parameters remain ignored, not additional selectors.
+
+Authentication, instance administration, RBAC licensing, method/provider checks
+and endpoint-binder precedence remain unchanged. The default adapter is used
+when no binder is registered or a binder returns nil; a real override still
+owns its endpoint. `rbac_integrity_query_test.go` covers selection, no created
+manager/files on rejection, supported results, existing denials and both
+fallbacks. `TestContractRBACIntegrityQueryAdmission` exercises the registered
+router and unchanged authentication/licence gates. No frontend consumes this
+admin-only check; this changes no rendered state, recovery token or sign-in.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index f5f3826e3c..8cf254ff01 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -8219,3 +8219,14 @@ initial assessments, retry, deferred initial assessment, common filters/hash,
replace-history semantics, explicit views and empty inventory. Browser proof
must exercise the actual table, inventory parsers and posture client through a
local safe producer at desktop and narrow widths, with native pixel inspection.
+
+### Damaged RBAC selections are not successful recovery evidence
+
+The existing RBAC integrity-check fallback rejects malformed query encoding,
+repeated decoded organisation selections and explicit blanks before manager
+initialization or an integrity verdict. The API contract and
+`TestContractRBACIntegrityQueryAdmission` bind the wire errors and unchanged
+authentication/licence gates; `rbac_integrity_query_test.go` checks rejected
+requests create no manager/files while omitted and valid scoped checks work.
+This changes no reset token, backup, guest operation, storage format or native
+recovery guarantee. Existing default-context compatibility stays intact.
diff --git a/internal/api/access_admin_handlers.go b/internal/api/access_admin_handlers.go
index c826f06b7b..772767716f 100644
--- a/internal/api/access_admin_handlers.go
+++ b/internal/api/access_admin_handlers.go
@@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"net/http"
+ "net/url"
"strings"
)
@@ -19,15 +20,26 @@ func (h *RBACHandlers) HandleRBACIntegrityCheck(w http.ResponseWriter, r *http.R
return
}
+ // Query() discards malformed pairs and Get() selects the first repeated
+ // value. Neither may turn a damaged selection into a successful check.
+ query, err := url.ParseQuery(r.URL.RawQuery)
+ if err != nil {
+ writeErrorResponse(w, http.StatusBadRequest, "invalid_query", "Invalid query encoding", nil)
+ return
+ }
+ if len(query["org_id"]) > 1 {
+ writeErrorResponse(w, http.StatusBadRequest, "invalid_query", "org_id must be supplied at most once", nil)
+ return
+ }
+
contextOrgID := strings.TrimSpace(GetOrgID(r.Context()))
if contextOrgID == "" {
contextOrgID = "default"
}
- orgID := strings.TrimSpace(r.URL.Query().Get("org_id"))
- if orgID == "" {
- orgID = contextOrgID
- } else {
+ orgID := contextOrgID
+ if query.Has("org_id") {
+ orgID = strings.TrimSpace(query.Get("org_id"))
if !isValidOrganizationID(orgID) {
writeErrorResponse(w, http.StatusBadRequest, "invalid_org_id", "Invalid organization ID", nil)
return
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 7065243769..8ab5975138 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -83,6 +83,66 @@ import (
tmock "github.com/stretchr/testify/mock"
)
+// The registered public fallback remains reachable behind the ordinary
+// authentication and licence gates, without an Enterprise endpoint binder.
+func TestContractRBACIntegrityQueryAdmission(t *testing.T) {
+ SetRBACAdminEndpointsBinder(nil)
+ t.Cleanup(func() { SetRBACAdminEndpointsBinder(nil) })
+ resetPersistentAuthStoresForTests()
+ t.Cleanup(resetPersistentAuthStoresForTests)
+ rawToken := "integrity-query-contract-token.12345678"
+ cfg := newTestConfigWithTokens(t, newTokenRecord(t, rawToken, []string{config.ScopeWildcard}, nil))
+ router := NewRouter(cfg, nil, nil, nil, nil, "test")
+ cleanupTestRouter(t, router)
+ setLicenseTierForHandlersForTests(t, router.licenseHandlers, "default", pkglicensing.TierEnterprise)
+ serve := func(query, token string) *httptest.ResponseRecorder {
+ req := httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity?"+query, nil)
+ req.Header.Set("Accept", "application/json")
+ if token != "" {
+ req.Header.Set("X-API-Token", token)
+ }
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ return rec
+ }
+ for _, tt := range []struct {
+ name, query, code string
+ status int
+ }{
+ {"damaged", "org_id=%zz", "invalid_query", http.StatusBadRequest},
+ {"repeated", "org_id=default&org_id=other", "invalid_query", http.StatusBadRequest},
+ {"blank", "org_id=", "invalid_org_id", http.StatusBadRequest},
+ {"foreign", "org_id=other", "access_denied", http.StatusForbidden},
+ {"omitted", "", "", http.StatusOK},
+ {"encoded", "org_%69d=%64efault", "", http.StatusOK},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ rec := serve(tt.query, rawToken)
+ if rec.Code != tt.status {
+ t.Fatalf("status = %d, want %d: %s", rec.Code, tt.status, rec.Body.String())
+ }
+ if tt.code != "" {
+ var result APIError
+ if err := json.Unmarshal(rec.Body.Bytes(), &result); err != nil || result.Code != tt.code {
+ t.Fatalf("invalid error contract: %s", rec.Body.String())
+ }
+ } else {
+ var result RBACIntegrityResult
+ if err := json.Unmarshal(rec.Body.Bytes(), &result); err != nil || result.OrgID != "default" || !result.Healthy {
+ t.Fatalf("invalid integrity contract: %s", rec.Body.String())
+ }
+ }
+ })
+ }
+ if rec := serve("org_id=%zz", ""); rec.Code != http.StatusUnauthorized {
+ t.Fatalf("unauthenticated damaged query = %d, want 401", rec.Code)
+ }
+ setLicenseTierForHandlersForTests(t, router.licenseHandlers, "default", pkglicensing.TierFree)
+ if rec := serve("org_id=%zz", rawToken); rec.Code != http.StatusPaymentRequired {
+ t.Fatalf("unlicensed damaged query = %d, want 402", rec.Code)
+ }
+}
+
// Exercise the proof's real CLI, child execution and on-disk receipts without
// running a latency workload. Only capacity telemetry and sampling delays are
// synthetic; a malformed/failed child must never become a neutral budget result.
diff --git a/internal/api/rbac_integrity_query_test.go b/internal/api/rbac_integrity_query_test.go
new file mode 100644
index 0000000000..412ef17c11
--- /dev/null
+++ b/internal/api/rbac_integrity_query_test.go
@@ -0,0 +1,183 @@
+package api
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/pkg/extensions"
+)
+
+func TestRBACIntegrityQueryRejectsDamagedSelection(t *testing.T) {
+ for _, tt := range []struct{ name, query, code string }{
+ {"bad escape", "org_id=%zz", "invalid_query"},
+ {"bare escape", "org_id=%", "invalid_query"},
+ {"short escape", "org_id=%0", "invalid_query"},
+ {"damaged selector key", "org_%zz=default", "invalid_query"},
+ {"damaged unrelated key", "%zz=ignored", "invalid_query"},
+ {"damaged suffix", "org_id=default&future=%zz", "invalid_query"},
+ {"damaged prefix", "future=%zz&org_id=default", "invalid_query"},
+ {"unescaped semicolon", "org_id=default;future=value", "invalid_query"},
+ {"damaged repeated value", "org_id=default&org_id=%zz", "invalid_query"},
+ {"damaged encoded duplicate", "org_id=default&%6frg_id=%zz", "invalid_query"},
+ {"identical duplicate", "org_id=default&org_id=default", "invalid_query"},
+ {"allowed first", "org_id=default&org_id=other", "invalid_query"},
+ {"denied first", "org_id=other&org_id=default", "invalid_query"},
+ {"empty first", "org_id=&org_id=default", "invalid_query"},
+ {"empty second", "org_id=default&org_id=", "invalid_query"},
+ {"encoded duplicate key", "%6frg_id=default&org_id=default", "invalid_query"},
+ {"two encoded keys", "%6frg_id=default&org_%69d=other", "invalid_query"},
+ {"three values", "org_id=default&org_id=default&org_id=default", "invalid_query"},
+ {"explicit empty", "org_id=", "invalid_org_id"},
+ {"bare selector", "org_id", "invalid_org_id"},
+ {"plus whitespace", "org_id=+", "invalid_org_id"},
+ {"encoded whitespace", "org_id=%20%09", "invalid_org_id"},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ dir := t.TempDir()
+ provider := NewTenantRBACProvider(dir)
+ t.Cleanup(func() { _ = provider.Close() })
+ handlers := NewRBACHandlers(nil, provider)
+ rec := httptest.NewRecorder()
+ handlers.HandleRBACIntegrityCheck(rec, httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity?"+tt.query, nil))
+ var body APIError
+ if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
+ t.Fatal(err)
+ }
+ if rec.Code != http.StatusBadRequest || body.Code != tt.code {
+ t.Errorf("status/code = %d/%q, want 400/%q", rec.Code, body.Code, tt.code)
+ }
+ if provider.ManagerCount() != 0 {
+ t.Error("rejected selection initialized an RBAC manager")
+ }
+ entries, err := os.ReadDir(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(entries) != 0 || strings.Contains(rec.Body.String(), `"healthy"`) {
+ t.Error("rejected selection created RBAC files or returned an integrity verdict")
+ }
+ })
+ }
+}
+
+func TestRBACIntegrityQueryPreservesSupportedSelection(t *testing.T) {
+ for _, tt := range []struct{ name, query, contextOrg, wantOrg string }{
+ {"omitted legacy context", "", "", "default"},
+ {"blank legacy context", "", " \t", "default"},
+ {"explicit default", "org_id=default", "", "default"},
+ {"encoded key", "%6frg_id=default", "", "default"},
+ {"encoded value", "org_id=%64efault", "", "default"},
+ {"trimmed value", "org_id=%20default%20", "", "default"},
+ {"unknown parameters", "future=a&future=b&org_id=default", "", "default"},
+ {"encoded unknown semicolon", "future=a%3Bb", "", "default"},
+ {"empty pairs", "&&org_id=default&", "", "default"},
+ {"omitted scoped selection", "", "org-a", "org-a"},
+ {"encoded scoped selection", "org_%69d=org%2Da", "org-a", "org-a"},
+ {"trimmed scoped context", "org_id=+org-a+", " org-a ", "org-a"},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ dir := t.TempDir()
+ if tt.wantOrg != "default" {
+ if err := os.MkdirAll(filepath.Join(dir, "orgs", tt.wantOrg), 0700); err != nil {
+ t.Fatal(err)
+ }
+ }
+ provider := NewTenantRBACProvider(dir)
+ t.Cleanup(func() { _ = provider.Close() })
+ req := httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity?"+tt.query, nil)
+ req = req.WithContext(context.WithValue(req.Context(), OrgIDContextKey, tt.contextOrg))
+ rec := httptest.NewRecorder()
+ NewRBACHandlers(nil, provider).HandleRBACIntegrityCheck(rec, req)
+ var result RBACIntegrityResult
+ if err := json.Unmarshal(rec.Body.Bytes(), &result); err != nil {
+ t.Fatal(err)
+ }
+ if rec.Code != http.StatusOK || result.OrgID != tt.wantOrg || !result.Healthy || !result.DBAccessible {
+ t.Fatalf("status/result = %d/%+v, want healthy %s", rec.Code, result, tt.wantOrg)
+ }
+ if rec.Header().Get("Content-Type") != "application/json" || provider.ManagerCount() != 1 {
+ t.Fatal("supported selection lost its JSON result or scoped manager")
+ }
+ })
+ }
+}
+
+func TestRBACIntegrityQueryPreservesDenials(t *testing.T) {
+ for _, tt := range []struct {
+ name, query, contextOrg, code string
+ status int
+ }{
+ {"foreign org", "org_id=org-b", "org-a", "access_denied", http.StatusForbidden},
+ {"encoded foreign org", "org_id=org%2Db", "org-a", "access_denied", http.StatusForbidden},
+ {"foreign org without context", "org_id=org-b", "", "access_denied", http.StatusForbidden},
+ {"path", "org_id=..%2Fother", "org-a", "invalid_org_id", http.StatusBadRequest},
+ {"dot", "org_id=.", "org-a", "invalid_org_id", http.StatusBadRequest},
+ {"invalid character", "org_id=org%2Ba", "org-a", "invalid_org_id", http.StatusBadRequest},
+ {"too long", "org_id=" + strings.Repeat("a", 65), "org-a", "invalid_org_id", http.StatusBadRequest},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ provider := NewTenantRBACProvider(t.TempDir())
+ t.Cleanup(func() { _ = provider.Close() })
+ req := httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity?"+tt.query, nil)
+ req = req.WithContext(context.WithValue(req.Context(), OrgIDContextKey, tt.contextOrg))
+ rec := httptest.NewRecorder()
+ NewRBACHandlers(nil, provider).HandleRBACIntegrityCheck(rec, req)
+ var body APIError
+ if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
+ t.Fatal(err)
+ }
+ if rec.Code != tt.status || body.Code != tt.code || provider.ManagerCount() != 0 {
+ t.Fatalf("status/code/managers = %d/%q/%d, want %d/%q/0", rec.Code, body.Code, provider.ManagerCount(), tt.status, tt.code)
+ }
+ })
+ }
+}
+
+func TestRBACIntegrityFallbackUsesQueryAdmission(t *testing.T) {
+ for _, mode := range []string{"no binder", "binder returns nil"} {
+ t.Run(mode, func(t *testing.T) {
+ SetRBACAdminEndpointsBinder(nil)
+ t.Cleanup(func() { SetRBACAdminEndpointsBinder(nil) })
+ if mode == "binder returns nil" {
+ SetRBACAdminEndpointsBinder(func(extensions.RBACAdminEndpoints, extensions.RBACAdminRuntime) extensions.RBACAdminEndpoints {
+ return nil
+ })
+ }
+ provider := NewTenantRBACProvider(t.TempDir())
+ t.Cleanup(func() { _ = provider.Close() })
+ handlers := NewRBACHandlers(nil, provider)
+ endpoints := resolveRBACAdminEndpoints(rbacAdminEndpointAdapter{handlers: handlers}, newRBACAdminRuntime(handlers))
+ for _, query := range []string{"org_id=%zz", "org_id=default&org_id=other", "org_id="} {
+ rec := httptest.NewRecorder()
+ endpoints.HandleIntegrityCheck(rec, httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity?"+query, nil))
+ if rec.Code != http.StatusBadRequest || provider.ManagerCount() != 0 {
+ t.Fatalf("fallback admitted %q: status/managers = %d/%d", query, rec.Code, provider.ManagerCount())
+ }
+ }
+ rec := httptest.NewRecorder()
+ endpoints.HandleIntegrityCheck(rec, httptest.NewRequest(http.MethodGet, "/api/admin/rbac/integrity", nil))
+ if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"healthy":true`) {
+ t.Fatalf("fallback lost its ordinary check: %d %s", rec.Code, rec.Body.String())
+ }
+ })
+ }
+}
+
+func TestRBACIntegrityQueryPreservesUnavailableAndMethodChecks(t *testing.T) {
+ for _, tt := range []struct {
+ method string
+ status int
+ }{{http.MethodGet, http.StatusNotImplemented}, {http.MethodPost, http.StatusMethodNotAllowed}} {
+ rec := httptest.NewRecorder()
+ NewRBACHandlers(nil, nil).HandleRBACIntegrityCheck(rec, httptest.NewRequest(tt.method, "/api/admin/rbac/integrity?org_id=%zz", nil))
+ if rec.Code != tt.status {
+ t.Errorf("%s without provider = %d, want %d", tt.method, rec.Code, tt.status)
+ }
+ }
+}