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

+28 -3
View File
@@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"strings"
"time"
"github.com/jackc/pgx/v5"
@@ -22,9 +23,10 @@ import (
)
var (
_ access.PolicyStore = (*Store)(nil)
_ access.Resetter = (*Store)(nil)
_ access.DenialStore = (*Store)(nil)
_ access.PolicyStore = (*Store)(nil)
_ access.Resetter = (*Store)(nil)
_ access.DenialStore = (*Store)(nil)
_ access.DenialPruner = (*Store)(nil)
)
// shippedOrgPolicyIDs lists an org's shipped role policy IDs: the seed's
@@ -403,3 +405,26 @@ func (s *Store) ListDenials(ctx context.Context, orgID org.OrgID, limit int) ([]
}
return out, nil
}
// denialPruneBatch is one delete's bound, so a single sweep does not own the
// table for an unbounded time.
const denialPruneBatch = 10_000
// PruneDenials deletes the denial records created before cutoff in bounded
// batches and returns how many rows it removed. The State Store's retention
// sweep is the only caller: the configured retention sets the cutoff.
func (s *Store) PruneDenials(ctx context.Context, cutoff time.Time) (int64, error) {
var total int64
for {
removed, err := s.queries().PruneDenials(ctx, postgresdb.PruneDenialsParams{
Cutoff: cutoff.UTC(), Batch: denialPruneBatch,
})
if err != nil {
return total, err
}
total += removed
if removed < denialPruneBatch {
return total, nil
}
}
}