diff --git a/api/openapi.yaml b/api/openapi.yaml index 6c5608c28..e8b713e9f 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -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: diff --git a/internal/platform/pg/migrations/00061_governance_rename_access_decisions.sql b/internal/platform/pg/migrations/00061_governance_rename_access_decisions.sql new file mode 100644 index 000000000..e3b8c8305 --- /dev/null +++ b/internal/platform/pg/migrations/00061_governance_rename_access_decisions.sql @@ -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; diff --git a/modules/governance/access.go b/modules/governance/access.go index ed4c84752..8c3c8341c 100644 --- a/modules/governance/access.go +++ b/modules/governance/access.go @@ -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 ( diff --git a/modules/governance/access_api.go b/modules/governance/access_api.go index 29b581450..8c1abd8d5 100644 --- a/modules/governance/access_api.go +++ b/modules/governance/access_api.go @@ -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 diff --git a/modules/governance/accounts_api.go b/modules/governance/accounts_api.go index a4a624292..378b94cab 100644 --- a/modules/governance/accounts_api.go +++ b/modules/governance/accounts_api.go @@ -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 diff --git a/modules/governance/decisions_test.go b/modules/governance/decisions_test.go index 0303898d5..1b52261e9 100644 --- a/modules/governance/decisions_test.go +++ b/modules/governance/decisions_test.go @@ -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)) diff --git a/modules/governance/enforce.go b/modules/governance/enforce.go index c00d75f15..7d4cf16b7 100644 --- a/modules/governance/enforce.go +++ b/modules/governance/enforce.go @@ -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, }) } diff --git a/modules/governance/enforce_test.go b/modules/governance/enforce_test.go index b3cf7f6f7..486bc0997 100644 --- a/modules/governance/enforce_test.go +++ b/modules/governance/enforce_test.go @@ -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{} diff --git a/modules/governance/internal/store/access.go b/modules/governance/internal/store/access.go index daf07d871..c98289df8 100644 --- a/modules/governance/internal/store/access.go +++ b/modules/governance/internal/store/access.go @@ -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() } diff --git a/modules/governance/members_api.go b/modules/governance/members_api.go index 76c6c9769..52af28d63 100644 --- a/modules/governance/members_api.go +++ b/modules/governance/members_api.go @@ -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) { diff --git a/modules/governance/members_api_test.go b/modules/governance/members_api_test.go index 4c5c37bf8..bc171d1c0 100644 --- a/modules/governance/members_api_test.go +++ b/modules/governance/members_api_test.go @@ -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) diff --git a/modules/governance/roles.go b/modules/governance/roles.go index c1f732999..320521863 100644 --- a/modules/governance/roles.go +++ b/modules/governance/roles.go @@ -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 diff --git a/modules/governance/store_access.go b/modules/governance/store_access.go index 4aa06a28c..b7f96a8bf 100644 --- a/modules/governance/store_access.go +++ b/modules/governance/store_access.go @@ -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 } } diff --git a/ui/pages/pages.json b/ui/pages/pages.json index d5ece0537..596dd7fb5 100644 --- a/ui/pages/pages.json +++ b/ui/pages/pages.json @@ -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." }, diff --git a/ui/src/audit/DenialsPage.vue b/ui/src/audit/DecisionsPage.vue similarity index 88% rename from ui/src/audit/DenialsPage.vue rename to ui/src/audit/DecisionsPage.vue index 69a5e3284..11239af01 100644 --- a/ui/src/audit/DenialsPage.vue +++ b/ui/src/audit/DecisionsPage.vue @@ -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[] = [ +const columns: DataTableColumn[] = [ { 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());
-

+

Loading decisions…

- + No decisions recorded - +