Setting up Secure Access Control

这个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.明确拒绝从 productpagedetails 的请求
运行如下命令设置拒绝规则以及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.” 在页面左下部。这表示从 productpagedetails 的请求被拒绝了。

Cleanup

  • 移除mixer配置
istioctl delete -f samples/bookinfo/kube/mixer-rule-deny-serviceaccount.yaml
  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值