备考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流量授权实验完成

相关推荐
hrhcode2 小时前
【云原生】三.Kubernetes核心对象(上):Pod与Label详解
云原生·k8s
only_Klein7 小时前
Kubernetes发布策略之蓝绿发布与金丝雀发布
云原生·容器·kubernetes
@hdd10 小时前
Kubernetes 可观测性:Prometheus 监控、日志采集与告警
云原生·kubernetes·wpf·prometheus
yunteng52112 小时前
Sealos部署k8s集群
云原生·容器·kubernetes·sealos
好学且牛逼的马16 小时前
从“配置地狱“到“云原生时代“:Spring Boot 1.x到4.x演进全记录与核心知识点详解
hive·spring boot·云原生
岱宗夫up17 小时前
FastAPI进阶3:云原生架构与DevOps最佳实践
前端·python·云原生·架构·前端框架·fastapi·devops
技术栈壳17 小时前
了解K8s
云原生·容器·kubernetes
Tadas-Gao17 小时前
微服务注册中心选型深度分析:Eureka、Nacos与新一代替代方案
java·分布式·微服务·云原生·eureka·架构·系统架构
m0_4889130117 小时前
新手小白也能学会的Dify本地部署教程(超详细)
人工智能·搜索引擎·云原生·eureka·开源·大模型·产品经理
AI开发架构师17 小时前
大数据领域Eureka的服务注册中心搭建
大数据·ai·云原生·eureka