Audit Append Enforcement
Component Detail
Infrastructure
low complexity
backend
0
Dependencies
2
Dependents
2
Entities
0
Integrations
Description
PostgreSQL-level safeguards that make the audit_logs table truly append-only regardless of application code. Consists of two mechanisms: (1) a BEFORE UPDATE OR DELETE trigger that raises an exception for any attempted mutation, and (2) a dedicated audit_log_writer PostgreSQL role that is GRANT INSERT only - the application connects with this role for all audit writes, making UPDATE/DELETE impossible from the application layer.
audit-append-enforcement
Responsibilities
- Install BEFORE UPDATE OR DELETE trigger raising exception on any mutation attempt
- Define and grant audit_log_writer role with INSERT-only privileges on audit_logs
- Include trigger and role DDL in the database migration files
- Provide test assertion that UPDATE and DELETE attempts throw expected exceptions
Interfaces
CREATE TRIGGER prevent_audit_mutation BEFORE UPDATE OR DELETE ON audit_logs
CREATE ROLE audit_log_writer; GRANT INSERT ON audit_logs TO audit_log_writer
Relationships
Related Data Entities (2)
Data entities managed by this component