feat(access): denial retention knob, State Store sweep and dashboard denials page (#1842)

Add [access].denial_retention (default 90 days, matching the audit-retention
seed) wired through config defaults and validation; the State Store sweeps
denial records older than the configured age hourly via the new
access.DenialPruner / PruneDenials store query. The dashboard gains
GET /api/access/denials (read_audit-gated, so org admins/owners see their
org's records; the store scopes by the credential's org) and an
/org/denials page backed by a Pinia store.
This commit is contained in:
sam committed 2026-10-31 14:23:31 +11:00
1 parent 369e741df1
commit da01f2cbe1
28 files changed
+625 -116

No files matched your search

+12 -3
View File
@@ -93,9 +93,7 @@ func compose(ctx context.Context, d deps) *webui.Server {
// client already carries them: withholding them would degrade two pages
// that have an owner, which is a different thing from the intake surfaces
// below.
if policies, ok := d.Store.(access.PolicyStore); ok {
srv.Policies = policies
}
wireAccessSurfaces(srv, d.Store)
wireAudit(srv, d.Store)
wireOrgSurface(srv, d.Store)
wireAlerts(srv, d.Store)
@@ -134,6 +132,17 @@ func compose(ctx context.Context, d deps) *webui.Server {
return srv
}
// wireAccessSurfaces attaches the stored policy chain and the denial-record
// list when the state client carries them.
func wireAccessSurfaces(srv *webui.Server, store storecontract.TaskStore) {
if policies, ok := store.(access.PolicyStore); ok {
srv.Policies = policies
}
if denials, ok := store.(access.DenialStore); ok {
srv.DenialLister = denials
}
}
// wireAudit attaches the State Store's org-scoped audit feed. A store that
// cannot serve it leaves the audit routes answering 503 rather than showing an
// empty timeline.
+3 -1
View File
@@ -74,10 +74,12 @@ func serviceAlert(name string) alert.Input {
}
// startSweeps starts the store's periodic work: auto-updating packages,
// checking service health and pruning alerts, and applying audit retention.
// checking service health and pruning alerts, and applying audit and denial
// retention.
func (b *server) startSweeps(ctx context.Context, deps staterpc.Deps) {
go b.autoUpdatePackages(ctx, deps.Packages)
go b.sweepAuditRetention(ctx)
go b.sweepDenials(ctx)
go b.sweepScheduleRuns(ctx, deps)
if deps.Alerts != nil {
go b.sweepAlerts(ctx, deps.Alerts)
@@ -0,0 +1,44 @@
package statestore
import (
"context"
"time"
"github.com/samcharles93/archie-core/internal/domain/access"
)
// denialSweepInterval is how often the configured denial retention is applied.
const denialSweepInterval = time.Hour
// sweepDenials deletes denial records older than the configured
// access.denial_retention until ctx ends. A non-positive retention keeps the
// records forever, so the sweep does not run at all in that case.
func (b *server) sweepDenials(ctx context.Context) {
pruner, ok := b.st.(access.DenialPruner)
if !ok {
return
}
retention := b.cfg.Access.DenialRetention.Std()
if retention <= 0 {
return
}
ticker := time.NewTicker(denialSweepInterval)
defer ticker.Stop()
for {
cutoff := time.Now().Add(-retention)
rows, err := pruner.PruneDenials(ctx, cutoff)
switch {
case err != nil:
if ctx.Err() == nil {
b.log.WarnContext(ctx, "prune access denials", "err", err)
}
case rows > 0:
b.log.InfoContext(ctx, "pruned access denials", "rows", rows, "cutoff", cutoff.UTC())
}
select {
case <-ctx.Done():
return
case <-ticker.C:
}
}
}