Security
This page covers who can connect and what they can do: roles, passwords and authentication methods, privileges with GRANT and REVOKE, row-level security, and TLS. Read it before you open a server to a network.
Production checklist
- Set the first role's password from the environment (
RASTERIZEDDB_PG_PASSWORDorRASTERIZEDDB_PASSWORD), never on the command line, where every local user can read it inps. - Keep
--pg-tls require(the default), and give the server a certificate your clients can verify with--pg-cert/--pg-keyand--rdb-cert/--rdb-key. - Bind only the addresses clients need (
--pg-addr,--rdb-addrand the others default to127.0.0.1), and firewall the rest. - Keep the default
scram-sha-256authentication. Usetrustonly on loopback or on a unix socket closed to other users. - Run applications as ordinary roles with only the privileges they need, not as the bootstrap superuser.
- Keep the data directory readable by the server's user only (the packaged service and the Docker images use mode
700).
Roles are per database
Each database has its own roles. A role created in postgres does not exist in analytics, and a login is checked against the roles of the database the connection names. Create the roles an application needs in the database it uses.
What a new database starts with:
CREATE DATABASEgives the new database the role that created it, and the role named inOWNER, with their passwords.SET CONFIG roles.create_database_roles = allcopies every role of the default database instead.- Before 1.1.0,
CREATE DATABASEgave the new database only the bootstrap role (--pg-user, defaultrasterized) with the password the server was started with.
CREATE DATABASE analytics OWNER app;The bootstrap role
The first time a database has no roles, the server creates one superuser in it: --pg-user (default rasterized) with --pg-password or RASTERIZEDDB_PG_PASSWORD, or under --protocol rastcp alone, --rdb-user with --rdb-password or RASTERIZEDDB_PASSWORD. It happens once; a restart with other values changes nothing. See Running the server.
Change its password after the first start:
ALTER ROLE rasterized PASSWORD 'a-new-strong-password';Managing roles
CREATE USER app PASSWORD 'app-password';
CREATE ROLE reporting LOGIN PASSWORD 'report-password';
CREATE ROLE readers;
CREATE ROLE admin SUPERUSER LOGIN PASSWORD 'admin-password';
ALTER USER app PASSWORD 'rotated-password';
ALTER USER app PASSWORD NULL;
DROP ROLE IF EXISTS reporting;| Option | Meaning |
|---|---|
LOGIN / NOLOGIN | Whether the role can connect. CREATE USER implies LOGIN; CREATE ROLE does not. |
SUPERUSER / NOSUPERUSER | A superuser passes every privilege check and may run the server's administration statements. |
PASSWORD 'secret' / PASSWORD NULL | Sets or removes the password. A role with no password cannot log in with one. |
ROLE and USER are interchangeable in every statement. Before 1.1.0, CREATE ROLE, ALTER ROLE and DROP ROLE needed a superuser, and ALTER ROLE changed only a password.
Passwords are stored as SCRAM-SHA-256 verifiers (as an MD5 hash under --pg-auth md5), never as written. A stored verifier cannot be used as a password. Over the native protocol the text of a role statement is never written to the log in full, since it contains a password.
To see the roles of the current database:
SELECT rolname, rolsuper, rolcanlogin FROM pg_roles;PostgreSQL's other role attributes and statements:
| Option or statement | Meaning |
|---|---|
CREATEDB / NOCREATEDB | May run CREATE DATABASE without being a superuser. |
CREATEROLE / NOCREATEROLE | May create, alter and drop roles that are not superusers. |
CONNECTION LIMIT n | Most sessions the role may have at once; one more is refused with 53300. -1 is no limit. |
VALID UNTIL 'timestamp' | The password stops working after this instant (28P01). 'infinity' removes the limit. |
BYPASSRLS / NOBYPASSRLS | Row-level security policies do not apply to the role. |
ALTER ROLE a RENAME TO b | Renames a role. |
ALTER ROLE a SET statement_timeout = '30s' | A default for the role's sessions; also lock_timeout and rdb.shape_change. RESET and RESET ALL remove them. |
A role may change its own password with ALTER ROLE <itself> PASSWORD '…' without being a superuser.
Authentication methods
| Method | Meaning | Where it is offered |
|---|---|---|
scram-sha-256 | The client proves it knows the password without sending it. The default everywhere it is offered. | PostgreSQL, native |
md5 | Salted MD5 challenge. For old drivers only; a role's password must have been set under md5 for it to work. | PostgreSQL |
password | The password is sent as written. Use only under TLS. | PostgreSQL |
peer | A role logs in without a password when its name is the operating-system user connecting, as the kernel reports it. | Unix sockets only (PostgreSQL, native) |
trust | No check. | Every listener, with the restrictions below |
| Listener | Flag | Default | Accepts |
|---|---|---|---|
| PostgreSQL over TCP | --pg-auth | scram-sha-256 | trust, password, md5, scram-sha-256 |
| PostgreSQL socket | --pg-socket-auth | --pg-auth | the above and peer |
| Native over TCP | --rdb-auth | scram-sha-256 | scram-sha-256, trust |
| Native socket | --rdb-socket-auth | --rdb-auth | scram-sha-256, trust, peer |
| MySQL | --mysql-auth, --mysql-socket-auth | password | password (caching_sha2_password), trust |
| SQL Server | --mssql-auth, --mssql-socket-auth | password | password (SQL Server authentication), trust |
| Redis | --kv-auth | password | password (AUTH against the roles), trust |
The server refuses configurations that would open it to strangers:
truston a unix socket is refused when the socket's mode admits users outside its owner and group.--kv-auth trustis refused on anything but a loopback address.- The native listener on a non-loopback address is refused when nobody could authenticate (no password configured and no role with one).
--pg-auth peeris refused: over TCP the user name would be the caller's own claim.
A login that fails is answered with SQLSTATE 28P01 (wrong password) or 28000 (no such role, or a role that cannot log in).
Native protocol logins
The native protocol always runs over TLS 1.3 on TCP, with SCRAM-SHA-256 bound to the TLS connection: an attacker who intercepts a connection cannot relay the exchange to the real server, even when the client does not verify the server's certificate. The Rust client also refuses a server that lets it in without proving it holds the role's verifier. Client-side login options are described in Rust client: connecting.
With no password configured and no role holding one, the native listener on loopback accepts any caller, and warns about it at --log-level warn. It requires a password as soon as one exists.
Privileges
A table belongs to the role that created it. Other roles need a grant to use it, as in PostgreSQL. A superuser passes every check.
GRANT SELECT ON orders TO reporting;
GRANT SELECT, INSERT, UPDATE, DELETE ON orders, order_items TO app;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readers;
GRANT readers TO reporting;
GRANT SELECT ON orders TO app WITH GRANT OPTION;
ALTER DEFAULT PRIVILEGES GRANT SELECT ON TABLES TO readers;
REVOKE UPDATE, DELETE ON orders FROM app;
REVOKE readers FROM reporting;- Table privileges are
SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGERandMAINTAIN, orALL. PUBLICas the grantee means every role.GRANT role TO membermakesmemberhold every privilegerolehas.ALTER DEFAULT PRIVILEGES [FOR ROLE r] GRANT … ON TABLES TO …grants on tables created from then on.- Grants on schemas, databases and types are accepted and not enforced.
- A permission failure is SQLSTATE
42501.
Every check fails closed. The first start gives each table with no recorded owner the bootstrap superuser as owner and grants PUBLIC every table privilege on it, so existing applications keep working; revoke from PUBLIC to lock such tables down.
Statements only a superuser may run
These administer the server rather than the data, and are refused with 42501 for other roles: CREATE/ALTER/DROP ROLE, CREATE DATABASE, DROP DATABASE, the branch statements (CREATE/DROP/RESET/PROMOTE/MERGE BRANCH, SHOW BRANCH DIFF), IMPORT, SET CONFIG, SET FILTER, RESET QUERY STATS, BACKUP, RESTORE, STORAGE, REPLICATION, KV FLUSHALL, KV SAVE and KV CONFIG SET. SHOW statements read state and are open to every role.
Trust sessions
Before 1.1.0, a session admitted under trust passed every privilege check and could run every administration statement, whatever role it named. In 1.1.0:
- A
trustsession is exactly the role it names, with that role's privileges, and the role must exist and be allowed to log in. A native connection undertrustthat names no role is no administrator: in a database with roles it reaches only the tables it created and whatPUBLICis granted. A native client names its role withClient::connect_as_role. See Upgrading. Keeptrustto loopback and closed sockets. CREATEROLEroles may manage roles that are not superusers, andCREATEDBroles may create databases.- Grants extend to sequences (
USAGE,SELECT,UPDATE), functions and procedures (EXECUTE), and single columns (GRANT SELECT (email) ON users TO support).
Row-level security
Row-level security limits which rows of a table a role sees and changes. It works as in PostgreSQL:
CREATE TABLE documents (id BIGINT PRIMARY KEY, owner TEXT NOT NULL, body TEXT);
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
CREATE POLICY own_documents ON documents
FOR ALL TO PUBLIC
USING (owner = current_user)
WITH CHECK (owner = current_user);
GRANT SELECT, INSERT, UPDATE, DELETE ON documents TO app;- With row-level security on and no policy for a command, a role sees no rows and can write none.
- Permissive policies (the default) are combined with
OR;AS RESTRICTIVEpolicies are combined withANDon top of them. FOR SELECT,INSERT,UPDATE,DELETEorALLchooses the commands;TOthe roles.USINGfilters the rows a statement reads, updates or deletes.WITH CHECKchecks new rows; without it,USINGchecks them.- The table's owner, superusers and
BYPASSRLSroles are exempt.ALTER TABLE … FORCE ROW LEVEL SECURITYapplies the policies to the owner too. ALTER POLICYandDROP POLICYchange and remove policies;ALTER TABLE … DISABLE ROW LEVEL SECURITYturns it off.
TLS
| Listener | TLS | Certificate flags | Without a certificate |
|---|---|---|---|
| PostgreSQL | --pg-tls disable|prefer|require (default require); TLS 1.2 and 1.3 | --pg-cert, --pg-key | self-signed at every start |
| Native | always on TCP; TLS 1.3 only | --rdb-cert, --rdb-key | self-signed at every start |
| MySQL | --mysql-tls (default prefer) | --mysql-cert, --mysql-key, else the PostgreSQL ones | self-signed |
| SQL Server | --mssql-tls (default prefer) | --mssql-cert, --mssql-key, else the PostgreSQL ones | self-signed |
| Redis | --kv-tls on|off (default off) | the PostgreSQL ones | self-signed |
| Replication | always | --replication-cert, --replication-key, --replication-ca | see Replication |
A self-signed certificate encrypts but proves nothing about the server, and it changes at every restart. For anything beyond one machine:
- Get a certificate for the server's host name from your CA (or a public one), as PEM files.
- Start the server with
--pg-cert/--pg-keyand--rdb-cert/--rdb-key, keeping--pg-tls require. - Have PostgreSQL clients use
sslmode=verify-fullwith the CA, and native clients verify the server (Options::trustin the Rust client).
Unix sockets carry no TLS; their file permissions decide who connects.
Limits
- Roles are per database; there is no cluster-wide role.
- There is no
pg_hba.conf. Authentication is chosen per listener, not per user, database or client address. - Kerberos, GSSAPI, LDAP, RADIUS, client certificates and Windows authentication are not offered.
md5works only for roles whose password was set while the server ran under--pg-auth md5.- Unix sockets and
peerauthentication are Linux-only.