本文介绍如何在ASM网关配置TLS协议版本,增强网站安全性。
前提条件
- 已创建ASM实例。具体操作,请参见创建ASM实例。
- 已创建ACK集群。具体操作,请参见创建Kubernetes托管版集群。
- 添加集群到ASM实例。具体操作,请参见添加集群到ASM实例。
- 已部署入口网关服务。具体操作,请参见添加入口网关服务。
- 已部署应用到ASM实例的集群中。具体操作,请参见部署应用到ASM实例。
背景信息
包括TLS v1.0在内的早期TLS版本存在已知的安全问题,并且使用功能强大的工具和系统进行了解密,导致传输中的数据泄露。因此,一个增强网站安全性的最佳做法是禁用早期版本的TLS(v1.0和v1.1)并仅启用TLS v1.2及更高版本。同时,禁用TLS v1.2中的弱密码也非常重要。
准备网关使用的证书和私钥
以域名aliyun.com为例,为网关生成证书和私钥,并保存为Secret。例如,如果您已经拥有针对aliyun.com可用的证书和私钥,需要将密钥命名为aliyun.com.key,证书命名为aliyun.com.crt;如果没有,可以通过openssl执行以下步骤来生成证书和密钥。
- 执行以下命令,创建根证书和私钥。
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj '/O=myexample Inc./CN=aliyun.com' -keyout aliyun.root.key -out aliyun.root.crt
- 执行以下命令,为aliyun.com服务器生成证书和私钥。
openssl req -out aliyun.com.csr -newkey rsa:2048 -nodes -keyout aliyun.com.key -subj "/CN=aliyun.com/O=myexample organization" openssl x509 -req -days 365 -CA aliyun.root.crt -CAkey aliyun.root.key -set_serial 0 -in aliyun.com.csr -out aliyun.com.crt
- 在入口网关Pod所在的集群对应的kubeconfig环境下,执行以下命令,在istio-system命名空间中创建包含证书和私钥的Secret。
kubectl create -n istio-system secret tls myexample-tlsversion-credential --key=aliyun.com.key --cert=aliyun.com.crt
创建网关规则
- 登录ASM控制台。
- 在左侧导航栏,选择服务网格 > 网格管理。
- 在网格管理页面,找到待配置的实例,单击实例的名称或在操作列中单击管理。
- 在网格详情页面左侧导航栏选择流量管理中心 > 网关规则,然后在右侧页面单击使用YAML创建。
- 在创建页面,选择目标命名空间和任意场景模板,配置如下YAML。本文以default命名空间为例,YAML中设置minProtocolVersion值为TLSV1_2,表示禁用TLS v1.0和v1.1。
apiVersion networking.istio.io/v1beta1 kind Gateway metadata name mysdsgateway-tlsversion-sample spec selector istio ingressgateway servershosts'*' port name https number443 protocol HTTPS tls credentialName myexample-tlsversion-credential minProtocolVersion TLSV1_2 mode SIMPLE
创建虚拟服务
- 在网格详情页面左侧导航栏选择流量管理中心 > 虚拟服务,然后在右侧页面单击使用YAML创建。
- 在创建页面,选择目标命名空间和任意场景模板,配置如下YAML。
apiVersion networking.istio.io/v1beta1 kind VirtualService metadata name bookinfo-tlsversion-sample spec gateways mysdsgateway-tlsversion-sample hosts'*' httpmatchuri exact /productpage uri prefix /static uri exact /login uri exact /logout uri prefix /api/v1/products routedestination host productpage port number9080
验证TLS版本
testssl.sh是一个免费的命令行工具,可以检查服务器在任何端口上的服务是否支持TLS/SSL密钥、协议以及一些加密缺陷等。本文使用testssl.sh对TLS版本进行验证。
- 执行以下命令,以容器方式运行testssl.sh。
docker run --rm -ti registry.cn-hangzhou.aliyuncs.com/acs/testssl.sh https://网关地址/productpage
预期输出:
Testing protocols via sockets except NPN+ALPN SSLv2 not offered (OK)SSLv3 not offered (OK)TLS 1 not offered TLS 1.1 not offered TLS 1.2 offered (OK)TLS 1.3 offered (OK): final ...... Running client simulations (HTTP) via sockets Browser Protocol Cipher Suite Name (OpenSSL) Forward Secrecy ------------------------------------------------------------------------------------------------ Android 6.0 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Android 7.0 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Android 8.1 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519)Android 9.0 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Android 10.0 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Android 11 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Android 12 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Chrome 79 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Chrome 101 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Firefox 66 (Win 8.1/10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Firefox 100 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)IE 6 XP No connection IE 8 Win 7 No connection IE 8 XP No connection IE 11 Win 7 No connection IE 11 Win 8.1 No connection IE 11 Win Phone 8.1 No connection IE 11 Win 10 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Edge 15 Win 10 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519)Edge 101 Win 1021H2 TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Safari 12.1 (iOS 12.2) TLSv1.3 TLS_CHACHA20_POLY1305_SHA256 253 bit ECDH (X25519)Safari 13.0 (macOS 10.14.6) TLSv1.3 TLS_CHACHA20_POLY1305_SHA256 253 bit ECDH (X25519)Safari 15.4 (macOS 12.3.1) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)Java 7u25 No connection Java 8u161 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Java 11.0.2 (OpenJDK) TLSv1.3 TLS_AES_128_GCM_SHA256 256 bit ECDH (P-256)Java 17.0.3 (OpenJDK) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519)go 1.17.8 TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)LibreSSL 2.8.3 (Apple) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519)OpenSSL 1.0.2e TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)OpenSSL 1.1.0l (Debian) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519)OpenSSL 1.1.1d (Debian) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519)OpenSSL 3.0.3 (git) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519)Apple Mail (16.0) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Thunderbird (91.9) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)
由预期输出得到,TLS 1和TLS 1.1版本均为not offered
,说明已禁用这两个版本;TLS 1.2和1.3版本均为offered
,说明支持这两个版本。
在客户端的模拟请求中,也可以看到只有支持TLS 1.2和1.3版本的客户端才能建立连接。
如何严格限制到TLS 1.2版本
若您需要严格限制到TLS 1.2版本,请参照以下步骤。
- 参照如下YAML,修改Gateway网格规则配置,设置maxProtocolVersion和minProtocolVersion均为TLSV1_2。
apiVersion networking.istio.io/v1beta1 kind Gateway metadata name mysdsgateway namespace default spec selector istio ingressgateway servershosts'*' port name https number443 protocol HTTPS tls credentialName myexample-credential maxProtocolVersion TLSV1_2 minProtocolVersion TLSV1_2 mode SIMPLE
2.执行以下命令,进行验证测试。
docker run --rm-ti registry.cn-hangzhou.aliyuncs.com/acs/testssl.sh https://网关地址/productpage
3.预期输出:
Testing protocols via sockets except NPN+ALPN SSLv2 not offered (OK) SSLv3 not offered (OK) TLS 1 not offered TLS 1.1 not offered TLS 1.2 offered (OK) TLS 1.3 not offered and downgraded to a weaker protocol ...... Running client simulations (HTTP) via sockets Browser Protocol Cipher Suite Name (OpenSSL) Forward Secrecy ------------------------------------------------------------------------------------------------ Android 6.0 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) Android 7.0 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) Android 8.1 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Android 9.0 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Android 10.0 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Android 11 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Android 12 (native) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Chrome 79 (Win 10) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Chrome 101 (Win 10) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Firefox 66 (Win 8.1/10) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Firefox 100 (Win 10) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) IE 6 XP No connection IE 8 Win 7 No connection IE 8 XP No connection IE 11 Win 7 No connection IE 11 Win 8.1 No connection IE 11 Win Phone 8.1 No connection IE 11 Win 10 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) Edge 15 Win 10 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Edge 101 Win 1021H2 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Safari 12.1 (iOS 12.2) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Safari 13.0 (macOS 10.14.6) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Safari 15.4 (macOS 12.3.1) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) Java 7u25 No connection Java 8u161 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) Java 11.0.2 (OpenJDK) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) Java 17.0.3 (OpenJDK) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519) go 1.17.8 TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519) LibreSSL 2.8.3 (Apple) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519) OpenSSL 1.0.2e TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256) OpenSSL 1.1.0l (Debian) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519) OpenSSL 1.1.1d (Debian) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519) OpenSSL 3.0.3 (git) TLSv1.2 ECDHE-RSA-CHACHA20-POLY1305 253 bit ECDH (X25519) Apple Mail (16.0) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 256 bit ECDH (P-256)Thunderbird (91.9) TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 253 bit ECDH (X25519)
由预期输出得到,TLS 1和TLS 1.1版本均为not offered
,TLS 1.3版本为not offered and downgraded to a weaker protocol
,说明已禁用这三个版本;TLS 1.2版本为offered
,说明只支持TLS 1.2版本。
在客户端的模拟请求中,也可以看到只有支持TLS 1.2版本的客户端才能建立连接。
如何严格限制到TLS 1.3版本
若您需要严格限制到TLS 1.3版本,请参照以下步骤。
- 参照如下YAML,修改Gateway网格规则配置,设置maxProtocolVersion和minProtocolVersion均为TLSV1_3。
apiVersion networking.istio.io/v1beta1 kind Gateway metadata name mysdsgateway namespace default spec selector istio ingressgateway servershosts'*' port name https number443 protocol HTTPS tls credentialName myexample-credential maxProtocolVersion TLSV1_3 minProtocolVersion TLSV1_3 mode SIMPLE
2.执行以下命令,进行验证测试。
docker run --rm-ti registry.cn-hangzhou.aliyuncs.com/acs/testssl.sh https://网关地址/productpage
3.预期输出:
Testing protocols via sockets except NPN+ALPN SSLv2 not offered (OK)SSLv3 not offered (OK)TLS 1 not offered TLS 1.1 not offered TLS 1.2 not offered TLS 1.3 offered (OK): final ...... Running client simulations (HTTP) via sockets Browser Protocol Cipher Suite Name (OpenSSL) Forward Secrecy ------------------------------------------------------------------------------------------------ Android 6.0 No connection Android 7.0 (native) No connection Android 8.1 (native) No connection Android 9.0 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Android 10.0 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Android 11 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Android 12 (native) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Chrome 79 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Chrome 101 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Firefox 66 (Win 8.1/10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Firefox 100 (Win 10) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) IE 6 XP No connection IE 8 Win 7 No connection IE 8 XP No connection IE 11 Win 7 No connection IE 11 Win 8.1 No connection IE 11 Win Phone 8.1 No connection IE 11 Win 10 No connection Edge 15 Win 10 No connection Edge 101 Win 1021H2 TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Safari 12.1 (iOS 12.2) TLSv1.3 TLS_CHACHA20_POLY1305_SHA256 253 bit ECDH (X25519) Safari 13.0 (macOS 10.14.6) TLSv1.3 TLS_CHACHA20_POLY1305_SHA256 253 bit ECDH (X25519) Safari 15.4 (macOS 12.3.1) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) Java 7u25 No connection Java 8u161 No connection Java 11.0.2 (OpenJDK) TLSv1.3 TLS_AES_128_GCM_SHA256 256 bit ECDH (P-256) Java 17.0.3 (OpenJDK) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519) go 1.17.8 TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519) LibreSSL 2.8.3 (Apple) No connection OpenSSL 1.0.2e No connection OpenSSL 1.1.0l (Debian) No connection OpenSSL 1.1.1d (Debian) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519) OpenSSL 3.0.3 (git) TLSv1.3 TLS_AES_256_GCM_SHA384 253 bit ECDH (X25519) Apple Mail (16.0) No connection Thunderbird (91.9) TLSv1.3 TLS_AES_128_GCM_SHA256 253 bit ECDH (X25519)
由预期输出得到,TLS 1、TLS 1.1和TLS 1.2版本均为not offered
,说明已禁用这三个版本;TLS 1.3版本为offered
,说明只支持TLS 1.3版本。
在客户端的模拟请求中,也可以看到只有支持TLS 1.3版本的客户端才能建立连接。