Kütüphane / Güvenlik ve Uyumluluk
Güvenlik ve Uyumluluk
Supabase Postgres'e değişikliğe karşı korumalı, yalnızca eklenebilir denetim günlükleri yazın
Manuel tetikleyiciyle çalışır; her olayı Supabase audit_log tablosuna sıralı ve karma değerli bir satır olarak kaydeder, böylece değişiklikler izlenebilir kalır.
Ne yapar
## SQL (run once in the Supabase SQL Editor) sql create extension if not exists pgcrypto with schema extensions; create table public.audit_log ( seq bigint primary key, ts timestamptz not null, event_type text not null, action text not null, status text not null check (status in ('success','error','pending','rejected')), actor text, actor_type text not null check (actor_type in ('human','system','ai_agent')), reason text, workflow_id text, workflow_name text, workflow_version text, execution_id text, correlation_id text, details jsonb, payload_hash text, schema_version int not null default 1, prev_hash text not null, hash text not null ); create or replace function public.audit_hash(r public.audit_log) returns text language sql immutable set search_path = '' as $$ select encode(extensions.digest(concat_ws('|', r.prev_hash, r.seq::text, to_char(r.ts at time zone 'UTC','YYYY-MM-DD"T"HH24:MI:SS.US'), r.event_type, r.action, r.status, coalesce(r.actor,''), r.actor_type, coalesce(r.reason,''), coalesce(r.workflow_id,''), coalesce(r.workflow_name,''), coalesce(r.workflow_version,''), coalesce(r.execution_id,''), coalesce(r.correlation_id,''), coalesce(r.details::text,''), coalesce(r.payload_hash,''), r.schema_version::text), 'sha256'), 'hex'); $$; create or replace function public.audit_log_chain() returns trigger language plpgsql set search_path = '' as $$ declare last_row public.audit_log; begin perform pg_advisory_xact_lock(hashtext('audit_log_chain')); select * into last_row from public.audit_log order by seq desc limit 1; new.seq := coalesce(last_row.seq, 0) + 1; new.ts := clock_timestamp(); new.prev_hash := coalesce(last_row.hash, 'GENESIS'); new.hash := public.audit_hash(new); return new; end $$; create trigger trg_audit_chain before insert on public.audit_log for each row execute function public.audit_log_chain(); create or replace function public.audit_log_block() returns trigger language plpgsql set search_path = '' as $$ begin raise exception 'audit_log is append-only'; end $$; create trigger trg_audit_no_change before update or delete on public.audit_log for each row execute function public.audit_log_block(); create trigger trg_audit_no_truncate before truncate on public.audit_log for each statement execute function public.audit_log_block(); alter table public.audit_log enable row level security; revoke all on public.audit_log from anon, authenticated;
Adımlar
- Run demo
- Set demo configuration
- Create demo events
- Hash original payload
- Receive audit event
- Validate audit event
- Write audit event
- Check if run came from demo
- Verify hash chain
- Check if chain is intact
- Report chain intact
- Report chain broken
- Try to UPDATE a record
- Try to DELETE a record
Toplam 21 adım.
Benzer otomasyonlar
RAG ve Bilgi BankalarıSupabase vektör deposu ve Postgres hafızasıyla sohbet12 adımVeri Senkronizasyonu ve ETLSupabase Postgres kayıtlarını Gemini ile doldur6 adımVeri Senkronizasyonu ve ETLGemini ile Supabase Postgres Tablosu Kurma8 adımRAG ve Bilgi BankalarıIndex Zoom meeting recordings for Telegram Q&A with OpenAI and Supabase52 adım