Please ease my suffering here: I'm trying to block a single IP from getting to one of the sites hosted on EKS. I've tried the server-snippet annotation, but it didn't work. I've also tried creating a network policy to block, no luck. Any idea how to set up a list of restricted IPs?
Here's the Network Policy:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: web-dev-network-policy
namespace: target_namespace
spec:
podSelector:
matchLabels:
app: php
policyTypes:
- Ingress
ingress:
- from:
- ipBlock:
cidr: source_ip_value/32
ports:
- protocol: TCP
port: 80
And here's the server-snippet:
nginx.ingress.kubernetes.io/server-snippet: |
location / {
deny source_ip;
}
Edit:
When monitoring incoming requests for the domain, I can see that CoreDNS rewrites the requests (I suppose) to match the service name where the site is hosted. I guess that's why the location /
doesn't match the request and is allowed, ex.:
source.ip.address - - [time/date] "HEAD / HTTP/2.0" 200 0 "-" "curl/7.58.0" 54 0.382 [service-name-service-name-80] [] private.ip:80 0 0.384 200 7a06748e7395fbsssceb737723399919