mirror of https://github.com/istio/istio.io.git
zh: content/docs/tasks/traffic-management/secure-ingress/index.md (#2678)
This commit is contained in:
parent
531bda2945
commit
e684ce75b8
|
|
@ -5,8 +5,6 @@ weight: 31
|
|||
keywords: [流量管理,ingress]
|
||||
---
|
||||
|
||||
> 本文任务使用了新的 [v1alpha3 流量控制 API](/zh/blog/2018/v1alpha3-routing/)。旧版本 API 已经过时,会在下一个 Istio 版本中移除。如果需要使用旧版本 API,请阅读[旧版本文档](https://archive.istio.io/v0.7/docs/tasks/traffic-management/)
|
||||
|
||||
[控制 Ingress 流量](/zh/docs/tasks/traffic-management/ingress)任务描述了如何对 Ingress gateway 进行配置,从而对外以 HTTP 端点的形式暴露服务。本文中将会对这一任务进行扩展,为服务启用普通或双向 TLS 保护,以 HTTPS 的形式对网格外提供服务。
|
||||
|
||||
## 开始之前
|
||||
|
|
@ -20,11 +18,13 @@ keywords: [流量管理,ingress]
|
|||
curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
|
||||
{{< /text >}}
|
||||
|
||||
如果命令输出中包含了 _LibreSSL_ ,那么 `curl` 命令就是适合于本文任务的。否则就要尝试使用其他的 `curl` 了,例如使用 Linux 系统。
|
||||
如果上面的命令输出中包含了 _LibreSSL_ ,那么 `curl` 命令就是适合于本文任务的。
|
||||
否则就要尝试使用其他的 `curl` 了,例如使用 Linux 系统。
|
||||
|
||||
## 生成客户端与服务器的证书和密钥
|
||||
|
||||
这里可以使用任意工具来生成证书和密钥,下面我们使用了[一个脚本](https://github.com/nicholasjackson/mtls-go-example/blob/master/generate.sh):
|
||||
对于此任务,您可以使用自己喜欢的工具生成证书和密钥。此示例使用[脚本](https://github.com/nicholasjackson/mtls-go-example/blob/master/generate.sh)
|
||||
来自 <https://github.com/nicholasjackson/mtls-go-example> 存储库。
|
||||
|
||||
1. 克隆 <https://github.com/nicholasjackson/mtls-go-example> 仓库:
|
||||
|
||||
|
|
@ -38,10 +38,10 @@ keywords: [流量管理,ingress]
|
|||
$ pushd mtls-go-example
|
||||
{{< /text >}}
|
||||
|
||||
1. 使用以下的命令(密码任意指定)为 `httpbin.example.com` 生成证书:
|
||||
1. 为 `httpbin.example.com` 生成证书。将以下命令中 `password` 改为您喜欢的任何值:
|
||||
|
||||
{{< text bash >}}
|
||||
$ ./generate.sh httpbin.example.com <password>
|
||||
$ ./generate.sh httpbin.example.com password
|
||||
{{< /text >}}
|
||||
|
||||
所有提示问题都选择 `y`。这一命令会生成四个目录: `1_root`、`2_intermediate`、`3_application` 以及 `4_client`,其中包含了后续步骤所需的客户端和服务器的证书。
|
||||
|
|
@ -71,7 +71,8 @@ keywords: [流量管理,ingress]
|
|||
secret "istio-ingressgateway-certs" created
|
||||
{{< /text >}}
|
||||
|
||||
注意缺省情况下,`istio-system` 命名空间中所有的 Service account 都是可以访问 Secret 的,所以可能会泄漏私钥。可以通过 [RBAC](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) 设置来进行对涉密数据的保护。
|
||||
注意 默认情况下,`istio-system` 命名空间中所有的 Service account 都是可以访问 Secret 的,
|
||||
所以可能会泄漏私钥。可以通过 [Role-Based Access Control (RBAC)](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) 设置来进行对涉密数据的保护。
|
||||
|
||||
1. 定义一个 Gateway 对象,其中包含了使用 443 端口的 `server` 部分。
|
||||
|
||||
|
|
@ -85,7 +86,7 @@ keywords: [流量管理,ingress]
|
|||
name: mygateway
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway # 使用 Istio 的缺省 Gateway
|
||||
istio: ingressgateway # 使用 Istio 默认的 Gateway
|
||||
servers:
|
||||
- port:
|
||||
number: 443
|
||||
|
|
@ -134,7 +135,7 @@ keywords: [流量管理,ingress]
|
|||
发送请求到 `/status/418`,会看到漂亮的返回内容,这说明我们成功访问了 `httpbin`。`httpbin` 服务会返回 [418 I'm a Teapot](https://tools.ietf.org/html/rfc7168#section-2.3.3)。
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -v --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
$ curl -v -HHost:httpbin.example.com --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
...
|
||||
Server certificate:
|
||||
subject: C=US; ST=Denial; L=Springfield; O=Dis; CN=httpbin.example.com
|
||||
|
|
@ -162,8 +163,6 @@ keywords: [流量管理,ingress]
|
|||
|
||||
查看 `curl` 命令返回内容中的 `Server certificate` 部分,注意其中的 `common name`:`common name: httpbin.example.com (matched)`。另外输出中还包含了 `SSL certificate verify ok`,这说明对服务器的证书校验是成功的,返回状态码为 418 和一个茶壶画。
|
||||
|
||||
如果需要支持 [双向 TLS](https://en.wikipedia.org/wiki/Mutual_authentication) ,请继续下一节内容。
|
||||
|
||||
## 配置 Ingress gateway 的双向 TLS 支持
|
||||
|
||||
这一节中会再次对 Gateway 定义进行扩展,从而在从外部客户端到 Gateway 的访问中添加对 [双向 TLS](https://en.wikipedia.org/wiki/Mutual_authentication) 的支持。
|
||||
|
|
@ -189,7 +188,7 @@ keywords: [流量管理,ingress]
|
|||
name: mygateway
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway # 是用缺省的 Istio Gateway
|
||||
istio: ingressgateway # 使用 Istio 默认的 Gateway
|
||||
servers:
|
||||
- port:
|
||||
number: 443
|
||||
|
|
@ -209,7 +208,7 @@ keywords: [流量管理,ingress]
|
|||
|
||||
{{< text bash >}}
|
||||
|
||||
$ curl --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
$ curl -HHost:httpbin.example.com --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
curl: (35) error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
|
||||
{{< /text >}}
|
||||
|
||||
|
|
@ -220,7 +219,7 @@ keywords: [流量管理,ingress]
|
|||
1. 再次使用 `curl` 命令发送请求,这次的参数加入了客户端证书(`--cert`)以及私钥(`--key`):
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert 2_intermediate/certs/ca-chain.cert.pem --cert 4_client/certs/httpbin.example.com.cert.pem --key 4_client/private/httpbin.example.com.key.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
$ curl -HHost:httpbin.example.com --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem --cert httpbin.example.com/4_client/certs/httpbin.example.com.cert.pem --key httpbin.example.com/4_client/private/httpbin.example.com.key.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
|
||||
-=[ teapot ]=-
|
||||
|
||||
|
|
@ -241,7 +240,8 @@ keywords: [流量管理,ingress]
|
|||
|
||||
### 为 `bookinfo.com` 生成客户端和服务器证书和密钥
|
||||
|
||||
在本小节中,执行与[生成客户端和服务器证书和密钥](/zh/docs/tasks/traffic-management/secure-ingress/#生成客户端与服务器的证书和密钥)子部分相同的步骤。为方便起见,我在下面列出它们。
|
||||
执行与[生成客户端和服务器证书和密钥](#生成客户端与服务器的证书和密钥)相同的步骤,
|
||||
仅适用于主机 `bookinfo.com` 而不是 `httpbin.example.com`。
|
||||
|
||||
1. 进入代码目录:
|
||||
|
||||
|
|
@ -249,10 +249,10 @@ keywords: [流量管理,ingress]
|
|||
$ pushd mtls-go-example
|
||||
{{< /text >}}
|
||||
|
||||
1. 使用以下的命令(密码任意指定)为 `httpbin.example.com` 生成证书:
|
||||
1. 为 `bookinfo.com` 生成证书。将以下命令中 `password` 改为您喜欢的任何值:
|
||||
|
||||
{{< text bash >}}
|
||||
$ ./generate.sh bookinfo.com <password>
|
||||
$ ./generate.sh bookinfo.com password
|
||||
{{< /text >}}
|
||||
|
||||
出现提示时,为所有问题选择 `y` 。
|
||||
|
|
@ -386,7 +386,7 @@ keywords: [流量管理,ingress]
|
|||
1. 向 _Bookinfo_ `productpage` 发送请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -o /dev/null -s -v -w "%{http_code}\n" --resolve bookinfo.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert bookinfo.com/2_intermediate/certs/ca-chain.cert.pem -HHost:bookinfo.com https://bookinfo.com:$SECURE_INGRESS_PORT/productpage
|
||||
$ curl -o /dev/null -s -v -w "%{http_code}\n" -HHost:bookinfo.com --resolve bookinfo.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert bookinfo.com/2_intermediate/certs/ca-chain.cert.pem -HHost:bookinfo.com https://bookinfo.com:$SECURE_INGRESS_PORT/productpage
|
||||
...
|
||||
Server certificate:
|
||||
subject: C=US; ST=Denial; L=Springfield; O=Dis; CN=bookinfo.com
|
||||
|
|
@ -402,7 +402,7 @@ keywords: [流量管理,ingress]
|
|||
1. 像以前一样访问 `httbin.example.com` 的方式验证一下。向它发送请求,你应该再次看到喜欢的茶壶画:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -v --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
$ curl -v -HHost:httpbin.example.com --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert httpbin.example.com/2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
|
||||
...
|
||||
-=[ teapot ]=-
|
||||
|
||||
|
|
@ -482,6 +482,12 @@ keywords: [流量管理,ingress]
|
|||
Subject: C=US, ST=Denial, L=Springfield, O=Dis, CN=httpbin.example.com
|
||||
{{< /text >}}
|
||||
|
||||
1. 如果创建了密钥但未加载密钥,则终止入口网关 pod 并强制它重新加载证书:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete pod -n istio-system -l istio=ingressgateway
|
||||
{{< /text >}}
|
||||
|
||||
## 清理
|
||||
|
||||
1. 删除 `Gateway` 配置、`VirtualService` 以及 Secret 对象:
|
||||
|
|
|
|||
Loading…
Reference in New Issue