feat: record access decisions, not just denials

- add an outcome column and migration so allowed and denied decisions share one audit trail
- fail closed when an allowed decision cannot be recorded
- expose outcome filtering in the API and dashboard

Route chat through the recording authorizer so its decisions are audited too.
This commit is contained in:
sam committed 2026-11-23 01:00:46 +11:00
1 parent e1ada94d78
commit 60d9b6b7aa
17 files changed
+291 -98

No files matched your search

+3 -3
View File
@@ -59,8 +59,8 @@ func (o *operations) Start(ctx context.Context) error {
if err != nil {
return err
}
// Every entry point asks the same chain, and each refusal is stored as a
// denial.
// Every entry point uses the same chain, and every decision, allowed or
// refused, is stored.
checked := governance.Recording(access, o.settings, o.log.With("module", "governance"))
// A workflow takes its context from the run handle, as a handler takes it
// from the request.
@@ -96,7 +96,7 @@ func (o *operations) Start(ctx context.Context) error {
o.hear.UseDeliveryPolicy(governance.RecordingDelivery(access, o.settings, o.log.With("module", "governance")))
o.hear.UseTrustedProxies(o.settings.TrustedProxies)
o.talk.Use(chat.Deps{
People: o.settings, Access: access, Settings: o.settings, Toolbox: o.conns, Judge: o.judge,
People: o.settings, Access: checked, Settings: o.settings, Toolbox: o.conns, Judge: o.judge,
Approver: o.allow, Memory: o.remember, Runs: o.engine, Notifier: o.tell,
})
for _, loop := range []func(context.Context){o.engine.Work, o.hear.Work, o.tell.Work, o.talk.Work, o.retryDeletionRecord} {
@@ -0,0 +1,16 @@
-- +goose Up
-- The table that held refusals now holds every authorization decision. A row
-- records one outcome, coalesced per minute with identical requests, so rows
-- that exist already are refusals.
ALTER TABLE governance.access_denials
ADD COLUMN outcome text NOT NULL DEFAULT 'denied' CHECK (outcome IN ('allowed', 'denied'));
DROP INDEX governance.idx_governance_access_denials_dedup;
CREATE UNIQUE INDEX idx_governance_access_denials_dedup
ON governance.access_denials (org_id, principal, action, resource_kind, resource_id, outcome, level, policies, minute_at);
-- +goose Down
DELETE FROM governance.access_denials WHERE outcome = 'allowed';
DROP INDEX governance.idx_governance_access_denials_dedup;
CREATE UNIQUE INDEX idx_governance_access_denials_dedup
ON governance.access_denials (org_id, principal, action, resource_kind, resource_id, level, policies, minute_at);
ALTER TABLE governance.access_denials DROP COLUMN outcome;