Skip to content

TLS and authentication for PostgreSQL

How the collector connects to a PostgreSQL database, and how it proves who it is. WatchTower15 stores neither a password nor a key: it stores where your collectors find them (see Self-managed PostgreSQL and Amazon RDS and Aurora PostgreSQL).

Connection TLS
Unix socket Not used: the connection never leaves the server
Loopback, private network Always on. Verify the certificate and the host name (the default), Verify the certificate, or Encrypt, no verification
Public endpoint Verify the certificate and the host name or Verify the certificate: an unverified connection is not offered, because it crosses the internet
Amazon RDS and Aurora The same, with the Amazon RDS CA bundle built into the agent as the default authority: nothing to download
Mode What it checks
Verify the certificate and the host name The certificate chains to your authority and names the host the collector connects to. Connect by the name on the certificate, or set Name in the certificate
Verify the certificate The certificate chains to your authority; the name is not checked
Encrypt, no verification The connection is encrypted but the server is not authenticated. Refused for an endpoint whose host name resolves to a public address, whatever its connection type

There is no fallback: a connection that cannot be encrypted as the mode says fails, and never continues without TLS. A server that does not offer TLS reads TLS required, and a handshake that fails reads TLS failed, on the database’s collectors. The certificate authority of a self-managed database is the file named ssl-ca in the credentials file, or the server’s system store.

A password login uses SCRAM-SHA-256 and nothing weaker: the agent refuses a server that would answer with an MD5 challenge, and it asks for channel binding when the server offers it. The grant script therefore sets password_encryption = 'scram-sha-256' before it creates the role, so a PostgreSQL 13 left at its default still makes a SCRAM verifier, and it adds a hostssl … scram-sha-256 line, never a plain host line, to pg_hba.conf.

On a self-managed server, over the Unix socket, the collector can log in as the agent’s own OS user, wt15-server-agent, with no password anywhere. The script for that variant creates the role without a password and prints the two lines to add, then reload PostgreSQL (SELECT pg_reload_conf();):

pg_hba.conf: local all wt15_monitor peer map=wt15
pg_ident.conf: wt15 wt15-server-agent wt15_monitor

The map lets the agent’s OS user log in as the role; no other OS user can. Two things the socket needs: write permission on it (add the agent’s user to the socket’s group, then restart the agent), and a socket outside /tmp (the agent’s service runs with PrivateTmp=yes).

To use a password on the socket instead, the script’s line is local all wt15_monitor scram-sha-256.

Enable IAM database authentication on the instance or cluster. The grant script for it creates the role with no password and ends with GRANT rds_iam TO wt15_monitor;. A role holding rds_iam can no longer log in with a password, so run either the IAM script or the password one for a role, never both. Policy for the collectors’ instance role, on port 5432:

{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Action": "rds-db:connect",
"Resource": "arn:aws:rds-db:<region>:<account>:dbuser:<the instance resource id>/wt15_monitor" }
]
}

For Aurora the Resource names the cluster resource id (cluster-…) in place of the instance resource id. IAM has no secret to carry the redaction key: give it its own SSM parameter (or a secret, or a file), and the role read access to it.