question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The `postgres` role doesn't have access to newly created tables?

See original GitHub issue

Describe the bug

Confused by this, but if I create a new table in the UI, and then try to SELECT or INSERT into it with the “Connection Pooling” connection (using the postgres role) I get the following error:

error: permission denied for table test

This happens even without enabling row-level access control.

Expected behavior

I thought the postgres role would have permissions to all objects by default? (Especially ones created through the dashboard.)

None of the creating tables examples have any extra permissions-granting steps. When I first created the database I restored some data from a previous backup, might that have messed up permissions somehow? Very unclear.

Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ydennisycommented, Feb 14, 2022

Hey @kiwicopple I was wondering if you had a chance to add more docs for resetting permissions?

2reactions
ianstormtaylorcommented, Oct 4, 2021

@kiwicopple Thank you, that’s helpful!

I think you’re right that it was due to the restore. What I did was pipe pg_dump | psql originally to load ~50 large tables from a previous database provider I was using into Supabase when I created the project. But there might have been some logic in the dump that changed how public schema permissions were setup.

I looked over the existing grants:

image

And it does seem like all the imported tables didn’t get permissions extended to anyone but postgres—which would likely be a problem as soon as I start trying to use the PostgREST API I’d assume.

And I found this file too which was helpful. I think specifically these lines might restore the default behavior for the future:

https://github.com/supabase/supabase/blob/d1d6278913f5a752253a3d47a0d4adabd3bfaf7a/docker/volumes/db/init/00-initial-schema.sql#L37-L43

I think the biggest thing that would have helped me (not knowing much about granting privileges in PG before running into this) was a page in the docs describing each of the roles that Supabase uses. I found reference in different places to many different names:

  • anon
  • authenticated
  • service_role
  • postgres
  • supabase_admin
  • supabase_auth_admin
  • supabase_storage_admin
  • dashboard_user
  • pgbouncer
  • authenticator

Explaining what they are for, and what permissions they need to have to work properly. (Also potentially eliminating some of them, because it feels like a lot, but obviously that’s not my call.)


Follow up question: Do I need to grant those tables, functions, sequences privileges to all of these grantees: anon, authenticated, dashboard_user, postgres, service_role, supabase_admin?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grant permissions to user for any new tables created in ...
Found the answer. It is in this line in the ALTER DEFAULT PRIVILEGES documentation. You can change default privileges only for objects that ......
Read more >
postgresql - Why is a new user allowed to create a table?
When you create a new database, any role is allowed to create objects in the public schema. To remove this possibility, you may...
Read more >
Documentation: 9.1: GRANT - PostgreSQL
The default is no public access for tables, columns, schemas, and tablespaces; CONNECT privilege and TEMP table creation privilege for databases; EXECUTE ...
Read more >
How To Use Roles and Manage Grant Permissions in ...
When a database or table is created, usually only the role that created it, not including the roles with superuser status, has permission...
Read more >
Messing with PostgreSQL users and permissions - Jay Marcyes
So we needed to add a Postgres user that could only read tables from our database--not only the currently existing tables, but any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found