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:
1 parent
369e741df1
commit
da01f2cbe1
28 files changed
+625
-116
No files matched your search
@@ -7,6 +7,7 @@ package postgresdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
@@ -329,6 +330,32 @@ func (q *Queries) LockPolicyWrite(ctx context.Context, key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const pruneDenials = `-- name: PruneDenials :execrows
|
||||
DELETE FROM access_denials
|
||||
WHERE id IN (
|
||||
SELECT id FROM access_denials
|
||||
WHERE created_at < $1::timestamptz
|
||||
ORDER BY created_at
|
||||
LIMIT $2::bigint
|
||||
)
|
||||
`
|
||||
|
||||
type PruneDenialsParams struct {
|
||||
Cutoff time.Time
|
||||
Batch int64
|
||||
}
|
||||
|
||||
// The retention sweep's delete: every denial record created before the
|
||||
// cutoff, oldest first in bounded batches so one sweep does not own the
|
||||
// table for an unbounded time.
|
||||
func (q *Queries) PruneDenials(ctx context.Context, arg PruneDenialsParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, pruneDenials, arg.Cutoff, arg.Batch)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const recordDenial = `-- name: RecordDenial :exec
|
||||
INSERT INTO access_denials (org_id, principal, action, resource_kind, resource_id, level, policies)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
|
||||
Reference in new issue
Block a user