-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
"docker network inspect" requires at least 1 argument. #1
Comments
Interesting, once I get home tonight I'll take a look. In one of the files should be some configs. Can you paste what you are using so I have the same setup when I test. I actually need to change those because I think right now they default to manual mode out of the box. If I remember correctly it may be looking for your network adapter starting with
If you do I have the following:
And finally, what distro are you running. |
Thanks. I do, but:
|
Can you check my previous reply, I asked about several pieces of info, including what configs you are using in the section csf-firewall/2-patch-docker/2-patch-post/docker.sh Lines 16 to 22 in 240e2d0
And what OS you are running so that I can test. |
Our config is:
As far, we figured out the error comes at the container loop here:
bridge=$(docker inspect -f "{{with index .NetworkSettings.Networks "${netmode}"}}{{.NetworkID}}{{end}}" ${container} | cut -c -12) returns blank in some cases, due to the previous command: which in our case in some scenarios is the network name (works fine) in others is a hash. Sample:
And therefore the variables there do not get correctly set for some containers. I hope that makes sense. |
Yeah this makes sense. At present, I'm sort of "re-working" the script. It was sort of a quick slap together, but there are some easier ways to do this such as merging all of the steps together and making a simple single file to run, as well as error messages when certain things aren't configured properly. With this, I'll look through the issue above and see if I can clean it up and make it work better. |
Alright, I see what's going on. Manual mode works fine. The error is thrown when manual mode is turned off. Need to re-organize some stuff. |
fixes the error: "docker network inspect" requires at least 1 argument.
adds logging which displays each ip rule added to detect when things go wrong
Alright, the scripts have been dramatically changed. I need to do some more testing tomorrow, but currently, it works for me in and out of manual mode. Once the scripts are installed, you can also track what is added as the scripts do their thing if you run sudo csf -r This should re-add the rules again, but spit out the steps. Keep in mind however, when I re-did the script today, I added a bunch of automation to make things easier. So when the However, if CSF is not installed; it will download the latest version and install the required packages used with CSF. I updated the README, so it should explain everything. Also added OpenVPN server support as another script in the |
Thanks. I will be giving them a try but at the moment we are actually looking into alternative firewalls, unless we can solve the open ports issue with Docker Networking on one hand and the source IP on container level, which for some reason we loose too when implementing CSF and manual rules. The first we think we can solve since we've been routing NAT traffic through CSF with a set of rules passing through CSF LOCALINPUT chain and we hope we can emulate that. The second one we are completely unclear why. It would be great if you can clarify how indispensable it is to install your "csf" copy. I mean, as far as I understood, your modifications come from the csfpost/pre processes, so they should work on a standard CSF installation. Is that so? I am still extremely surprised that the firewall + Docker networking is so complicated and with such a lack of alternatives. On the other hand, also concerned about the current development situation of CSF itself. |
If you're asking if you need to install the copy of CSF I have provided in this repo, no. You can download CSF straight from the website. I provide a copy of CSF because it just makes my life easier. When I create a new build of the scripts, my workflow automatically grabs the latest version of CSF from the developer server, finds the version number in the version.txt, appends the version number to the .tgz archive and then adds it as an artifact along with the patches zip. My copy of the csf .tgz is exactly what the developer also publishes, with no edits. That's why I also outlined that several times in the readme:
What matters is you installing the I can probably kill the
Sadly, this is also the case with UFW (which are basically just more simple versions of iptables). There have been numerous scripts published which do the same things this repo does, except for UFW instead of straight iptables.
From what I understand, CSF is still actively maintained, and is also a big part of the cPanel + WHM combination. If you see CSF being removed from WHM as an automatic install; then that's the moment you should be concerned that development is dead. Right now CSF is pretty stable, and contains a lot of the functionality that a firewall should have with a GUI. Sure, there are some extra things that would make life easier, but that developer also works on several other projects; and he has a paid service. But for as long as I've ran CSF; I haven't found anything that is massively needed on my end. I've had docker, traefik, and CSF running now for about a year; and it has been flawless.
When you say lose, do you mean that you add the firewall rules, but then they disappear from iptables? Have you tried installing / using the With the script I provide, every single time you start CSF; my patch re-adds the iptable rules to your table. However, if you manually add new iptable rules; they will be lost when you restart the system, shut down iptables, or clear the table. However, if you use the After you install the package, run sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6 Your iptables will be saved to
Alternatively, you can use the commands:
What you could do is bring docker down completely, and CSF; then wipe your iptables, completely. The latest version of my install.sh includes a ./install.sh --flush Or manually, you can run the commands below: iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X Then add any custom rules you need that should be persistent, and then save them to file with iptables-persistent
After you have the rules in place you need, you can bring docker, csf/lfd back up, and then let my scripts automatically add their rules. Reason for that is that my script is dynamic, and will add new rules based on any new containers you add to your docker install. So if you run docker + my script first, and then use the persistent command, you'll save my rules too. But then they'll be added again once you restart csf, along with any new rules if you add new containers. That is the major complaint of iptables; it has no way of determining if a rule is added multiple times, it will allow the same rule to be added over and over again, and you could end up with an iptables list that has 10 of the same rule; which just makes it cluttered. |
I went ahead and removed the |
I finally had time to test your new config and unfortunately errors remain when executing post rules. A brief list, but perhaps they are all derived from the first one. Please note this is a manually created network:
Then we get one network correctly created but then again:
As explained earlier we are trying alternative solutions/scripts but thought you might be interested in this outcomes |
Yeah that's fine, but at least we'll get these bugs ironed out. Can you re-paste me what you have now in the docker.sh (docker_int, etc) file at the top? My current settings don't throw this error. For some reason, it's not fetching the bridge, which means it's not tracking the initial network being used by the container(s). Going to go plug some values in. |
There was a mistake there but we've retried with the same result.
The settings are:
Please note:
We have a few scripts done parsing docker networks to generate rules that seem to do their job, in case you have interest. To be honest we are still struggling with our objective to avoid that by having the docker open ports in PREROUTING skips all CSF IP white and blacklist. Trying to make sure that traffic gets route via the FORWARD chain LOCALINPUT that CSF handles. We also, for some reason, loose source IP at Docker level. |
Dumb question. On the items that are erroring, you wouldn't happen to have multiple network adapters assigned to that container would you? I got some time, so I went through the code, and I noticed something I should have caught earlier. It was even doing it on mine. Containers with multiple networks, such as the Mailu SMTP server would error because I have that returning a newline list of network adapters. So if a container had multiple networks, it would error out because it was reading the entire list of networks, instead of line by line. Because when I compare your errors to mine, it errors in the exact same spot. I patched that bug, but I'm also going to throw some other debug proof prints in to at least track these down if they occur. |
Also, |
Alright. I've tested the patches on my own setup, and I've also tested on a secondary machine fresh installed. Even when a container has multiple network adapters assigned to it. The patch will include all depending on their settings. |
Thanks for the new version. Tested and working great! 🔥 |
@Aetherinox Only a little warning I have on Debian 10 (Buster):
Is it possible to uninstall iptables-legacy to remove that warning? I am not sure whether CSF supports nftables. Without the iptables-legacy (iptables package) the CSF would not work, right? |
Good to hear. Progress is nice. At least the manual mode stuff is gone now. One less thing for users to worry about. Usually that error appears is because iptables has found that one of 5 legacy modules needs to be loaded:
At present, CSF is not utilizing the netfilter structure (see: https://forum.configserver.com/viewtopic.php?t=10795) This is where I've sort of come to a cross road. Obviously CSF still gets updates, granted, they are very small updates that don't do a lot of changes. I've debated on branching CSF off into my own version, and doing the needed changes to update CSF to utilize said functionality. As mentioned elsewhere, Ubuntu 20.10 decided to migrate completely over to nftables and do away with iptables, coupled with the fact that nftables brings a lot more to the table that I'd rather CSF be using. I'm on ubuntu 24, and it annoys me that I still need iptables-legacy installed. CSF is a great asset, but there's a few places that need an overhaul. And I don't see the original developer doing it anytime soon. So it may be something I debate on doing, and would at least make life easier for patches I've made such as the Dark Theme. Sadly until then, we're stuck with legacy. |
I see, so if I understand correctly, it is not currently possible to get rid of the warning? Would blacklisting or removing modules using rmmod fix the warning, or CSF would fail to set iptables rules altogether? |
I've been reading through the CSF rules, and I noticed in v21.19, the developer added a section which converts iptables-legacy over to iptables-nft csf-firewall/src/official/os.pl Lines 42 to 49 in c3ba828
The check in CSF is looking specifically for
And see if you get a response and list of rules. Finally, when you get the error
Can you print me the surrounding lines around the error? It appears when I run it on my two servers, I don't have any legacy iptables. It you run the following command, it should spit out what rules are using legacy structure:
Mine currently looks like: Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination You can also spit them out to a file using iptables-legacy-save > iptables-legacy-save.txt
ip6tables-legacy-save > ip6tables-legacy-save.txt If you use the legacy list command, it should show specifically what rules are legacy. If they are custom rules you've added, you can convert them over to nftables using (random rule example here) iptables-translate <rule>
iptables-translate -A DOCKER -d 172.18.0.3/32 ! -i br-a58c28cc477d -o br-a58c28cc477d -p tcp -m tcp --dport 995 -j ACCEPT Which will spit out the nft equivalent you can add as a rule: nft 'add rule ip filter DOCKER iifname != "br-a58c28cc477d" oifname "br-a58c28cc477d" ip daddr 172.18.0.3 tcp dport 995 counter accept' Obviously CSF's usage of converting is better than nothing, but there are still a few places where things could be improved. Yet another thing I can add to my list. I'd much rather just straight up use nftables instead of the iptables-nft wrapper. |
Hi, thanks much for the information! When I execute this command:
I get:
When I execute this command:
I get:
I've checked what binaries does the "iptables" package contain using the following command:
It seems that this package contains:
When I executed:
It turned out it is a symlink to:
When I further executed:
It turned out it is another symlink to:
So I am not sure if I can get rid of that warning at all. The warning is shown when executing your script:
And furthermore for each of the container rules:
And as shown before, also when executing:
So now I am not quite sure whether I can easily remove the "iptables" package just to get rid of that warning. Furthermore I see that your patch:
What happens when the docker container is restarted or upgraded? Currently I use the Watchtower and once it upgraded the container, I lost access to that container. I had to run:
For nginx proxy to be able to get a direct connection to the container once again.. Is there any hook for docker, which will restart csf automatically, so that upgraded/restared containers work flawlessly? And last but not least regarding the: "csf.allow" file, I see that the file can get polluted very quickly depending on how many containers are used on the system. Is there any clean-up procedure, so that it does not have thousands of lines after a year? Currently, over 50 lines were added within 2 days.. So three points to discuss here:
Hope we can perfect this script, so it can be used by everyone without any issues! PS: Now I remember that I also added a systemd docker drop-in: "run-before-csf.conf":
I don't know if this is needed, but it made starting my containers and WireGuard connection faster on startup.. |
You are running Debian 10 / Buster on this machine correct? I want to bring up a VM and test it out on there. I'm currently on Ubuntu 24.04 LTS.
Out of box with ConfigServer Firewall + If you attempted to bring a container up after shutting down / restarting CSF; it would originally throw an error that rules were not available for that container and it would cause the container to not respond to any actions.
Let me guess, you have the docker container automatically assigning IPs correct? You're not using a static IP assigned in the nginx Let me pop into an install of docker + CSF on Debian 10 and I'll take a look at some type of automatic refresh functionality. Since docker is containerized, it limits what can be done on the host machine (for security reasons). Obviously the simple solution would be to create a systemd job which runs through your containers each day. But that presents other issues like tags. I usually advise people against using the Of course the user could have a bash script to check the current image hash against the latest using something such as: docker inspect your-container -f '{{index .Config.Labels "com.docker.compose.config-hash"}}' Another option is also via a script, but with the use of the Portainer API. This is a good example (or argument) for me wanting to actually write my own version of CSF, vs just these patch scripts. Because actually changing the functionality of CSF itself gives me much more vast abilities. Docker service monitoring could then be built in, as well as a complete migration of nftables.
This one is fair to think about. I can come up with something for this so that it's automated. I just have to differentiate between a custom added rule by you, and one added by the system. Then on CSF startup, I can just clean up the list of the ones added by the system, leaving only the custom user additions. I'll come up with something for this once I get a debian install going. The only concern I have about this is that /etc/csf/csf.allow is usually owned by root. And trying to automate this without the need for a sudo password every time. When instead, editing the CSF app itself would solve the issue. |
Yes, I use Debian 10 Buster. Will upgrade to Debian 12 once I have more free time..
I am aware of this. Your patch is working very well!
I have nginx on host. Running pi-hole, watchtower and several other containers in the docker.
I see, this is probably the best approach. I checked Docker website and found that hooks are not implemented and probably never will be: So one option is maybe to use Watchtower hooks (if there are any).. In case of manual restart, one could simply run your patch or execute:
This could be done by awk/sed I guess.. In your script there is a variable for description, so this could be leveraged IMHO..
Thanks!
When running:
..in the console, I guess sudo/root is used anyway even for executing your docker patch, so this should be fine I guess. Thanks! |
adds logging which displays each ip rule added to detect when things go wrong
Thanks, let me test it tomorrow! :) |
Sure thing, I'm just cleaning up the repository a bit. I've set up an automated service which can also be used with CSF. The repository now contains a list of the top abusive IP addresses which are featured on websites like AbuseIPDB, as well as long-term bad actor IPs. So people can implement those blocks into their firewall rules to cut down on SSH brute-forces, sniffing, etc. |
@Aetherinox Hey, does your service use ipset and csf.blocklists? I have currently these entries in that file to prevent spam:
|
The end answer is multiple. At present, I've finished the entries for individual blocks which go inside Both will support 100% confidence hits from abuseipdb and ipthreat.net. I'm also looking at adding the possibility of MaxmindGeoIP, but I need to write up the workflows for that first to fetch the proper entries. I use Maxmind myself, but I need to go read up on the API limits, so that I can pull them and ensure they're constantly updated. I forget how often Maxmind updates. Then at the end, you can just include the github file in your list (much like the one you have for The basic But in short, the Edit: Actually, the more I think about it. I may just not do the |
Yeah, this sounds great. Is your block list periodically updated? I had to disable #AWS list, since I wasn't receiving emails nor was able to connect to sites hosted on Amazon.. |
Yes, every 6 hours. I'm in the middle of re-working it to remove the URLs may change. I'll throw a message once I'm done. |
Great. Thx! |
Alright, one final major change. The blocklist is now compatible with the CSF blocklist feature. The new URL is:
It's also compatible with pihole, and the other major ones. The rules with AWS have been removed, they'll be added to another list. The IPs in this master list are strictly ssh bruteforce and port scanners ONLY. The master list should only ever have IPs which nobody would need to edit or remove some from (unless your own IP is in there). AWS and the other privacy rules have been moved to Updates every 6 hours.
The header at the top of the files contains the count, and update time
Now comes the fun part where I have to write scripts to grab all the different types of IPs. |
Alright, I've finished cleaning things up and getting the base finished. All of the blocklists can be found at: Services like AWS are broken up into their own files, this also includes:
You can pick whatever privacy rulesets you want. Check back from time to time, I'm adding more. The only major thing I need to do is break up some of these into different timers / crons. Right now, all lists are updated every 6 hours. Which is good for private / vps ip addresses, but isn't needed for things like Amazon / Bing, since their IP addresses don't change much. Those should be on a once per 7 day cycle. But it's not a big deal. |
Yes, you can add any of them. The biggest ones are
The others are based on your preferences. Cloudfront and Fastly are a CDN, I haven't seen too many servers owned by them trying to hit other servers, they're mostly a CDN. Amazon AWS / EC2, since they are types of VMs, are used by clients to do things such as port scanning / ssh bruteforce. Surprisingly, on my own setup, Amazon is who I get hit by the most. A note that the AWS and EC2 server IPs should not interfere with legitimate root Amazon servers which perform services. These are only rented boxes. Google and Bing lists will kill crawlers for those search engines, so if you don't want your site crawled, you should block those two. And these are all official lists. I get them directly from the companies. Currently working on adding Spamhaus. Just need to add some new functionality in place to break up the subnets and count them for the header. |
Alright, the ipset system had another overhaul today. Now the header of each file gives a description of what they do. There's also statistics in the header.
Also added Getting the actual IPs was the easy part. Automating all the counting and template headers is what ate the time. I'll continue to add more. |
Cool! So which lists I should actually keep when using yours? Are those lists included in your lists as well?
Thanks! |
Let me look through those lists and see if I include any.
If you notice the 2nd link and go to it in your browser, it's empty. That's because Spamhaus merged the And my Spamhaus ipset is the same one that is in You can also remove The other one I am merging is That file is a combination of the same Spamhaus rules, as well as the IPs in my master list. There's only a few I'm missing, but they'll be added today. The other lists I need to review and see where I can merge them at. I'm in the middle of creating a few rules which will auto-check my ipsets before they are pushed, and ensure there's no doubles. I don't want the same IPs being loaded over and over on a client. The one in your list that confuses me is Edit: I wrote up a script to grab the IPs on that page I listed above on MaxMind. It'll be in a list. |
In your list, you can now replace:
With: If you also want to remove
They are now included in the master list on mine: So if you want to replace just the ones you already had in your list, you should have:
The master list is rather big. Not as big as some others I've seen, but I also go through and ensure duplicates are removed.
|
Thanks much! I am in hospital now. Will check it once I am back and let you know. |
Hope all is well with you. Whenever you get back if you have questions, let me know. I've added some more lists since then. I recently just added ipsets for all of the countries / continents. So you can block whichever countries you don't want accessing your server. |
@Aetherinox Just one more point .. I see that there is actually one issue:
How can this be fixed? Thanks! |
@Aetherinox Okay, so I eventually changed:
And it seems to solve the issue. But let me ask you - doesn't this slow down the machine significantly? |
@Aetherinox Update: Your blocklists seem to really got rid of all the spam messages for me - thanks! 🙏 Also please check the above messages once it is feasible for you. Thank you! |
Sorry, didn't get notifications for some reason.
Glad to hear. I run these rules, it makes life easier.
This depends. CSF has two ways it can handle these lists. If your machine has If you don't have ipset installed on your server, then ConfigServer uses iptables, and that is where you have severe performance degredation, because then it needs to add a new iptable firewall rule for EACH block, and it gets loaded into memory. Loading up over 100,000 brand new rules into iptables would be an insane amount. Once you install ipset I run the full set of my firewall rules with ipset on, and I hardly notice any performance impact at all. But if I turn ipset off and try to load up these rules, the machine will crawl. (I tried this before for bench-marking, not fun) If my memory is correct, I believe the iptables test machine was 16GB memory, and it took over 20 minutes for the rules to load. And there was significant performance, the mouse wouldn't even move freely. So just install the ipset package, enable the setting in CSF, and then give a restart of all services with Now, there is a limit. Last time I read the docs, the ipset max is
Just to give an idea of how many IPs that is. The AbuseIPDB database I use, if you were to set the "confidence" level down to 25%, you'd still only get 395,476 IPs in your list. And I never recommend a confidence level that low, because you will most definitely get false positives. That's why the IPs I provide have a 95 - 100% confidence. They are guaranteed blocks. I want my blocklists to keep you from getting port sniffers and brutce-forcers, not blocking legitimate connections. Most servers coming from Amazon or Microsoft are already in those blocklists if you set the confidence level low enough, and while some of those are VPSs that are rented by bad actors, that would also block legitimate servers from Microsoft or Amazon, and we don't want that. |
@Aetherinox Thanks for the reply and also for the thorough information. So this is what I currently use:
With this setting:
And it works well.. Any other settings/lists/tips/tricks I should add or change? Thanks much! |
Can't really think of any others off the top of my head. Obviously there's the geo database feature provided by Maxmind. It depends on how you want your server accessible. ConfigServer Firewall has settings in place to where you can blacklist certain countries from accessing your server, which is what I do. Out of box, I immediately block anyone attempting to connect from China, Russia, India, and UAE. Only because those are the locations where the most attacks come from. And my server should have no businesses dealing with servers in any of those countries at all. So I would recommend at a minimum, you restrict a few of those countries from accessing your server. I'd say that almost 50% of my connections alone were from China, and when I'd trace them, it always came back to these Chinese companies who rented out VPS boxes to customers. So they were all just port sniffers, and people attempting to bruteforce SMTP or SSH. Any public facing services (nginx, PHP, etc), I'd highly recommend you run them through Docker and containerize those services. And if you really want to go an extra level, I'd slap Traefik onto those services. That way I can host the services, without exposing the ports on your host machine. I love Traefik. I use it in combination with Authentik. And Traefik includes things called "middleware", which are plugins you can assign to each subdomain. I use the IP whitelist middleware as an extra layer of protection. Yeah services like Cloudflare offer firewall rules / WAF, but I prefer to manage it from the server level. That way if something happens to Cloudflare, I'm not sitting naked. |
Sure thing. You may want to edit the message and remove the email, I wrote it down. Bots will pick it up and you'll get spammed to hell. |
Great! Removed two posts. I guess we can close this thread then.. |
Awesome. Hit me up if you have any other issues / questions. I've still got some stuff I need to do to CSF, just finishing up the last of the blocklist generation. Hope this all helped ya. |
@Aetherinox Cool, just ping me on my email. Thanks for all! |
Thanks for publishing this. I am trying to get them to work on our system. We had some similar working rules but lacking somehow that the source IP passes to the containers.
While executing csf -e I get the following error from the docker.sh script:
The text was updated successfully, but these errors were encountered: