跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

TLS 管理

最后更新 查看 MarkdownAgent 设置

双向 TLS (mTLS) ↗ 通过对服务器和客户端的证书进行验证,为应用程序连接增加额外保护层。在构建 SaaS 应用时,你可能希望强制执行 mTLS,以保护与支付处理、数据库更新等相关的敏感端点。

最低 TLS 版本 仅允许支持所选 TLS 协议版本或更新版本的访问者建立 HTTPS 连接。Cloudflare 建议使用 TLS 1.2,以符合支付卡行业 (PCI) 安全标准委员会的要求。作为 SaaS 提供商,你可控制整个 zone 以及各个自定义主机名的最低 TLS 版本。

密码套件 是在 SSL/TLS 握手 ↗ 期间用于协商安全设置的一组密码组合。作为 SaaS 提供商,你可为整个 zone 指定密码套件配置,也可通过 API 为各个自定义主机名指定密码套件。

启用 mTLS

添加自定义主机名后,你可使用 Cloudflare Access 启用 mTLS。在 Cloudflare 仪表板 ↗ 中,前往 Zero Trust,并通过几次点击添加 mTLS 身份验证。

最低 TLS 版本

范围

最低 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 Write
  • SSL and Certificates Read
Custom Hostname Detailsbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Response examplejson
  "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": [
            "[email protected]",
            "[email protected]"
          ],
          "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 版本

请参阅 Minimum TLS version - SSL/TLS。

自定义主机名的最低 TLS 版本

  1. 在 Cloudflare 仪表板中,前往 Custom Hostnames(自定义主机名) 页面。

    前往 Custom Hostnames(自定义主机名) ↗
  2. 找到要应用最低 TLS 版本的主机名。选择 Edit(编辑)。

  3. 在 Minimum TLS Version(最低 TLS 版本) 下选择所需的 TLS 版本,然后选择 Save(保存)。

在 API 文档中,请参阅自定义主机名的 SSL 属性。PATCH 请求会替换现有的 ssl.settings 对象。请检索并复用所有当前设置,以免重置不相关的值。

  1. 向 Custom Hostname Details 端点发出 GET 请求,以获取当前的 ssl.settings 对象。

Required API token permissions

At least one of the following token permissions is required:
  • SSL and Certificates Write
  • SSL and Certificates Read
Custom Hostname Detailsbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Response examplejson
  "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": [
            "[email protected]",
            "[email protected]"
          ],
          "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
    },
  }
  1. 复制完整的 ssl.settings 对象。仅更改 min_tls_version,然后向 Edit Custom Hostname 端点发出 PATCH 请求。省略 GET 响应中不存在的设置。

Required API token permissions

At least one of the following token permissions is required:
  • SSL and Certificates Write
Edit Custom Hostnamebash
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": {
				"settings": {
						"min_tls_version": "1.2"
				}
		}
	}'

密码套件

出于安全和合规原因,你可能只希望允许来自某些密码套件的连接。Cloudflare 在密码套件文档中提供了推荐值和完整密码套件参考。

限制 zone 的密码套件

请参阅 Customize cipher suites - SSL/TLS。

限制自定义主机名的密码套件

在 API 文档中,请参阅自定义主机名的 SSL 属性。PATCH 请求会替换现有的 ssl.settings 对象。请检索并复用所有当前设置,以免重置不相关的值。

  1. 向 Custom Hostname Details 端点发出 GET 请求,以获取当前的 ssl.settings 对象。

Required API token permissions

At least one of the following token permissions is required:
  • SSL and Certificates Write
  • SSL and Certificates Read
Custom Hostname Detailsbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Response examplejson
  "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": {
        "ciphers": ["ECDHE-RSA-AES256-GCM-SHA384"],
        "early_hints": "on",
        "http2": "on",
        "min_tls_version": "1.2",
        "tls_1_3": "on"
      },
      "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": [
            "[email protected]",
            "[email protected]"
          ],
          "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
    },
  }
  1. 复制完整的 ssl.settings 对象。仅更改 ciphers,然后向 Edit Custom Hostname 端点发出 PATCH 请求。省略 GET 响应中不存在的设置。

Required API token permissions

At least one of the following token permissions is required:
  • SSL and Certificates Write
Edit Custom Hostnamebash
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": {
				"settings": {
						"ciphers": [
								"ECDHE-ECDSA-AES128-GCM-SHA256",
								"ECDHE-RSA-AES128-GCM-SHA256"
						],
						"early_hints": "on",
						"http2": "on",
						"min_tls_version": "1.2",
						"tls_1_3": "on"
				}
		}
	}'

限制使用自定义证书的自定义主机名的密码套件

在 API 文档中,请参阅自定义主机名的 SSL 属性。对于带有自定义证书的自定义主机名,你必须在 Edit Custom Hostname PATCH 调用 中包含自定义证书,以及 settings 规范;其中你必须在 ssl 对象中包含 type 和 method,如下所述。

  1. 向 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 Write
  • SSL and Certificates Read
Custom Hostname Detailsbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
	--request GET \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Response examplejson
  "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": [
            "[email protected]",
            "[email protected]"
          ],
          "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
    },
  }
  1. 记下这些值后,向 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
Edit Custom Hostnamebash
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 证书警报

你可以配置警报,在双向 TLS 证书过期前接收通知。

Access mTLS Certificate Expiration Alert

适用对象

使用客户端证书进行双向 TLS 身份验证的 Access 客户。此通知将在证书过期前 30 天和 14 天发送。

其他选项/筛选条件

无。

包含于

已购买 Access 和/或 Cloudflare for SaaS。

收到通知后应如何处理?

上传续期后的证书。

有关如何设置警报的更多信息,请参阅 Cloudflare Notifications。

这篇文档对您有帮助吗?