双向 TLS (mTLS) ↗ 通过对服务器和客户端的证书进行验证,为应用程序连接增加额外保护层。在构建 SaaS 应用时,你可能希望强制执行 mTLS,以保护与支付处理、数据库更新等相关的敏感端点。
最低 TLS 版本 仅允许支持所选 TLS 协议版本或更新版本的访问者建立 HTTPS 连接。Cloudflare 建议使用 TLS 1.2,以符合支付卡行业 (PCI) 安全标准委员会的要求。作为 SaaS 提供商,你可控制整个 zone 以及各个自定义主机名的最低 TLS 版本。
密码套件 是在 SSL/TLS 握手 ↗ 期间用于协商安全设置的一组密码组合。作为 SaaS 提供商,你可为整个 zone 指定密码套件配置,也可通过 API 为各个自定义主机名指定密码套件。
添加自定义主机名后,你可使用 Cloudflare Access 启用 mTLS。在 Cloudflare 仪表板 ↗ 中,前往 Zero Trust,并通过几次点击添加 mTLS 身份验证。
最低 TLS 版本既作为 zone 级设置 存在(在 Edge Certificates(边缘证书) ↗ 页面的 Minimum TLS Version(最低 TLS 版本) 下),也作为自定义主机名设置存在。这意味着:
- 对于通过 API 创建的自定义主机名,可以不显式定义
min_tls_version的值。在这种情况下,将应用你为 zone 定义的最低 TLS 版本值。要确认给定自定义主机名是否设置了特定的最低 TLS 版本,请使用以下 API 调用。
检查自定义主机名 TLS 设置
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates WriteSSL and Certificates Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "success": true,
"result": {
"id": "<CUSTOM_HOSTNAME_ID>",
"ssl": {
"id": "<CERTIFICATE_ID>",
"bundle_method": "ubiquitous",
"certificate_authority": "<CERTIFICATE_AUTHORITY>",
"custom_certificate": "",
"custom_csr_id": "",
"custom_key": "",
"expires_on": "",
"hosts": [
"app.example.com",
"*.app.example.com"
],
"issuer": "",
"method": "http",
"settings": {},
"signature": "SHA256WithRSA",
"type": "dv",
"uploaded_on": "2020-02-06T18:11:23.531995Z",
"validation_errors": [
{
"message": "SERVFAIL looking up CAA for app.example.com"
}
],
"validation_records": [
{
"emails": [
"administrator@example.com",
"webmaster@example.com"
],
"http_body": "ca3-574923932a82475cb8592200f1a2a23d",
"http_url": "http://app.example.com/.well-known/pki-validation/ca3-da12a1c25e7b48cf80408c6c1763b8a2.txt",
"txt_name": "_acme-challenge.app.example.com",
"txt_value": "810b7d5f01154524b961ba0cd578acc2"
}
],
"wildcard": false
},
}-
每当你通过仪表板对自定义主机名进行更改时,为最低 TLS 版本设置的值都会生效。若存在上一条所述场景,仪表板更改将覆盖正在应用的 zone 级配置。
-
对于启用了通配符的自定义主机名,你创建的直接自定义主机名(例如
saas-customer.test)将使用主机名特定设置,而其他主机名(sub1.saas-customer.test、sub2.saas-customer.test等)将默认使用 zone 级设置。
zone 的最低 TLS 版本
自定义主机名的最低 TLS 版本
-
在 Cloudflare 仪表板中,前往 Custom Hostnames(自定义主机名) 页面。
Go to Custom Hostnames ↗ -
找到要应用最低 TLS 版本的主机名。选择 Edit(编辑)。
-
在 Minimum TLS Version(最低 TLS 版本) 下选择所需的 TLS 版本,然后选择 Save(保存)。
在 API 文档中,请参阅自定义主机名的 SSL 属性。除 settings 规范外,你还必须在 ssl 对象中包含 type 和 method,如下所述。
- 向 Custom Hostname Details 端点发出
GET请求,以检查ssl.type和ssl.method的当前值。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates WriteSSL and Certificates Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "success": true,
"result": {
"id": "<CUSTOM_HOSTNAME_ID>",
"ssl": {
"id": "<CERTIFICATE_ID>",
"bundle_method": "ubiquitous",
"certificate_authority": "<CERTIFICATE_AUTHORITY>",
"custom_certificate": "",
"custom_csr_id": "",
"custom_key": "",
"expires_on": "",
"hosts": [
"app.example.com",
"*.app.example.com"
],
"issuer": "",
"method": "http",
"settings": {},
"signature": "SHA256WithRSA",
"type": "dv",
"uploaded_on": "2020-02-06T18:11:23.531995Z",
"validation_errors": [
{
"message": "SERVFAIL looking up CAA for app.example.com"
}
],
"validation_records": [
{
"emails": [
"administrator@example.com",
"webmaster@example.com"
],
"http_body": "ca3-574923932a82475cb8592200f1a2a23d",
"http_url": "http://app.example.com/.well-known/pki-validation/ca3-da12a1c25e7b48cf80408c6c1763b8a2.txt",
"txt_name": "_acme-challenge.app.example.com",
"txt_value": "810b7d5f01154524b961ba0cd578acc2"
}
],
"wildcard": false
},
}- 记下这些值后,向 Edit Custom Hostname 端点发出
PATCH请求,同时提供你要定义的最低 TLS 版本,以及从上一步获得的相同type和method值。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"ssl": {
"method": "http",
"type": "dv",
"settings": {
"min_tls_version:": "1.2"
}
}
}'出于安全和合规原因,你可能只希望允许来自某些密码套件的连接。Cloudflare 在密码套件文档中提供了推荐值和完整密码套件参考。
限制 zone 的密码套件
限制自定义主机名的密码套件
在 API 文档中,请参阅自定义主机名的 SSL 属性。除 settings 规范外,你还必须在 ssl 对象中包含 type 和 method,如下所述。
- 向 Custom Hostname Details 端点发出
GET请求,以检查ssl.type和ssl.method的当前值。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates WriteSSL and Certificates Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "success": true,
"result": {
"id": "<CUSTOM_HOSTNAME_ID>",
"ssl": {
"id": "<CERTIFICATE_ID>",
"bundle_method": "ubiquitous",
"certificate_authority": "<CERTIFICATE_AUTHORITY>",
"custom_certificate": "",
"custom_csr_id": "",
"custom_key": "",
"expires_on": "",
"hosts": [
"app.example.com",
"*.app.example.com"
],
"issuer": "",
"method": "http",
"settings": {},
"signature": "SHA256WithRSA",
"type": "dv",
"uploaded_on": "2020-02-06T18:11:23.531995Z",
"validation_errors": [
{
"message": "SERVFAIL looking up CAA for app.example.com"
}
],
"validation_records": [
{
"emails": [
"administrator@example.com",
"webmaster@example.com"
],
"http_body": "ca3-574923932a82475cb8592200f1a2a23d",
"http_url": "http://app.example.com/.well-known/pki-validation/ca3-da12a1c25e7b48cf80408c6c1763b8a2.txt",
"txt_name": "_acme-challenge.app.example.com",
"txt_value": "810b7d5f01154524b961ba0cd578acc2"
}
],
"wildcard": false
},
}- 记下这些值后,向 Edit Custom Hostname 端点发出
PATCH请求,同时提供授权密码套件列表,以及从上一步获得的相同type和method值。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"ssl": {
"method": "http",
"type": "dv",
"settings": {
"ciphers": [
"ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES128-GCM-SHA256"
]
}
}
}'限制带有自定义证书的自定义主机名的密码套件
在 API 文档中,请参阅自定义主机名的 SSL 属性。对于带有自定义证书的自定义主机名,你必须在 Edit Custom Hostname PATCH 调用 中包含自定义证书,以及 settings 规范;其中你必须在 ssl 对象中包含 type 和 method,如下所述。
- 向 Custom Hostname Details 端点发出
GET请求,以检查ssl.type和ssl.method的当前值。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates WriteSSL and Certificates Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "success": true,
"result": {
"id": "<CUSTOM_HOSTNAME_ID>",
"ssl": {
"id": "<CERTIFICATE_ID>",
"bundle_method": "ubiquitous",
"certificate_authority": "<CERTIFICATE_AUTHORITY>",
"custom_certificate": "",
"custom_csr_id": "",
"custom_key": "",
"expires_on": "",
"hosts": [
"app.example.com",
"*.app.example.com"
],
"issuer": "",
"method": "http",
"settings": {},
"signature": "SHA256WithRSA",
"type": "dv",
"uploaded_on": "2020-02-06T18:11:23.531995Z",
"validation_errors": [
{
"message": "SERVFAIL looking up CAA for app.example.com"
}
],
"validation_records": [
{
"emails": [
"administrator@example.com",
"webmaster@example.com"
],
"http_body": "ca3-574923932a82475cb8592200f1a2a23d",
"http_url": "http://app.example.com/.well-known/pki-validation/ca3-da12a1c25e7b48cf80408c6c1763b8a2.txt",
"txt_name": "_acme-challenge.app.example.com",
"txt_value": "810b7d5f01154524b961ba0cd578acc2"
}
],
"wildcard": false
},
}- 记下这些值后,向 Edit Custom Hostname 端点发出
PATCH请求,同时提供授权密码套件列表、从上一步获得的相同type和method值,以及custom_certificate和custom_key。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"ssl": {
"method": "http",
"type": "dv",
"custom_certificate": "<CERTIFICATE_STRING>",
"custom_key": "<CERTIFICATE_PRIVATE_KEY>",
"settings": {
"ciphers": [
"ECDHE-ECDSA-AES128-GCM-SHA256",
"ECDHE-RSA-AES128-GCM-SHA256"
],
"min_tls_version": "1.2"
}
}
}'你可以配置警报,在双向 TLS 证书过期前接收通知。
Access mTLS Certificate Expiration Alert
Who is it for?Access customers that use client certificates for mutual TLS authentication. This notification will be sent 30 and 14 days before the expiration of the certificate.
Other options / filtersNone.
Included withPurchase of Access and/or Cloudflare for SaaS.
What should you do if you receive one?Upload a renewed certificate.
有关如何设置警报的更多信息,请参阅 Cloudflare Notifications。