https://github.com/ribbybibby/ssl_exporter

Exports metrics for certificates collected from various sources:

The metrics are labelled with fields from the certificate, which allows for informational dashboards and flexible alert routing.

Building

make
./ssl_exporter <flags>

Similarly to the blackbox_exporter, visiting http://localhost:9219/probe?target=example.com:443 will return certificate metrics for example.com. The ssl_probe_success metric indicates if the probe has been successful.

Docker

docker run -p 9219:9219 ribbybibby/ssl-exporter:latest <flags>

Release process

  • Create a release in Github with a semver tag and GH actions will:

    • Add a changelog
    • Upload binaries
    • Build and push a Docker image

Usage

usage: ssl_exporter [<flags>]

Flags:
-h, --help Show context-sensitive help (also try --help-long and
--help-man).
--web.listen-address=":9219"
Address to listen on for web interface and telemetry.
--web.metrics-path="/metrics"
Path under which to expose metrics
--web.probe-path="/probe" Path under which to expose the probe endpoint
--config.file="" SSL exporter configuration file
--log.level="info" Only log messages with the given severity or above. Valid
levels: [debug, info, warn, error, fatal]
--log.format="logger:stderr"
Set the log target and format. Example:
"logger:syslog?appname=bob&local=7" or
"logger:stdout?json=true"
--version Show application version.

Metrics

Metric Meaning Labels Probers
ssl_cert_not_after The date after which a peer certificate expires. Expressed as a Unix Epoch Time. serial_no, issuer_cn, cn, dnsnames, ips, emails, ou tcp, https
ssl_cert_not_before The date before which a peer certificate is not valid. Expressed as a Unix Epoch Time. serial_no, issuer_cn, cn, dnsnames, ips, emails, ou tcp, https
ssl_file_cert_not_after The date after which a certificate found by the file prober expires. Expressed as a Unix Epoch Time. file, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou file
ssl_file_cert_not_before The date before which a certificate found by the file prober is not valid. Expressed as a Unix Epoch Time. file, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou file
ssl_kubernetes_cert_not_after The date after which a certificate found by the kubernetes prober expires. Expressed as a Unix Epoch Time. namespace, secret, key, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou kubernetes
ssl_kubernetes_cert_not_before The date before which a certificate found by the kubernetes prober is not valid. Expressed as a Unix Epoch Time. namespace, secret, key, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou kubernetes
ssl_kubeconfig_cert_not_after The date after which a certificate found by the kubeconfig prober expires. Expressed as a Unix Epoch Time. kubeconfig, name, type, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou kubeconfig
ssl_kubeconfig_cert_not_before The date before which a certificate found by the kubeconfig prober is not valid. Expressed as a Unix Epoch Time. kubeconfig, name, type, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou kubeconfig
ssl_ocsp_response_next_update The nextUpdate value in the OCSP response. Expressed as a Unix Epoch Time   tcp, https
ssl_ocsp_response_produced_at The producedAt value in the OCSP response. Expressed as a Unix Epoch Time   tcp, https
ssl_ocsp_response_revoked_at The revocationTime value in the OCSP response. Expressed as a Unix Epoch Time   tcp, https
ssl_ocsp_response_status The status in the OCSP response. 0=Good 1=Revoked 2=Unknown   tcp, https
ssl_ocsp_response_stapled Does the connection state contain a stapled OCSP response? Boolean.   tcp, https
ssl_ocsp_response_this_update The thisUpdate value in the OCSP response. Expressed as a Unix Epoch Time   tcp, https
ssl_probe_success Was the probe successful? Boolean.   all
ssl_prober The prober used by the exporter to connect to the target. Boolean. prober all
ssl_tls_version_info The TLS version used. Always 1. version tcp, https
ssl_verified_cert_not_after The date after which a certificate in the verified chain expires. Expressed as a Unix Epoch Time. chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou tcp, https
ssl_verified_cert_not_before The date before which a certificate in the verified chain is not valid. Expressed as a Unix Epoch Time. chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou tcp, https

Configuration

TCP

Just like with the blackbox_exporter, you should pass the targets to a single instance of the exporter in a scrape config with a clever bit of relabelling. This allows you to leverage service discovery and keeps configuration centralised to your Prometheus config.

scrape_configs:
- job_name: "ssl"
metrics_path: /probe
static_configs:
- targets:
- example.com:443
- prometheus.io:443
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9219 # SSL exporter.

HTTPS

By default the exporter will make a TCP connection to the target. This will be suitable for most cases but if you want to take advantage of http proxying you can use a HTTPS client by setting the https module parameter:

scrape_configs:
- job_name: "ssl"
metrics_path: /probe
params:
module: ["https"] # <-----
static_configs:
- targets:
- example.com:443
- prometheus.io:443
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9219

This will use proxy servers discovered by the environment variables HTTP_PROXYHTTPS_PROXY and ALL_PROXY. Or, you can set the proxy_url option in the module configuration.

The latter takes precedence.

File

The file prober exports ssl_file_cert_not_after and ssl_file_cert_not_before for PEM encoded certificates found in local files.

Files local to the exporter can be scraped by providing them as the target parameter:

curl "localhost:9219/probe?module=file&target=/etc/ssl/cert.pem"

The target parameter supports globbing (as provided by the doublestar package), which allows you to capture multiple files at once:

curl "localhost:9219/probe?module=file&target=/etc/ssl/**/*.pem"

One specific usage of this prober could be to run the exporter as a DaemonSet in Kubernetes and then scrape each instance to check the expiry of certificates on each node:

scrape_configs:
- job_name: "ssl-kubernetes-file"
metrics_path: /probe
params:
module: ["file"]
target: ["/etc/kubernetes/**/*.crt"]
kubernetes_sd_configs:
- role: node
relabel_configs:
- source_labels: [__address__]
regex: ^(.*):(.*)$
target_label: __address__
replacement: ${1}:9219

Kubernetes

The kubernetes prober exports ssl_kubernetes_cert_not_after and ssl_kubernetes_cert_not_before for PEM encoded certificates found in secrets of type kubernetes.io/tls.

Provide the namespace and name of the secret in the form <namespace>/<name> as the target:

curl "localhost:9219/probe?module=kubernetes&target=kube-system/secret-name"

Both the namespace and name portions of the target support glob matching (as provided by the doublestar package):

curl "localhost:9219/probe?module=kubernetes&target=kube-system/*"

curl "localhost:9219/probe?module=kubernetes&target=*/*"

The exporter retrieves credentials and context configuration from the following sources in the following order:

  • The kubeconfig path in the module configuration
  • The $KUBECONFIG environment variable
  • The default configuration file ($HOME/.kube/config)
  • The in-cluster environment, if running in a pod
- job_name: "ssl-kubernetes"
metrics_path: /probe
params:
module: ["kubernetes"]
static_configs:
- targets:
- "test-namespace/nginx-cert"
relabel_configs:
- source_labels: [ __address__ ]
target_label: __param_target
- source_labels: [ __param_target ]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9219

Kubeconfig

The kubeconfig prober exports ssl_kubeconfig_cert_not_after and ssl_kubeconfig_cert_not_before for PEM encoded certificates found in the specified kubeconfig file.

Kubeconfigs local to the exporter can be scraped by providing them as the target parameter:

curl "localhost:9219/probe?module=kubeconfig&target=/etc/kubernetes/admin.conf"

One specific usage of this prober could be to run the exporter as a DaemonSet in Kubernetes and then scrape each instance to check the expiry of certificates on each node:

scrape_configs:
- job_name: "ssl-kubernetes-kubeconfig"
metrics_path: /probe
params:
module: ["kubeconfig"]
target: ["/etc/kubernetes/admin.conf"]
kubernetes_sd_configs:
- role: node
relabel_configs:
- source_labels: [__address__]
regex: ^(.*):(.*)$
target_label: __address__
replacement: ${1}:9219

Configuration file

You can provide further module configuration by providing the path to a configuration file with --config.file. The file is written in yaml format, defined by the schema below.

# The default module to use. If omitted, then the module must be provided by the
# 'module' query parameter
default_module: <string> # Module configuration
modules: [<module>]

<module>

# The type of probe (https, tcp, file, kubernetes, kubeconfig)
prober: <prober_string> # The probe target. If set, then the 'target' query parameter is ignored.
# If omitted, then the 'target' query parameter is required.
target: <string> # How long the probe will wait before giving up.
[ timeout: <duration> ] # Configuration for TLS
[ tls_config: <tls_config> ] # The specific probe configuration
[ https: <https_probe> ]
[ tcp: <tcp_probe> ]
[ kubernetes: <kubernetes_probe> ]

<tls_config>

# Disable target certificate validation.
[ insecure_skip_verify: <boolean> | default = false ] # Configure TLS renegotiation support.
# Valid options: never, once, freely
[ renegotiation: <string> | default = never ] # The CA cert to use for the targets.
[ ca_file: <filename> ] # The client cert file for the targets.
[ cert_file: <filename> ] # The client key file for the targets.
[ key_file: <filename> ] # Used to verify the hostname for the targets.
[ server_name: <string> ]

<https_probe>

# HTTP proxy server to use to connect to the targets.
[ proxy_url: <string> ]

<tcp_probe>

# Use the STARTTLS command before starting TLS for those protocols that support it (smtp, ftp, imap, pop3, postgres)
[ starttls: <string> ]

<kubernetes_probe>

# The path of a kubeconfig file to configure the probe
[ kubeconfig: <string> ]

Example Queries

Certificates that expire within 7 days:

ssl_cert_not_after - time() < 86400 * 7

Wildcard certificates that are expiring:

ssl_cert_not_after{cn=~"\*.*"} - time() < 86400 * 7

Certificates that expire within 7 days in the verified chain that expires latest:

ssl_verified_cert_not_after{chain_no="0"} - time() < 86400 * 7

Number of certificates presented by the server:

count(ssl_cert_not_after) by (instance)

Identify failed probes:

ssl_probe_success == 0

Peer Certificates vs Verified Chain Certificates

Metrics are exported for the NotAfter and NotBefore fields for peer certificates as well as for the verified chain that is constructed by the client.

The former only includes the certificates that are served explicitly by the target, while the latter can contain multiple chains of trust that are constructed from root certificates held by the client to the target's server certificate.

This has important implications when monitoring certificate expiry.

For instance, it may be the case that ssl_cert_not_after reports that the root certificate served by the target is expiring soon even though clients can form another, much longer lived, chain of trust using another valid root certificate held locally. In this case, you may want to use ssl_verified_cert_not_after to alert on expiry instead, as this will contain the chain that the client actually constructs:

ssl_verified_cert_not_after{chain_no="0"} - time() < 86400 * 7

Each chain is numbered by the exporter in reverse order of expiry, so that chain_no="0" is the chain that will expire the latest. Therefore the query above will only alert when the chain of trust between the exporter and the target is truly nearing expiry.

It's very important to note that a query of this kind only represents the chain of trust between the exporter and the target. Genuine clients may hold different root certs than the exporter and therefore have different verified chains of trust.

Grafana

You can find a simple dashboard here that tracks certificate expiration dates and target connection errors.

[转帖]SSL Certificate Exporter的更多相关文章

  1. SSL certificate problem unable to get local issuer certificate解决办法

    SSL certificate problem unable to get local issuer certificate 解决办法: 下载:ca-bundle.crt 将它放在自己的wamp或者x ...

  2. How To Set Up Apache with a Free Signed SSL Certificate on a VPS

    Prerequisites Before we get started, here are the web tools you need for this tutorial: Google Chrom ...

  3. How To Create a SSL Certificate on Apache for CentOS 6

    About Self-Signed Certificates 自签证书.一个SSL证书,是加密网站的信息,并创建更安全的链接的一种方式.附加地,证书可以给网站浏览者显示VPS的的身份证明信息.如果一个 ...

  4. Configure custom SSL certificate for RDP on Windows Server 2012 in Remote Administration mode

    Q: So the release of Windows Server 2012 has removed a lot of the old Remote Desktop related configu ...

  5. (转)How to renew your Apple Push Notification Push SSL Certificate

    转自:https://blog.serverdensity.com/how-to-renew-your-apple-push-notification-push-ssl-certificate/ It ...

  6. 执行Git命令时出现 SSL certificate problem 的解决办法

    比如我在windows下用git clone gitURL 就提示  SSL certificate problem: self signed certificate 这种问题,在windows下出现 ...

  7. last error : SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate veri

    今天在用搜狐提供的邮件群发系统的sdk,做发送邮件的测试时,提示: last error : SSL certificate problem, verify that the CA cert is O ...

  8. Failed to connect to VMware Lookup Service……SSL certificate verification failed

    今天登陆vsphere web-client时候,报错如下: Failed to connect to VMware Lookup Service https://vc-test.cebbank.co ...

  9. The SSL certificate used to load resources from xxx will be distrusted in M70.

    今天在浏览网站的时候遇到如下报警信息: The SSL certificate used to load resources from https://xxx.com will be distrust ...

  10. 执行Git命令时出现各种 SSL certificate problem 的解决办法

    执行Git命令时出现各种 SSL certificate problem 的解决办法 来源  https://www.cnblogs.com/chenzc/p/5842932.html 比如我在win ...

随机推荐

  1. Angular 实现分页器组件

    很感谢 angular实现简单的pagination分页组件 - Amor丶Diamond - 博客园 (cnblogs.com) , 我根据这位博主代码做了修改, 增加了跳转和每页行数功能. 先看图 ...

  2. 2023-06-01:讲一讲Redis常见数据结构以及使用场景。

    2023-06-01:讲一讲Redis常见数据结构以及使用场景. 答案2023-06-01: 字符串(String) 适合场景 缓存功能 Redis 作为缓存层,MySQL 作为存储层,在大部分请求中 ...

  3. 手把手教你使用ModelArts的自动学习识别毒蘑菇分类

    摘要:本文介绍了ModelArts如何通过自动学习进行毒蘑菇的识别. 想当年,白雪公主吃了毒蘑菇,换来了白马王子的一吻.如果白雪公主没有吃毒蘑菇,还会遇到白马王子吗?张小白觉得不见得--说不定她会遇到 ...

  4. 教你用Python自制拼图小游戏,轻松搞定熊孩子

    摘要:本文主要为大家详细介绍了python实现拼图小游戏,文中还有示例代码介绍,感兴趣的小伙伴们可以参考一下. 开发工具 Python版本:3.6.4 相关模块: pygame模块: 以及一些Pyth ...

  5. 终于搞懂了Python模块之间的相互引用问题

    摘要:详细讲解了相对路径和绝对路径的引用方法. 在某次运行过程中出现了如下两个报错: 报错1: ModuleNotFoundError: No module named '__main__.src_t ...

  6. 华为云开天aPaaS 上线,服务千万开发者,使能行业场景化创新

    摘要:9月25日,华为云在华为全联接2021发布四大生态策略,并宣布2022年投入1亿美元升级沃土云创计划.华为云开天aPaaS正式上线,实现经验即服务,使能行业场景化创新. 本文分享自华为云社区&l ...

  7. 云图说|玩转华为HiLens之端云协同AI开发

    阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要: 华为HiLens ...

  8. 译文丨伯克利对serverless的看法:简化云编程

    摘要:Serveless计算的目标和机会是让云编程者像使用高级语言那样受益. 本文分享自华为云社区<简化云编程,伯克利对serverless的看法(翻译)>,作者: 二手雄狮. 译者言: ...

  9. 再谈BOM和DOM(5):各个大流浪器DOM和BOM里面的那些坑—兼容性

    三大不冒泡事件 所有浏览器的focus/blur事件都不冒泡,万幸的是大部分浏览器支持focusin/focusout事件,不过可恶的firefox连这个都不支持. IE6.7.8下 submit事件 ...

  10. 小姐姐跳舞,AI 视频生成太酷了

    大家好,我是章北海 最近AI视频领域的研究进展神速,看得眼花缭乱. 这里老章就把最近几天看过印象深刻的四个项目介绍给大家,同时附上项目相关简介.论文.代码等资料,感兴趣的同学可以深度研究一下. < ...