security: public Deploy härten (Reverse-Proxy, GoTrue-Rate-Limit, RLS-Revoke)

Für die öffentlich erreichbare Instanz (dev.openbureau.ch):

1. Reverse-Proxy nur /auth/* durchreichen — /rest, /storage, /realtime raus.
   PostgREST /rest/v1/ gab die komplette DB-Schema-Beschreibung (OpenAPI) preis;
   der Browser nutzt Supabase nur fürs Login, Daten laufen über /api/*.
   (Caddy-Block in create-openbureau-lxc.sh + proxmox/README.md angepasst.)
2. GoTrue GOTRUE_RATE_LIMIT_TOKEN_REFRESH=100 — bremst Brute-Force aufs /token,
   das public direkt gegen GoTrue läuft (nicht übers Node-Rate-Limit).
3. db/schema.sql: revoke all from anon/authenticated auf posts/comments/forums/
   threads; grants nur noch service_role. RLS bleibt so auch bei künftigen
   Policies dicht (Defense-in-Depth statt "RLS ohne Policy").

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 05:11:19 +02:00
parent 50cec7a965
commit 9163f5c90d
5 changed files with 34 additions and 7 deletions
+11 -3
View File
@@ -31,6 +31,7 @@ create index if not exists posts_section_idx on public.posts (section);
-- RLS aktivieren; die api nutzt den Service-Key (umgeht RLS). Wenn das
-- Frontend später direkt liest, hier gezielte Policies ergänzen.
alter table public.posts enable row level security;
revoke all on public.posts from anon, authenticated;
-- ── Dialog / Diskussionen ───────────────────────────────────────────────
-- Thread = Pfad des Beitrags (z.B. /library/software/stack/). Flache Wortmeldungen
@@ -50,7 +51,12 @@ create table if not exists public.comments (
alter table public.comments add column if not exists author_role text;
create index if not exists comments_thread_idx on public.comments (thread, created_at);
alter table public.comments enable row level security;
grant all on public.comments to anon, authenticated, service_role;
-- Nur die Node-API (service_role) greift auf die Tabellen zu; der Browser geht
-- ausschliesslich über /api/*. anon/authenticated bekommen KEINE Tabellenrechte,
-- damit das öffentlich erreichbare /rest/v1 auch bei künftigen RLS-Policies dicht
-- bleibt (Defense-in-Depth, nicht nur "RLS ohne Policy").
grant all on public.comments to service_role;
revoke all on public.comments from anon, authenticated;
-- Aggregat je Thread (Anzahl + letzte Aktivität). Spart der API den Full-Table-
-- Scan + JS-Aggregation bei jedem Forum-Aufruf; Postgres zählt direkt.
@@ -75,7 +81,8 @@ create table if not exists public.forums (
created_at timestamptz not null default now()
);
alter table public.forums enable row level security;
grant all on public.forums to anon, authenticated, service_role;
grant all on public.forums to service_role;
revoke all on public.forums from anon, authenticated;
-- ── Threads (Diskussionen) ──────────────────────────────────────────────
-- key = stabiler Bezeichner, den comments.thread referenziert:
@@ -96,7 +103,8 @@ create table if not exists public.threads (
);
create index if not exists threads_forum_idx on public.threads (forum_id);
alter table public.threads enable row level security;
grant all on public.threads to anon, authenticated, service_role;
grant all on public.threads to service_role;
revoke all on public.threads from anon, authenticated;
-- Seed-Kategorien (idempotent; im Admin umbenenn-/erweiterbar).
insert into public.forums (slug, name, sort, kind) values