Openflow Connector for PostgreSQL: Security¶
This page describes how to limit what the connector can read on the PostgreSQL server.
Exclude columns from the PostgreSQL connector¶
To prevent column values from leaving the PostgreSQL server, use the configuration on this page. Replicate a subset of columns in a table filters columns after the connector has read the row.
Warning
PostgreSQL can’t stop this role from copying the data directory. Logical replication requires the REPLICATION attribute, and that attribute also allows a base backup. The connector opens a logical replication connection (replication=database). On that connection the server accepts a base-backup command and, with the default target, sends the files to the client. A pg_hba.conf entry that denies the replication pseudo-database doesn’t apply to this connection. No role attribute both allows logical replication and refuses a base backup.
A managed PostgreSQL service might refuse base backups on its own. Self-managed PostgreSQL doesn’t.
This role can copy the cluster. Sensitive values stay on the server only when they are absent from every database on that cluster, including existing WAL segments and backups. Dropping a column from a table that already contains the column leaves the values in existing files.
Server version¶
Publication column lists require PostgreSQL 15 or later.
Restricting which output plugins a replication role can use requires PostgreSQL 15.19, 16.15, 17.11, or 18.6, or a newer minor release of that major version. You can apply that restriction only on a server where you can set output_plugin_libraries. Amazon RDS and Amazon Aurora don’t expose this parameter, so you can’t restrict the plugin list there.
Role, grants, and publication¶
Replace the names, the password, and the column list in the following statements with your own. Every replica-identity column, including the primary key, must stay in the column list. The connector role can’t own the table.
Run the following steps on self-managed PostgreSQL, Amazon RDS, or Amazon Aurora:
-
Allow only the
pgoutputoutput plugin, and reload the configuration. Amazon RDS and Amazon Aurora don’t exposeoutput_plugin_libraries, so skip this step on those services: -
Create a login role for the connector:
-
On a server you manage, include the
REPLICATIONattribute. The role isn’t a superuser, and it can’t bypass row-level security, create databases, or create roles: -
On Amazon RDS or Amazon Aurora, create the role without the
REPLICATIONattribute, and then grantrds_replication. Don’t grantrds_superuser. Column grants and the publication column list still apply, and the connector still usespgoutput:
-
-
Allow the role to use the schema:
-
Remove every privilege the role has on the table:
-
Remove table-level
SELECTfromPUBLIC, so members ofPUBLICdon’t receiveSELECTon every column: -
Grant
SELECTon the columns to replicate: -
Create a publication that lists those same columns:
Don’t grant pg_read_all_data, pg_read_server_files, or pg_write_server_files. Don’t make the connector role a member of the table owner.
Table-level SELECT, GRANT SELECT ON ALL TABLES, and ALTER DEFAULT PRIVILEGES ... GRANT SELECT ON TABLES cover every column, including columns added later. A column grant doesn’t extend to a new column. When a new column should be replicated, add it to the grant and to the publication.
Warning
This database must contain only the openflow_pub publication because publications have no privileges of their own, so any replication connection to the database can use any publication. FOR ALL TABLES, FOR TABLES IN SCHEMA, or a publication of this table with no column list publishes every column.
Host-based authentication¶
This section applies to a server whose host-based authentication file you can edit. Amazon RDS and Amazon Aurora don’t give you access to pg_hba.conf.
Allow the connector role to connect to the application database. Don’t add a line whose database field is replication:
This line allows openflow_user to connect to the appdb database from the connector’s network range and authenticates the connection with scram-sha-256.
Check the configuration¶
Run the following queries, and replace the role, table, and publication names with the names you used:
-
Where you set
output_plugin_libraries, confirm the value. On Amazon RDS and Amazon Aurora, skip this query:The setting must be
pgoutput. -
Confirm that the database contains only the connector publication, and that the publication doesn’t include every table:
The result must contain only
openflow_pub, andpuballtablesmust be false. -
Confirm which columns the connector role can select:
can_selectmust be false for every excluded column.
In the connector, set the source user to openflow_user and the publication name to openflow_pub.