Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Filtering collections based on permission AND also on external search params #280

Open
henkosch opened this issue Nov 11, 2021 · 9 comments
Labels
area/perf Affects performance or scalability kind/question Clarifying a question without code changes

Comments

@henkosch
Copy link

henkosch commented Nov 11, 2021

We have started implementing a permission system using spicedb, but we are tackling with the following theoretical question. Suppose we have documents and users. The documents are organized in folders and some users have permission to view documents in some folders. The use case in question is to search for documents using a full text search or some other criteria, but taking into account that you would only need to search the ones that the user has view permissions on.

Something like:

SELECT id FROM document
WHERE document.title LIKE search
AND check(document:id#can_view@user:current)

I can imagine 2 strategies:

  1. First perform a spicedb lookup query to find all the documents that the current user has view permission on, stream all the document ids from the permission system and then filter that down more based on the other search criteria.
  2. First perform the full text search locally, then check each item one-by-one in spicedb if the user has the view permission on it or not.

Both of these seem suboptimal and could result in a very expensive operation of potentially moving the whole database between systems. Are there any guidelines, docs or cases studies that we could read? Thank you!

@josephschorr
Copy link
Member

josephschorr commented Nov 11, 2021

Hi @henkosch, your two listed options are the recommendations today: pre and post filtering.

As you mention, however, they can become quite burdensome at much larger scales or where filtering is tied to external metadata. To solve that problem, we're currently working on this proposal: #207.

In summary, it will provide an API called LookupWatch which can be used to actively monitor the changes in resources to which a subject has access, and an API called RoaringLookupResources, which will return a cached roaring bitmap representing that access. Once available, the expectation is that a caller can then retrieve the roaring bitmap from the cache, and then pass it as an additional filter to something like ElasticSearch, thereby providing the ability to do an ACL-aware filtered search.

@daniel-munch-cko
Copy link

Hi! I've stumbled upon this discussion which gauged my interest pretty quickly - ACL-aware filtered search is the biggest pain point I've seen in most permissions systems so far.

I've particularly liked the idea of the roaring bitmap - Reading up on #207 and roaring bitmaps (which made some fun weekend reads), I've got some questions to know on how you think this might work / not work.

I've also spent some time reading up on roaring bitmaps (again a fun weekend read!) and came up with the following potential obstacles - I'm curious if you've put these into consideration for the roaring bitmap support?

Thanks ahead! (And thanks as well for the fabulous work already put into SpiceDb, I've only discovered it a few days ago and it's already been a great joy working with it!)

@josephschorr
Copy link
Member

Native has been hard to find, unfortunately. There are, however, numerous plugins available, such as this one for Postgres: https://pgxn.org/dist/pg_roaringbitmap/.

I've also spent some time reading up on roaring bitmaps (again a fun weekend read!) and came up with the following potential obstacles - I'm curious if you've put these into consideration for the roaring bitmap support?

Yeah, its been a consideration as well. The idea of using the roaring bitmap at all is to provide the most efficient means of sending the full list of accessible resource IDs to the client; we've also had discussions of providing other kinds of similar caches (all built on top of the same lookup watch API), with different data types if necessary. For example, a bloom filter might be another idea, although it has its own concerns.

I decided to start with roaring bitmap on the theory that, at worst, its fairly easy to convert into other forms if necessary

@jzelinskie jzelinskie added kind/question Clarifying a question without code changes area/perf Affects performance or scalability labels Nov 18, 2021
@henkosch
Copy link
Author

henkosch commented Feb 9, 2024

@jzelinskie Regarding your answer in the LookupWatch API draf implementation PR, here is our use case described at the beginning of the thread. We are still looking for a way to filter our entities based on permissions and other search criteria at the same time. It would require us to stream permission changes to our consumer services so they can do the filtering in their own databases.

@josephschorr
Copy link
Member

https://authzed.com/blog/materialize-early-access is now available for Early Access to solve this problem for very large scales

@Krustie101
Copy link

Krustie101 commented Mar 20, 2024

https://authzed.com/blog/materialize-early-access is now available for Early Access to solve this problem for very large scales

Will this be available on prem? When will more details be made available? Not having this kind of solution available is a blocker for us even considering SpiceDB. Does this solution require us to use PostgreSQL as the datastore for the read models of our domain?

@vroldanbet
Copy link
Contributor

@Krustie101 early access is only in the dedicated offering, we will explore on-prem as part of the SpiceDB Enterprise on-prem offering after that. For now, it supports CockroachDB, and PostgreSQL is the next in line. What datastore are you using?

@Krustie101
Copy link

Krustie101 commented Mar 21, 2024

@vroldanbet Thanks for the reply. The datastore for our business domain read and write models is currently SQLServer but PostgreSQL will be our preferred datastore for our new bounded contexts. I assumed that the choice of data store for our business domain entities and read projections (we use CQRS) did not matter, but that we need to choose CockroachDB or PostgreSQL for the SpiceDB datastore.

Does this change if we want to use Authzed Materialize? If we choose PostgreSQL for our SpiceDB datastore, do we also need to choose PostgreSQL to store our business domain read projections. This would not be a blocker, but I am curious to know if and why this is the case. Has it something to do with "roaring bitmap" support in PostgreSQL?

@vroldanbet
Copy link
Contributor

I assumed that the choice of data store for our business domain entities and read projections (we use CQRS) did not matter, but that we need to choose CockroachDB or PostgreSQL for the SpiceDB datastore.

That is correct, specially with CQRS, were you will treat SpiceDB as another projection of your business data.

Does this change if we want to use Authzed Materialize? If we choose PostgreSQL for our SpiceDB datastore, do we also need to choose PostgreSQL to store our business domain read projections. This would not be a blocker, but I am curious to know if and why this is the case. Has it something to do with "roaring bitmap" support in PostgreSQL?

No. Materialize provides streaming APIs you listen to and then write back to any database you choose. We are exploring deeper integrations with various data storage engines in the future, but for now the customer is responsible to ingest the output from Materialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/perf Affects performance or scalability kind/question Clarifying a question without code changes
Projects
None yet
Development

No branches or pull requests

6 participants