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
Propagate Basic auth identity into action authorization
rcourtman1397f72c1f43
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 51199125cb..0331f7c218 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -4596,3 +4596,9 @@ configuration write lock; a simultaneous local credential check must not takea recursive read lock while already inside `checkAuth`'s read-locked decision.The server must continue accepting reports and command registrations underthat mixed-auth load rather than allowing a queued writer to freeze the API.+Once that local credential check succeeds, the verified operator identity must+travel in the request context into action-governance authorization. A response+header alone is not identity. This lets a Basic-authenticated qualification+operator approve or reject an agent action while preserving the agent token's+separate reporting and command authority; invalid credentials must never reach+the action handler or acquire an operator principal.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 5be02344e1..26b8bdcb73 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -7720,3 +7720,13 @@ queued writer would create a circular wait and freeze every API consumer,including live agent reporting and Patrol qualification. Contract proof pinsthe single-lock boundary, and concurrency proof queues the writer beforeexercising the local credential snapshot.++Successful local Basic authentication must also attach the independently+verified configured username to the request context before the protected+handler runs. The response `X-Authenticated-User` header is presentation+metadata and must not be used as the authorization identity. RBAC and action+governance therefore authorize the exact principal accepted by `checkAuth`;+invalid Basic credentials attach no principal and fail before the handler.+This is required for qualification clients and local operators to read,+approve, reject, and execute governed actions without weakening the same+capability checks for sessions, proxy users, or API tokens.diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex ac52e76f9e..7f37efff74 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -1971,6 +1971,11 @@ clients on error (now the agent-stable envelope rather than theplatform-wide `APIError` shape). Recovery posture is identical:when the action audit store rehydrates on startup, the actionendpoints recover the same lifecycle records they always did.+Local Basic-auth identity propagation into those handlers remains an API+authorization concern: successful verification attaches the operator to the+request context, while invalid credentials fail before any action audit write.+It does not add recovery storage, alter `ActionAuditRecord`, or let response+headers participate in approval identity.The Patrol finding lifecycle endpoints advertised in the agentcapabilities manifest (`acknowledge_finding`, `snooze_finding`,diff --git a/internal/api/auth.go b/internal/api/auth.goindex 1f7f5a60e6..711f25218b 100644--- a/internal/api/auth.go+++ b/internal/api/auth.go@@ -891,6 +891,14 @@ func checkAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request, writeClearFailedLogins(parts[0])ClearFailedLogins(GetClientIP(r))+ // Authentication response headers are presentation metadata, not+ // an identity channel. Persist the independently verified Basic+ // auth subject on the request itself so downstream RBAC and action+ // governance checks authorize the same principal that checkAuth+ // accepted. Mutating the request in place is required because+ // RequireAuth passes the original request pointer to its handler.+ *r = *attachUserContext(r, parts[0])+// Valid credentials - create sessionif w != nil {// Invalidate any pre-existing session to prevent session fixation attacks.diff --git a/internal/api/auth_context_middleware_test.go b/internal/api/auth_context_middleware_test.goindex ede122c641..f14e74707d 100644--- a/internal/api/auth_context_middleware_test.go+++ b/internal/api/auth_context_middleware_test.go@@ -1,6 +1,7 @@package apiimport (+ "encoding/base64""net/http""net/http/httptest""testing"@@ -181,6 +182,69 @@ func TestExtractAndStoreAuthContext_ProxyAuth(t *testing.T) {}}+func TestRequireAuthBasicCredentialsAttachVerifiedUserContext(t *testing.T) {+ dataPath := t.TempDir()+ InitSessionStore(dataPath)+ InitCSRFStore(dataPath)+ hash, err := internalauth.HashPassword("correct-password")+ if err != nil {+ t.Fatalf("hash password: %v", err)+ }+ cfg := &config.Config{AuthUser: "admin", AuthPass: hash}++ var observedUser string+ handler := RequireAuth(cfg, func(w http.ResponseWriter, req *http.Request) {+ observedUser = internalauth.GetUser(req.Context())+ w.WriteHeader(http.StatusNoContent)+ })++ req := httptest.NewRequest(http.MethodGet, "/api/actions/example", nil)+ req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:correct-password")))+ recorder := httptest.NewRecorder()++ handler(recorder, req)++ if recorder.Code != http.StatusNoContent {+ t.Fatalf("expected authenticated handler response, got %d: %s", recorder.Code, recorder.Body.String())+ }+ if observedUser != "admin" {+ t.Fatalf("expected verified Basic auth user in handler context, got %q", observedUser)+ }+}++func TestRequireAuthInvalidBasicCredentialsDoNotAttachUserContext(t *testing.T) {+ dataPath := t.TempDir()+ InitSessionStore(dataPath)+ InitCSRFStore(dataPath)+ hash, err := internalauth.HashPassword("correct-password")+ if err != nil {+ t.Fatalf("hash password: %v", err)+ }+ cfg := &config.Config{AuthUser: "admin", AuthPass: hash}++ called := false+ handler := RequireAuth(cfg, func(w http.ResponseWriter, req *http.Request) {+ called = true+ w.WriteHeader(http.StatusNoContent)+ })++ req := httptest.NewRequest(http.MethodGet, "/api/actions/example", nil)+ req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:wrong-password")))+ recorder := httptest.NewRecorder()++ handler(recorder, req)++ if recorder.Code != http.StatusUnauthorized {+ t.Fatalf("expected invalid Basic auth to fail closed, got %d: %s", recorder.Code, recorder.Body.String())+ }+ if called {+ t.Fatal("protected handler ran with invalid Basic credentials")+ }+ if user := internalauth.GetUser(req.Context()); user != "" {+ t.Fatalf("invalid Basic credentials attached user %q", user)+ }+}+func TestGetAuthUsernameUsesAPITokenOwnerBinding(t *testing.T) {rawToken := "ctx-owner-auth-123.12345678"record, err := config.NewAPITokenRecord(rawToken, "ctx-token", []string{config.ScopeMonitoringRead})diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 8b37ea0c05..99902f8b86 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -61,6 +61,47 @@ import (tmock "github.com/stretchr/testify/mock")+type basicActionContractAuthorizer struct {+ wantUser string+}++func (a basicActionContractAuthorizer) Authorize(ctx context.Context, action, resource string) (bool, error) {+ return authpkg.GetUser(ctx) == a.wantUser && action == authpkg.ActionApprove && resource == authpkg.ResourceActions, nil+}++func TestContract_BasicAuthenticatedAdminReachesActionAuthorizationAsVerifiedPrincipal(t *testing.T) {+ dataPath := t.TempDir()+ InitSessionStore(dataPath)+ InitCSRFStore(dataPath)+ hashedPassword, err := authpkg.HashPassword("correct-password")+ if err != nil {+ t.Fatalf("hash password: %v", err)+ }+ cfg := &config.Config{AuthUser: "admin", AuthPass: hashedPassword}++ reachedActionHandler := false+ handler := RequireAuth(cfg, requireActionCapability(+ basicActionContractAuthorizer{wantUser: "admin"},+ authpkg.ActionApprove,+ func(w http.ResponseWriter, _ *http.Request) {+ reachedActionHandler = true+ w.WriteHeader(http.StatusNoContent)+ },+ ))++ req := httptest.NewRequest(http.MethodGet, "/api/actions/act_contract_basic_identity", nil)+ req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:correct-password")))+ recorder := httptest.NewRecorder()+ handler(recorder, req)++ if recorder.Code != http.StatusNoContent {+ t.Fatalf("Basic-authenticated action detail status = %d, want 204: %s", recorder.Code, recorder.Body.String())+ }+ if !reachedActionHandler {+ t.Fatal("verified Basic admin did not reach the governed action handler")+ }+}+func TestContract_ActionLifecycleReplayIsCreateOnceAndMonotonic(t *testing.T) {service, err := os.ReadFile("../actionlifecycle/service.go")if err != nil {