Monitoring TLS Certificate Expiry

Static sites mostly get TLS for free: Cloudflare, Netlify, Vercel, GitHub Pages and Caddy all obtain and renew certificates without anyone touching them. That is precisely why expiry incidents still happen. When renewal is invisible, nobody notices when it stops working — a DNS record moved to a new provider, a CAA record added by the security team that does not list the platform's authority, an API token for a DNS challenge that expired, a forgotten subdomain still pointing at a server that was switched off. The first sign is readers seeing a full-page browser warning, often on a Saturday.

This guide sets up expiry and configuration monitoring for the domains behind a set of static sites: an inventory of every hostname, including forgotten ones, checks for expiry, coverage and chain, alert thresholds tied to renewal behaviour, and a test of the alerting itself. It is part of Monitoring Static Sites in Production, and complements Custom Domains and TLS on Cloudflare Pages.

Prerequisites

  • A list of the organisation's domains and DNS provider access.
  • An uptime or synthetic monitoring tool, or a scheduled CI job, to run checks.
  • An alerting channel that reaches a person (not only a dashboard).

Step 1: Build the Hostname Inventory

The hostnames you know about are not the problem. The forgotten ones are. Certificate Transparency logs record every publicly trusted certificate issued for your domains, which makes them an excellent inventory source:

curl -s "https://crt.sh/?q=%25.example.com&output=json" \
  | jq -r '.[].name_value' | tr '[:upper:]' '[:lower:]' | sed 's/^\*\.//' | sort -u > ct-hostnames.txt
wc -l ct-hostnames.txt

For the organisation's five static sites, the known list had 14 hostnames. CT logs showed 41, of which 23 still resolved in DNS. Among them: an old beta-docs.example.com still serving a two-year-old copy of the documentation from a forgotten VM with a manually installed certificate expiring in 19 days, and two event microsites on a platform host whose custom domains had been removed from the platform but not from DNS.

Hostnames discovered from the known list compared with Certificate Transparency logs Vertical bars. The known list of hostnames had 14 entries. Certificate Transparency logs listed 41 distinct hostnames. 23 of those still resolved in DNS and served something, including a forgotten beta docs host with a certificate expiring in 19 days. Hostnames found by each method 14 Known list 41 In CT logs 23 Still resolving
CT data from crt.sh for all organisation domains; DNS checked with dig for every name.

The forgotten beta host was decommissioned and its DNS record removed; the microsite records were removed too, closing a subdomain takeover risk as well as an expiry risk.

Step 2: Check More Than the Date

For each hostname, a check connects with TLS SNI and inspects what is actually served:

check() {
  host=$1
  out=$(echo | timeout 10 openssl s_client -connect "$host:443" -servername "$host" -showcerts 2>/dev/null)
  end=$(echo "$out" | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
  days=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 ))
  issuer=$(echo "$out" | openssl x509 -noout -issuer 2>/dev/null | sed 's/.*O = //;s/,.*//')
  san_ok=$(echo "$out" | openssl x509 -noout -ext subjectAltName 2>/dev/null | grep -qE "DNS:($host|\*\.${host#*.})" && echo yes || echo no)
  chain=$(echo "$out" | grep -c 'BEGIN CERTIFICATE')
  echo "$host days=$days issuer=\"$issuer\" san=$san_ok chain=$chain"
}
while read -r h; do check "$h"; done < hostnames.txt

The checks cover expiry, whether the certificate's names cover the hostname, the issuer (unexpected issuers suggest a hostname has moved to a different provider), and chain length (a single certificate without intermediates breaks some clients). Many uptime tools do this natively; the script is useful for a scheduled CI job and for understanding what the tools check.

TLS checks and the failures they detect A matrix of four checks. Days to expiry catches failed automatic renewal. Hostname coverage catches certificates for the wrong name after a DNS change. Issuer catches a hostname silently moving to another provider. Chain completeness catches servers sending only the leaf certificate, which breaks some clients. What each check catches Check Catches Past incidents Days to expiry failed auto-renewal 2 Hostname in SAN wrong cert after DNS change 1 Expected issuer host moved providers 0 Full chain served missing intermediates 1
Expiry is the most common failure, but the other three caused two of the four incidents in the previous two years.

Step 3: Thresholds That Match Renewal

Thresholds should reflect how the certificate is renewed. Platform-managed Let's Encrypt and Google Trust Services certificates are 90 days long and renew with about 30 days left. So:

  • Warning at 21 days: a platform certificate at 21 days has missed its renewal window; investigate during working hours.
  • Page at 7 days: renewal has failed repeatedly; someone must act today.
  • Manually managed certificates (one-year): warning at 45 days, page at 14.

Alerts go to the team channel and, at the paging threshold, to the on-call rotation. A daily check is sufficient; certificates do not change by the hour.

Step 4: Monitor the Renewal Prerequisites

The most useful checks look at why renewal would fail, before it does. For each domain: CAA records must allow the issuers the platforms use (letsencrypt.org, pki.goog, digicert.com for some Cloudflare certificates, sectigo.com for others); DNS must still point at the platform; and API tokens used for DNS-01 challenges on self-hosted Caddy must be valid. A CAA check caught one change in advance: the security team added 0 issue "digicert.com" to the apex domain as a hardening step, which would have blocked Let's Encrypt renewals for three sites; the check flagged the missing issuers the same day.

dig +short CAA example.com
# 0 issue "letsencrypt.org"
# 0 issue "pki.goog"
# 0 issue "digicert.com"
Prerequisites for automatic certificate renewal and their checks Automatic renewal needs DNS to point at the platform, CAA records to allow the platform's issuers, validation traffic or DNS API credentials to work, and the platform to still host the domain. Each prerequisite has a daily check. The expiry check at 21 days is the backstop when a prerequisite check misses something. What must stay true for renewal to work DNS points at host daily dig CAA allows issuers daily dig CAA Validation works tokens valid, port 80 open Domain still attached platform API Expiry backstop warn 21 d, page 7 d
Prerequisite checks warn weeks before an expiry check could.

Step 5: Test the Alert Path

An alert that has never fired may not work. The team keeps a test hostname with a deliberately short-lived certificate (issued with a 6-day validity from a private test setup, served on a staging VM, excluded from paging but included in warnings) so the warning path fires every week and proves the whole chain — check, threshold, notification — still works. When a notification integration broke after a chat tool migration, the weekly test caught it within days.

Beyond Certificates: The Rest of the TLS Picture

The same daily job checks two related properties that affect every reader. It records the negotiated protocol and cipher for each hostname, so a configuration change that disables TLS 1.3 or re-enables a legacy cipher is noticed; and it checks that HTTP requests redirect to HTTPS with a single hop, since a broken redirect after a platform migration can leave the plain-HTTP version serving content. For hostnames with HSTS, it verifies the header is present on the HTTPS response, because a site with HSTS preloaded and a broken certificate is unreachable rather than merely showing a warning, as described in Enabling HSTS and Preload Safely. These checks cost nothing extra — the connection is already open — and they have caught one regression: an nginx upgrade on a self-hosted mirror that reset its protocol list to a default without TLS 1.3.

Keep the hostname inventory in the repository as a plain text file, reviewed like code, so adding a new subdomain and adding its monitoring happen in the same pull request.

Measured Impact

MeasureBeforeAfter (12 months)
Hostnames monitored1423
Certificate-related incidents visible to readers4 in prior 2 years0
Renewal problems caught before expiry—3 (CAA change, moved DNS, expired DNS token)
Forgotten hosts found and removed—18
Median warning lead time before would-be expiry—19 days

Pitfalls & Rollback

  • Monitoring only the apex. Subdomains, previews and asset hosts expire too.
  • Trusting "managed" to mean "monitored". Managed renewal fails silently when DNS or CAA changes.
  • Checking dates but not names or chains. A valid certificate for the wrong host is still an outage.
  • Alerts that nobody receives. Test the alert path regularly.
  • Rollback: monitoring changes nothing on the sites; checks can be removed at any time.

Conclusion

Automatic certificates removed the routine work of TLS, not the need to know when it fails. Inventory every hostname from Certificate Transparency logs, check expiry, names, issuer and chain daily, set thresholds that match renewal behaviour, watch the prerequisites that renewal depends on, and prove the alert path works. On these sites that found eighteen forgotten hosts and caught three renewal failures weeks before any reader would have seen a warning page.

FAQ

If certificates renew automatically, why monitor them?

Automatic renewal fails silently more often than people expect, because of DNS changes, firewall rules blocking validation, CAA records, expired API credentials for DNS challenges, or a hostname that moved to a different provider. Monitoring catches the failure while there are still weeks left to fix it.

How early should expiry alerts fire?

With 90-day certificates renewed around 30 days before expiry, alert when fewer than 21 days remain, and page someone at 7 days. If a certificate reaches 21 days without being renewed, automatic renewal has already failed at least once.

Which hostnames should be monitored?

Every hostname that serves the site or its assets, including apex and www, subdomains for docs, previews and status pages, custom domains on platform hosts, and any CDN or image hostnames. Certificate Transparency logs are a good source for finding forgotten ones.

What else besides expiry should be checked?

That the certificate covers the hostname, that the full chain is served, that it is issued by the expected authority, and that the TLS configuration still supports modern protocols. A valid but wrong or incomplete certificate breaks some clients just as badly as an expired one.

Filed underHow-tos