How can I create a read-only user in Azure PostgreSQL?
On my local postgres installation, I can run these commands to create a read-only user:
CREATE USER spqr1 WITH ENCRYPTED PASSWORD 'password'; REVOKE CONNECT ON DATABASE postgres FROM PUBLIC; CREATE DATABASE mydb; REVOKE CONNECT ON DATABASE mydb FROM PUBLIC; GRANT CONNECT ON DATABASE mydb TO spqr1; \connect mydb REVOKE ALL PRIVILEGES ON SCHEMA public FROM PUBLIC; GRANT USAGE ON SCHEMA public TO spqr1; When I run these commands on an Azure PostgreSQL database, the new user spqr1 has privileges that I don't want: they can connect to the postgres database, and create tables in mydb. On my local machine, the new user doesn't have these privileges.
It looks to me like there is a default user azure_superadmin who has granted PUBLIC the privilege of connecting to the postgres database, and the privilege of creating tables in any public schema. My admin account (meadmin) didn't grant those privileges, and can't remove them. Is this what's going on, and if so then how should I create a read-only account?
Here is the trimmed output from \l:
Name | Owner | Access privileges -----------+-----------------+------------------------------------- mydb | meadmin | =T/meadmin + | | meadmin=CTc/meadmin + | | spqr1=c/meadmin postgres | azure_superuser | =Tc/azure_superuser + | | azure_superuser=CTc/azure_superuser template0 | azure_superuser | =c/azure_superuser + | | azure_superuser=CTc/azure_superuser template1 | azure_superuser | =c/azure_superuser + | | azure_superuser=CTc/azure_superuser And here is the trimmed output from \dn+, after I have connected to mydb:
Name | Owner | Access privileges --------+-----------------+------------------------------------ public | azure_superuser | azure_superuser=UC/azure_superuser+ | | =UC/azure_superuser