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.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
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:
|
|
}
|
|
}
|
|
}
|