You will start by denying all traffic.
1apiVersion: security.istio.io/v1beta12kind: AuthorizationPolicy3metadata:4 name: deny-all5 namespace: default6spec: {}
1---2apiVersion: "security.istio.io/v1beta1"3kind: "AuthorizationPolicy"4metadata:5 name: "allow-get"6 namespace: default7spec:8 selector:9 matchLabels:10 app: httpbin11 rules:12 - to:13 - operation:14 methods: ["GET"]
1---2apiVersion: "security.istio.io/v1beta1"3kind: "AuthorizationPolicy"4metadata:5 name: "view-productpage"6 namespace: default7spec:8 selector:9 matchLabels:10 app: productpage11 rules:12 - to:13 - operation:14 methods: ["GET", "POST"] # try login with just GET (fails)15---16apiVersion: "security.istio.io/v1beta1"17kind: "AuthorizationPolicy"18metadata:19 name: "view-details"20 namespace: default21spec:22 selector:23 matchLabels:24 app: details25 rules:26 - from:27 - source:28 principals: ["cluster.local/ns/default/sa/bookinfo-productpage"]29 to:30 - operation:31 methods: ["GET", "POST"]32---33apiVersion: "security.istio.io/v1beta1"34kind: "AuthorizationPolicy"35metadata:36 name: "view-reviews"37 namespace: default38spec:39 selector:40 matchLabels:41 app: reviews42 rules:43 - from:44 - source:45 principals: ["cluster.local/ns/default/sa/bookinfo-productpage"]46 to:47 - operation:48 methods: ["GET", "POST"]49---50apiVersion: "security.istio.io/v1beta1"51kind: "AuthorizationPolicy"52metadata:53 name: "view-ratings"54 namespace: default55spec:56 selector:57 matchLabels:58 app: ratings59 rules:60 - from:61 - source:62 principals: ["cluster.local/ns/default/sa/bookinfo-reviews"]63 to:64 - operation:65 methods: ["GET", "POST"]
1---2apiVersion: "security.istio.io/v1beta1"3kind: "AuthorizationPolicy"4metadata:5 name: "view-reviews"6 namespace: default7spec:8 selector:9 matchLabels:10 app: reviews11 rules:12 - from:13 - source:14 principals: ["cluster.local/ns/default/sa/bookinfo-productpage"]15 to:16 - operation:17 methods: ["GET"]18 when:19 - key: request.headers[end-user]20 values: ["naruto"]
1apiVersion: networking.istio.io/v1alpha32kind: DestinationRule3metadata:4 name: productpage5spec:6 host: productpage7 subsets:8 - name: v19 labels:10 version: v111---12apiVersion: networking.istio.io/v1alpha313kind: DestinationRule14metadata:15 name: reviews16spec:17 host: reviews18 subsets:19 - name: v120 labels:21 version: v122 - name: v223 labels:24 version: v225 - name: v326 labels:27 version: v328---29apiVersion: networking.istio.io/v1alpha330kind: DestinationRule31metadata:32 name: ratings33spec:34 host: ratings35 subsets:36 - name: v137 labels:38 version: v139 - name: v240 labels:41 version: v242 - name: v2-mysql43 labels:44 version: v2-mysql45 - name: v2-mysql-vm46 labels:47 version: v2-mysql-vm48---49apiVersion: networking.istio.io/v1alpha350kind: DestinationRule51metadata:52 name: details53spec:54 host: details55 subsets:56 - name: v157 labels:58 version: v159 - name: v260 labels:61 version: v262---
Note: this lab uses the sample application HTTPbin.
Using Meshery, deploy the HTTPbin sample application.
1apiVersion: security.istio.io/v1beta12kind: AuthorizationPolicy3metadata:4 name: require-jwt5 namespace: foo6spec:7 selector:8 matchLabels:9 app: httpbin10 action: ALLOW11 rules:12 - from:13 - source:14 requestPrincipals:15 ["testing@secure.istio.io/testing@secure.istio.io"]16 when:17 - key: request.auth.claims[groups]18 values: ["group1"]
1apiVersion: "security.istio.io/v1beta1"2kind: "RequestAuthentication"3metadata:4 name: "jwt"5 namespace: default6spec:7 selector:8 matchLabels:9 app: httpbin10 jwtRules:11 - issuer: "testing@secure.istio.io"12 jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.7/security/tools/jwt/samples/jwks.json"
Using Meshery, you can change mTLS enforcement for a namespace.
To configure mTLS on more selective level, you can change and apply this configuration:
1apiVersion: "security.istio.io/v1beta1"2kind: "PeerAuthentication"3metadata:4 name: "default"5 namespace: "istio-system"6spec:7 # selector:8 # matchLabels:9 # app: httpbin10 mtls:11 mode: STRICT #ISTIO_MUTUAL,DISABLE12 # portLevelMtls:13 # 80:14 # mode: DISABLE