九 Istio:istio安全之授權( 四 )


apiVersion: security.istio.io/v1beta1 kind: AuthorizationPolicy metadata:name: allow-web-frontend-customersnamespace: default spec:selector:matchLabels:app: customersversion: v1action: ALLOWrules:- from:- source:namespaces: ["default"]source:principals: ["cluster.local/ns/default/sa/web-frontend"]將上述 YAML 保存為 allow-web-frontend-customers.yaml,并使用 kubectl apply -f allow-web-frontend-customers.yaml 創建策略 。
一旦策略被創建 , 我們將看到 Web 前端再次工作——它將獲得 customers 服務的回應 。
我們使用了多個授權策略 , 明確地允許從入口到前端以及從前端到 customers 服務的調用 。使用 deny-all 策略是一個很好的開始,因為我們可以控制、管理,然后明確地允許我們希望在服務之間發生的通信 。
4.2 清理刪除 Deployment、Service、VirtualService 和 Gateway:
kubectl delete sa customers-v1 web-frontend kubectl delete deploy web-frontend customers-v1 kubectl delete svc customers web-frontend kubectl delete vs customers web-frontend kubectl delete gateway gateway kubectl delete authorizationpolicy allow-ingress-frontend allow-web-frontend-customers deny-all kubectl delete pod curl

推薦閱讀