备考ICA----Istio实验16---HTTP流量授权

备考ICA----Istio实验16---HTTP流量授权

1. 环境准备

bash 复制代码
kubectl apply -f istio/samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f istio/samples/bookinfo/networking/bookinfo-gateway.yaml

访问测试

bash 复制代码
curl -I http://192.168.126.220/productpage

2. 开启mtls

mtls/mtls-default.yaml

yaml 复制代码
apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: default
  namespace: default
spec:
  mtls:
    mode: STRICT

部署生效

bash 复制代码
kubectl apply -f mtls/mtls-default.yaml

3. 拒绝请求

default名称空间,拒绝所有请求

yaml 复制代码
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: deny-all
  namespace: default

配置生效

bash 复制代码
kubectl apply -f mtls/allow-nothing.yaml

访问测试

bash 复制代码
curl -I http://192.168.126.220/productpage

此时访问被拒绝.返回码403

4. 允许请求

4.1 productpage允许请求

允许以get方式访问productpage

auth/productpage-viewer.yaml

yaml 复制代码
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: productpage-viewer
  namespace: default
spec:
  selector:
    matchLabels:
      app: productpage
  action: ALLOW
  rules:
  - to:
    - operation:
        methods: ["GET"]

部署生效

bash 复制代码
kubectl apply -f auth/productpage-viewer.yaml 

访问测试

4.2 details允许请求

创建details-viewer允许从productpage访问到details

bash 复制代码
kubectl get pods productpage-v1-675fc69cf-xlg4x -o yaml|grep -i serviceaccount

cluster.local 本地集群

ns/default 命名空间

sa/bookinfo-productpage sa账号

auth/details-viewer.yaml

yaml 复制代码
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: details-viewer
  namespace: default
spec:
  selector:
    matchLabels:
      app: details
  action: ALLOW
  rules:
  - from:
    - source:
        principals: ["cluster.local/ns/default/sa/bookinfo-productpage"]
    to:
    - operation:
        methods: ["GET"]

部署生效

bash 复制代码
kubectl apply  -f auth/details-viewer.yaml

浏览器再次访问

4.3 reviews允许请求

创建reviews-viewer允许从productpage访问到reviews

auth/reviews-viewer.yaml

yaml 复制代码
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: reviews-viewer
  namespace: default
spec:
  selector:
    matchLabels:
      app: reviews
  action: ALLOW
  rules:
  - from:
    - source:
        principals: ["cluster.local/ns/default/sa/bookinfo-productpage"]
    to:
    - operation:
        methods: ["GET"]

部署生效

bash 复制代码
kubectl apply -f auth/reviews-viewer.yaml

此时reviews已经可以正常显示,但ratings还是有问题.

4.4 ratings允许请求

创建ratings-viewer允许从productpage访问到ratings

auth/ratings-viewer.yaml

yaml 复制代码
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: ratings-viewer
  namespace: default
spec:
  selector:
    matchLabels:
      app: ratings
  action: ALLOW
  rules:
  - from:
    - source:
        principals: ["cluster.local/ns/default/sa/bookinfo-reviews"]
    to:
    - operation:
        methods: ["GET"]

部署生效

bash 复制代码
kubectl apply -f auth/ratings-viewer.yaml

再次访问,现在所有页面都能正常展示了

至此备考ICA----Istio实验16---HTTP流量授权实验完成

相关推荐
岚天start19 分钟前
Kubernetes(k8s)中命令行查看Pod所属控制器之方法总结
kubernetes·k8s·pod·daemonset·deployment·statefulset
退役小学生呀1 小时前
十五、K8s可观测能力:日志收集
linux·云原生·容器·kubernetes·k8s
指月小筑9 小时前
K8s 自定义调度器 Part1:通过 Scheduler Extender 实现自定义调度逻辑
云原生·容器·kubernetes·go
Ashlee_code15 小时前
裂变时刻:全球关税重构下的券商交易系统跃迁路线图(2025-2027)
java·大数据·数据结构·python·云原生·区块链·perl
代码老y1 天前
从单线程到云原生:Redis 二十年演进全景与内在机理深剖
数据库·redis·云原生
David爱编程1 天前
Kubernetes 中的 Ingress 详解:HTTP 负载均衡、TLS 与路径转发实践
云原生·容器·kubernetes
逆羽飘扬1 天前
【云原生网络】Istio基础篇
网络·云原生·istio
江东大都督周总2 天前
springboot项目部署到K8S
运维·k8s
mysql学习中2 天前
k8s集群搭建
云原生·容器·kubernetes