Is there a way to only allow selecting rows with k...
# help
d
Is there a way to only allow selecting rows with known id's using RLS? I'd like my database to be public but only for accessing records with known ID's. Something where a RLS policy would require a where clause on the id column.
n
Hello @Dexter! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
🆕 Restricting Select with a known ID using RLS
s
Yeah you can do that, remember you are just writing SQL inside of a RLS policy.
n
Restricting Select with a known ID using RLS
d
How can a policy check if a where clause is used?
And nice to see you here @silentworks 🙂
s
It can't check if a where clause is being used, what you can do is create an allowlist with ids that can be accessed from any query.
Unless I'm not understanding what you are trying to accomplish well enough?
Good to see a fellow Svelte user over here too.
d
Ah no. id want to have users access all, as long as they know the ID. so I'd have clients store the id somewhere. but not go through the hassle of setting up user accounts.
s
I'm still not clear on what you are trying to accomplish
d
I want not the whole set of data to be disoverable.
So users should only be allowed to query by id, not get all the records.
So I can keep using the public client.
I can also make a private endpoint. prolly be doing that now.
l
I guess you can create a Database function with the ID as parameter and then return the row
Be sure to use non guessable ids though, else this is vulnerable to resource enumeration.
d
i've been thinking about it. but it doesn't allow for subscribing to those records.
l
so you also want to use realtime?
d
ye
so it seems that RLS is designed for use with auth.user() in the constraints. instead of only selecting rows with specific uuid's
l
RLS is a generic postgres features.
can you elaborate on the broader problem you are trying to solve?
s
It can be used for almost any sql queries, but you are asking for it to restrict a feature or SQL which it cannot do as it has no way of knowing if you are querying for one or for all records.