Hacker News new | past | comments | ask | show | jobs | submit login

It's a nice example but when would you actually want RLS in the database? In practice you'd want to validate phone number formats etc, so between this and adding a "WHERE row_owner = X" to every query doesn't seem that different.



> so between this and adding a "WHERE row_owner = X" to every query doesn't seem that different.

The difference is you will forget to add the condition to a query at one point.


This will make it easier to replicate with say iPhone clients running Sqlite. Everyone can write to the same db, but only see their own stuff.

You could dramatically reduce SQL Injections by giving each user their own database login with limited rights. Login to web site as foo, which connects you to database as foo. With RLS you can do less damage.

Or let management connect directly to the database via Excel. Use RLS to prevent lower managers from seeing upper managers' salaries.


One example I've had in the past:

Inside governments, there are often individual pieces of data within a larger dataset that are protectively marked. For example, fake identities created by the government, identities of prominent people (like members of the Royal family) or maybe even people at high risk of identity theft like bank managers.

Your normal app just thinks the records for these people are missing or knows that they are present but can't access all of the data for them. These people have to make special arrangements to eg, apply for a driving licence.

The way it works in paper processes is that normal caseworkers will get the file and see that it's protectively marked and then hand over to a caseworker who has security clearance.

Obviously it depends on how much of your problem ___domain you're reifying in your database but it can be a nice option, particularly as part of defence-in-depth.


Whenever you have tables of data where users should only have access to certain rows and want that enforced at the DB layer rather than the app layer.

It probably only makes sense if your users also have user accounts on your postgres server.


>In practice you'd want to validate phone number formats etc

Uh huh? That's what check constraints are for.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: