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.

Keep admin recovery reachable when the legacy RBAC import fails

rcourtman3324ef390937
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 17445fea06..e57875e729 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -2158,6 +2158,22 @@ Agent` secondary handoff against the live setup wizard instead of relying
consume one declared-type initial registration after durable first-host
binding and serialized completion.
+22. A rejected legacy RBAC import must not destroy the store. The import is
+ transactional and leaves the legacy files in place, so a failure leaves the
+ database un-migrated rather than half-migrated, which denies access rather
+ than granting it. Failing manager construction instead takes the whole org's
+ RBAC surface offline including `ResetAdminRole`, the operator's only way
+ back, on a conflict an ordinary v5 upgrade can produce. The store therefore
+ stays live and records the failure on `SQLiteManager.MigrationError`.
+ Management routes still fail closed with `rbac_store_unavailable` through
+ the handler manager accessors; recovery reaches the provider directly and is
+ deliberately exempt. Regression coverage:
+ `TestAdminRecoverySurvivesFailedLegacyRBACMigration` in
+ `internal/api/contract_test.go`,
+ `TestRBACHandlersReportLegacyMigrationFailure` in
+ `internal/api/rbac_handlers_test.go`, and the rejection cases in
+ `pkg/auth/sqlite_manager_test.go`.
+
## Current State
### PBS connection health does not create agent lifecycle evidence
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 9ee64723c8..83d13e5c23 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -3642,6 +3642,22 @@ PVE/PBS install token may create one matching source, after durable first-host
binding, and completion must consume that grant under the serialized
auto-register mutation boundary.
+34. A rejected legacy RBAC import must not destroy the store. The import is
+ transactional and leaves the legacy files in place, so a failure leaves the
+ database un-migrated rather than half-migrated, which denies access rather
+ than granting it. Failing manager construction instead takes the whole org's
+ RBAC surface offline including `ResetAdminRole`, the operator's only way
+ back, on a conflict an ordinary v5 upgrade can produce. The store therefore
+ stays live and records the failure on `SQLiteManager.MigrationError`.
+ Management routes still fail closed with `rbac_store_unavailable` through
+ the handler manager accessors; recovery reaches the provider directly and is
+ deliberately exempt. Regression coverage:
+ `TestAdminRecoverySurvivesFailedLegacyRBACMigration` in
+ `internal/api/contract_test.go`,
+ `TestRBACHandlersReportLegacyMigrationFailure` in
+ `internal/api/rbac_handlers_test.go`, and the rejection cases in
+ `pkg/auth/sqlite_manager_test.go`.
+
## Current State
### Agent update target responses are reconciliation-safe
diff --git a/docs/release-control/v6/internal/subsystems/organization-settings.md b/docs/release-control/v6/internal/subsystems/organization-settings.md
index 5fc3071872..8d6d239857 100644
--- a/docs/release-control/v6/internal/subsystems/organization-settings.md
+++ b/docs/release-control/v6/internal/subsystems/organization-settings.md
@@ -135,6 +135,22 @@ create, review, and approve cross-organization shares.
rows, disable mutations, retain a visible retry notice, and do not render
the normal empty state until a healthy response has been received.
+11. A rejected legacy RBAC import must not destroy the store. The import is
+ transactional and leaves the legacy files in place, so a failure leaves the
+ database un-migrated rather than half-migrated, which denies access rather
+ than granting it. Failing manager construction instead takes the whole org's
+ RBAC surface offline including `ResetAdminRole`, the operator's only way
+ back, on a conflict an ordinary v5 upgrade can produce. The store therefore
+ stays live and records the failure on `SQLiteManager.MigrationError`.
+ Management routes still fail closed with `rbac_store_unavailable` through
+ the handler manager accessors; recovery reaches the provider directly and is
+ deliberately exempt. Regression coverage:
+ `TestAdminRecoverySurvivesFailedLegacyRBACMigration` in
+ `internal/api/contract_test.go`,
+ `TestRBACHandlersReportLegacyMigrationFailure` in
+ `internal/api/rbac_handlers_test.go`, and the rejection cases in
+ `pkg/auth/sqlite_manager_test.go`.
+
## Current State
This subsystem now sits under the dedicated security, identity, and privacy
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index 3fdcdce938..a72ec6c5b0 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -557,6 +557,22 @@ tokens, and path-normalization variants.
host/container summary fields plus aggregate stats, with no
`docker inspect`, environment, mount, file, command, or process collection.
+13. A rejected legacy RBAC import must not destroy the store. The import is
+ transactional and leaves the legacy files in place, so a failure leaves the
+ database un-migrated rather than half-migrated, which denies access rather
+ than granting it. Failing manager construction instead takes the whole org's
+ RBAC surface offline including `ResetAdminRole`, the operator's only way
+ back, on a conflict an ordinary v5 upgrade can produce. The store therefore
+ stays live and records the failure on `SQLiteManager.MigrationError`.
+ Management routes still fail closed with `rbac_store_unavailable` through
+ the handler manager accessors; recovery reaches the provider directly and is
+ deliberately exempt. Regression coverage:
+ `TestAdminRecoverySurvivesFailedLegacyRBACMigration` in
+ `internal/api/contract_test.go`,
+ `TestRBACHandlersReportLegacyMigrationFailure` in
+ `internal/api/rbac_handlers_test.go`, and the rejection cases in
+ `pkg/auth/sqlite_manager_test.go`.
+
## Current State
### Canonical mutation-plane dependency
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index a9b4a31e5f..eff1f8a67b 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -1967,6 +1967,22 @@ that Safe auto-fix or Autopilot remediation is verified.
vdev layout is reported` in
`frontend-modern/src/features/storageBackups/__tests__/storageAdapters.test.ts`.
+27. A rejected legacy RBAC import must not destroy the store. The import is
+ transactional and leaves the legacy files in place, so a failure leaves the
+ database un-migrated rather than half-migrated, which denies access rather
+ than granting it. Failing manager construction instead takes the whole org's
+ RBAC surface offline including `ResetAdminRole`, the operator's only way
+ back, on a conflict an ordinary v5 upgrade can produce. The store therefore
+ stays live and records the failure on `SQLiteManager.MigrationError`.
+ Management routes still fail closed with `rbac_store_unavailable` through
+ the handler manager accessors; recovery reaches the provider directly and is
+ deliberately exempt. Regression coverage:
+ `TestAdminRecoverySurvivesFailedLegacyRBACMigration` in
+ `internal/api/contract_test.go`,
+ `TestRBACHandlersReportLegacyMigrationFailure` in
+ `internal/api/rbac_handlers_test.go`, and the rejection cases in
+ `pkg/auth/sqlite_manager_test.go`.
+
## Current State
### Proxmox runtime continuity is not protection evidence
diff --git a/internal/api/access_control_handlers.go b/internal/api/access_control_handlers.go
index 43e9ea7ac3..a6983867c9 100644
--- a/internal/api/access_control_handlers.go
+++ b/internal/api/access_control_handlers.go
@@ -40,6 +40,21 @@ func NewRBACHandlers(cfg *config.Config, rbacProvider ...*TenantRBACProvider) *R
}
}
+// rbacMigrationFailure reports a store whose legacy import was rejected.
+//
+// The store itself stays live so admin recovery keeps working, but RBAC
+// management routes must still fail closed: the operator is looking at data
+// that does not include their legacy roles and assignments, and editing it
+// would build on an incomplete picture. Recovery reaches the provider directly
+// and so is deliberately not routed through this check.
+func rbacMigrationFailure(manager any) error {
+ degraded, ok := manager.(interface{ MigrationError() error })
+ if !ok {
+ return nil
+ }
+ return degraded.MigrationError()
+}
+
// getManager returns the RBAC Manager for the org in the request context.
// Falls back to global manager if no provider is set (backward compat).
func (h *RBACHandlers) getManager(ctx context.Context) (auth.Manager, error) {
@@ -49,6 +64,9 @@ func (h *RBACHandlers) getManager(ctx context.Context) (auth.Manager, error) {
if err != nil {
return nil, err
}
+ if err := rbacMigrationFailure(manager); err != nil {
+ return nil, err
+ }
return manager, nil
}
return auth.GetManager(), nil
@@ -62,6 +80,9 @@ func (h *RBACHandlers) getExtendedManager(ctx context.Context) (auth.ExtendedMan
if err != nil {
return nil, err
}
+ if err := rbacMigrationFailure(manager); err != nil {
+ return nil, err
+ }
return manager, nil
}
return auth.GetExtendedManager(), nil
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index c174d5eab5..de828d0e4a 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -21686,3 +21686,80 @@ func TestContract_DockerContainerUpdateRidesTheLifecycleExecutor(t *testing.T) {
t.Fatalf("restart operation resolves handler %q, want %q", handler, dockerContainerLifecycleHandler)
}
}
+
+// TestAdminRecoverySurvivesFailedLegacyRBACMigration is the regression guard for
+// the recovery hole in d235aab3c. That commit put MigrateFromFiles on a
+// production path for the default org and failed the whole manager when the
+// import was rejected, so GetManager returned an error, every RBAC route 503'd,
+// and ResetAdminRole (the operator's only way back) was unreachable. The
+// realistic trigger is a v5 install that recreated a role the v6 store already
+// holds under the same ID.
+func TestAdminRecoverySurvivesFailedLegacyRBACMigration(t *testing.T) {
+ dataDir := t.TempDir()
+
+ // Seed a v6 store so the legacy file below is a genuine current-state
+ // conflict rather than a first-time import.
+ seed, err := authpkg.NewSQLiteManager(authpkg.SQLiteManagerConfig{DataDir: dataDir})
+ if err != nil {
+ t.Fatalf("seed manager: %v", err)
+ }
+ if err := seed.SaveRole(authpkg.Role{
+ ID: "operations",
+ Name: "Operations",
+ Permissions: []authpkg.Permission{{Action: "read", Resource: "*", Effect: authpkg.EffectAllow}},
+ }); err != nil {
+ t.Fatalf("seed role: %v", err)
+ }
+ if err := seed.Close(); err != nil {
+ t.Fatalf("close seed manager: %v", err)
+ }
+
+ // Same ID, different content: the conflict the migration must reject.
+ legacy, err := json.Marshal([]authpkg.Role{{
+ ID: "operations",
+ Name: "Operations (legacy)",
+ Permissions: []authpkg.Permission{{Action: "admin", Resource: "*", Effect: authpkg.EffectAllow}},
+ }})
+ if err != nil {
+ t.Fatalf("marshal legacy roles: %v", err)
+ }
+ if err := os.WriteFile(filepath.Join(dataDir, "rbac_roles.json"), legacy, 0600); err != nil {
+ t.Fatalf("write legacy roles: %v", err)
+ }
+
+ provider := NewTenantRBACProvider(dataDir)
+
+ manager, err := provider.GetManager("default")
+ if err != nil {
+ t.Fatalf("GetManager must survive a rejected legacy import: %v", err)
+ }
+ sqliteManager, ok := manager.(*authpkg.SQLiteManager)
+ if !ok {
+ t.Fatalf("expected a SQLite-backed manager, got %T", manager)
+ }
+ migrationErr := sqliteManager.MigrationError()
+ if migrationErr == nil || !strings.Contains(migrationErr.Error(), "conflicts with current v6 data") {
+ t.Fatalf("migration error = %v, want the rejected current-state conflict", migrationErr)
+ }
+
+ // The whole point: recovery is still reachable.
+ if err := ResetAdminRole(provider, "default", "operator"); err != nil {
+ t.Fatalf("admin recovery unreachable after a failed migration: %v", err)
+ }
+
+ if _, exists := manager.GetRole(authpkg.RoleAdmin); !exists {
+ t.Fatal("admin role missing after recovery")
+ }
+
+ // The rejected legacy data stayed rejected and its source was preserved.
+ role, exists := manager.GetRole("operations")
+ if !exists {
+ t.Fatal("pre-existing v6 role was lost")
+ }
+ if role.Name != "Operations" {
+ t.Fatalf("legacy data overwrote current v6 role: %+v", role)
+ }
+ if _, err := os.Stat(filepath.Join(dataDir, "rbac_roles.json")); err != nil {
+ t.Fatalf("legacy source was not preserved for a retry: %v", err)
+ }
+}
diff --git a/internal/api/rbac_handlers_test.go b/internal/api/rbac_handlers_test.go
index dd7c6532d9..802b651011 100644
--- a/internal/api/rbac_handlers_test.go
+++ b/internal/api/rbac_handlers_test.go
@@ -430,6 +430,14 @@ func TestRBACHandlersReportLegacyMigrationFailure(t *testing.T) {
if !bytes.Contains(response.Body.Bytes(), []byte(`"code":"rbac_store_unavailable"`)) {
t.Fatalf("missing explicit RBAC store error: %s", response.Body.String())
}
+
+ // Management routes fail closed, but the store itself stays live so admin
+ // recovery remains reachable. Failing the manager outright used to take
+ // ResetAdminRole down with the rest of the surface, leaving no way back
+ // from a rejected legacy import.
+ if err := ResetAdminRole(provider, "default", "operator"); err != nil {
+ t.Fatalf("admin recovery must stay reachable while RBAC routes fail closed: %v", err)
+ }
if _, err := os.Stat(filepath.Join(baseDir, "rbac_roles.json")); err != nil {
t.Fatalf("corrupt source was not preserved: %v", err)
}
diff --git a/pkg/auth/sqlite_manager.go b/pkg/auth/sqlite_manager.go
index 9b01074e93..ada1c75166 100644
--- a/pkg/auth/sqlite_manager.go
+++ b/pkg/auth/sqlite_manager.go
@@ -34,6 +34,9 @@ type SQLiteManager struct {
db *sql.DB
dbPath string
changeLogRetention int
+ // migrationErr records a failed legacy import. The store stays usable so
+ // the operator can still reach RBAC, including admin recovery.
+ migrationErr error
}
// NewSQLiteManager creates a new SQLite-backed RBAC manager.
@@ -102,17 +105,39 @@ func NewSQLiteManager(cfg SQLiteManagerConfig) (*SQLiteManager, error) {
return nil, fmt.Errorf("failed to initialize built-in roles: %w", err)
}
- // Migrate from file-based storage if requested
+ // Migrate from file-based storage if requested.
+ //
+ // A failure here must not take the manager down with it. importLegacyRBAC
+ // runs in a transaction and the legacy files are left in place, so a failed
+ // import leaves the database un-migrated rather than half-migrated: users
+ // are missing roles, which denies access rather than granting it. Returning
+ // nil instead would fail GetManager for the whole org and 503 every RBAC
+ // route, including ResetAdminRole, which is the operator's only way back.
+ // The realistic trigger is a v5 install that recreated a role the v6 store
+ // already has under the same ID, so this is reachable on ordinary upgrades.
if cfg.MigrateFromFiles {
if err := m.migrateFromFiles(dataDir); err != nil {
- db.Close()
- return nil, fmt.Errorf("migrate legacy RBAC data: %w", err)
+ m.migrationErr = fmt.Errorf("migrate legacy RBAC data: %w", err)
+ log.Error().
+ Err(err).
+ Str("dataDir", dataDir).
+ Msg("Legacy RBAC import failed. The RBAC store is running without the legacy data; " +
+ "the legacy files were left untouched. Resolve the conflict and restart to retry.")
}
}
return m, nil
}
+// MigrationError reports a failed legacy RBAC import, or nil when the import
+// succeeded or was not requested. The manager is usable either way; this exists
+// so callers can surface the degraded state instead of it living only in logs.
+func (m *SQLiteManager) MigrationError() error {
+ m.mu.RLock()
+ defer m.mu.RUnlock()
+ return m.migrationErr
+}
+
func (m *SQLiteManager) initSchema() error {
schema := `
-- Roles table
diff --git a/pkg/auth/sqlite_manager_test.go b/pkg/auth/sqlite_manager_test.go
index 288bf29ef7..5ec1ca99b4 100644
--- a/pkg/auth/sqlite_manager_test.go
+++ b/pkg/auth/sqlite_manager_test.go
@@ -454,11 +454,21 @@ func TestSQLiteManagerMigrationRejectsCorruptAndStaleData(t *testing.T) {
DataDir: tmpDir,
MigrateFromFiles: true,
})
- if manager != nil {
- _ = manager.Close()
+ // A rejected import must not take the store down with it: the
+ // manager still has to serve RBAC, including admin recovery.
+ if err != nil {
+ t.Fatalf("rejected migration must not fail manager construction: %v", err)
+ }
+ if manager == nil {
+ t.Fatal("manager is nil after a rejected migration")
+ }
+ defer func() { _ = manager.Close() }()
+ migrationErr := manager.MigrationError()
+ if migrationErr == nil || !strings.Contains(migrationErr.Error(), tt.wantError) {
+ t.Fatalf("migration error = %v, want substring %q", migrationErr, tt.wantError)
}
- if err == nil || !strings.Contains(err.Error(), tt.wantError) {
- t.Fatalf("error = %v, want substring %q", err, tt.wantError)
+ if roles := manager.GetRoles(); len(roles) == 0 {
+ t.Fatal("store unusable after a rejected migration: no built-in roles")
}
if _, err := os.Stat(rolesPath); err != nil {
t.Fatalf("legacy roles source was not preserved: %v", err)
@@ -512,12 +522,22 @@ func TestSQLiteManagerMigrationRejectsCurrentStateConflicts(t *testing.T) {
DataDir: tmpDir,
MigrateFromFiles: true,
})
- if manager != nil {
- _ = manager.Close()
+ if err != nil {
+ t.Fatalf("conflicting migration must not fail manager construction: %v", err)
+ }
+ if manager == nil {
+ t.Fatal("manager is nil after a conflicting migration")
+ }
+ migrationErr := manager.MigrationError()
+ if migrationErr == nil || !strings.Contains(migrationErr.Error(), "conflicts with current v6 data") {
+ t.Fatalf("migration error = %v, want current-state conflict", migrationErr)
}
- if err == nil || !strings.Contains(err.Error(), "conflicts with current v6 data") {
- t.Fatalf("error = %v, want current-state conflict", err)
+ // The conflict is the realistic v5 upgrade case, so the operator must still
+ // be able to reach RBAC rather than facing a store-wide outage.
+ if roles := manager.GetRoles(); len(roles) == 0 {
+ t.Fatal("store unusable after a conflicting migration: no built-in roles")
}
+ _ = manager.Close()
reopened, err := NewSQLiteManager(SQLiteManagerConfig{DataDir: tmpDir})
if err != nil {