-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Unable to insert into table using a write-only role #399
Comments
You're hitting a bug actually. I suspect this is happening because the generated SQL has a |
@begriffs It can't be a bug in postgrest, if the db is returning the data then it means the role has access to that data. @angerman |
@ruslantalpa it's not a bug per se, just that postgrest asks for the inserted row back in order to create the Location response header. In a write-only table it's not permitted. Here's a possible solution. Just like we support the |
I will try to cook up a complete example when I'm back home. My expectation would be that, the system adapts to the role, and hence would result in the |
Alright here we go:
and the database
Create a table with a key and a
Add permissions (
Ensure that the permissions work
So far so good. Let's allow
Let's try PostgREST
And try to POST data.
The executed query looks like this:
Edit: Formatted Statement for better readability on GitHub |
@angerman @begriffs now that i read the question again i realise my previous comment was wrong. Yes, the problem is that we are using "RETURNING *" regardless of the fact if we need the inserted result back (and in this case we don't want it back since we can't actually have it because we do not have SELECT rights). I will look at implementing this case of prefer header but i would actually call it "return=nothing", we can debate this when the PR is ready. |
@ruslantalpa May I add, that I would expect that header to be implicit if the |
That is not possible since there is no way to know (at least in the introspection we currently do) if there is a SELECT granted. I view your "requirement/suggestion" when translated into sql as something like this: |
@angerman I can understand how you'd rather not have to specify a special header to make things work on a write-only table. We might be able to modify the sql to include the SELECT has_table_privilege('myschema.mytable', 'select'); Thus we could gracefully omit the Location response header when we're unable to read the table. |
@ruslantalpa I see your point about being explicit, maybe I got a wrong impression of PostgREST initially. To me the idea that the REST interface adapts to the database kind of left me to believe that the interface should not return anything if the privilege is not given. And technically I can execute the query. Just the translation from REST to SQL, adds the select requirement. I'd likely translate it as: @begriffs if that works, that would be awesome. Yet I certainly understand @ruslantalpa concert about adding too much complexity. |
I'm not very vested in SQL, so please excuse if my suggestion makes no sense. |
@ruslantalpa let me know how I can help. |
Fix #399 insert records in tables with no SELECT privileges
Assuming I want public writability, but secured readability.
Say
running with
I would expect that
returns success instead of
What am I doing wrong?
The text was updated successfully, but these errors were encountered: