-
Notifications
You must be signed in to change notification settings - Fork 3k
Access Lists: support for dynamic IP-Addresses #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would really like this as well. I think the approach presented by Mike from WPBullet would work really well if containerized. https://guides.wp-bullet.com/auto-whitelist-multiple-dynamic-dns-addresses-for-nginx-security/ The variables the script relies on could be written to a file or environment variables, and later be retrieved by the script that could run as a cron job. The Access List could be extended so either an IP address is given or a domain is given. Entering a domain should extend the list of domains the script would whitelist. |
I'm in the same situation, did you find any workarounds for this? |
+1 |
1 similar comment
+1 |
Is there any way for me to finagle this to work with npm running in docker? |
I did some finagling, and I have it working, but it requires modifying the docker container and adding a script. The downside, of course, is that you have to re-modify the container when you update. But I figure that doing this is better than the unpredictability of having your IP address change and then having to manually change it right when you needed access to your site. I did the following:
The cat command showed my IP so the script worked for that purpose. In Nginx Proxy Manager, I navigated to Hosts > Edit > Advanced and in Custom Nginx Configuration I pasted:
This adds to a conf file in (the docker container) The problem is, when I go to my site (from my added IP address), I get 403 Forbidden. Checked the error log (again, within the docker container): tail -100 /data/logs/proxy-host-4_error.log (log path was defined in
I also had the same issue with the address 10.6.0.2 if I went outside my LAN (data on my phone) and connected to my home via OpenVPN. This is because I am trying to connect to it from within the same network my machine (with NPM and my site) is on. So I modified my Custom Nginx Configuration in NPM to:
I don't have any way to test this currently, but I think all of this will work properly if I connect to one of the LANs for one of the public IPs in the list. All I have left to do is create a cron job to keep the IP addresses updated. Edit: I wanted to add that I changed the script a little (copied from someone who commented on the page with the script) so that if a host is unreachable, it doesn't crash the nginx. This is the section that I changed:
|
Nice work! Thank you for that! What do others think, is there any chance to see this in the final build as optional feature? You may start a Pull Request, so that others can review your changes directly. |
I hope this isn't a dumb question, but wouldn't I need a more complete solution to start a pull request? Like, we would need a GUI solution added so that users can perhaps add their DDNS address in Access Lists > Add Access List > Access and there would be the addition of typing in a DDNS and not just IP address or CIDR. I'm new to the whole PR thing. lol |
@threehappypenguins crontab -e But after restarting the container, it's gone again. How can I make this permanent? Should be included in the release. |
I don't have enough coding experience so I'm hoping someone can maybe poke around a little more and find a way to implement this. Here are my observations so far: When you create an Access List, Then, if you apply your access list to a host, it writes the IP address(es) to a conf file in
to:
I'm thinking that maybe somehow add the ability to access a DDNS in the access list, and it will trigger the script (with placeholders/variables in place of the actual IP addresses), and those IP addresses could then be saved to the mysql database, ready to be added to the OR, maybe we could have everything function as normal where the script writes to a file, and if the access list is applied to the host, it writes that line Just thinking out loud here. |
I just wanted to give an update not that add a CIDR like 192.168.1.1/24. When I would try to connect from one of the public IP addresses in my dynamicips list, it was forbidden, despite being in the list.
So I removed the /24 from the end, and I could connect just fine. |
I noticed when the IP changes. You also have to save again in Custom Nginx Configuration so that it applies the change of the new IP |
Something else I noticed, if you do an update of your container, then you get a connection refused error in the browser when trying to open the npm management page. Looking at the npm logs from portainer, I noticed:
So what happens is the dynamicips file disappears upon update, and because the Custom Nginx Configuration is still there (calling on to include a file that doesn't exist), it causes the npm site not to load. So I had to go into the docker container shell, and I commented out the location / section that shows up when you add to Custom Nginx Configuration. After I saved, I was able to log into the npm site. Then I deleted the Custom Nginx Configuration, and had to start over with all the steps I outlined above (creation of the script, etc). |
I developed a little auth helper that handles this usecase with It's a go binary you need to run next to nginx that will handle reverse dns lookups. Maybe you can also make use of this in NginxProxyManager |
Can you explain how we implement this? I don't really understand what to do with it... like, do we install it within the docker container or something? |
you need to run it in a seperate (not exposed to the internet) container but it all boils down if you can configure the |
I've created a fork of NPM that builds the hack from @threehappypenguins here into a docker image that lets you pass your DDNS hosts as an environment variable. The script has been added to a cron schedule also, which checks every 60s for a change to the IP and outputs if there was an update or not to var/log/cron More info on the repo here |
Awesome! I'm gonna take a look! Thanks! |
@rbullers "127.0.0.1;" should be "allow 127.0.0.1;" right? |
@mczeus Yes you're right - I've amended the error, thanks for pointing it out. |
rbullers this is great!! Would you mind doing a pull request to https://github.com/NginxProxyManager/nginx-proxy-manager ? |
I created a PR which lets you use the NPM web UI to directly specify dynamic host names in the access list address field (using It automatically handles recreating host config & nginx reloading whenever the IP changes (by default it polls every 1 hour, but this can be configured via the Since its integrated to nginx proxy manager backend server, it is much easier to use than specifying a list of domains via env var and having to go in to
E.g. in your docker compose file, replace: |
Thank you! I'm really late in trying this out, but I just did, and it works great! |
Glad you found it useful! |
@vari Hoping it will be merged on main as well! |
Hey all <3 I had a hard crack at doing this with a cron+script and got something fairly simple in place. I'm running docker with Nginx Proxy Manager and wanted to update my access control lists to my dynamic DNS IP address, since I don't have a static IP. This is so I can lock down my proxy hosts to only be accessible from my WAN address with the inbuilt Nginx proxy manager access lists. I didn't want to use a fork because i wanted to make sure i was always running the latest version of NPM for security reasons. My nginx host configs are located at '/apps/nginxproxy/data/nginx/proxy_host/'. My docker volumes for NPM are mounted on the host at this folder location for easy access. Your location for this will more than likely be different, but if you can find your nginxproxymanager folder, the configs for your hosts should be in the 'data/nginx/proxy_host/' subfolders. The below script does the following: WAN IP Retrieval: Previous IP Check: WAN IP Change Detection: WAN IP Update: Configuration File Modification: Reload nginx proxy manager configuration `#!/bin/bash #check if the WAN IP file exists, create it with the WAN IP if not. if [ "$WAN_IP" == "$OLD_WAN_IP" ]; then docker exec nginxproxy-app-1 /bin/bash -c "/usr/sbin/nginx -s reload"` This solved my issues and now I won't get locked out of my Nginx proxy manager hosted sites from my ACL's every time my WAN IP changes..!! Also this won't get wiped out of NPM happens to release an update. I hope this helps someone else 💜 I'll keep an eye out for replies so if you have questions shoot them through and i'll answer if I can help 😊 |
Hey, I try to implement your script, but it won't change the line in the config. Could it be, that the format of the sed command was messed up, because of markdown? Could you maybe provide the script in a code bracket so with three backticks (```) instead of one? 😊 |
I give it a shot to scratch my itch with NPM on this topic which I was having, it might help you with this issue. |
Issue is now considered stale. If you want to keep it open, please comment 👍 |
I'm still interested in this feature. |
Is your feature request related to a problem? Please describe.
I use the access list feature to restrict access to a subdomain to devices from my home network. Since my ISP does not assign IP addresses statically, I have to log into the webinterface every so often and replace my old IP address with my new one.
Describe the solution you'd like
I have a dynamic dns record that is kept up-to-date with my home IP address. I would like to use this dynamic dns entry for the access list. I imagine that the proxy manager periodically resolves the domain and then replaces the ip address in this access list accordingly.
Describe alternatives you've considered
I dont really see an alternative to my proposal. Will update this issue if a better solution comes to my mind.
The text was updated successfully, but these errors were encountered: