Thread: Clarity Bug for Schema Permissions, Potential Vulnerability?

Clarity Bug for Schema Permissions, Potential Vulnerability?

From
Justis Lincoln Mackaoui
Date:

Hi there,

 

There’s an issue with the consistency of “ERROR: permission denied” which is a small gotcha for new Postgres users like myself. It may be desirable behavior but please bear with me.

 

Here’s a scenario displaying the current behavior in PostgreSQL 11.5:

  1. The database has two schemas, “public” and “test”.
  2. The database has two users, “admin” and “test_user”.
  3. Admin user runs a variation of “CREATE SCHEMA test_schema”
  4. Admin user runs “CREATE TABLE test_schema.test_table”

 

  1. Test_user runs “SELECT * FROM test_schema.test_table”, receives “ERROR: permission denied” (as expected).
  2. Admin runs “GRANT ALL PRIVILEGES ON test_schema.test_table TO test_user”, receives “Query returned successfully”
  3. Test user runs “SELECT * FROM test_schema.test_table”, receives “ERROR: permission denied”

---

If you now check the permissions on “test_table”, you’ll see that it correctly granted all privileges to “test_user”, despite throwing errors when “test_user” attempts to access it; this is the source of confusion. Experienced users will know that you must FIRST run “GRANT USAGE ON SCHEMA test_schema TO test_user”, so that the user has access to the schema.

 

My argument is that step #6, the granting of privileges on the table, should return an “ERROR: permission denied” because the “test_user” should not know at all about the objects contained within “test_schema”. This would prevent the confusing state of contradictory permissions and access-errors.

---

 

This problem with contradictory permissions and access-errors is relatively minor and can be fixed by the user with a little playing around, however I’m curious if it might expose any real vulnerabilities. It seems as though the driver only validates the permissions of the logged-in user “admin”, who does have access to the schema “test_schema” as well as “test_table”, and not the permissions of “test_user”.

 

My suggestion is that the separation of permissions between Database/Schema/Table/User be respected equally by the driver, in the sense that both the logged-in user and any user-object pair in the expression have the same permission validation ran against them.

 

I’m no security specialist or expert on PostgreSQL’s source code, but I worry that someone who IS might come up with a strategy to exploit this behavior.

 

Thank you for your work,

Justis Mackaoui

 

New PostgreSQL user

 

 

 

Re: Clarity Bug for Schema Permissions, Potential Vulnerability?

From
Oleksandr Shulgin
Date:
On Wed, May 6, 2020 at 9:23 AM Justis Lincoln Mackaoui <jmackaou@calpoly.edu> wrote:

Hi there,

 

There’s an issue with the consistency of “ERROR: permission denied” which is a small gotcha for new Postgres users like myself. It may be desirable behavior but please bear with me.


Hi Justis,

I believe your question does not constitute a bug report and could be better answered in pgsql-general or pgsql-novice mailing list.

Here’s a scenario displaying the current behavior in PostgreSQL 11.5:

  1. The database has two schemas, “public” and “test”.
  2. The database has two users, “admin” and “test_user”.
  3. Admin user runs a variation of “CREATE SCHEMA test_schema”
  4. Admin user runs “CREATE TABLE test_schema.test_table”

 

  1. Test_user runs “SELECT * FROM test_schema.test_table”, receives “ERROR: permission denied” (as expected).
  2. Admin runs “GRANT ALL PRIVILEGES ON test_schema.test_table TO test_user”, receives “Query returned successfully”
  3. Test user runs “SELECT * FROM test_schema.test_table”, receives “ERROR: permission denied”

---

If you now check the permissions on “test_table”, you’ll see that it correctly granted all privileges to “test_user”, despite throwing errors when “test_user” attempts to access it; this is the source of confusion. Experienced users will know that you must FIRST run “GRANT USAGE ON SCHEMA test_schema TO test_user”, so that the user has access to the schema.


I'm wondering if we could provide a more helpful error message in this case, something along the lines of:

DETAIL: 'usage' permission required on schema 'test_schema'

Cheers,
--
Alex

Re: Clarity Bug for Schema Permissions, Potential Vulnerability?

From
"David G. Johnston"
Date:
On Tuesday, May 5, 2020, Justis Lincoln Mackaoui <jmackaou@calpoly.edu> wrote:

My argument is that step #6, the granting of privileges on the table, should return an “ERROR: permission denied” because the “test_user” should not know at all about the objects contained within “test_schema”. This would prevent the confusing state of contradictory permissions and access-


Hiding object existence is not something PostgreSQL does.  Anyone can view pg_class.  So this is strictly a usability concern.  At first glance I concur that there seems to be room for improvement here.

David J.

Re: Clarity Bug for Schema Permissions, Potential Vulnerability?

From
Jeff Janes
Date:
On Wed, May 6, 2020 at 3:47 AM Oleksandr Shulgin <oleksandr.shulgin@zalando.de> wrote:
I'm wondering if we could provide a more helpful error message in this case, something along the lines of:

DETAIL: 'usage' permission required on schema 'test_schema'

The actual error message is not just "permission denied", it is already:

ERROR:  permission denied for schema test_schema

Given that, I don't think the additional DETAIL upon ERROR would be all that helpful.

I think a more useful change (if any) would be a NOTICE or WARNING when granting privs on a object in a schema, to a user who does not already have privs on the schema itself.  I thought there was already a similar situation, where a NOTICE was issued where a permission change was executed which didn't do anything, because it was already done.  But now I can't find.

Re: Clarity Bug for Schema Permissions, Potential Vulnerability?

From
"David G. Johnston"
Date:
On Wed, May 6, 2020 at 6:38 AM Jeff Janes <jeff.janes@gmail.com> wrote:
I think a more useful change (if any) would be a NOTICE or WARNING when granting privs on a object in a schema, to a user who does not already have privs on the schema itself.

Definitely not a warning but maybe a notice.  But if that's the extent of things I don't really see enough value to warrant having a command targeting one object go looking around the system for other related state to comment upon.  If one revokes usage on a schema should we inform the user of any remaining grants on contained objects?  I suspect there are other useful notices to consider beyond those two.  It feels like something better left to a third-party tool rather than something built into core.

David J.