Commit Graph

10 Commits

Author SHA1 Message Date
rcourtman
d3d8fbbf88 Harden SSO principal identity and group role mapping lifecycle
Reject whitespace-padded SSO subjects and stable sso: principals during legacy migration, drop free-form OIDC name claims from legacy candidates, record original SSO provider issuers without renaming existing users on upgrade, withdraw mapped roles when the last group mapping is removed, and replace stale roles or fail closed when a mapped role does not exist.

Contract-Neutral: Security fixes tightening SSO principal derivation, legacy migration, and authoritative role replacement
2026-11-24 14:12:05 +00:00
pulse-triage[bot]
96d3508ea9 Fail closed when inherited access policy cannot be read
Preserve role and permission read failures through inherited policy evaluation instead of granting from a partial policy. Keep valid inheritance, deny precedence, configured administrator recovery and legacy manager adapters; exercise registered settings admission and unchanged saved credentials.

Contract-Neutral: Restores existing fail-closed RBAC authorization without changing routes, grants, wire schemas or existing manager interfaces.
Change-source: pulse-maintainer
2026-11-08 08:32:36 +00:00
pulse-triage[bot]
4dc3043b90 Match role-read recovery fixtures to the saved allow effect
The store normalizes an omitted permission effect to allow. Make that existing saved value explicit in the fault/recovery fixture so the exact recovered-permission comparison checks the persisted contract rather than an unsaved input. Keep the failed first assertion and all production code unchanged.

Change-source: pulse-maintainer
2026-11-08 07:12:04 +00:00
pulse-triage[bot]
aafbdf8a3d Report unavailable role reads without inventing absence
Use a separate optional error-aware role reader for the registered GET-by-ID endpoint. Distinguish missing roles from failed row or permission reads and return the existing fixed unavailable error rather than an absent or partially populated role. Keep legacy readers, tenant selection, grants and gates unchanged; cover read faults, saved/empty/missing roles and same-ID tenant isolation.

Contract-Neutral: Restore the existing distinction between unavailable RBAC storage and absent saved data on the registered role-detail read. No new route, response shape, successful payload, grant, gate, mutation, inheritance evaluation or frontend behavior is introduced.
Change-source: pulse-maintainer
2026-11-08 06:52:58 +00:00
rcourtman
c3fcddf94c sqlite: bound every store's page cache to SQLite's default
Five stores set private page caches of 16 to 64 MB per connection.
The modernc driver allocates that cache with anonymous mmap outside
the Go heap, so GC and GOMEMLIMIT never see it, and each page costs
about twice its size. Measured: reading a 107 MB database through a
64 MB cache_size added 117 MB of resident memory, against 6 MB at
SQLite's 2 MB default. On a long-running dogfood install about 165 MB
of 360 MB resident sat outside the Go heap, with a 126 MB audit
database behind a 64 MB cache (#1803).

Audit, RBAC, notification queue, unified resources and the alert
event log (writer and both readers) now take pdb.PageCachePragma.
Pages that miss it come from the kernel file cache, which the kernel
can reclaim. The audit suite, including its large legacy migration,
takes the same time as before (309 s on both trees).

pkg/db tests reject any other cache_size in production code and bound
the resident growth of a 30 MB scan. Each store's test pins its
effective value. Negative controls: restoring the audit cache fails
the source scan, and a 64 MB reader cache grows a scan by 55 MB
against a 16 MB budget. modernc sorts _pragma values before applying
them, so a second cache_size in one DSN cannot reliably override.

Related to #1803
2026-10-21 14:16:08 +01:00
rcourtman
be18f99d24 fix(rbac): make SSO user access manageable 2026-08-09 13:36:07 +01:00
rcourtman
3324ef3909 Keep admin recovery reachable when the legacy RBAC import fails
d235aab3c put MigrateFromFiles on a production path for the default org and
failed NewSQLiteManager whenever the import was rejected. That propagated to
GetManager, so every RBAC route returned 503 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 holds under the same ID, so an
ordinary upgrade could leave an operator with no route to repair it short of
hand-editing the legacy JSON.

Rejecting the import is right and stays: importLegacyRBAC is transactional
and the legacy files are left in place, so a failure leaves the database
un-migrated rather than half-migrated. Missing roles deny access rather than
granting it, which is why the store is safe to keep serving.

The store now stays live and records the failure on MigrationError. The
deliberate fail-closed behaviour of the management surface is preserved
rather than removed: the handler manager accessors surface the migration
failure as the same 503 rbac_store_unavailable as before. Recovery reaches
the provider directly, so it is exempt by construction.

The existing 503 contract test is what caught the first attempt at this,
which simply let the surface serve un-migrated data. It now additionally
asserts recovery is reachable, so the two halves are pinned together.
2026-07-24 22:56:09 +01:00
rcourtman
d235aab3cf Fix RBAC assignment migration and loading 2026-07-23 22:11:48 +01:00
rcourtman
b707512e38 Clear all errcheck and gofmt violations so make lint gates on real findings
golangci-lint run ./... failed on ~190 pre-existing errcheck violations and
5 unformatted files, burying any new regression in noise. Fix all of them:

- Test files that hand-rolled mock-mode set/restore (vmware, truenas, and
  friends) now use the canonical setMockModeForTest/testutil.SetMockMode
  helper instead of drift copies that ignored SetEnabled errors.
- internal/mock and internal/monitoring tests get package-local
  mustSetEnabled/mustSetMockEnabled/mustSetMonitorMockMode helpers that
  fail the test on toggle errors.
- pkg/auth/sqlite_manager.go, pkg/metrics/store.go, pkg/server/server.go:
  rollbacks in defers use the explicit-discard idiom, migration renames and
  rollup commits log failures, the hosted reaper goroutine logs an error
  exit, shutdown mock-disable logs failures.
- Remaining test sites check errors with t.Fatalf/t.Errorf or explicitly
  discard best-effort calls (restore-chmods, handler-closure unmarshals)
  per existing repo style.
- gofmt: internal/api/maintenance_verification.go, internal/ai/demo.go and
  three findings test files.

Only dupl findings remain (44 pre-existing production-code duplication
pairs) — those need real refactors, not mechanical fixes.

Full test suites pass for every touched package.
2026-06-09 21:42:21 +01:00
rcourtman
0ddbf37c59 feat(auth): add policy evaluator and SQLite auth manager for RBAC
- Add policy evaluator for fine-grained access control
- Implement SQLite-backed auth manager for user/role persistence
- Support role-based permissions evaluation
2026-01-12 15:20:49 +00:00