Skip to content

fix(postgres): support or refuse the remaining libpq TLS parameters - #3416

Open
angela-helios wants to merge 2 commits into
mainfrom
fix/2765-postgres-tls-remaining-settings
Open

angela-helios wants to merge 2 commits into
mainfrom
fix/2765-postgres-tls-remaining-settings

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Refs #2765

This branch is stacked on the PR for #2764 (PR #3399): its diff includes that commit until #3399 merges.

Behaviour change to review

  • Unsupported ssl* URL parameters now refuse to start. HFS ignored them (for example ?ssl=true, ?sslcompression=0 or ?SSLMODE=require); HTS already refused them through the driver. The message names the parameter and never its value.
  • On Unix, a client key file that its group or others can use now refuses to start, by libpq's rule: 0600 or less, or 0640 or less when root owns the file. A key mounted from a Kubernetes secret with the default mode (0644) needs defaultMode.
  • New URL parameters on HFS and HTS: sslcrl, sslnegotiation, ssl_min_protocol_version, ssl_max_protocol_version. New variable HFS_PG_SSL_CRL (used when the URL has no sslcrl).
  • sslcrl is stricter than libpq in two cases where libpq ignores the setting: a mode that does not verify the server certificate, and a file that cannot be read, both refuse to start.
  • The CRL file is read at startup. Once a list is past its next update, new connections fail until a restart with a newer file.

Summary

Each libpq TLS setting on a connection URL is now either supported or refused with a clear message.

Item of #2765 Status
Unknown ssl* URL parameters Done: refused at startup
Key file permissions (Unix) Done: libpq's rule
sslcrl Done: URL and HFS_PG_SSL_CRL
ssl_min_protocol_version, ssl_max_protocol_version Done on the URL. TLS 1.2 is the oldest version rustls has: a maximum below it is refused, a minimum below it means TLS 1.2
sslnegotiation=direct Done on the URL; needs sslmode=require or stronger
sslpassword, encrypted client key Not done: refused with a message. Decrypting the key needs a crate that is not in Cargo.lock, and the issue asks for it only if there is demand
sslcrldir Not done: refused, pointing to sslcrl. libpq looks the files up by OpenSSL hash; rustls has no equivalent
~/.postgresql/* default files Not done, needs a decision: reading them would change the trust store of existing deployments. Both READMEs say they are not read
PG* environment variables Not done, needs a decision: variables already set for psql would start to change the servers. Both READMEs say they are not read
  • With sslcrl, every certificate of the chain except the trusted root needs a current list from its issuer, as in libpq. Revoked, not covered, or an expired list: the connection fails. verify-ca and require with a root certificate still do not check the host name.
  • sslnegotiation is set in PostgresTlsSettings::driver_config, so both pools and the stored-view LISTEN connection use it. With direct the client offers the ALPN protocol PostgreSQL requires.
  • No dependency was added or upgraded.

Tests

  • Unit (tls.rs): revoked, expired-list, uncovered and wrong-CA certificates; host name checked only by verify-full, also with a CRL; sslcrl refused without verification or with an unusable file; the permission rule, plus a real file on Unix; encrypted key message; protocol version bounds; sslnegotiation=direct per mode and in the driver configuration; URL parsing; refusal of unsupported ssl* parameters without their value.
  • Unit (backend.rs): the URL parameters reach PostgresTlsSettings; the refusal names the variable and not the value.
  • Unit (HTS build_pool): both connection string forms for sslnegotiation, protocol versions, refusals.
  • New fixtures (crl-ca.pem, crl-server.pem, crl-revoked.pem, crl.pem) in crates/persistence/tests/fixtures/pg_tls.
  • No test against a live server for sslcrl, sslnegotiation=direct or the protocol bounds.

Results:

  • cargo test -p helios-persistence --lib with all backend features, filtered to the touched modules (among them backends::postgres::tls and backends::postgres::backend::tests): 1202 passed.
  • cargo test -p helios-hts --features postgres --lib url_tls_tests: 6 passed.
  • cargo test -p helios-persistence --test postgres_tests postgres_tls against PostgreSQL containers: 4 passed (existing tests; none covers the new settings).
  • cargo test -p helios-hfs --bin hfs env_names: 7 passed.
  • These ran on Windows, where the Unix-only key-permission test does not run; Linux CI runs it. I did not run clippy locally; CI runs it.

These ran on current main together with three other pending fixes.

…ions

Read libpq's channel_binding (disable / prefer / require) from the
connection URL next to sslmode, plus HFS_PG_CHANNEL_BINDING as a minimum
for HFS. With require, a connection that was not authenticated with
SCRAM-SHA-256-PLUS is refused, so sslmode=require resists a
man-in-the-middle without a root certificate.

deadpool-postgres does not pass its channel_binding field to the driver,
so both pools are built through PostgresTlsSettings::pool_builder, which
sets it on the tokio_postgres::Config. An unknown value, or require with
sslmode=disable, refuses to start. The startup security log reports the
mode.

Closes #2764
Read sslcrl, sslnegotiation and ssl_min/max_protocol_version from the
connection URL on HFS and HTS, plus HFS_PG_SSL_CRL on HFS. Any other
ssl* parameter refuses to start instead of being ignored, and on Unix so
does an sslkey file open to its group or others, by libpq's rule.

sslpassword and sslcrldir are refused with a message. libpq's default
files and PG* variables are documented as not read.

Refs #2765
@claude

claude Bot commented Dec 2, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.


🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant