My structure
- Kubernetes cluster on GKE
- Ingress controller deployed using helm
- An application which will return list of IP ranges note: it will get updated periodically
curl https://allowed.domain.com
172.30.1.210/32,172.30.2.60/32
- Secured application which is not working
What I am trying to do?
- Have my clients IPs in my API endpoint which is done
curl https://allowed.domain.com
172.30.1.210/32,172.30.2.60/32
- Deploy my example app with ingress so it can pull from the
https://allowed.domain.com
and allow people to access to the app
What I tried and didn’t work?
- Deploy the application with
include
feature of nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
include /tmp/allowed-ips.conf;
deny all;
yes its working but the problem is when /tmp/allowed-ips.conf
gets updated the ingress config doesn’t
- I tried to use if condition to pull the IPs from the endpoint and deny if user is not in the list
nginx.ingress.kubernetes.io/configuration-snippet: |
set $deny_access off;
if ($remote_addr !~ (https://2ce8-73-56-131-204.ngrok.io)) {
set $deny_access on;
}
- I am using
nginx.ingress.kubernetes.io/whitelist-source-range
annotation but that is not what I am looking for
None of the options are working for me.
2
Answers
From the official docs of ingress-nginx controller:
After the nginx
ingress resource
was initially created, theingress controller
assembles the nginx.conf file and uses it for routing traffic. Nginx web server does not auto-reload its configuration if the nginx.conf and other config files were changed.So, you can work around this problem in several ways:
ingress resource
with new IP addresses and then apply changes to the Kubernetes cluster (kubectl apply / kubectl patch / smth else) / for your options 2 and 3.nginx -s reload
inside an ingress Pod to reload nginx configuration / for your option 1 withinclude
the allowed list file.Sharing what I implemented at my workplace. We had a managed monitoring tool called Site24x7. The tool pings our server from their VMs with dynamic IPs and we had to automate the whitelisting of the IPs at GKE.
nginx.ingress.kubernetes.io/configuration-snippet
allows you to set arbitrary Nginx configurations.curl
,getent
, etc.)nginx.ingress.kubernetes.io/configuration-snippet
)kubectl
command which overwrites the annotation of the target ingresses.Example shell/bash script:
The shell/bash script can be stored as ConfigMap to be mounted on the CronJob resource.