refactor: rename denial records to access decisions
- rename governance.access_denials table, indexes and API types via migration 00061 - expose /api/access/decisions and decisions payload; keep audit auth unchanged - rename UI store, page and route from denials to decisions
This commit is contained in:
23 files changed
+187
-172
No files matched your search
+8
-8
@@ -1917,7 +1917,7 @@ components:
|
||||
- id
|
||||
- token
|
||||
type: object
|
||||
GovernanceDenial:
|
||||
GovernanceDecisionRecord:
|
||||
additionalProperties: false
|
||||
properties:
|
||||
action:
|
||||
@@ -1958,12 +1958,12 @@ components:
|
||||
- at
|
||||
- count
|
||||
type: object
|
||||
GovernanceDenialsBody:
|
||||
GovernanceDecisionsBody:
|
||||
additionalProperties: false
|
||||
properties:
|
||||
denials:
|
||||
decisions:
|
||||
items:
|
||||
$ref: "#/components/schemas/GovernanceDenial"
|
||||
$ref: "#/components/schemas/GovernanceDecisionRecord"
|
||||
type:
|
||||
- array
|
||||
- "null"
|
||||
@@ -1971,7 +1971,7 @@ components:
|
||||
description: Whether older decisions match beyond this page
|
||||
type: boolean
|
||||
required:
|
||||
- denials
|
||||
- decisions
|
||||
- more
|
||||
type: object
|
||||
GovernanceIdentity:
|
||||
@@ -4218,9 +4218,9 @@ info:
|
||||
version: dev
|
||||
openapi: 3.1.0
|
||||
paths:
|
||||
/api/access/denials:
|
||||
/api/access/decisions:
|
||||
get:
|
||||
operationId: list-access-denials
|
||||
operationId: list-access-decisions
|
||||
parameters:
|
||||
- description: Only decisions about this identity
|
||||
explode: false
|
||||
@@ -4295,7 +4295,7 @@ paths:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/GovernanceDenialsBody"
|
||||
$ref: "#/components/schemas/GovernanceDecisionsBody"
|
||||
description: OK
|
||||
default:
|
||||
content:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
-- +goose Up
|
||||
-- The table records every authorization decision, allowed or denied, so it is
|
||||
-- named for decisions.
|
||||
ALTER TABLE governance.access_denials RENAME TO access_decisions;
|
||||
ALTER TABLE governance.access_decisions RENAME CONSTRAINT access_denials_pkey TO access_decisions_pkey;
|
||||
ALTER SEQUENCE governance.access_denials_id_seq RENAME TO access_decisions_id_seq;
|
||||
ALTER INDEX governance.idx_governance_access_denials_dedup RENAME TO idx_governance_access_decisions_dedup;
|
||||
|
||||
-- +goose Down
|
||||
ALTER INDEX governance.idx_governance_access_decisions_dedup RENAME TO idx_governance_access_denials_dedup;
|
||||
ALTER SEQUENCE governance.access_decisions_id_seq RENAME TO access_denials_id_seq;
|
||||
ALTER TABLE governance.access_decisions RENAME CONSTRAINT access_decisions_pkey TO access_denials_pkey;
|
||||
ALTER TABLE governance.access_decisions RENAME TO access_denials;
|
||||
@@ -367,10 +367,10 @@ const (
|
||||
OutcomeDenied Outcome = "denied"
|
||||
)
|
||||
|
||||
// Denial is one recorded authorization decision, allowed or denied according
|
||||
// DecisionRecord is one recorded authorization decision, allowed or denied according
|
||||
// to Outcome: the principal, action, resource and deciding policies. It never
|
||||
// holds request credentials.
|
||||
type Denial struct {
|
||||
type DecisionRecord struct {
|
||||
Principal IdentityID `json:"principal"`
|
||||
Org OrgID `json:"org"`
|
||||
Action Action `json:"action"`
|
||||
@@ -416,20 +416,20 @@ type Resetter interface {
|
||||
ResetInstancePolicies(ctx context.Context) error
|
||||
}
|
||||
|
||||
// DenialRecorder records one access refusal.
|
||||
type DenialRecorder interface {
|
||||
RecordDenial(ctx context.Context, d Denial) error
|
||||
// DecisionRecorder records one access refusal.
|
||||
type DecisionRecorder interface {
|
||||
RecordDecision(ctx context.Context, d DecisionRecord) error
|
||||
}
|
||||
|
||||
// DenialStore records and lists coalesced denial records.
|
||||
type DenialStore interface {
|
||||
DenialRecorder
|
||||
ListDenials(ctx context.Context, orgID OrgID, limit int) ([]Denial, error)
|
||||
// DecisionStore records and lists coalesced decision records.
|
||||
type DecisionStore interface {
|
||||
DecisionRecorder
|
||||
ListDecisions(ctx context.Context, orgID OrgID, limit int) ([]DecisionRecord, error)
|
||||
}
|
||||
|
||||
// DenialPruner deletes denial records older than a cutoff.
|
||||
type DenialPruner interface {
|
||||
PruneDenials(ctx context.Context, cutoff time.Time) (int64, error)
|
||||
// DecisionPruner deletes decision records older than a cutoff.
|
||||
type DecisionPruner interface {
|
||||
PruneDecisions(ctx context.Context, cutoff time.Time) (int64, error)
|
||||
}
|
||||
|
||||
type (
|
||||
|
||||
@@ -21,20 +21,20 @@ type policyAdmin interface {
|
||||
DeletePolicy(context.Context, Policy) error
|
||||
}
|
||||
|
||||
// denialSearch reads the recorded decisions.
|
||||
type denialSearch interface {
|
||||
SearchDenials(context.Context, DenialQuery) ([]Denial, error)
|
||||
// decisionSearch reads the recorded decisions.
|
||||
type decisionSearch interface {
|
||||
SearchDecisions(context.Context, DecisionQuery) ([]DecisionRecord, error)
|
||||
}
|
||||
|
||||
// accessAPI serves the access policies and the record of decisions.
|
||||
type accessAPI struct {
|
||||
policies policyAdmin
|
||||
denials denialSearch
|
||||
log *slog.Logger
|
||||
policies policyAdmin
|
||||
decisions decisionSearch
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func (m *Module) access() *accessAPI {
|
||||
return &accessAPI{policies: m, denials: m, log: m.log}
|
||||
return &accessAPI{policies: m, decisions: m, log: m.log}
|
||||
}
|
||||
|
||||
type policiesBody struct {
|
||||
@@ -50,7 +50,7 @@ type policyInput struct {
|
||||
Body Policy
|
||||
}
|
||||
|
||||
type denialsInput struct {
|
||||
type decisionsInput struct {
|
||||
Principal string `query:"principal" doc:"Only decisions about this identity"`
|
||||
Action string `query:"action" doc:"Only decisions about this action"`
|
||||
Kind string `query:"kind" doc:"Only decisions about this resource kind"`
|
||||
@@ -61,9 +61,9 @@ type denialsInput struct {
|
||||
Offset int `query:"offset" default:"0" minimum:"0" doc:"How many of the newest matching decisions to skip"`
|
||||
}
|
||||
|
||||
type denialsBody struct {
|
||||
Denials []Denial `json:"denials"`
|
||||
More bool `json:"more" doc:"Whether older decisions match beyond this page"`
|
||||
type decisionsBody struct {
|
||||
Decisions []DecisionRecord `json:"decisions"`
|
||||
More bool `json:"more" doc:"Whether older decisions match beyond this page"`
|
||||
}
|
||||
|
||||
func (m *Module) registerPolicies(api huma.API, op func(id, method, path, summary string, status int) huma.Operation) {
|
||||
@@ -73,9 +73,9 @@ func (m *Module) registerPolicies(api huma.API, op func(id, method, path, summar
|
||||
httpapi.Register(api, httpapi.Authorized(ActionManagePolicies, KindPolicy), op("delete-access-policy", http.MethodDelete, "/api/access/policies", "Delete an access policy", http.StatusNoContent), a.deletePolicy)
|
||||
}
|
||||
|
||||
func (m *Module) registerDenials(api huma.API, op func(id, method, path, summary string, status int) huma.Operation) {
|
||||
func (m *Module) registerDecisions(api huma.API, op func(id, method, path, summary string, status int) huma.Operation) {
|
||||
a := m.access()
|
||||
httpapi.Register(api, httpapi.Authorized(ActionReadAudit, KindAudit), op("list-access-denials", http.MethodGet, "/api/access/denials", "List access policy decisions", 0), a.listDenials)
|
||||
httpapi.Register(api, httpapi.Authorized(ActionReadAudit, KindAudit), op("list-access-decisions", http.MethodGet, "/api/access/decisions", "List access policy decisions", 0), a.listDecisions)
|
||||
}
|
||||
|
||||
func (a *accessAPI) listPolicies(ctx context.Context, _ *struct{}) (*httpapi.Reply[policiesBody], error) {
|
||||
@@ -144,20 +144,20 @@ func (a *accessAPI) scoped(ctx context.Context, value Policy) (Policy, error) {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (a *accessAPI) listDenials(ctx context.Context, in *denialsInput) (*httpapi.Reply[denialsBody], error) {
|
||||
func (a *accessAPI) listDecisions(ctx context.Context, in *decisionsInput) (*httpapi.Reply[decisionsBody], error) {
|
||||
p, err := caller(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
found, err := a.denials.SearchDenials(ctx, DenialQuery{
|
||||
found, err := a.decisions.SearchDecisions(ctx, DecisionQuery{
|
||||
Org: p.Org, Principal: IdentityID(in.Principal), Action: Action(in.Action), Kind: ResourceKind(in.Kind),
|
||||
Outcome: Outcome(in.Outcome), Since: in.Since, Until: in.Until, Limit: in.Limit + 1, Offset: in.Offset,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, a.failed(ctx, "read the denials", err)
|
||||
return nil, a.failed(ctx, "read the decisions", err)
|
||||
}
|
||||
more := len(found) > in.Limit
|
||||
return httpapi.OK(denialsBody{Denials: found[:min(len(found), in.Limit)], More: more}), nil
|
||||
return httpapi.OK(decisionsBody{Decisions: found[:min(len(found), in.Limit)], More: more}), nil
|
||||
}
|
||||
|
||||
// failed answers a policy failure with the status a person can act on: the
|
||||
|
||||
@@ -623,7 +623,7 @@ func (m *Module) capabilities(ctx context.Context, _ *struct{}) (*httpapi.Reply[
|
||||
// The access pages are offered to those the policy chain lets use them.
|
||||
sections["org_members"] = m.mayUse(ctx, p, ActionManageMembers, KindMember)
|
||||
sections["org_policies"] = m.mayUse(ctx, p, ActionManagePolicies, KindPolicy)
|
||||
sections["org_denials"] = m.mayUse(ctx, p, ActionReadAudit, KindAudit)
|
||||
sections["org_decisions"] = m.mayUse(ctx, p, ActionReadAudit, KindAudit)
|
||||
// Every member reads the organisation they belong to and its workspaces.
|
||||
sections["org"] = signedIn
|
||||
sections["org_workspaces"] = signedIn
|
||||
|
||||
@@ -25,7 +25,9 @@ func (f fixedAuthorizer) Authorize(context.Context, Principal, Action, Resource,
|
||||
|
||||
type brokenLog struct{}
|
||||
|
||||
func (brokenLog) RecordDenial(context.Context, Denial) error { return errors.New("database down") }
|
||||
func (brokenLog) RecordDecision(context.Context, DecisionRecord) error {
|
||||
return errors.New("database down")
|
||||
}
|
||||
|
||||
// TestEveryDecisionIsRecorded guards the audit trail: an allowed decision and a
|
||||
// refused one are each stored with the principal, action, resource and deciding
|
||||
@@ -35,23 +37,23 @@ func TestEveryDecisionIsRecorded(t *testing.T) {
|
||||
const signature = "sha256=feedface"
|
||||
quiet := slog.New(slog.DiscardHandler)
|
||||
workflow := Resource{Kind: KindWorkflow, ID: "triage", Org: DefaultOrgID}
|
||||
ask := func(ctx context.Context, d Decision, rec DenialRecorder) {
|
||||
ask := func(ctx context.Context, d Decision, rec DecisionRecorder) {
|
||||
Recording(fixedAuthorizer{d}, rec, quiet).Authorize(ctx, SharedTokenOwner(), ActionRun, workflow, AccessContext{Signature: signature})
|
||||
}
|
||||
deliver := func(ctx context.Context, d Decision, rec DenialRecorder) {
|
||||
deliver := func(ctx context.Context, d Decision, rec DecisionRecorder) {
|
||||
RecordingDelivery(fixedDelivery{d}, rec, quiet).AuthorizeDelivery(ctx, DefaultOrgID, "alerts", "203.0.113.9")
|
||||
}
|
||||
chain := Denial{Principal: SystemID, Org: DefaultOrgID, Action: ActionRun, Kind: KindWorkflow, ResourceID: "triage", Level: LevelOrg}
|
||||
delivery := Denial{Principal: SenderID, Org: DefaultOrgID, Action: ActionDeliver, Kind: KindSource, ResourceID: "alerts", Level: LevelInstance}
|
||||
with := func(d Denial, outcome Outcome, policy string) Denial {
|
||||
chain := DecisionRecord{Principal: SystemID, Org: DefaultOrgID, Action: ActionRun, Kind: KindWorkflow, ResourceID: "triage", Level: LevelOrg}
|
||||
delivery := DecisionRecord{Principal: SenderID, Org: DefaultOrgID, Action: ActionDeliver, Kind: KindSource, ResourceID: "alerts", Level: LevelInstance}
|
||||
with := func(d DecisionRecord, outcome Outcome, policy string) DecisionRecord {
|
||||
d.Outcome, d.Policies = outcome, []string{policy}
|
||||
return d
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
run func(context.Context, Decision, DenialRecorder)
|
||||
run func(context.Context, Decision, DecisionRecorder)
|
||||
in Decision
|
||||
want Denial
|
||||
want DecisionRecord
|
||||
}{
|
||||
{"an allowed request", ask, AllowedAt(LevelOrg, []string{"org-owner"}), with(chain, OutcomeAllowed, "org-owner")},
|
||||
{"a refused request", ask, DeniedAt(LevelOrg, []string{"org-viewer"}), with(chain, OutcomeDenied, "org-viewer")},
|
||||
@@ -60,7 +62,7 @@ func TestEveryDecisionIsRecorded(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
log := &denialLog{}
|
||||
log := &decisionLog{}
|
||||
tt.run(t.Context(), tt.in, log)
|
||||
if len(log.recorded) != 1 {
|
||||
t.Fatalf("records = %d, want 1", len(log.recorded))
|
||||
|
||||
@@ -55,7 +55,7 @@ func RequireWorkload(ctx context.Context, a Authorizer, action Action, r Resourc
|
||||
|
||||
type recording struct {
|
||||
Authorizer
|
||||
records DenialRecorder
|
||||
records DecisionRecorder
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
@@ -65,20 +65,20 @@ type recording struct {
|
||||
// An allowed decision whose record cannot be written is returned as
|
||||
// ErrChainUnavailable: access that leaves no trace is not granted. A refusal
|
||||
// stays a refusal when its record fails, and the failure is logged.
|
||||
func Recording(a Authorizer, records DenialRecorder, log *slog.Logger) Authorizer {
|
||||
func Recording(a Authorizer, records DecisionRecorder, log *slog.Logger) Authorizer {
|
||||
return recording{Authorizer: a, records: records, log: log}
|
||||
}
|
||||
|
||||
func (r recording) Authorize(ctx context.Context, p Principal, action Action, res Resource, c AccessContext) Decision {
|
||||
d := r.Authorizer.Authorize(ctx, p, action, res, c)
|
||||
return recordDecision(ctx, r.records, r.log, d, Denial{
|
||||
return recordDecision(ctx, r.records, r.log, d, DecisionRecord{
|
||||
Principal: p.IdentityID, Org: p.Org, Action: action, Kind: res.Kind, ResourceID: res.ID,
|
||||
})
|
||||
}
|
||||
|
||||
// recordDecision stores d as the outcome of the request described by rec and
|
||||
// returns the decision the caller may act on.
|
||||
func recordDecision(ctx context.Context, records DenialRecorder, log *slog.Logger, d Decision, rec Denial) Decision {
|
||||
func recordDecision(ctx context.Context, records DecisionRecorder, log *slog.Logger, d Decision, rec DecisionRecord) Decision {
|
||||
if errors.Is(d.Err, ErrChainUnavailable) {
|
||||
return d
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func recordDecision(ctx context.Context, records DenialRecorder, log *slog.Logge
|
||||
rec.Outcome = OutcomeAllowed
|
||||
}
|
||||
rec.Level, rec.Policies, rec.At, rec.Count = d.Level, d.Policies, time.Now(), 1
|
||||
err := records.RecordDenial(context.WithoutCancel(ctx), rec)
|
||||
err := records.RecordDecision(context.WithoutCancel(ctx), rec)
|
||||
if err == nil {
|
||||
return d
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (m *Module) Allow(ctx context.Context, action, kind string) error {
|
||||
}
|
||||
|
||||
// mayUse reports whether p's grants cover action on a kind of resource in its
|
||||
// org. It asks the chain without recording a denial, since a dashboard probing
|
||||
// org. It asks the chain without recording a decision, since a dashboard probing
|
||||
// which pages to offer has not been refused anything.
|
||||
func (m *Module) mayUse(ctx context.Context, p Principal, action Action, kind ResourceKind) bool {
|
||||
chain := m.authz()
|
||||
@@ -131,7 +131,7 @@ func (m *Module) mayUse(ctx context.Context, p Principal, action Action, kind Re
|
||||
|
||||
type recordingDelivery struct {
|
||||
DeliveryAuthorizer
|
||||
records DenialRecorder
|
||||
records DecisionRecorder
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
@@ -139,13 +139,13 @@ type recordingDelivery struct {
|
||||
// outcome, for webhook and listener intake alike. An allowed delivery whose
|
||||
// record cannot be written is returned as ErrChainUnavailable, as Recording
|
||||
// does.
|
||||
func RecordingDelivery(a DeliveryAuthorizer, records DenialRecorder, log *slog.Logger) DeliveryAuthorizer {
|
||||
func RecordingDelivery(a DeliveryAuthorizer, records DecisionRecorder, log *slog.Logger) DeliveryAuthorizer {
|
||||
return recordingDelivery{DeliveryAuthorizer: a, records: records, log: log}
|
||||
}
|
||||
|
||||
func (r recordingDelivery) AuthorizeDelivery(ctx context.Context, orgID OrgID, sourcePath, addr string) Decision {
|
||||
d := r.DeliveryAuthorizer.AuthorizeDelivery(ctx, orgID, sourcePath, addr)
|
||||
return recordDecision(ctx, r.records, r.log, d, Denial{
|
||||
return recordDecision(ctx, r.records, r.log, d, DecisionRecord{
|
||||
Principal: SenderID, Org: orgID, Action: ActionDeliver, Kind: KindSource, ResourceID: sourcePath,
|
||||
})
|
||||
}
|
||||
@@ -51,18 +51,18 @@ func TestShippedPoliciesLetTheWorkloadWork(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type denialLog struct{ recorded []Denial }
|
||||
type decisionLog struct{ recorded []DecisionRecord }
|
||||
|
||||
func (d *denialLog) RecordDenial(_ context.Context, denial Denial) error {
|
||||
d.recorded = append(d.recorded, denial)
|
||||
func (d *decisionLog) RecordDecision(_ context.Context, rec DecisionRecord) error {
|
||||
d.recorded = append(d.recorded, rec)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestEnforcementFailsClosedAndRecordsRefusals guards the single seam every
|
||||
// entry point shares: a chain that is not loaded refuses with
|
||||
// ErrChainUnavailable, as does one with no authorizer at all, a refusal is
|
||||
// recorded as a denial, and an undecidable request is not.
|
||||
func TestEnforcementFailsClosedAndRecordsRefusals(t *testing.T) {
|
||||
// ErrChainUnavailable, as does one with no authorizer at all, every allowed or
|
||||
// refused request is recorded, and an undecidable request is not.
|
||||
func TestEnforcementFailsClosedAndRecordsDecisions(t *testing.T) {
|
||||
failing := func(context.Context) (int64, error) { return 0, errors.New("database down") }
|
||||
nothing := func(context.Context) ([]Policy, error) { return nil, nil }
|
||||
pending := NewPending(failing, nothing, slog.New(slog.DiscardHandler))
|
||||
@@ -72,30 +72,30 @@ func TestEnforcementFailsClosedAndRecordsRefusals(t *testing.T) {
|
||||
resource := Resource{Kind: KindWorkflow, ID: "triage", Org: DefaultOrgID}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
authorizer Authorizer
|
||||
who Principal
|
||||
wantErr error
|
||||
wantDenials int
|
||||
wantHTTPDeny error
|
||||
name string
|
||||
authorizer Authorizer
|
||||
who Principal
|
||||
wantErr error
|
||||
wantDecisions int
|
||||
wantHTTPDeny error
|
||||
}{
|
||||
{name: "a chain that is not loaded", authorizer: pending, who: admin, wantErr: ErrChainUnavailable, wantHTTPDeny: httpapi.ErrUnavailable},
|
||||
{name: "no authorizer", authorizer: nil, who: admin, wantErr: ErrChainUnavailable, wantHTTPDeny: httpapi.ErrUnavailable},
|
||||
{name: "a refusal", authorizer: loaded, who: viewer, wantErr: ErrDenied, wantDenials: 1, wantHTTPDeny: httpapi.ErrDenied},
|
||||
{name: "a grant", authorizer: loaded, who: admin, wantDenials: 1},
|
||||
{name: "a refusal", authorizer: loaded, who: viewer, wantErr: ErrDenied, wantDecisions: 1, wantHTTPDeny: httpapi.ErrDenied},
|
||||
{name: "a grant", authorizer: loaded, who: admin, wantDecisions: 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
denials := &denialLog{}
|
||||
log := &decisionLog{}
|
||||
var a Authorizer
|
||||
if tt.authorizer != nil {
|
||||
a = Recording(tt.authorizer, denials, slog.New(slog.DiscardHandler))
|
||||
a = Recording(tt.authorizer, log, slog.New(slog.DiscardHandler))
|
||||
}
|
||||
if err := Require(t.Context(), a, tt.who, ActionRun, resource); !errors.Is(err, tt.wantErr) {
|
||||
t.Fatalf("Require = %v, want %v", err, tt.wantErr)
|
||||
}
|
||||
if len(denials.recorded) != tt.wantDenials {
|
||||
t.Fatalf("denials recorded = %d, want %d", len(denials.recorded), tt.wantDenials)
|
||||
if len(log.recorded) != tt.wantDecisions {
|
||||
t.Fatalf("decisions recorded = %d, want %d", len(log.recorded), tt.wantDecisions)
|
||||
}
|
||||
|
||||
m := &Module{}
|
||||
|
||||
@@ -57,8 +57,8 @@ type PolicyRow struct {
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
// DenialRow is a coalesced authorization decision in governance.access_denials.
|
||||
type DenialRow struct {
|
||||
// DecisionRow is a coalesced authorization decision in governance.access_decisions.
|
||||
type DecisionRow struct {
|
||||
ID int64 `db:"id"`
|
||||
OrgID string `db:"org_id"`
|
||||
Principal string `db:"principal"`
|
||||
@@ -279,36 +279,36 @@ func (s *Store) ResetInstancePolicies(ctx context.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
// RecordDenial stores or increments a per-minute coalesced access decision.
|
||||
func (s *Store) RecordDenial(ctx context.Context, d DenialRow) error {
|
||||
// RecordDecision stores or increments a per-minute coalesced access decision.
|
||||
func (s *Store) RecordDecision(ctx context.Context, d DecisionRow) error {
|
||||
policies := d.Policies
|
||||
if policies == nil {
|
||||
policies = []string{}
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx, `
|
||||
INSERT INTO governance.access_denials (org_id, principal, action, resource_kind, resource_id, outcome, level, policies)
|
||||
INSERT INTO governance.access_decisions (org_id, principal, action, resource_kind, resource_id, outcome, level, policies)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
ON CONFLICT (org_id, principal, action, resource_kind, resource_id, outcome, level, policies, minute_at)
|
||||
DO UPDATE SET count = governance.access_denials.count + 1, updated_at = now()`,
|
||||
DO UPDATE SET count = governance.access_decisions.count + 1, updated_at = now()`,
|
||||
d.OrgID, d.Principal, d.Action, d.ResourceKind, d.ResourceID, d.Outcome, d.Level, policies); err != nil {
|
||||
return fmt.Errorf("record denial: %w", err)
|
||||
return fmt.Errorf("record decision: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListDenials returns an org's most recent decisions, newest first.
|
||||
func (s *Store) ListDenials(ctx context.Context, orgID string, limit int) ([]DenialRow, error) {
|
||||
var out []DenialRow
|
||||
// ListDecisions returns an org's most recent decisions, newest first.
|
||||
func (s *Store) ListDecisions(ctx context.Context, orgID string, limit int) ([]DecisionRow, error) {
|
||||
var out []DecisionRow
|
||||
if err := s.db.SelectContext(ctx, &out, `
|
||||
SELECT id, org_id, principal, action, resource_kind, resource_id, outcome, level, policies, minute_at, count, created_at, updated_at
|
||||
FROM governance.access_denials WHERE org_id = $1 ORDER BY id DESC LIMIT $2`, orgID, limit); err != nil {
|
||||
return nil, fmt.Errorf("list denials: %w", err)
|
||||
FROM governance.access_decisions WHERE org_id = $1 ORDER BY id DESC LIMIT $2`, orgID, limit); err != nil {
|
||||
return nil, fmt.Errorf("list decisions: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DenialFilter narrows SearchDenials. A zero field matches everything.
|
||||
type DenialFilter struct {
|
||||
// DecisionFilter narrows SearchDecisions. A zero field matches everything.
|
||||
type DecisionFilter struct {
|
||||
OrgID string
|
||||
Principal string
|
||||
Action string
|
||||
@@ -319,12 +319,12 @@ type DenialFilter struct {
|
||||
Offset int
|
||||
}
|
||||
|
||||
// SearchDenials returns an org's decisions matching f, newest first.
|
||||
func (s *Store) SearchDenials(ctx context.Context, f DenialFilter) ([]DenialRow, error) {
|
||||
var out []DenialRow
|
||||
// SearchDecisions returns an org's decisions matching f, newest first.
|
||||
func (s *Store) SearchDecisions(ctx context.Context, f DecisionFilter) ([]DecisionRow, error) {
|
||||
var out []DecisionRow
|
||||
if err := s.db.SelectContext(ctx, &out, `
|
||||
SELECT id, org_id, principal, action, resource_kind, resource_id, outcome, level, policies, minute_at, count, created_at, updated_at
|
||||
FROM governance.access_denials
|
||||
FROM governance.access_decisions
|
||||
WHERE org_id = $1
|
||||
AND ($2 = '' OR principal = $2)
|
||||
AND ($3 = '' OR action = $3)
|
||||
@@ -334,7 +334,7 @@ func (s *Store) SearchDenials(ctx context.Context, f DenialFilter) ([]DenialRow,
|
||||
AND ($7::timestamptz IS NULL OR created_at < $7)
|
||||
ORDER BY id DESC LIMIT $8 OFFSET $9`,
|
||||
f.OrgID, f.Principal, f.Action, f.ResourceKind, f.Outcome, nullTime(f.Since), nullTime(f.Until), f.Limit, f.Offset); err != nil {
|
||||
return nil, fmt.Errorf("search denials: %w", err)
|
||||
return nil, fmt.Errorf("search decisions: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -346,18 +346,18 @@ func nullTime(t time.Time) *time.Time {
|
||||
return &t
|
||||
}
|
||||
|
||||
// PruneDenials deletes up to batch denial rows created before cutoff.
|
||||
func (s *Store) PruneDenials(ctx context.Context, cutoff time.Time, batch int) (int64, error) {
|
||||
// PruneDecisions deletes up to batch decision rows created before cutoff.
|
||||
func (s *Store) PruneDecisions(ctx context.Context, cutoff time.Time, batch int) (int64, error) {
|
||||
res, err := s.db.ExecContext(ctx, `
|
||||
DELETE FROM governance.access_denials
|
||||
DELETE FROM governance.access_decisions
|
||||
WHERE id IN (
|
||||
SELECT id FROM governance.access_denials
|
||||
SELECT id FROM governance.access_decisions
|
||||
WHERE created_at < $1
|
||||
ORDER BY created_at
|
||||
LIMIT $2
|
||||
)`, cutoff.UTC(), batch)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("prune denials: %w", err)
|
||||
return 0, fmt.Errorf("prune decisions: %w", err)
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (m *Module) RegisterAccess(api huma.API) {
|
||||
httpapi.Register(api, httpapi.Authorized(ActionManageMembers, KindMember), op("suspend-org-member", http.MethodPost, "/api/orgs/{id}/members/{identity}/suspend", "Suspend a member's identity", http.StatusNoContent), a.suspend)
|
||||
httpapi.Register(api, httpapi.Authorized(ActionManageMembers, KindMember), op("reactivate-org-member", http.MethodPost, "/api/orgs/{id}/members/{identity}/reactivate", "Reactivate a member's identity", http.StatusNoContent), a.reactivate)
|
||||
m.registerPolicies(api, op)
|
||||
m.registerDenials(api, op)
|
||||
m.registerDecisions(api, op)
|
||||
}
|
||||
|
||||
func (a *memberAPI) list(ctx context.Context, in *orgPath) (*httpapi.Reply[membersBody], error) {
|
||||
|
||||
@@ -105,14 +105,14 @@ func TestAccessWritesNeedTheirGrant(t *testing.T) {
|
||||
if (mutates || candidates) && action != wantAction {
|
||||
t.Errorf("%s declares %q, want %q", route.ID, action, wantAction)
|
||||
}
|
||||
if !mutates && route.Path == "/api/access/denials" && action != string(ActionReadAudit) {
|
||||
if !mutates && route.Path == "/api/access/decisions" && action != string(ActionReadAudit) {
|
||||
t.Errorf("%s declares %q, want read_audit", route.ID, action)
|
||||
}
|
||||
resource := Resource{Kind: ResourceKind(kind), Org: DefaultOrgID}
|
||||
if !engine.Authorize(t.Context(), actor("admin", RoleAdmin), Action(action), resource, AccessContext{}).Allowed {
|
||||
t.Errorf("%s: an admin is refused %s %s", route.ID, action, kind)
|
||||
}
|
||||
if mutates || candidates || route.Path == "/api/access/denials" {
|
||||
if mutates || candidates || route.Path == "/api/access/decisions" {
|
||||
for _, role := range []Role{RoleViewer, RoleDeveloper} {
|
||||
if engine.Authorize(t.Context(), actor("lowly", role), Action(action), resource, AccessContext{}).Allowed {
|
||||
t.Errorf("%s: a %s is allowed %s %s", route.ID, role, action, kind)
|
||||
|
||||
@@ -97,7 +97,7 @@ func ShippedOrgPolicies(orgID OrgID) []Policy {
|
||||
return slices.Clip(append(ShippedRolePolicies(orgID), shippedExtraPolicies(orgID)...))
|
||||
}
|
||||
|
||||
// CrossOrgForbidID is the ID reported in denial records for cross-org refusals.
|
||||
// CrossOrgForbidID is the ID reported in decision records for cross-org refusals.
|
||||
const CrossOrgForbidID = PolicyCrossOrgID
|
||||
|
||||
// CrossOrgForbidText describes the non-removable cross-org forbid enforced
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ PolicyStore = (*Module)(nil)
|
||||
_ Resetter = (*Module)(nil)
|
||||
_ DenialStore = (*Module)(nil)
|
||||
_ DenialRecorder = (*Module)(nil)
|
||||
_ DenialPruner = (*Module)(nil)
|
||||
_ PolicyStore = (*Module)(nil)
|
||||
_ Resetter = (*Module)(nil)
|
||||
_ DecisionStore = (*Module)(nil)
|
||||
_ DecisionRecorder = (*Module)(nil)
|
||||
_ DecisionPruner = (*Module)(nil)
|
||||
)
|
||||
|
||||
const (
|
||||
denialPruneBatch = 10_000
|
||||
defaultDenials = 100
|
||||
maxDenials = 10_000
|
||||
decisionPruneBatch = 10_000
|
||||
defaultDecisions = 100
|
||||
maxDecisions = 10_000
|
||||
)
|
||||
|
||||
func shippedOrgPolicyIDs() []string {
|
||||
@@ -268,15 +268,15 @@ func (m *Module) ResetInstancePolicies(ctx context.Context) error {
|
||||
return m.store.ResetInstancePolicies(ctx)
|
||||
}
|
||||
|
||||
// RecordDenial persists one coalesced access decision, allowed or denied.
|
||||
func (m *Module) RecordDenial(ctx context.Context, d Denial) error {
|
||||
// RecordDecision persists one coalesced access decision, allowed or denied.
|
||||
func (m *Module) RecordDecision(ctx context.Context, d DecisionRecord) error {
|
||||
if d.Org == "" || d.Principal == "" {
|
||||
return fmt.Errorf("%w: org and principal are required", ErrInvalidPolicy)
|
||||
}
|
||||
if d.Outcome != OutcomeAllowed && d.Outcome != OutcomeDenied {
|
||||
return fmt.Errorf("%w: unknown outcome %q", ErrInvalidPolicy, d.Outcome)
|
||||
}
|
||||
return m.store.RecordDenial(ctx, store.DenialRow{
|
||||
return m.store.RecordDecision(ctx, store.DecisionRow{
|
||||
OrgID: string(d.Org),
|
||||
Principal: string(d.Principal),
|
||||
Action: string(d.Action),
|
||||
@@ -288,13 +288,13 @@ func (m *Module) RecordDenial(ctx context.Context, d Denial) error {
|
||||
})
|
||||
}
|
||||
|
||||
// ListDenials returns an org's most recent decisions, newest first.
|
||||
func (m *Module) ListDenials(ctx context.Context, orgID OrgID, limit int) ([]Denial, error) {
|
||||
return m.SearchDenials(ctx, DenialQuery{Org: orgID, Limit: limit})
|
||||
// ListDecisions returns an org's most recent decisions, newest first.
|
||||
func (m *Module) ListDecisions(ctx context.Context, orgID OrgID, limit int) ([]DecisionRecord, error) {
|
||||
return m.SearchDecisions(ctx, DecisionQuery{Org: orgID, Limit: limit})
|
||||
}
|
||||
|
||||
// DenialQuery narrows SearchDenials. A zero field matches everything.
|
||||
type DenialQuery struct {
|
||||
// DecisionQuery narrows SearchDecisions. A zero field matches everything.
|
||||
type DecisionQuery struct {
|
||||
Org OrgID
|
||||
Principal IdentityID
|
||||
Action Action
|
||||
@@ -306,28 +306,28 @@ type DenialQuery struct {
|
||||
Offset int
|
||||
}
|
||||
|
||||
// SearchDenials returns the decisions matching q, newest first, at most
|
||||
// maxDenials per call.
|
||||
func (m *Module) SearchDenials(ctx context.Context, q DenialQuery) ([]Denial, error) {
|
||||
// SearchDecisions returns the decisions matching q, newest first, at most
|
||||
// maxDecisions per call.
|
||||
func (m *Module) SearchDecisions(ctx context.Context, q DecisionQuery) ([]DecisionRecord, error) {
|
||||
if q.Limit <= 0 {
|
||||
q.Limit = defaultDenials
|
||||
} else if q.Limit > maxDenials {
|
||||
q.Limit = maxDenials
|
||||
q.Limit = defaultDecisions
|
||||
} else if q.Limit > maxDecisions {
|
||||
q.Limit = maxDecisions
|
||||
}
|
||||
rows, err := m.store.SearchDenials(ctx, store.DenialFilter{
|
||||
rows, err := m.store.SearchDecisions(ctx, store.DecisionFilter{
|
||||
OrgID: string(q.Org), Principal: string(q.Principal), Action: string(q.Action),
|
||||
ResourceKind: string(q.Kind), Outcome: string(q.Outcome), Since: q.Since, Until: q.Until, Limit: q.Limit, Offset: max(q.Offset, 0),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return denialsFromRows(rows), nil
|
||||
return decisionsFromRows(rows), nil
|
||||
}
|
||||
|
||||
func denialsFromRows(rows []store.DenialRow) []Denial {
|
||||
out := make([]Denial, 0, len(rows))
|
||||
func decisionsFromRows(rows []store.DecisionRow) []DecisionRecord {
|
||||
out := make([]DecisionRecord, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
out = append(out, Denial{
|
||||
out = append(out, DecisionRecord{
|
||||
Principal: IdentityID(r.Principal),
|
||||
Org: OrgID(r.OrgID),
|
||||
Action: Action(r.Action),
|
||||
@@ -343,16 +343,16 @@ func denialsFromRows(rows []store.DenialRow) []Denial {
|
||||
return out
|
||||
}
|
||||
|
||||
// PruneDenials deletes denial rows older than cutoff in bounded batches.
|
||||
func (m *Module) PruneDenials(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
// PruneDecisions deletes decision rows older than cutoff in bounded batches.
|
||||
func (m *Module) PruneDecisions(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
var total int64
|
||||
for {
|
||||
removed, err := m.store.PruneDenials(ctx, cutoff, denialPruneBatch)
|
||||
removed, err := m.store.PruneDecisions(ctx, cutoff, decisionPruneBatch)
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
total += removed
|
||||
if removed < denialPruneBatch {
|
||||
if removed < decisionPruneBatch {
|
||||
return total, nil
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@
|
||||
"description": "Settings, access, identity and runtime events."
|
||||
},
|
||||
{
|
||||
"path": "/org/denials",
|
||||
"path": "/org/decisions",
|
||||
"label": "Access decisions",
|
||||
"description": "Access requests the policy chain allowed or refused, newest first."
|
||||
},
|
||||
|
||||
@@ -13,13 +13,13 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { useDenialsStore } from "@/stores/denials";
|
||||
import { denialResource, type Denial } from "./denials";
|
||||
import { useDecisionsStore } from "@/stores/decisions";
|
||||
import { decisionResource, type AccessDecision } from "./decisions";
|
||||
|
||||
const store = useDenialsStore();
|
||||
const { denials, filters, more, loading, error } = storeToRefs(store);
|
||||
const store = useDecisionsStore();
|
||||
const { decisions, filters, more, loading, error } = storeToRefs(store);
|
||||
|
||||
const columns: DataTableColumn<Denial>[] = [
|
||||
const columns: DataTableColumn<AccessDecision>[] = [
|
||||
{ id: "at", label: "When", fixed: true, width: "9rem", sort: (d) => d.at },
|
||||
{ id: "principal", label: "Principal", fixed: true, width: "auto", class: "whitespace-normal" },
|
||||
{ id: "outcome", label: "Outcome", width: "7rem" },
|
||||
@@ -60,18 +60,18 @@ onMounted(() => void store.load());
|
||||
<Button type="button" variant="outline" size="sm" :disabled="loading" @click="store.clear()">Clear</Button>
|
||||
</form>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p v-if="loading && !denials.length" class="flex items-center gap-2 text-label text-fg-muted">
|
||||
<p v-if="loading && !decisions.length" class="flex items-center gap-2 text-label text-fg-muted">
|
||||
<Spinner />Loading decisions…
|
||||
</p>
|
||||
<Empty v-else-if="!error && !denials.length">
|
||||
<Empty v-else-if="!error && !decisions.length">
|
||||
<EmptyHeader><EmptyTitle>No decisions recorded</EmptyTitle></EmptyHeader>
|
||||
</Empty>
|
||||
<DataTable
|
||||
v-else-if="!error || denials.length"
|
||||
v-else-if="!error || decisions.length"
|
||||
:columns="columns"
|
||||
:rows="denials"
|
||||
:rows="decisions"
|
||||
:row-key="(d) => `${d.at}:${d.principal}:${d.action}:${d.kind}:${d.resource}:${d.outcome}`"
|
||||
storage-key="denials"
|
||||
storage-key="decisions"
|
||||
>
|
||||
<template #empty>
|
||||
<Empty><EmptyHeader><EmptyTitle>No decisions recorded</EmptyTitle></EmptyHeader></Empty>
|
||||
@@ -82,7 +82,7 @@ onMounted(() => void store.load());
|
||||
</template>
|
||||
<template #cell-action="{ row }"><span class="font-mono text-caption">{{ row.action }}</span></template>
|
||||
<template #cell-principal="{ row }"><span class="font-mono text-caption">{{ row.principal }}</span></template>
|
||||
<template #cell-resource="{ row }"><span class="font-mono text-caption">{{ denialResource(row) }}</span></template>
|
||||
<template #cell-resource="{ row }"><span class="font-mono text-caption">{{ decisionResource(row) }}</span></template>
|
||||
<template #cell-level="{ row }"><Badge variant="idle">{{ row.level }}</Badge></template>
|
||||
<template #cell-policies="{ row }">
|
||||
<span class="font-mono text-caption text-fg-muted">{{ row.policies.join(", ") || "–" }}</span>
|
||||
@@ -1,6 +1,6 @@
|
||||
/** Access decisions as the dashboard reads them from /api/access/denials:
|
||||
/** Access decisions as the dashboard reads them from /api/access/decisions:
|
||||
* one recorded outcome, coalesced per minute into a count. */
|
||||
export interface Denial {
|
||||
export interface AccessDecision {
|
||||
principal: string;
|
||||
org: string;
|
||||
action: string;
|
||||
@@ -13,13 +13,13 @@ export interface Denial {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface DenialsResponse {
|
||||
denials: Denial[];
|
||||
export interface AccessDecisionsResponse {
|
||||
decisions: AccessDecision[];
|
||||
/** Whether older decisions match beyond this page. */
|
||||
more: boolean;
|
||||
}
|
||||
|
||||
/** The resource column: the kind and id together, or just the kind. */
|
||||
export function denialResource(d: Denial): string {
|
||||
export function decisionResource(d: AccessDecision): string {
|
||||
return d.resource ? `${d.kind}/${d.resource}` : d.kind;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export const useAuditStore = defineStore("audit", () => {
|
||||
|
||||
/** Merges a fresh page one into the loaded feed: an id already on screen
|
||||
* keeps its place, replaced when the server now sends different content (a
|
||||
* coalesced denial count, say). An unseen id is returned so the page can
|
||||
* coalesced access decision count, for example). An unseen id is returned so the page can
|
||||
* prepend it or hold it behind the new-events button. */
|
||||
function mergePageOne(incoming: AuditRecord[]): AuditRecord[] {
|
||||
const positions = new Map(records.value.map((record, index) => [recordKey(record), index]));
|
||||
|
||||
@@ -91,7 +91,7 @@ export function suggestionsForRoute(route: SuggestionRoute): string[] {
|
||||
return [
|
||||
"Which model is Archie using right now?",
|
||||
"How do I connect a new repository?",
|
||||
"Show recent access denials",
|
||||
"Show recent access decisions",
|
||||
];
|
||||
default:
|
||||
return [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const stores = {
|
||||
denials: {
|
||||
decisions: {
|
||||
unavailable: "Decision records are unavailable.",
|
||||
},
|
||||
settings: {
|
||||
|
||||
+2
-2
@@ -360,8 +360,8 @@ export const api = {
|
||||
systemHealth: () => request<SystemHealth>("/api/system/health"),
|
||||
bootstrap: () => request<Bootstrap>("/api/system/bootstrap"),
|
||||
policies: <T = unknown>() => request<T>("/api/access/policies"),
|
||||
denials: <T = unknown>(params: QueryParams = {}) =>
|
||||
request<T>("/api/access/denials" + qs(params)),
|
||||
decisions: <T = unknown>(params: QueryParams = {}) =>
|
||||
request<T>("/api/access/decisions" + qs(params)),
|
||||
putPolicy: (policy: unknown) =>
|
||||
request<{ version: number }>("/api/access/policies", { method: "PUT", body: policy }),
|
||||
deletePolicy: (policy: unknown) =>
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ const orgSpecs: NavSpec[] = [
|
||||
sections: [
|
||||
{
|
||||
label: "People & access",
|
||||
paths: ["/org/members", "/org/approvals", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||
paths: ["/org/members", "/org/approvals", "/org/agents", "/org/workspaces", "/org/policies", "/org/decisions", "/org/audit"],
|
||||
},
|
||||
{
|
||||
label: "Agents",
|
||||
|
||||
@@ -8,7 +8,7 @@ const MemoryPage = () => import("@/memory/MemoryPage.vue");
|
||||
const SharedMemoryPage = () => import("@/memory/SharedMemoryPage.vue");
|
||||
const LogsPage = () => import("@/logs/LogsPage.vue");
|
||||
const AuditPage = () => import("@/audit/AuditPage.vue");
|
||||
const DenialsPage = () => import("@/audit/DenialsPage.vue");
|
||||
const DecisionsPage = () => import("@/audit/DecisionsPage.vue");
|
||||
const OrgShell = () => import("@/org/OrgShell.vue");
|
||||
const OrgOverviewPage = () => import("@/org/OrgOverviewPage.vue");
|
||||
const OrgMembersPage = () => import("@/org/OrgMembersPage.vue");
|
||||
@@ -280,11 +280,11 @@ export const routes: RouteRecordRaw[] = [
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "denials",
|
||||
name: "org-denials",
|
||||
component: DenialsPage,
|
||||
path: "decisions",
|
||||
name: "org-decisions",
|
||||
component: DecisionsPage,
|
||||
meta: {
|
||||
section: "org_denials",
|
||||
section: "org_decisions",
|
||||
label: "Access decisions",
|
||||
navPath: "/org",
|
||||
description: "Access requests the policy chain allowed or refused, newest first.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { reactive, ref } from "vue";
|
||||
|
||||
import type { Denial, DenialsResponse } from "@/audit/denials";
|
||||
import type { AccessDecision, AccessDecisionsResponse } from "@/audit/decisions";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ApiError, api, describeError } from "@/lib/api";
|
||||
|
||||
@@ -9,7 +9,7 @@ const PAGE = 100;
|
||||
|
||||
/** What narrows the list; an empty field matches everything. `since` and
|
||||
* `until` are datetime-local values, read in the browser's time zone. */
|
||||
export interface DenialFilters {
|
||||
export interface DecisionFilters {
|
||||
principal: string;
|
||||
action: string;
|
||||
kind: string;
|
||||
@@ -19,14 +19,14 @@ export interface DenialFilters {
|
||||
until: string;
|
||||
}
|
||||
|
||||
const noFilters = (): DenialFilters => ({ principal: "", action: "", kind: "", outcome: "any", since: "", until: "" });
|
||||
const noFilters = (): DecisionFilters => ({ principal: "", action: "", kind: "", outcome: "any", since: "", until: "" });
|
||||
|
||||
const toISO = (local: string): string => (local ? new Date(local).toISOString() : "");
|
||||
|
||||
/** The caller's org's recorded access decisions, newest first, a page at a time. */
|
||||
export const useDenialsStore = defineStore("denials", () => {
|
||||
const denials = ref<Denial[]>([]);
|
||||
const filters = reactive<DenialFilters>(noFilters());
|
||||
export const useDecisionsStore = defineStore("decisions", () => {
|
||||
const decisions = ref<AccessDecision[]>([]);
|
||||
const filters = reactive<DecisionFilters>(noFilters());
|
||||
const more = ref(false);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
@@ -38,7 +38,7 @@ export const useDenialsStore = defineStore("denials", () => {
|
||||
const mine = ++attempt;
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await api.denials<DenialsResponse>({
|
||||
const response = await api.decisions<AccessDecisionsResponse>({
|
||||
principal: filters.principal.trim(),
|
||||
action: filters.action.trim(),
|
||||
kind: filters.kind.trim(),
|
||||
@@ -46,16 +46,16 @@ export const useDenialsStore = defineStore("denials", () => {
|
||||
since: toISO(filters.since),
|
||||
until: toISO(filters.until),
|
||||
limit: PAGE,
|
||||
offset: next ? denials.value.length : 0,
|
||||
offset: next ? decisions.value.length : 0,
|
||||
});
|
||||
if (mine !== attempt) return;
|
||||
denials.value = next ? [...denials.value, ...(response.denials ?? [])] : (response.denials ?? []);
|
||||
decisions.value = next ? [...decisions.value, ...(response.decisions ?? [])] : (response.decisions ?? []);
|
||||
more.value = response.more;
|
||||
error.value = "";
|
||||
} catch (err) {
|
||||
if (mine !== attempt) return;
|
||||
error.value = err instanceof ApiError && err.status === 503
|
||||
? errors.stores.denials.unavailable
|
||||
? errors.stores.decisions.unavailable
|
||||
: describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
if (mine === attempt) loading.value = false;
|
||||
@@ -67,5 +67,5 @@ export const useDenialsStore = defineStore("denials", () => {
|
||||
void load();
|
||||
}
|
||||
|
||||
return { denials, filters, more, loading, error, load, clear };
|
||||
return { decisions, filters, more, loading, error, load, clear };
|
||||
});
|
||||
Reference in new issue
Block a user