由于Let’s Encrypt 交叉信任根 DST Root CA X3 过期导致的 Sentry 无法正常报告Event

背景

Let’s Encrypt是一个为1.8亿个网站提供TLS证书的非盈利性证书颁发机构。它具有免费、开放以及良好的自动化集成特性,目的是以尽可能对用户友好的方式免费提供为网站启用 HTTPS(SSL/TLS)所需的数字证书。
Let’s Encrypt是一个相对较新的项目,众所周知,如果一个CA不能被广泛信任,那么就失去了在互联网环境下使用它的意义。下图是Let’s Encrypt目前的证书链。

Let’s Encrypt一开始使用IdenTrust DST Root CA X3这个已经被浏览器和系统广泛信任的CA来做为它的根,同时LE从很早就开始推进他们的根ISRG Root X1进入各个浏览器和系统的根CA列表。
但是需要注意的是,IdenTrust DST Root CA X3目前已经过期了!

信任是链式的,根证书的过期导致了由DST签发的CA以及最终实体的证书都无法被信任,由于Let’s Encrypt自己的根ISRG Root X1最近几年才陆续被信任,这就导致了一部分的客户端在9月30日后就无法与使用Let’s Encrypt证书的服务器建立连接了。注:1. 关于兼容列表可以参考 https://letsencrypt.org/docs/certificate-compatibility/2. 部分老的安卓设备,由于不会校验根证书的过期时间,会通过上图中的新链来保证信任,可参考 https://letsencrypt.org/2020/12/21/extending-android-compatibility.html

故障及处理

我们发现从2021年10月1日开始,Sentry不再报告事件了。我们登录实例执行

Sentry.capture_message("test message")

尝试发送测试信息,得到以下报错

Sending envelope [event] xxxxx to Sentry
Event sending failed: SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired)
Unreported Event: test message

同时在机器上执行curl,也可以发现同样的错误

[ubuntu@ip-172-27-253-84 current]$ curl -I https://xxxxx.ingest.sentry.io
curl: (60) SSL certificate problem: certificate has expired
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

最简单的,我们是使用SSL Labs来确认Sentry使用了什么证书,当然你也可以使用openssl来直接获取证书。


可以看到其拥有两条证书链,其中一条因为DST Root CA X3的过期,而不被信任。
解决方法也很简单,我们更新系统的CA证书库,添加ISRG的自签名CA


[ec2-user@ip-172-27-253-84 ~]$ sudo yum update ca-certificates -y
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                                                                                                                                                                                                            | 2.1 kB  00:00:00
amzn-updates                                                                                                                                                                                                                                                                                         | 3.8 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package ca-certificates.noarch 0:2017.2.14-65.0.1.17.amzn1 will be updated
---> Package ca-certificates.noarch 0:2018.2.22-65.1.24.amzn1 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================================================================================================
 Package                                                                       Arch                                                                 Version                                                                                Repository                                                                  Size
============================================================================================================================================================================================================================================================================================================================
Updating:
 ca-certificates                                                               noarch                                                               2018.2.22-65.1.24.amzn1                                                                amzn-updates                                                               1.0 M
Transaction Summary
============================================================================================================================================================================================================================================================================================================================
Upgrade  1 Package
Total download size: 1.0 M
Downloading packages:
ca-certificates-2018.2.22-65.1.24.amzn1.noarch.rpm                                                                                                                                                                                                                                                   | 1.0 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction

  Updating   : ca-certificates-2018.2.22-65.1.24.amzn1.noarch                                                                                                                                                                                                                                                           1/2
  Cleanup    : ca-certificates-2017.2.14-65.0.1.17.amzn1.noarch                                                                                                                                                                                                                                                         2/2
  Verifying  : ca-certificates-2018.2.22-65.1.24.amzn1.noarch                                                                                                                                                                                                                                                           1/2
  Verifying  : ca-certificates-2017.2.14-65.0.1.17.amzn1.noarch                                                                                                                                                                                                                                                         2/2
Updated:
  ca-certificates.noarch 0:2018.2.22-65.1.24.amzn1
Complete!

再次发送测试信息,可以看到Sentry中已经出现了。


后记

AWS的Premium Support也针对该问题做了完整的解答,可见
https://aws.amazon.com/cn/premiumsupport/knowledge-center/ec2-expired-certificate/为了保证Android老设备的兼容性,由DST签署的ISRG CA将于2024年过期,到时候又将遇到类似的问题。新的ISRG自签名CA将于2035年过期,所以及时将可以维护的设备升级,是解决该问题的根本方法。