NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›

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_PASSWORD or RASTERIZEDDB_PASSWORD), never on the command line, where every local user can read it in ps.
  • Keep --pg-tls require (the default), and give the server a certificate your clients can verify with --pg-cert/--pg-key and --rdb-cert/--rdb-key.
  • Bind only the addresses clients need (--pg-addr, --rdb-addr and the others default to 127.0.0.1), and firewall the rest.
  • Keep the default scram-sha-256 authentication. Use trust only 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 DATABASE gives the new database the role that created it, and the role named in OWNER, with their passwords. SET CONFIG roles.create_database_roles = all copies every role of the default database instead.
  • Before 1.1.0, CREATE DATABASE gave the new database only the bootstrap role (--pg-user, default rasterized) with the password the server was started with.
sql
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:

sql
ALTER ROLE rasterized PASSWORD 'a-new-strong-password';

Managing roles

sql
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;
OptionMeaning
LOGIN / NOLOGINWhether the role can connect. CREATE USER implies LOGIN; CREATE ROLE does not.
SUPERUSER / NOSUPERUSERA superuser passes every privilege check and may run the server's administration statements.
PASSWORD 'secret' / PASSWORD NULLSets 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:

sql
SELECT rolname, rolsuper, rolcanlogin FROM pg_roles;

PostgreSQL's other role attributes and statements:

Option or statementMeaning
CREATEDB / NOCREATEDBMay run CREATE DATABASE without being a superuser.
CREATEROLE / NOCREATEROLEMay create, alter and drop roles that are not superusers.
CONNECTION LIMIT nMost 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 / NOBYPASSRLSRow-level security policies do not apply to the role.
ALTER ROLE a RENAME TO bRenames 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

MethodMeaningWhere it is offered
scram-sha-256The client proves it knows the password without sending it. The default everywhere it is offered.PostgreSQL, native
md5Salted MD5 challenge. For old drivers only; a role's password must have been set under md5 for it to work.PostgreSQL
passwordThe password is sent as written. Use only under TLS.PostgreSQL
peerA 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)
trustNo check.Every listener, with the restrictions below
ListenerFlagDefaultAccepts
PostgreSQL over TCP--pg-authscram-sha-256trust, password, md5, scram-sha-256
PostgreSQL socket--pg-socket-auth--pg-auththe above and peer
Native over TCP--rdb-authscram-sha-256scram-sha-256, trust
Native socket--rdb-socket-auth--rdb-authscram-sha-256, trust, peer
MySQL--mysql-auth, --mysql-socket-authpasswordpassword (caching_sha2_password), trust
SQL Server--mssql-auth, --mssql-socket-authpasswordpassword (SQL Server authentication), trust
Redis--kv-authpasswordpassword (AUTH against the roles), trust

The server refuses configurations that would open it to strangers:

  • trust on a unix socket is refused when the socket's mode admits users outside its owner and group.
  • --kv-auth trust is 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 peer is 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.

sql
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, TRIGGER and MAINTAIN, or ALL.
  • PUBLIC as the grantee means every role.
  • GRANT role TO member makes member hold every privilege role has.
  • 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 trust session 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 under trust that names no role is no administrator: in a database with roles it reaches only the tables it created and what PUBLIC is granted. A native client names its role with Client::connect_as_role. See Upgrading. Keep trust to loopback and closed sockets.
  • CREATEROLE roles may manage roles that are not superusers, and CREATEDB roles 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:

sql
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 RESTRICTIVE policies are combined with AND on top of them.
  • FOR SELECT, INSERT, UPDATE, DELETE or ALL chooses the commands; TO the roles.
  • USING filters the rows a statement reads, updates or deletes. WITH CHECK checks new rows; without it, USING checks them.
  • The table's owner, superusers and BYPASSRLS roles are exempt. ALTER TABLE … FORCE ROW LEVEL SECURITY applies the policies to the owner too.
  • ALTER POLICY and DROP POLICY change and remove policies; ALTER TABLE … DISABLE ROW LEVEL SECURITY turns it off.

TLS

ListenerTLSCertificate flagsWithout a certificate
PostgreSQL--pg-tls disable|prefer|require (default require); TLS 1.2 and 1.3--pg-cert, --pg-keyself-signed at every start
Nativealways on TCP; TLS 1.3 only--rdb-cert, --rdb-keyself-signed at every start
MySQL--mysql-tls (default prefer)--mysql-cert, --mysql-key, else the PostgreSQL onesself-signed
SQL Server--mssql-tls (default prefer)--mssql-cert, --mssql-key, else the PostgreSQL onesself-signed
Redis--kv-tls on|off (default off)the PostgreSQL onesself-signed
Replicationalways--replication-cert, --replication-key, --replication-casee Replication

A self-signed certificate encrypts but proves nothing about the server, and it changes at every restart. For anything beyond one machine:

  1. Get a certificate for the server's host name from your CA (or a public one), as PEM files.
  2. Start the server with --pg-cert/--pg-key and --rdb-cert/--rdb-key, keeping --pg-tls require.
  3. Have PostgreSQL clients use sslmode=verify-full with the CA, and native clients verify the server (Options::trust in 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.
  • md5 works only for roles whose password was set while the server ran under --pg-auth md5.
  • Unix sockets and peer authentication are Linux-only.
✓ page rendered in 358 µs axum + tera + htmx · no other javascript