Skip to content

Password authentication and TLS

Match HBA entries, authenticate existing PostgreSQL roles and verify TLS from a MySQL connection.

Password authentication

Authenticate as a PostgreSQL role with LOGIN and CONNECT on the target database. PostgreSQL evaluates pg_hba.conf using that database, role, transport and client address. The first matching rule wins. MySQL schema selection and its privileges come later. The listener handles reject, trust, password, md5, scram-sha-256 and cert; other HBA authentication methods return an unsupported-method error. PostgreSQL HBA matching

Full and cached login

With MariaDB CLI 11.8.9 over TLS, a trust rule accepts a passwordless login. Supplying a password on that path produces error 1047. For a password-based login, use a matching scram-sha-256 HBA entry.

With the default plugin, a cache miss requires full authentication over TLS or an RSA-OAEP password exchange on a non-TLS connection. The server verifies the password using the role’s PostgreSQL verifier. A scram-sha-256 HBA entry requires a SCRAM verifier. Later connections can use the fast challenge/response path. Changing the role password invalidates the old cached credential. RSA protects the password exchange only. To protect queries and rows in transit, use TLS. For a legacy client requiring mysql_clear_password, require TLS by HBA and enable that plugin on the client.

Require and verify TLS

Configure an OpenSSL-enabled server with ssl=on, a server certificate and private key (ssl_cert_file, ssl_key_file). The certificate must cover the name or IP used by the client. For example, put these rules above broader host rules for the application subnet, substituting your actual CIDR. They apply to this role and PostgreSQL database on both TCP protocols. Reload HBA after editing.

hostssl   postgres  app_user  192.0.2.0/24  scram-sha-256
hostnossl postgres  app_user  192.0.2.0/24  reject

With Oracle MySQL use --ssl-mode=VERIFY_IDENTITY --ssl-ca=ca.pem. With MariaDB use --ssl-verify-server-cert --ssl-ca=ca.pem. Connect to the certificate’s host and check the TLS status of this backend in the MySQL client.

SELECT ssl, version, cipher FROM pg_stat_ssl WHERE pid = pg_backend_pid();