-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
Efficiently calculate list things a user can do / list of users who can do a thing #1152
Comments
This is a classic challenge in permissions systems. If I want Datasette to be able to handle thousands of tables I need a reasonable solution for it. Twitter conversation: https://twitter.com/simonw/status/1339791768842248192 |
One enormous advantage I have is that after #1150 I will have a database table full of databases and tables that I can execute queries against. This means I could calculate visible tables using SQL where clauses, which should be easily fast enough even against ten thousand plus tables. The catch is the permissions hooks. Since I haven't hit Datasette 1.0 yet maybe I should redesign those hooks to work against the new in-memory database schema stuff? |
What would Datasette's permission hooks look like if they all dealt with sets of items rather than individual items? So plugins could return a set of items that the user has permission to access, or even a WHERE clause? |
Perhaps this can be solved by keeping the existing plugin hooks and adding new, optional ones for bulk lookups. If your plugin doesn't implement the bulk lookup hooks Datasette will do an inefficient loop through everything checking permissions on each one. If you DO implement it you can speed things up dramatically. Not sure if this would solve the homepage problem though, where you might need to run 1,000 table permission checks. That's more a case where you want to think in terms of a SQL where clause. |
I want to keep the existing |
Could I solve this using a configured canned query against the |
Redefining all Datasette permissions in terms of SQL queries that return the set of databases and tables that the user is allowed to interact with does feel VERY Datasette-y. |
It's also a really good fit for the new mechanism that's coming together in #1150. |
Another permissions thought: what if ALL Datasette permissions were default-deny, and plugins could only grant permission to things, not block permission? Right now a plugin can reply If everything in Datasette was default-deny then the user could use More importantly: plugins could return SQL statements that select a list of databases/tables the user is allowed access to. These could then be combined with |
#1150 is landed now, which means there's a new, hidden |
I think the way to do this is to have a new plugin hook that returns two SQL where clauses: one returning a list of resources that the user should be able to access (the allow-list) and one returning a list of resources they are explicitly forbidden from accessing (the deny-list). Either of these can be blank. Datasette can then combine those into a full SQL query and use it to answer the question "show me a list of resources that the user is allowed to perform action X on". It can also answer the existing question, "is user X allowed to perform action Y on resource Z"? |
Another option: rethink permissions to always work in terms of where clauses users as part of a SQL query that returns the overall allowed set of databases or tables. This would require rethinking existing permissions but it might be worthwhile prior to 1.0. |
One option: keep the existing That way plugins that don't upgrade will remain secure, while plugins that DO upgrade will gain extra functionality. |
Relevant quote: https://simonwillison.net/2024/Apr/16/wkirby-on-hacker-news/
|
I think the This itself is tricky though, because right now actors are entirely decoupled - which is useful, because it means you can implement things like API tokens which act-as a specific actor ID but come with an extra set of restrictions, as seen in datasette-auth-tokens. Is it dangerously misleading to offer a page of "people who can do this thing?" which omits API tokens or actors that might come in through some other mechanism? |
This can be influenced by explorations I did for https://github.com/datasette/datasette-acl - which is also the prime example of why this stuff is important. |
Originally posted by @simonw in #1150 (comment)
UPDATE 25th April 2024: This should also cover efficient lookup of "what users are allowed to view this table / do this thing?"
The text was updated successfully, but these errors were encountered: