Skip to content

feat: setup supabase_realtime_admin#1852

Open
leandrocp wants to merge 9 commits into
mainfrom
lp-revoke-supabase_realtime_admin
Open

feat: setup supabase_realtime_admin#1852
leandrocp wants to merge 9 commits into
mainfrom
lp-revoke-supabase_realtime_admin

Conversation

@leandrocp
Copy link
Copy Markdown
Contributor

@leandrocp leandrocp commented May 7, 2026

Part of project Migrations v2.

The main change is connecting tenants using supabase_realtime_admin instead of supabase_admin. Related to https://github.com/orgs/supabase/discussions/34270

The complexity of this PR is because we need to handle existing tenant running with supabase_admin and new projects that should start with supabase_realtime_admin, so existing projects upgrades via migrations and new projects should get fresh DB with all permissions in place which requires a following PR in supabase/postgres

Breaking changes

  • PG15 before postgres:15.14.1.113 doesn't grant policy on realtime.subscriptions so it's not possible to create/alter policies after these changes are applied
  • for all tables option in create publication requires superuser and is no longer allowed

Tasks

Closes REAL-25
Closes REAL-377
Closes REAL-527
Closes REAL-630
Closes REAL-778
Closes REAL-781
Closes SEC-562

@coveralls
Copy link
Copy Markdown

coveralls commented May 7, 2026

Coverage Status

Coverage is 91.87%lp-revoke-supabase_realtime_admin into main. No base build found for main.

@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch from d3573fe to 2b98f96 Compare May 12, 2026 12:41
@leandrocp leandrocp changed the title fix: restrict realtime schema feat: setup supabase_realtime_admin May 12, 2026
@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch 3 times, most recently from 72e61c1 to c3a692e Compare May 12, 2026 15:11
Comment thread .github/workflows/tests.yml Outdated
name: Tests PG15 (Partition ${{ matrix.partition }})
runs-on: blacksmith-8vcpu-ubuntu-2404
env:
POSTGRES_IMAGE: supabase/postgres:15.14.1.113
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimum PG15 version that grants policy on realtime.subscription via supautils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous function required grant usage because of ::regclass casting, see test "subscription works when role lacks usage permission".

@leandrocp leandrocp force-pushed the lp-revoke-supabase_realtime_admin branch from c3a692e to 9353942 Compare May 12, 2026 15:39
Comment thread priv/repo/dev_seeds.exs
_ -> raise "Running Migrations failed"
end

Tenants.Migrations.run_migrations(tenant)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant so I removed it but not sure about this change.

%{oids: oids2} = :sys.get_state(subscriber_manager_pid)
assert !Map.equal?(oids, oids2)

Postgrex.query!(conn, "create publication supabase_realtime_test for all tables", [])
Copy link
Copy Markdown
Contributor Author

@leandrocp leandrocp May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all tables requires superuser - is this a blocker? Otherwise we can grant it on supabase/supautils or create a function like create_publication_for_all_tables(name text).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a blocker because we don't control this publication ourselves, right? 🤔 This is just for the test

Comment thread .github/workflows/tests.yml Outdated
name: coverage-partition-${{ matrix.partition }}
path: cover/lcov.info

tests-pg15:
Copy link
Copy Markdown
Contributor Author

@leandrocp leandrocp May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could execute this test only on main or when some specific files changes if running on every branch is too expensive.

Copy link
Copy Markdown
Contributor Author

@leandrocp leandrocp May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test module to verify permissions, ie: restrict what must be restricted without breaking the system.

Comment thread test/support/containers.ex
@blacksmith-sh

This comment has been minimized.

Copy link
Copy Markdown
Member

@edgurgel edgurgel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests on schema_test.exs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants