Setting up Secure Access Control

xiaoxiao2021-02-28  49

这个task展示如何通过使用Istio认证提供的服务账户来安全控制访问服务。

当Istio的相互TLS身份认证开启后,服务端通过它的证书认证客户端,并从证书中获得服务端的服务账户。服务账户在 source.user 属性中。对于Istio中的服务账户格式,请参考 Istio auth identity。

Before you begin

在开启认证的k8s集群中安装Istio。注意认证在 installation steps 中的第5步。部署 Bookinfo 运行下列命令创建服务账户 bookinfo-productpage,使用服务账户重新部署 productpage 服务。 kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo-add-serviceaccount.yaml)

你能看到如下预期打印:

serviceaccount "bookinfo-productpage" created deployment "productpage-v1" configured

注意: 如果你使用的是非 default 命名空间,使用istioctl -n namespace ... 来指定命名空间。

Access Control using denials

在 Bookinfo 中, productpage 服务同时访问 reviews 服务和 details 。我们希望 details 服务拒绝来自 productpage 的请求。

1.在你的浏览器中访问Bookinfo productpage (http://$GATEWAY_URL/productpage). 你应该在页面左下部看到 “Book Details” 小节,包括type, pages, publisher, etc。 productpage 服务包含来自details 服务的“Book Details” 的信息。

2.明确拒绝从 productpage 到 details 的请求 运行如下命令设置拒绝规则以及handler和一个实例

istioctl create -f samples/bookinfo/kube/mixer-rule-deny-serviceaccount.yaml

预期结果:

Created config denier/default/denyproductpagehandler at revision 2877836 Created config checknothing/default/denyproductpagerequest at revision 2877837 Created config rule/default/denyproductpage at revision 2877838

注意下面的 denyproductpage 规则:

match: destination.labels["app"] == "details" && source.user == "cluster.local/ns/default/sa/bookinfo-productpage"

它匹配来自 details 服务的服务账号“cluster.local/ns/default/sa/bookinfo-productpage”的请求。 注意: 如果你使用非default 命名空间,将source.user 的值 default 替换为你的命名空间。 这个规则使用 denier 适配器拒绝这些请求。这个适配器总是用前置状态码和信息拒绝请求。状态码和信息在 denier 适配器的配置中指定。

3.在你的浏览器中刷新 productpage 你将看到信息:“Error fetching product details! Sorry, product details are currently unavailable for this book.” 在页面左下部。这表示从 productpage 到 details 的请求被拒绝了。

Cleanup

移除mixer配置 istioctl delete -f samples/bookinfo/kube/mixer-rule-deny-serviceaccount.yaml 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。
转载请注明原文地址: https://www.6miu.com/read-2613156.html

最新回复(0)