Back to blog
EngineeringDate unavailable· min read

When Anonymous Access Shouldn't Have Been Possible

Three tables in Sabine's core architecture—brains, memory_entity_links, and user_profiles—were accessible via anonymous Supabase client. That ended with migration 047.

SCE-859 and SCE-857 caught something that should have been impossible from day one: three of Sabine's core tables—brains, memory_entity_links, and user_profiles—were accessible via the anonymous Supabase client.

These tables hold identity, memory graph structure, and user metadata. They should only ever be touched by authenticated backend services using service_role credentials. But Supabase defaults to permissive: if you don't explicitly lock a table down, the anon key can query it.

What Changed

Migration 047 adds service_role_only RLS policies to all three tables. The policy is simple: USING (false). No SELECT, INSERT, UPDATE, or DELETE operations are allowed for the anon role. Only service_role can touch these rows.

The TDD audit added test_rls_service_role_only_migration.py with two test classes: one verifying production baseline SQL, one verifying live local_db.py bootstrap. Both confirm that anon SELECT attempts raise insufficient_privilege exceptions. The tests also check that service_role can still read and write.

Why It Matters

In practice, we never expose the anon key to end users—Sabine's frontend doesn't exist yet, and our backend services authenticate properly. But defense in depth means enforcing constraints at every layer. If a credential leaks, if a service misconfigures its client, if we accidentally use the wrong key in a script, the database should refuse the operation.

This is the Supabase tradeoff. The platform makes it trivial to ship a client-authenticated app—anon RLS policies let you build Instagram clones in an afternoon. But if your architecture is service-first, you have to explicitly lock every table that shouldn't be client-accessible. The default is permissive, not restrictive.

What's Next

This fix covers three tables. The next step is an RLS audit sweep across the entire schema: every table gets reviewed, every policy gets documented, and we formalize a default-deny posture for service-role-only tables. If a table is meant for backend services, it should say so in migration comments and RLS policies.

When we do build a client-facing layer for Sabine, we'll know exactly which tables are locked down and which ones are safe to query with anon credentials. Until then, the database enforces what the architecture diagram promises: these three tables are off-limits to anything but authenticated backend services.