Kong - 验证上游 ssl (ssl_proxy on)

Kong - verify upstream ssl (ssl_proxy on)

我已经成功地为 API 安装了 kong 网关,它通过上游到多个目标(应用程序服务器)进行负载平衡。

现在,我的应用程序服务器有一个自签名证书,kong 和目标 之间的 ssl 握手应该会失败。我推断kong没有验证上游证书。

经过一些研究,我发现 ssl_proxy on; 的 nginx 配置可以做到这一点。

我想在 openresty 中找到一个等价物来验证上游 ssl 证书。

解决方案可能是修改 kong nginx 配置以激活 ssl_proxy 但在同一实例上使用不同的目标很糟糕。

我原以为你会反过来做:让你的后端服务在联系你的服务时验证 Kong 是否有特定的 SSL 证书,这样实际上只有 Kong 可以连接到服务,并且在因此,任何 API 客户端都必须通过 Kong 进行连接。

我们用 Kong 0.11.0 为 wicked.haufe.io 做了这个,你可以在这里找到合适的 nginx_conf.lua 文件:https://github.com/apim-haufe-io/wicked.kong/blob/master/templates/nginx_kong.lua

这里有趣的一点是:

proxy_ssl_certificate /root/proxy-cert.pem;
proxy_ssl_certificate_key /root/proxy-key.pem;

指定 nginx 用于对后端服务进行代理调用的证书和密钥。这被Kong注意到了。

通过查看我们为 wicked.haufe.io 的 Kong docker 图像所做的工作,您应该能够适应自己的需要;另一个有趣的部分是 startup.sh,其中 certificate/key 从环境变量中提取并添加到 /root/proxy-...pem 文件中。

注意kong配置中client_ssl的注释:

If 'client_ssl' is enabled, the absolute path to the client SSL certificate for the 'proxy_ssl_certificate directive. Note that this value is statically defined on the node, and currently cannot be configured on a per-API basis.

目前不可能。

我设法让它与 Kong 0 一起工作。14.x 通过设置以下环境变量: KONG_NGINX_HTTP_PROXY_SSL_VERIFY: "on" KONG_NGINX_HTTP_PROXY_SSL_TRUSTED_CERTIFICATE: "/mnt/certs/ca.crt" (调整后者以指向您的自定义 CA 证书文件。)

这使用 "KONG_NGINX_HTTP_" 前缀来设置任意 nginx 'http' 设置。

这似乎不适用于 Kong 1。0.x 不过。目前正试图为此找到解决方案...