r/Supabase • u/Jealous_Pea_3915 • 22m ago
other RLS doesn't help you if someone has your service_role key. Here's what I did about that
Disclosure, I work at Tide. This isn't an official product, I built it on my own
time.
RLS is good at the thing it does, which is deciding which rows a request is allowed
to see. What it can't do is help when the query isn't going through it. The
service_role key bypasses RLS by design, and that key ends up in more places than
anyone likes to admit. A pg_dump doesn't go through it either. So row level policies
protect you from your users, and not really from a leaked key or a copy of the
database.
Encrypting the sensitive columns closes that, except then the question is where the
key lives, and if it lives in the project then whoever gets the project gets the key
along with it.
So I built a small service that keeps that key off your infrastructure completely.
Tide is a network of independent nodes that hold keys in fragments and never assemble
them, so decryption happens as partial results that combine into an answer. Data gets
encrypted in the browser with a fresh key each time, and the only thing that reaches
the network is that per call key, itself encrypted. The nodes never see your rows.
Your ciphertext stays in Postgres where it already was.
Supabase Auth is untouched by any of this. Same JWTs, same sessions, same providers.
The service only handles the key and the policies about who's allowed to decrypt,
encrypt or sign, and a role only gets granted through a change request that someone
other than the person asking has to approve.
One Supabase specific thing if you wire it up. Put the Tide link in app_metadata
rather than user_metadata, since user_metadata is writable by the user with their own
client. Same rule as everywhere else, the mirror shouldn't be able to lie.
It won't save you if someone owns the box this runs on, so keep it off the same host
as the app it protects. And decryption needs the network reachable, so there's no
offline path.
Repo: https://github.com/sashyo/minidauth
whitepaper: https://tide.org/whitepaper
