TLS for Databases and Message Brokers: Tracking Certificate Expiry

TLS for Databases and Message Brokers: Tracking Certificate Expiry

Database and message broker certificates are the TLS certificates most likely to expire unnoticed, because no browser ever loads them and no external uptime check ever touches them. If you run PostgreSQL, MySQL, MongoDB, Kafka or RabbitMQ with encryption in transit, this article explains how to track certificate expiry for these backend services, why standard HTTPS monitoring misses them, and how to build checks that catch problems 30 days ahead instead of at 3 a.m. during a failover.

Why Backend TLS Certificates Escape Normal Monitoring

Most SSL monitoring is built around HTTPS on port 443. A checker opens a connection, reads the certificate, and records the expiry date. Database and broker endpoints don’t fit that model.

PostgreSQL doesn’t start TLS immediately on connect. The client first sends an SSLRequest message, and only then does the TLS handshake begin. MySQL negotiates in a similar way inside its own protocol. A generic HTTPS checker pointed at port 5432 or 3306 gets back nothing it can read and reports an error, or silently reports nothing.

Kafka (usually 9093 for SSL listeners) and RabbitMQ (5671 for AMQPS) use direct TLS, so they are easier to probe. They still usually sit on private networks that external monitors can’t reach. These certificates also come from an internal CA, which brings its own lifecycle problems.

Common Myth: An Expired Database Certificate Breaks Things Immediately

Many teams assume that if a database certificate expires, applications will fail right away and someone will notice within minutes. That rarely happens.

The TLS certificate is checked only during the handshake. Existing connections keep working after expiry. Connection pools in HikariCP, PgBouncer or SQLAlchemy can hold sessions open for days. The outage shows up later, when something forces a reconnect: a deploy, a pod reschedule, a pooler restart, or a primary failover.

A typical failure looks like this. A PostgreSQL replica certificate expires on a Saturday and nothing happens. Nine days later the primary fails at 02:40, Patroni promotes the replica, and every application rejects the new primary with “certificate has expired”. The cert ran out over a week before. It only became an outage when the system was already under stress.

There is a second problem. Clients using PostgreSQL sslmode=require encrypt the connection but don’t verify the certificate at all. An expired certificate goes unnoticed for months. Then a security review moves everything to verify-full, and the old expiry becomes a production incident on the day you meant to improve security.

How to Track Certificate Expiry on Databases and Brokers

An experienced platform engineer starts with inventory and only then adds alerts. Finding every TLS-enabled backend endpoint is the hard part. If you don’t have a register yet, the approach in building an SSL certificate inventory applies to internal services too.

Then work through these steps:

Step 1 – Probe with protocol-aware tools. OpenSSL 1.1.1 and later can negotiate PostgreSQL and MySQL TLS directly: openssl s_client -connect db01:5432 -starttls postgres or -starttls mysql. Pipe the output to openssl x509 -noout -enddate to get the expiry date. For Kafka, RabbitMQ and Redis 6+ with TLS, a plain -connect host:port is enough. More command-line patterns are in this guide to checking SSL certificate health from the command line.

Step 2 – Check certificates on disk, not just on the wire. Kafka brokers and Java clients keep certificates in JKS or PKCS12 keystores. keytool -list -v -keystore kafka.server.keystore.jks shows the “Valid until” line for every entry, including client certificates that no network probe will ever see.

Step 3 – Include client certificates and the CA itself. With mTLS, each producer, consumer and replication user has its own certificate. Your internal intermediate or root CA also has an expiry date. A 5-year internal root issued in 2021 expires in 2026, and when it does, every certificate it signed stops validating at once.

Step 4 – Set alert thresholds that leave time for change windows. Database certificate rotation often needs a maintenance window and coordinated client updates. Alerts at 30, 14, 7 and 1 days work well. Make sure the 30-day alert goes to a ticket queue and not only to a chat channel.

Step 5 – Verify the running process actually reloaded. Renewing the file on disk is not the same as serving the new certificate. Probe the endpoint again after rotation and compare serial numbers.

Reload Behavior Differs by Engine

The renewal is rarely what goes wrong. The reload is. Each engine handles it differently.

PostgreSQL 10 and later picks up new certificate files on pg_ctl reload or SIGHUP, with no restart needed. MySQL 8.0.16 added ALTER INSTANCE RELOAD TLS. Before that version, a restart was required. MongoDB 5.0 introduced the rotateCertificates command. Kafka supports dynamic keystore updates per listener through kafka-configs.sh –alter. RabbitMQ is the one that catches people out: Erlang caches PEM files, so replacing the certificate does nothing until you clear the cache with ssl:clear_pem_cache() or restart the node.

If your automation renews certificates through cert-manager, Vault PKI or an Ansible playbook, the reload step must be part of the same job. Monitoring the live endpoint is what tells you whether that step actually ran.

Mistakes That Cause Backend Certificate Outages

Monitoring only the load balancer address. A Kafka cluster with six brokers has six certificates, sometimes renewed at different times. Checking the bootstrap address shows one broker. The other five can drift. Probe every broker and every replica directly.

Trusting the renewal job’s exit code. A cron job that writes a fresh PEM and exits 0 tells you nothing about what the server is serving. RabbitMQ will keep presenting the old certificate until it expires.

Forgetting non-production paths that production depends on. Replication streams, CDC connectors like Debezium, and backup agents connecting over TLS all hold their own trust stores and sometimes their own client certificates. They fail quietly, and the first sign is often a backup that didn’t run.

For broader coverage of private-network endpoints, see monitoring SSL certificates for internal enterprise systems.

Edge Cases Worth Planning For

The CA/Browser Forum validity reductions (200 days from March 2026, 100 days from March 2027 and 47 days from March 2029) apply only to publicly trusted certificates. Internal CAs aren’t bound by them. Many teams still issue 1-2 year database certificates, which means rotation happens so rarely that nobody remembers how it works.

Air-gapped and regulated environments, such as banking cores or healthcare systems under strict change control, often can’t run external probes at all. In those cases, an agent-based check reading keystores and PEM files locally, feeding into Prometheus via something like the x509-certificate-exporter, is the practical option.

Small teams with a single managed database on AWS RDS or Azure Database for PostgreSQL have a different issue: the server certificate is managed for them, but the provider’s CA bundle is not. AWS rotated RDS CAs to rds-ca-rsa2048-g1 in 2024, and applications pinning the old bundle broke on rotation.

FAQ

Can a standard SSL checker monitor PostgreSQL certificates?
Usually not. PostgreSQL negotiates TLS after an SSLRequest message, so the checker needs STARTTLS-style support for the postgres protocol. PostgreSQL 17 added direct TLS negotiation, but clients and checkers must explicitly opt in.

Do Kafka client certificates need monitoring too?
Yes. With mTLS, an expired client certificate causes the broker to reject that producer or consumer. Message flow stops for that service while the cluster itself looks healthy.

How far in advance should database certificate alerts fire?
At least 30 days. Backend rotations often need change approval, client trust store updates and a maintenance window, and 7 days is rarely enough for all three.

Final Practical Tip

Treat every TLS-enabled database and broker port as a monitored endpoint with its own expiry date, not as an implementation detail. Probe each node with protocol-aware tools, read keystores for client certificates, track your internal CA’s expiry, and verify after every renewal that the running process serves the new serial. Expiry at the moment of a failover is the outage you are preventing, and you only see it coming if you are already checking.