Replies: 4 comments 2 replies
|
Correction after rechecking the docs: the pooled/direct split is documented, but I overstated what it proves. Prisma documents the same generated The decisive check is to run this through each URL, before any SELECT
session_user,
current_user,
(SELECT rolsuper FROM pg_roles WHERE rolname = session_user) AS session_is_superuser;If both URLs report For (b), So the least-privilege solution is still a connection credential that authenticates as a non-superuser. If Prisma does not expose one, |
|
The pooled/direct split is real, but I don't think it can be the thing that selects the role. Prisma's own docs use the same USER:PASSWORD on both URLs and only change the hostname, and you already found that the role is resolved from the credential rather than from the string, so moving to the pooled host shouldn't take you off prisma_migration. Worth confirming rather than arguing about, though: run select current_user, (select rolsuper from pg_roles where rolname = current_user); through each URL. If both report prisma_migration, there's no URL-level answer to (a), and for what it's worth prisma_application doesn't appear anywhere in Prisma's public repos or docs, which makes it look like an internal provisioning role rather than something you're meant to connect as. On (b), I'd push back on dismissing SET ROLE: the pooling docs say session state is lost after each transaction boundary, and SET LOCAL lives inside one, so begin; set local role app_runtime; ... commit; does survive the pooler. That's the same shape PostgREST runs on. Just don't reach for RLS before that, since prisma_migration is both superuser and the owner of all 19 tables and so bypasses it twice over, and FORCE ROW LEVEL SECURITY only closes the owner half. |
|
I think the most useful next step is to separate what PostgreSQL itself allows from what Prisma Postgres exposes as a supported connection mechanism. Since the generated Prisma Postgres credential appears to authenticate as One experiment that seems worth trying is creating a dedicated CREATE ROLE app_runtime
LOGIN
PASSWORD '...'
NOSUPERUSER
NOCREATEDB
NOCREATEROLE;
GRANT USAGE ON SCHEMA public TO app_runtime;
GRANT SELECT, INSERT, UPDATE, DELETE
ON ALL TABLES IN SCHEMA public
TO app_runtime;
GRANT USAGE, SELECT, UPDATE
ON ALL SEQUENCES IN SCHEMA public
TO app_runtime;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE
ON TABLES TO app_runtime;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT USAGE, SELECT, UPDATE
ON SEQUENCES TO app_runtime;Then connect using that role's credentials and verify both the authenticated role and its privileges: SELECT
session_user,
current_user,
(SELECT rolsuper FROM pg_roles WHERE rolname = session_user) AS session_is_superuser;If If Prisma Postgres rejects that role or the generated connection mechanism cannot authenticate with it, then I think that is the key finding: PostgreSQL supports the model, but Prisma Postgres currently doesn't expose a documented way to provision a role-bound application credential. The current Prisma documentation describes the connection credentials as being generated by Prisma Console, with the pooled and direct URLs sharing the same credentials and differing by hostname. So I don't think the pooled/direct distinction itself can be assumed to select In that case, I'd agree that So I'd be interested to see whether the |
|
The connection string provided in the Prisma Data Platform console is hardcoded to the admin/migration role because Prisma CLI uses that same URL to execute schema migrations ( To connect your application with least privilege ( CREATE ROLE app_user WITH LOGIN PASSWORD 'your_secure_password' IN ROLE prisma_application;
GRANT USAGE ON SCHEMA public TO app_user;Then format your runtime connection string using that user: This connects directly as |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I run a small production app on Prisma Postgres (region: ap-northeast-1).
I would like the application to connect with least privilege, but I cannot find a way
to obtain a connection string that maps to a non-superuser role.
What I observe (all verified by querying the database directly):
My current direct connection string (postgres://@db.prisma.io:5432/postgres)
authenticates as the role
prisma_migration.The database already contains a role named
prisma_application.I could not find any way to get a connection string that authenticates as
prisma_application:"generate new connection string" button; it shows the same key I already use
which suggests the role is decided server-side from the key
My questions:
a) Is there a supported way to obtain a connection string that authenticates as
prisma_application(or any non-superuser role) for a Prisma Postgres database?b) If not, is there another recommended way to run an application without superuser
privileges on Prisma Postgres?
c) If neither exists today, is it on the roadmap?
For context, this is a construction-industry app holding customer names and addresses in
drawings, so limiting blast radius matters to us.
Thanks in advance.
All reactions