fix(state): correct audit backfill scoping and policy write races
This commit is contained in:
6 files changed
+120
-45
No files matched your search
@@ -283,6 +283,18 @@ func (q *Queries) ListDenials(ctx context.Context, arg ListDenialsParams) ([]Acc
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockPolicyWrite = `-- name: LockPolicyWrite :exec
|
||||
SELECT pg_advisory_xact_lock(hashtextextended($1::text, 0))
|
||||
`
|
||||
|
||||
// Serialises concurrent writes to one policy key. SELECT FOR UPDATE cannot
|
||||
// lock a row that does not exist yet, so without this two concurrent creates
|
||||
// both read no previous row and the second is audited as a create.
|
||||
func (q *Queries) LockPolicyWrite(ctx context.Context, key string) error {
|
||||
_, err := q.db.Exec(ctx, lockPolicyWrite, key)
|
||||
return err
|
||||
}
|
||||
|
||||
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