I need restrict based on source ip.
I trying use AuthorizationPolicy for this
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: deny-all
namespace: eng
spec:
selector:
matchLabels:
app: ords-frontend
action: DENY
rules:
- from:
- source:
notIpBlocks: ["187.103.152.251/32"]
I think this problem occurs because I don’t recivie the source ip from the client and is required by notIpBlocks and i don’t understand reason.
user --> LB(80) --> istio-gateway(31380) --> Virtual Service --> Pod
The LB Listen on port 80 and the istio-gateway listen port 31380 using nodeport.
I can see traffic between lb and istio-gateway show the real client ip.
14:00:50.142249 IP 192.168.224.137.31380 > 187.103.152.251.33544: Flags [P.], seq 1:168, ack 540, win 309, options [nop,nop,TS val 934972807 ecr 2749116122], length 167
14:00:50.142840 IP 187.103.152.251.33544 > 192.168.224.137.31380: Flags [.], ack 168, win 510, options [nop,nop,TS val 2749116127 ecr 934972807], length 0
14:00:50.389345 IP 187.103.152.251.33544 > 192.168.224.137.31380: Flags [P.], seq 540:1080, ack 168, win 511, options [nop,nop,TS val 2749116372 ecr 934972807], length 540
14:00:50.391023 IP 192.168.224.137.31380 > 187.103.152.251.33544: Flags [P.], seq 168:335, ack 1080, win 317, options [nop,nop,TS val 934973056 ecr 2749116372], length 167
14:00:50.391595 IP 187.103.152.251.33544 > 192.168.224.137.31380: Flags [.], ack 335, win 510, options [nop,nop,TS val 2749116376 ecr 934973056], length 0
14:00:50.576550 IP 187.103.152.251.33544 > 192.168.224.137.31380: Flags [P.], seq 1080:1620, ack 335, win 511, options [nop,nop,TS val 2749116560 ecr 934973056], length 540
14:00:50.577706 IP 192.168.224.137.31380 > 187.103.152.251.33544: Flags [P.], seq 335:502, ack 1620, win 325, options [nop,nop,TS val 934973243 ecr 2749116560], length 167
14:00:50.578293 IP 187.103.152.251.33544 > 192.168.224.137.31380: Flags [.], ack 502, win 510, options [nop,nop,TS val 2749116563 ecr 934973243], length 0
the tcpdump was executed in k8s server where istio-gateway is running
I defined the parameter externalTrafficPolicy to Local
kubectl patch svc istio-ingressgateway -n istio-system -p ‘{“spec”:{“externalTrafficPolicy”:“Local”}}’
Below is my configuration by gateway and virtual services
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gw-eng-ords-frontend
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "engenharia.xxxx.local"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-gw-eng-ords-frontend
spec:
hosts:
- "*"
gateways:
- gw-eng-ords-frontend
http:
- match:
- uri:
prefix: /
route:
- destination:
host: ords-frontend
port:
number: 80
timeout: 900s
---```
I need restrict the access to url engenharia.xxxx.local for source ip.
Am I do some configuration wrong ?