HomeDocumentationAPI Reference
Log In
Documentation

Postgres Replication

Located under Settings > Integrations > Postgres, the Postgres replication page enables the configuration of data replication to an external Postgres database for independent, long-term storage and data analysis. The Configuration details card shows the current Postgres replication settings.

ℹ️

INFO: Upgrade Feature - Postgres Replication

The ability to configure and use Postgres Replication requires an upgraded plan. Please see https://www.sandflysecurity.com/get-sandfly/🡵 for details.

Postgres Replication Tab

Postgres Replication Tab

Postgres Replication Form

To change these settings, open the Configuration details card's edit form. The form contains the following fields:

  • Postgres replication enabled - Select Enabled to start Postgres replication and make the other fields available.
  • Host - The network host name or the IP address of the external Postgres server. Required when replication is enabled.
  • Database - The external Postgres database name for the replication data. Required when replication is enabled.
  • Username - The external Postgres database username to connect as. Required when replication is enabled.
  • Extra options (optional) - A space-separated, key=value set (e.g., optionA=valueA optionB=valueB) of special connection options for the external Postgres connection. If Postgres is on a non-default port, use port=<PORT_NUMBER>.
  • Set password - Turn on to enter a new password. When it is off, Sandfly keeps the saved password.
  • Password (optional) - The external Postgres password associated with the specified username. This value is encrypted when saved and is not shown again.

Sandfly automatically creates the sandfly_results and sandfly_version tables in the target database. Sandfly sends the full JSON of new and changed results every 60 seconds. A changed result replaces its existing row. When you enable replication, Sandfly sends only results that are created or changed after that time. Existing results are not sent. Replication results and errors are recorded in the audit log.


Configuring Client Certificates

The Postgres client library supports the use of client certificates; however, additional steps are required to make the certificates available.

The Postgres replication edit form has an Extra options field. Sandfly appends any provided value to the Postgres connection string that is built, and most Postgres connection string parameters are supported. To support a client certificate, add the following space-delimited options in the Extra options field:

sslmode='verify-full' sslcert='/pqcerts/client.crt' sslkey='/pqcerts/client.key' sslrootcert='/pqcerts/root_ca.pem'

These certificate files will be loaded when Sandfly tries to connect and used for the mutual TLS authentication.

The technical complication is that those files do not exist inside the Sandfly Server container. One way to make it work is to create the pqcerts directory somewhere on the Sandfly server. Then, in start_server.sh, add -v /path/to/pqcerts:/pqcerts:ro to the $CONTAINERMGR run command, so those files are available to the Sandfly Server container at the /pqcerts path. If you use Podman, also add Volume=/path/to/pqcerts:/pqcerts:ro to the generated Quadlet section of the script. The files must be readable by the sandfly user in the container.


Did this page help you?