Verify a Certificate Renewal Before the Old Certificate Expires

Published · System Administration

A certificate authority issued the replacement. The renewal job exited successfully. The certificate on disk has a reassuring expiration date. None of that proves your customers are receiving it.

The awkward failure is a successful renewal followed by an incomplete deployment: a proxy that never reloaded, an old load-balancer listener, or a second region still serving the previous certificate. Everything looks healthy until the old certificate expires and a supposedly finished maintenance task becomes an incident.

Treat renewal as a delivery workflow with an observable result. The result is a valid, intended certificate served on every required client path, with enough time remaining to repair a failed rollout.

Inventory the places that terminate TLS

Start with the connection path, not the directory containing the certificate files. A public hostname might terminate at a CDN, a regional load balancer, an ingress proxy, or the application itself. Some systems terminate TLS more than once.

Write a small inventory that someone outside the renewal automation can understand:

Connection path Certificate consumer Verification route Accountable owner
Public API hostname Edge listener External probe using the public hostname Edge platform team
Regional origin Regional proxy Authorized direct probe preserving the TLS name Service platform team
Internal service name Private ingress Probe from the client network and trust store Service owner

Those are example roles, not a required architecture. Record the actual hostname, port, environment, deployment mechanism, and recovery contact for each consumer. Include IPv4 and IPv6 paths when both are supported. Include separate certificate variants when the platform intentionally serves different ones to different clients.

A certificate installed at the origin says nothing about the certificate a CDN presents to a browser. Likewise, probing only the CDN does not verify an origin certificate used for the next encrypted hop. Name both checks when both matter.

The production-secret rotation guide covers accountable replacement and revocation. Certificate renewal adds a particularly visible acceptance test: what does the remote endpoint actually serve?

Give issuance and deployment separate evidence

Use a short progression: requested, issued, installed, loaded, externally verified. A timestamp at one stage should not silently stand in for the next.

Record the expected leaf certificate's SHA-256 fingerprint, validity interval, names, and intended destinations. Obtain that identity from the issued artifact or the provider's certificate inventory. Keep private keys out of probe logs and tickets.

For managed certificate services, the provider may control distribution and choose among several valid leaf certificates. Define the acceptable set or provider-backed deployment state instead of assuming every listener must have one fingerprint. That decision belongs in the inventory before an alert starts firing.

Certbot's renewal documentation illustrates the distinction: certbot renew can exit successfully when nothing needed renewal. A deploy hook runs after successful renewal, but the hook's existence does not prove its downstream effects. Monitor deployment and endpoint verification separately. A renewal dry run is useful evidence about the renewal mechanism; it is not evidence that production endpoints now serve a replacement.

Check the TLS name and the destination deliberately

The following diagnostic sequence uses Bash and the OpenSSL CLI. It was exercised with OpenSSL 4.1.0; the options are also documented in OpenSSL 3.5. Check openssl version first, especially on macOS, where another binary may be LibreSSL. Set ca_bundle to a real PEM trust bundle approved for the clients you are representing.

tls_name is the DNS identity clients expect. connect_to is the socket destination. Usually they name the same service. For an authorized direct-listener check, the destination can be an IP address while the TLS identity stays the public hostname.

#!/usr/bin/env bash
set -euo pipefail

tls_name=api.example.com
connect_to=api.example.com:443
ca_bundle=/path/to/approved-ca-bundle.pem
minimum_remaining_seconds=604800  # Illustrative seven-day margin

probe_dir=$(mktemp -d)
trap 'rm -rf "$probe_dir"' EXIT

openssl s_client \
  -connect "$connect_to" \
  -servername "$tls_name" \
  -verify_hostname "$tls_name" \
  -verify_return_error \
  -CAfile "$ca_bundle" \
  -no_ign_eof \
  </dev/null >"$probe_dir/session.txt" 2>"$probe_dir/verify.txt"

awk '/-----BEGIN CERTIFICATE-----/ {copy=1}
     copy {print}
     /-----END CERTIFICATE-----/ {exit}' \
  "$probe_dir/session.txt" >"$probe_dir/leaf.pem"

openssl x509 -in "$probe_dir/leaf.pem" -noout \
  -subject -issuer -serial -dates -fingerprint -sha256

openssl x509 -in "$probe_dir/leaf.pem" -noout \
  -checkend "$minimum_remaining_seconds"

The OpenSSL client reference documents the important controls here: SNI selects the virtual service, hostname verification checks its identity, and -verify_return_error makes verification failures abort. Merely seeing a completed connection is insufficient.

The certificate inspection reference documents the fingerprint, validity output, and remaining-lifetime check. A successful final check says the leaf exceeds the selected margin; compare the printed fingerprint with the expected artifact too. An old certificate may still pass both trust validation and a seven-day check. This snippet prints identity for review; it does not automate that comparison or certify an entire deployment.

The temporary directory prevents an earlier successful capture from being reused after a failed probe. Bash stops on an unsuccessful command. When troubleshooting a failure, retain the diagnostic files in a protected location before cleanup; do not “fix” a trust failure by removing verification.

This is an interactive diagnostic, not a finished monitoring agent. Run automated probes under a bounded execution timeout, capture the failing stage, and alert on connection or parsing failures as well as expiry. The script does not perform a revocation check or an application request. Add those separately when your acceptance criteria require them.

Verify coverage, not just one lucky handshake

A fresh process creates a new connection, but it can still reach the same load-balancer member repeatedly. Ten successes from one laptop are ten observations, not proof that every replica reloaded.

Combine client-path probes with deployment evidence:

  • Check every known listener, region, and supported address family.
  • Use independent probe locations where geography or routing changes the endpoint.
  • Confirm certificate assignment and rollout completion through the platform's inventory.
  • Probe authorized individual terminators when the architecture exposes them.
  • Exercise relevant client capabilities when they select different certificate variants.

Do not bypass a private origin's access controls just to make an external checker work. Run the check from an authorized network with the correct trust roots. An internal trust model may differ from a browser's, so preserve that distinction in the results.

After TLS verification, perform a harmless application health request using a client that validates TLS. That catches a listener that presents the right certificate but routes to the wrong service. Keep authentication material and request side effects out of the certificate probe itself.

If loading a certificate requires process replacement, coordinate with the service-shutdown guide. Certificate maintenance is a poor reason to drop accepted requests through an untested restart.

Alert while recovery is still ordinary work

Monitor the certificate being served, the renewal process, and deployment completion. Each signal answers a different question. An issuer success metric cannot replace an outside-in expiry check.

Choose warning thresholds from the time needed to notice, investigate, obtain a replacement, deploy it, and verify all paths. The seven-day margin above is an example, not a universal policy. Short-lived certificates need a cadence and recovery budget compatible with their lifetime.

An alert should identify the hostname, observed certificate identity, expiry, probe location, failed stage, and owner. “TLS problem” sends the responder back to discovery work when the clock is already running.

A partially deployed renewal deserves attention even while the old certificate remains valid. Resolve mismatched listeners before the expiry alert becomes the first user-visible symptom.

Write the recovery decision before the deadline

Keep a tested path for repairing distribution or reloading the intended certificate. Identify who can change a managed listener, repair issuer credentials, or arrange emergency issuance. Confirm that the backup responder can reach those controls.

Returning to a previous certificate is only a temporary option if that certificate remains valid, trusted, appropriate for the hostname, and uncompromised. It creates no additional time beyond its existing expiry. Never turn disabled verification into the recovery plan, and do not restore a revoked or compromised identity.

Close the renewal task when the expected certificate set is loaded, required paths verify, monitoring recognizes the result, and an owner accepts any remaining exception. Successful issuance is a useful milestone. The endpoint is where the promise has to hold.

Find more practical infrastructure guidance at Slaptijack.

Slaptijack's Koding Kraken