Expired SSL certificates are a common and avoidable cause of downtime. When a certificate expires, browsers and API clients refuse to connect, and a website or application goes down until someone renews it.
Despite this, many organizations do not monitor certificate expiry dates. In 2018, an expired SSL certificate caused a widespread outage for O2 mobile customers in the UK. And in 2020, a root CA certificate issued by Sectigo expired, causing issues for a large number of websites.
Announcing the K8s SSL Validity Exporter
The Facets team built the K8s SSL Validity Exporter, an open-source tool that monitors SSL certificate expiry dates centrally in any Kubernetes cluster. It exports the metric for the entire certificate chain, including root and intermediate certificates, so an expiring intermediate certificate does not surprise you either.
How does it work?
The exporter scans for Kubernetes ingress objects to determine the unique set of domains to monitor. It then opens a TLS connection and retrieves the certificate chain for each domain. For each certificate in the chain, the exporter publishes a gauge metric called ssl_expiry, with the number of days until expiry as the gauge value, and these labels:
ssl_expiry{common_name = "commonName",domain = "ssl-checker.com",ingress = "default",namespace = "default"} 57Installation
The easiest way to deploy the exporter is with its Helm chart:
- Add the Helm repository:
helm repo add k8s-ssl-validity-exporter https://facets-cloud.github.io/k8s-ssl-validity-exporter/charts
helm repo update- Install the Helm chart:
helm install k8s-ssl-validity-exporter k8s-ssl-validity-exporter/k8s-ssl-validity-exporterIf you use the prometheus-operator, the Helm chart creates a ServiceMonitor, so Prometheus scrapes the new ssl_expiry metric.
Setting up Prometheus alerts
To alert the relevant team when a certificate is close to expiry, add an alert rule on the ssl_expiry metric. With the prometheus-operator, a PrometheusRule like this one fires when any certificate in a chain has fewer than 15 days left:
1234567891011121314151617apiVersion: monitoring.coreos.com/v1kind: PrometheusRulemetadata:name: ssl-certificate-expirynamespace: monitoringspec:groups:- name: ssl-certificatesrules:- alert: SSLCertificateExpiringSoonexpr: ssl_expiry < 15for: 1hlabels:severity: warningannotations:summary: "SSL certificate for {{ $labels.domain }} expires in {{ $value }} days"description: "The certificate {{ $labels.common_name }} for {{ $labels.domain }} (ingress {{ $labels.ingress }} in namespace {{ $labels.namespace }}) expires soon. Renew it before it lapses."
Your Prometheus may only pick up rules with certain labels (the ruleSelector of your Prometheus resource), so add those labels to the metadata if your setup needs them. Without the prometheus-operator, put the same expr, for, labels and annotations in a standard Prometheus rules file.
You get an alert days before a certificate expires, with the domain and ingress that need it.
Before you go…
Try the exporter and tell us what you think. You can also contribute directly to the GitHub project.
Facets is the infrastructure delivery platform for developers and their AI assistants. See why Facets or book a demo.
