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.

Permissions issue for postgres user on auth table objects (unable to drop triggers)

See original GitHub issue

Bug report

Describe the bug

The supabase examples sometimes take advantage of creating a trigger against the auth.users table - so that on sign up (or update of user information) you can also subsequently populate another table (e.g. your own application’s public.profile table via a function that is called from the trigger).

To do this, supabase provides a postgres db user. In the default setup, the postgres user is able to create a trigger on auth.users.

To Reproduce

Connect to your supabase db using the postgres user with the connection details provided by supabase console.

Create a function to populate your own profile table when a user signs up.

create or replace function public.handle_new_user() returns trigger as $$ begin insert into public.users (id, email) values (new.id, new.email); return new; end; $$ language plpgsql security definer;

Works fine.

Now add a trigger to call this function when data is inserted into auth.users

create trigger on_auth_user_created after insert on auth.users for each row execute procedure public.handle_new_user();

Works fine.

However, subsequently try and drop the trigger.

drop trigger if exists on_auth_user_created on auth.users;

This errors with

ERROR: must be owner of relation users

Understandably the internal auth schema is owned by a separate internal account supabase_auth_admin but some looks like perhaps the permission to create trigger has been granted to postgres user but not drop.

Expected behavior

Should be able to drop the trigger after creating it.

Screenshots

If applicable, add screenshots to help explain your problem.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kiwicopplecommented, Oct 8, 2021

We discussed this internally and think we have a solution using our supautils extension. I’ll update once we have tested a few ideas

1reaction
evhancommented, Feb 11, 2022

FWIW dropping any functions you’ve hooked up as triggers on auth.users with CASCADE seems to do the trick:

postgres=> drop function if exists handle_new_user() cascade;
NOTICE:  drop cascades to trigger on_auth_user_created on table auth.users
DROP FUNCTION

Hopefully this will help someone in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

postgresql - Permission denied for relation <table>
I was unable to GRANT on all tables in the schema as kept getting the same error. "permission denied for relation users" Running...
Read more >
postgresql - Permission denied for relation - Stack Overflow
This frequently happens when you create a table as user postgres and then try to access it as an ordinary user. In this...
Read more >
15: ALTER DEFAULT PRIVILEGES - PostgreSQL
This means you cannot revoke privileges per-schema if they are granted globally (either by default, or according to a previous ALTER DEFAULT PRIVILEGES...
Read more >
Documentation: 15: 5.8. Row Security Policies - PostgreSQL
By default, tables do not have any policies, so that if a user has access privileges to a table according to the SQL...
Read more >
Documentation: 15: GRANT - PostgreSQL
The GRANT command has two basic variants: one that grants privileges on a database object (table, column, view, foreign table, sequence, database, ...
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