117. TLS/SSL
网关可以通过遵循通常的 Spring 服务器 configuration 来监听 https 上的请求。 例:
application.yml.
server:
ssl:
enabled: true
key-alias: scg
key-store-password: scg1234
key-store: classpath:scg-keystore.p12
key-store-type: PKCS12
Gateway routes 可以路由到 http 和 https 后端。如果路由到 https 后端,则可以将网关配置为信任所有下游证书,并使用以下 configuration:
application.yml.
spring:
cloud:
gateway:
httpclient:
ssl:
useInsecureTrustManager: true
使用不安全的信任 manager 不适合 production。对于 production 部署,可以使用一组已知的证书配置网关,使用以下 configuration 可以信任该证书:
application.yml.
spring:
cloud:
gateway:
httpclient:
ssl:
trustedX509Certificates:
- cert1.pem
- cert2.pem
如果 Spring Cloud Gateway 未配置受信任证书,则使用默认信任 store(可以使用 system property javax.net.ssl.trustStore 覆盖)。
117.1 TLS 握手
网关维护一个用于 route 到后端的 client 池。通过 https 进行通信时,client 会启动 TLS 握手。这次握手会有很多超时。可以配置这些超时(显示默认值):
application.yml.
spring:
cloud:
gateway:
httpclient:
ssl:
handshake-timeout-millis: 10000
close-notify-flush-timeout-millis: 3000
close-notify-read-timeout-millis: 0