mirror of https://github.com/istio/istio.io.git
zh-translation: /docs/tasks/security/authorization/authz-tcp/index.md and some _index.md (#5938)
* zh-translation: /docs/tasks/security/authorization/authz-tcp/index.md and some _index.md * remove Multiple consecutive blank lines
This commit is contained in:
parent
ec20610f4e
commit
98e07c1df6
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Virtual Machines
|
||||
description: Examples that add workloads running on virtual machines to an Istio mesh.
|
||||
title: 虚拟机
|
||||
description: 将虚拟机中运行的工作负载添加到 Istio 网格的示例。
|
||||
weight: 30
|
||||
aliases:
|
||||
- /zh/docs/examples/mesh-expansion/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
title: Authorization
|
||||
description: Shows how to control access to Istio services.
|
||||
title: 授权
|
||||
description: 展示如何控制到 Istio 服务的访问。
|
||||
weight: 30
|
||||
---
|
||||
|
|
|
@ -1,49 +1,43 @@
|
|||
---
|
||||
title: Authorization for TCP traffic
|
||||
description: Shows how to set up access control for TCP traffic.
|
||||
title: TCP 流量的授权
|
||||
description: 展示如何设置 TCP 流量的访问控制。
|
||||
weight: 20
|
||||
keywords: [security,access-control,rbac,tcp,authorization]
|
||||
aliases:
|
||||
- /zh/docs/tasks/security/authz-tcp/
|
||||
---
|
||||
|
||||
This task shows you how to set up Istio authorization for TCP traffic in an Istio mesh.
|
||||
You can learn more about the Istio authorization in the
|
||||
[authorization concept page](/zh/docs/concepts/security/#authorization).
|
||||
该任务向您展示了在 Istio 网格中如何为 TCP 流量设置 Istio 授权。
|
||||
您可以在[授权概念页面](/zh/docs/concepts/security/#authorization)中了解到关于 Istio 授权的更多信息。
|
||||
|
||||
## Before you begin
|
||||
## 开始之前{#before-you-begin}
|
||||
|
||||
The activities in this task assume that you:
|
||||
本文任务假定您已经:
|
||||
|
||||
* Read the [authorization concept](/zh/docs/concepts/security/#authorization).
|
||||
* 阅读了[授权概念](/zh/docs/concepts/security/#authorization)。
|
||||
|
||||
* Follow the [Istio installation guide](/zh/docs/setup/install/istioctl/) to install Istio with mutual TLS enabled.
|
||||
* 按照 [Istio 安装指南](/zh/docs/setup/install/istioctl/)安装了 Istio 并启用了双向 TLS。
|
||||
|
||||
* Deploy the [Bookinfo](/zh/docs/examples/bookinfo/#deploying-the-application) sample application.
|
||||
* 部署了 [Bookinfo](/zh/docs/examples/bookinfo/#deploying-the-application) 示例应用。
|
||||
|
||||
After deploying the Bookinfo application, go to the Bookinfo product page at `http://$GATEWAY_URL/productpage`. On
|
||||
the product page, you can see the following sections:
|
||||
部署完 Bookinfo 应用后,打开 `http://$GATEWAY_URL/productpage` 地址进入到 Bookinfo 图书页面。在该页面中,您可以看到如下模块:
|
||||
|
||||
* **Book Details** on the lower left side, which includes: book type, number of
|
||||
pages, publisher, etc.
|
||||
* **Book Reviews** on the lower right of the page.
|
||||
* 在页面的左下方是图书详情 (**Book Detail**) 模块,内容包括:图书类型、页数、出版社等信息。
|
||||
* 在页面的右下方是图书评价(**Book Reviews**) 模块。
|
||||
|
||||
When you refresh the page, the app shows different versions of reviews in the product page.
|
||||
The app presents the reviews in a round robin style: red stars, black stars, or no stars.
|
||||
每次刷新页面后,图书页面的书评模块会有不同的版本样式,在三种版本(红色星级、黑色星级、没有星级)之间轮换。
|
||||
|
||||
{{< tip >}}
|
||||
If you don't see the expected output in the browser as you follow the task, retry in a few seconds
|
||||
because some delay is possible due to caching and other propagation overhead.
|
||||
如果您在按照说明操作时未在浏览器中看到预期的输出,请在几秒钟后重试,因为缓存和其他传播开销可能会导致有些延迟。
|
||||
{{< /tip >}}
|
||||
|
||||
## Configure access control for a TCP workload
|
||||
## 配置 TCP 工作负载的访问控制{#configure-access-control-for-a-TCP-workload}
|
||||
|
||||
By default, the [Bookinfo](/zh/docs/examples/bookinfo/) example application only uses the HTTP protocol.
|
||||
To showcase the authorization of TCP traffic, you must update the application to use TCP.
|
||||
The following steps deploy the Bookinfo application and update its `ratings` workload to the `v2` version,
|
||||
which talks to a MongoDB backend using TCP, and then apply the authorization policy to the MongoDB workload.
|
||||
默认情况下,[Bookinfo](/zh/docs/examples/bookinfo/) 示例应用只使用 HTTP 协议。
|
||||
为了演示 TCP 流量的授权,您需要将应用更新到使用 TCP 的版本。
|
||||
按照下面的步骤,部署 Bookinfo 应用示例,并且将 `ratings` 服务升级到 `v2` 版本,在该版本中会使用 TCP 调用后端 MongoDB 服务,然后将授权策略应用到 MongoDB 工作负载上。
|
||||
|
||||
1. Install `v2` of the `ratings` workload with the `bookinfo-ratings-v2` service account:
|
||||
1. 使用 `bookinfo-ratings-v2` 服务账户安装 `ratings` 工作负载的 `v2` 版本:
|
||||
|
||||
{{< tabset cookie-name="sidecar" >}}
|
||||
|
||||
|
@ -65,28 +59,26 @@ which talks to a MongoDB backend using TCP, and then apply the authorization pol
|
|||
|
||||
{{< /tabset >}}
|
||||
|
||||
1. Create the appropriate destination rules:
|
||||
1. 创建适当的 destination rules:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/destination-rule-all-mtls.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
Since the subset referenced in the virtual service rules relies on the destination rules,
|
||||
wait a few seconds for the destination rules to propagate before adding the virtual service rules.
|
||||
因为 virtual service 规则中引用的 subset 项依赖 destination rules,所以在添加 virtual service 规则之前先等待几秒钟以让 destination rules 传播生效。
|
||||
|
||||
1. After the destination rules propagate, update the `reviews` workload to only use the `v2` of the `ratings` workload:
|
||||
1. 在 destination rules 传播生效后,更新 `reviews` 工作负载以只使用 `v2` 版本的 `ratings` 工作负载:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-ratings-db.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. Go to the Bookinfo product page at (`http://$GATEWAY_URL/productpage`).
|
||||
1. 浏览 Bookinfo 的产品页面(`http://$GATEWAY_URL/productpage`)。
|
||||
|
||||
On the product page, you can see an error message on the **Book Reviews** section.
|
||||
The message reads: **"Ratings service is currently unavailable."**. The message appears because we
|
||||
now use the `v2` subset of the `ratings` workload but we haven't deployed the MongoDB workload.
|
||||
在这一页面中,您会在 **Book Reviews** 模块中看到一条错误信息:**"Ratings service is currently unavailable."**。
|
||||
这是因为我们现在用的是 `v2` 版本的 `ratings` 工作负载,但是我们还没有部署 MongoDB。
|
||||
|
||||
1. Deploy the MongoDB workload:
|
||||
1. 部署 MongoDB 工作负载:
|
||||
|
||||
{{< tabset cookie-name="sidecar" >}}
|
||||
|
||||
|
@ -108,15 +100,13 @@ which talks to a MongoDB backend using TCP, and then apply the authorization pol
|
|||
|
||||
{{< /tabset >}}
|
||||
|
||||
1. Go to the Bookinfo product page at `http://$GATEWAY_URL/productpage`.
|
||||
1. 浏览 Bookinfo 的产品页面(`http://$GATEWAY_URL/productpage`)。
|
||||
|
||||
1. Verify that the **Book Reviews** section shows the reviews.
|
||||
1. 确认 **Book Reviews** 模块显示了书评。
|
||||
|
||||
With the MongoDB workload deployed and before we configure authorization to only allow authorized requests,
|
||||
we need to apply a default `deny-all` policy for the workload to ensure that all requests to the MongoDB
|
||||
workload are denied by default.
|
||||
部署了 MongoDB 工作负载之后,在将授权配置为仅允许授权请求之前,我们需要为工作负载应用默认的 `deny-all` 策略,以确保默认情况下拒绝对 MongoDB 工作负载的所有请求。
|
||||
|
||||
1. Apply a default `deny-all` policy for the MongoDB workload:
|
||||
1. 对 MongoDB 工作负载应用默认的 `deny-all` 策略:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f - <<EOF
|
||||
|
@ -131,20 +121,15 @@ which talks to a MongoDB backend using TCP, and then apply the authorization pol
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
Point your browser at the Bookinfo `productpage` (`http://$GATEWAY_URL/productpage`). You should see:
|
||||
打开 Bookinfo 的 `productpage` 页面(`http://$GATEWAY_URL/productpage`)。您会看到:
|
||||
|
||||
* The **Book Details** section on the lower left of the page includes book type, number of pages, publisher, etc.
|
||||
* The **Book Reviews** section on the lower right of the page includes an error message **"Ratings service is
|
||||
currently unavailable"**.
|
||||
* 页面左下角的 **Book Details** 中包含了书籍类型、页数以及出版商等信息。
|
||||
* 页面右下角的 **Book Reviews** 显示了错误信息:**"Ratings service is currently unavailable"**。
|
||||
|
||||
After configuring that all requests be denied by default, we need to create a `bookinfo-ratings-v2`
|
||||
policy that lets requests coming from the `cluster.local/ns/default/sa/bookinfo-ratings-v2` service account
|
||||
through to the MongoDB workload at port `27017`. We grant access to the service account, because
|
||||
requests coming from the `ratings-v2` workload are issued using the `cluster.local/ns/default/sa/bookinfo-ratings-v2`
|
||||
service account.
|
||||
在配置了默认拒绝所有请求之后,我们需要创建一个 `bookinfo-ratings-v2` 策略以允许来自 `cluster.local/ns/default/sa/bookinfo-ratings-v2` 服务账户在 `27017` 端口上对 MongoDB 工作负载的请求。
|
||||
我们授权给这个服务账户,是因为来自 `ratings-v2` 工作负载的请求都用的是 `cluster.local/ns/default/sa/bookinfo-ratings-v2` 服务账户发出的。
|
||||
|
||||
1. Enforce workload-level access control for TCP traffic coming from the
|
||||
`cluster.local/ns/default/sa/bookinfo-ratings-v2` service account:
|
||||
1. 为来自 `cluster.local/ns/default/sa/bookinfo-ratings-v2` 服务账户的 TCP 流量增强工作负载级别的访问控制:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f - <<EOF
|
||||
|
@ -166,25 +151,23 @@ which talks to a MongoDB backend using TCP, and then apply the authorization pol
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
Point your browser at the Bookinfo `productpage` (`http://$GATEWAY_URL/productpage`),
|
||||
you should see now the following sections working as intended:
|
||||
打开 Bookinfo 的 `productpage` 页面(`http://$GATEWAY_URL/productpage`),您现在应该看到以下各节按预期工作:
|
||||
|
||||
* **Book Details** on the lower left side, which includes: book type, number of pages, publisher, etc.
|
||||
* **Book Reviews** on the lower right side, which includes: red stars.
|
||||
* 页面左下角的 **Book Details** 中包含了书籍类型、页数以及出版商等信息。
|
||||
* 页面右下角的 **Book Reviews** 显示了红色星级的书评。
|
||||
|
||||
**Congratulations!** You successfully deployed a workload communicating over TCP traffic and applied
|
||||
both a mesh-level and a workload-level authorization policy to enforce access control for the requests.
|
||||
**恭喜!** 您已经成功部署了通过 TCP 流量进行通信的工作负载,并应用了网格级别和工作负载级别的授权策略来对请求实施访问控制。
|
||||
|
||||
## Cleanup
|
||||
## 清理{#cleanup}
|
||||
|
||||
1. Remove Istio authorization policy configuration:
|
||||
1. 删除 Istio 授权策略配置:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete authorizationpolicy.security.istio.io/deny-all
|
||||
$ kubectl delete authorizationpolicy.security.istio.io/bookinfo-ratings-v2
|
||||
{{< /text >}}
|
||||
|
||||
1. Remove `v2` of the ratings workload and the MongoDB deployment:
|
||||
1. 删除 `v2` 版本的 ratings 工作负载和 MongoDB 的 deployment:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml@
|
||||
|
|
|
@ -1,172 +0,0 @@
|
|||
---
|
||||
title: TCP 服务的权限控制
|
||||
description: 展示如何为 TCP 服务设置基于角色的权限控制。
|
||||
weight: 10
|
||||
keywords: [security,access-control,rbac,tcp,authorization]
|
||||
---
|
||||
|
||||
本任务涵盖了在服务网格中为 TCP 服务设置 Istio RBAC 所需的操作。可以阅读[权限控制概念文档](/zh/docs/concepts/security/#authorization).中的相关内容。
|
||||
|
||||
## 开始之前{#before-you-begin}
|
||||
|
||||
本文任务假设,你已经:
|
||||
|
||||
* 了解 [Istio 的授权和鉴权](/zh/docs/concepts/security/#authorization).
|
||||
|
||||
* 按照 [快速开始](/zh/docs/setup/getting-started/) 的指导,在 Kubernetes 中安装完成 Istio。
|
||||
|
||||
* 部署完成 [Bookinfo](/zh/docs/examples/bookinfo/#deploying-the-application) 应用示例。
|
||||
|
||||
部署完成 Bookinfo 应用后,打开 `http://$GATEWAY_URL/productpage` 连接进入到 Bookinfo 图书页面。在该页面中,可以看到一下几个模块:
|
||||
|
||||
* 在页面的左下方是图书详情 (**Book Detail**) 模块,内容包括:图书类型、页数、出版社等信息。
|
||||
* 在页面的右下方是图书评价(**Book Reviews**) 模块。
|
||||
|
||||
每次刷新页面后,图书页面的书评模块会有不同的版本样式,在三种版本(红色星级、黑色星级、没有星级)之间轮换。
|
||||
|
||||
## 部署并配置 TCP 服务{#installing-and-configuring-a-tcp-service}
|
||||
|
||||
默认情况下,[Bookinfo](/zh/docs/examples/bookinfo/) 应用示例只调用 HTTP 服务。为了演示 Istio 如何配置 TCP 服务的权限控制,我们首先需要将应用更新到 TCP 调用的版本。按照下面的步骤,部署 Bookinfo 应用示例,并且将 `ratings` 服务升级到 `v2` 版本,在该版本中会使用 TCP 调用后端 MongoDB 服务。
|
||||
|
||||
1. 部署 `v2` 版本的 `ratings` 服务,服务的 `ServiceAccount` 命名为 `bookinfo-ratings-v2`,有以下两种方式:
|
||||
|
||||
* 如果集群已开启 sidecar 自动注入,使用以下命令创建 `ServiceAccount` 并且配置新版的 `ratings` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
* 集群未开启 sidecar 自动注入场景下,需要执行以下命令手动完成 sidecar 注入,并创建新版本 `ratings` 服务和`ServiceAccount`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
1. 创建 `DestinationRule` 配置:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/destination-rule-all-mtls.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
因为 `VirtualService` 的配置中 `subset` 项依赖 `DestinationRule` 配置,所以在 `DestinationRule` 完全生效前需要等待几秒钟再添加 `VirtualService` 。
|
||||
|
||||
1. 在 `DestinationRule` 完全生效后,更新 `reviews` 服务只使用 `v2` 版本的 `ratings` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-ratings-db.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 浏览位于 `http://$GATEWAY_URL/productpage` 的产品页面:
|
||||
|
||||
在这一页面中会看到 **Book Reviews** 中出现的错误信息:**"Ratings service is currently unavailable."**。因为 `ratings` 服务的 `v2` 版本所依赖的 MongoDB 服务尚未部署。
|
||||
|
||||
1. 部署 MongoDB 服务:
|
||||
|
||||
* 在**启用自动注入**的网格中部署 MongoDB 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-db.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
* 在**没有启用自动注入**的网格中部署 MongoDB 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/bookinfo/platform/kube/bookinfo-db.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
1. 再次浏览位于 `http://$GATEWAY_URL/productpage` 的产品页面。
|
||||
|
||||
1. 检查页面中的 **Book Reviews** 内容。
|
||||
|
||||
## 启用 Istio 的权限控制 {#enabling-Istio-authorization}
|
||||
|
||||
执行以下命令,为 MongoDB 服务启用权限控制:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/rbac-config-on-mongodb.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
打开 Bookinfo `productpage` 页面 (`http://$GATEWAY_URL/productpage`), 可以看到:
|
||||
|
||||
* 页面左下角的 **Book Details** 中包含了书籍类型、页数以及出版商等信息。
|
||||
* 页面右下角的 **Book Reviews** 显示了错误信息:**"Ratings service is currently unavailable"**。
|
||||
|
||||
因为 Istio 授权是`默认拒绝`的,所以需要配置合适的权限之后才能访问 MongoDB 服务。
|
||||
|
||||
{{< tip >}}
|
||||
因为缓存和传播的关系,可能会有一些延迟。
|
||||
{{< /tip >}}
|
||||
|
||||
## 增强 TCP 服务的访问控制 {#enforcing-access-control-on-tcp-service}
|
||||
|
||||
接下来配置服务级别访问控制,使用 Istio 授权机制允许 `ragings` v2 服务访问 MongoDB 服务。
|
||||
|
||||
执行以下命令,完成授权策略:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/bookinfo/platform/kube/rbac/mongodb-policy.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
配置完成后,策略会有以下效果:
|
||||
|
||||
* 创建一个命名为 `mongodb-viewer` 的角色,这个角色有权访问 MongoDB 服务的 `27017` 端口。
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: "rbac.istio.io/v1alpha1"
|
||||
kind: ServiceRole
|
||||
metadata:
|
||||
name: mongodb-viewer
|
||||
namespace: default
|
||||
spec:
|
||||
rules:
|
||||
- services: ["mongodb.default.svc.cluster.local"]
|
||||
constraints:
|
||||
- key: "destination.port"
|
||||
values: ["27017"]
|
||||
{{< /text >}}
|
||||
|
||||
* 创建一个命名为 `bind-mongodb-viewer` 角色绑定 `ServiceRoleBinding`,将 `mongodb-viewer` 角色分配给 `bookinfo-ratings-v2`.
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: "rbac.istio.io/v1alpha1"
|
||||
kind: ServiceRoleBinding
|
||||
metadata:
|
||||
name: bind-mongodb-viewer
|
||||
namespace: default
|
||||
spec:
|
||||
subjects:
|
||||
- user: "cluster.local/ns/default/sa/bookinfo-ratings-v2"
|
||||
roleRef:
|
||||
kind: ServiceRole
|
||||
name: "mongodb-viewer"
|
||||
{{< /text >}}
|
||||
|
||||
用浏览器打开产品页面(`http://$GATEWAY_URL/productpage`)会看到:
|
||||
|
||||
* 页面左下角的 **Book Details** 中包含了书籍类型、页数以及出版商等信息。
|
||||
* 页面右下角的 **Book Reviews** 显示了红色星星。
|
||||
|
||||
{{< tip >}}
|
||||
由于缓存和传播开销可能会造成一定延迟。
|
||||
{{< /tip >}}
|
||||
|
||||
## 清理 {#cleanup}
|
||||
|
||||
* 删除 Istio 权限策略配置:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/bookinfo/platform/kube/rbac/mongodb-policy.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
还可以删除所有的 `ServiceRole` 和 `ServiceRoleBinding` 对象:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete servicerole --all
|
||||
$ kubectl delete servicerolebinding --all
|
||||
{{< /text >}}
|
||||
|
||||
* 禁用 Istio 权限控制:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/bookinfo/platform/kube/rbac/rbac-config-on-mongodb.yaml@
|
||||
{{< /text >}}
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
title: Citadel Configuration
|
||||
description: Customizing the Citadel certificate authority.
|
||||
title: Citadel 配置
|
||||
description: 定制 Citadel 证书颁发机构。
|
||||
weight: 30
|
||||
---
|
||||
|
|
Loading…
Reference in New Issue