How to configure UFW on a per application basis

For questions regarding system and application security
Message
Author
User avatar
LinuxSpring1
Posts: 274
Joined: Sun May 05, 2024 8:57 am

How to configure UFW on a per application basis

#1 Post by LinuxSpring1 »

I am running MX Linux 23.3 with Kernel 6.1.0-25-amd64 and KDE plasma. UFW is running and configured. I want to change the UFW policy such that
Incoming = Ignore
Outgoing = Deny

and then on a per application basis update the firewall rule to allow connection to internet. For example give access to Firefox and Thunderbird binaries to connect to internet but not to python to connect to internet. Give access to dpkg/apt/aptitude but not to Kwrite or SSH or telnet or to connect to internet.

Is this possible with UFW? If yes can you please give some pointers? And if no then what is the alternative that can be used?

User avatar
Eadwine Rose
Administrator
Posts: 14879
Joined: Wed Jul 12, 2006 2:10 am

Re: How to configure UFW on a per application basis

#2 Post by Eadwine Rose »

With all help requests, as per forum rules (which, if you haven't, please read), please share your full Quick System Info, do not edit.
If need be, you can do this with the LiveUSB, thanks.
MX-23.6_x64 July 31 2023 * 6.1.0-37amd64 ext4 Xfce 4.20.0 * 8-core AMD Ryzen 7 2700
Asus TUF B450-Plus Gaming UEFI * Asus GTX 1050 Ti Nvidia 535.247.01 * 2x16Gb DDR4 2666 Kingston HyperX Predator
Samsung 870EVO * Samsung S24D330 & P2250 * HP Envy 5030

User avatar
DukeComposed
Posts: 1450
Joined: Thu Mar 16, 2023 1:57 pm

Re: How to configure UFW on a per application basis

#3 Post by DukeComposed »

LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am Is this possible with UFW? If yes can you please give some pointers? And if no then what is the alternative that can be used?
There is already an existing thread that discussed this recently.

User avatar
fehlix
Developer
Posts: 12741
Joined: Wed Apr 11, 2018 5:09 pm

Re: How to configure UFW on a per application basis

#4 Post by fehlix »

LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am Is this possible with UFW? If yes can you please give some pointers?
No. UFW is just helper to set iptables (nftable) rules to tell kernels packetfilter to apply. No app is identified by those rules.
LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am And if no then what is the alternative that can be used?
Use SElinux or AppArmor, to let the kernel restrict send/receive calls based on app armor profiles. And on top add process namespaces restrictions to creat a highe secure system, where user and network namespaces are in isolation.
All this is not setup in MX Linux, as the assumption is made that most MX Linux users may not deal with sensitive, confidential, or critical data where high-security systems is to be considerd to setup.

User avatar
LinuxSpring1
Posts: 274
Joined: Sun May 05, 2024 8:57 am

Re: How to configure UFW on a per application basis

#5 Post by LinuxSpring1 »

DukeComposed wrote: Thu Sep 19, 2024 3:18 am
LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am Is this possible with UFW? If yes can you please give some pointers? And if no then what is the alternative that can be used?
There is already an existing thread that discussed this recently.
Thanks @DukeComposed. When I had searched for UFW yesterday this post did not come up.
fehlix wrote: Thu Sep 19, 2024 6:14 am
LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am Is this possible with UFW? If yes can you please give some pointers?
No. UFW is just helper to set iptables (nftable) rules to tell kernels packetfilter to apply. No app is identified by those rules.
Thanks for the clarification.
fehlix wrote: Thu Sep 19, 2024 6:14 am
LinuxSpring1 wrote: Thu Sep 19, 2024 2:31 am And if no then what is the alternative that can be used?
Use SElinux or AppArmor, to let the kernel restrict send/receive calls based on app armor profiles. And on top add process namespaces restrictions to creat a highe secure system, where user and network namespaces are in isolation.
All this is not setup in MX Linux, as the assumption is made that most MX Linux users may not deal with sensitive, confidential, or critical data where high-security systems is to be considerd to setup.
@fehlix so using AppArmor profiles network calls can be restricted ? But what happens if an application is started without a AppArmor call ? Or a background service were to try to use the network?

User avatar
fehlix
Developer
Posts: 12741
Joined: Wed Apr 11, 2018 5:09 pm

Re: How to configure UFW on a per application basis

#6 Post by fehlix »

LinuxSpring1 wrote: Fri Sep 20, 2024 2:11 am @fehlix so using AppArmor profiles network calls can be restricted ? But what happens if an application is started without a AppArmor call ? Or a background service were to try to use the network?
Not sure I understand. This topic is about how to restrict/protect network access of an app. The answer was given to point to ways to achieve this. Now you ask, something like if you don't prepare the protection e.g with apparmor, whether apparmor protection is still applied.
No, you can simply bypass the protection by apparmor, either by turn apparmor off or by don't setting up apparmor profile for a specific executable. It's the responsibility of the admin of your system to setup protective rules, as combination of firewall rules and application level rules. Suggest to read and learn about, and provide some howtos, the community will benefit from your experiences made.
Thanks

User avatar
davidy
Posts: 818
Joined: Sat Jul 03, 2021 1:59 pm

Re: How to configure UFW on a per application basis

#7 Post by davidy »

Heres a nice webpage for application blocking using ufw and ubuntu.
https://super-unix.com/ubuntu/ubuntu-ho ... plication/
You could create a "no-internet" group first and then add rules in ufw by running that process in that group with:

Code: Select all

sudo -g no-internet -c "processFullPath args"

Code: Select all

sudo iptables -I OUTPUT 1 -m owner --gid-owner no-internet -j DROP
sudo ip6tables -I OUTPUT 1 -m owner --gid-owner no-internet -j DROP # To also block IPv6 traffic
I use opensnitch which is actually pretty good at doing all that without using cmd line arguments. It can let you specify what ap and what network interface to block, or just a single host or IP.
Op should understand that ufw is an ip address/host/port manipulation application. It does not do executables. I only found that out by reading that webpage.
Sys76 LemurPro-mx-23.4, EliteMinis HM90-mx-21.3, Deskmini UM350-phoenixLite win10, Qnap 12tb nas, Protectli FW4C-opnsense(=゜ω゜)

zero privacy = zero security . All MX'd Up
UAP = up above people

User avatar
LinuxSpring1
Posts: 274
Joined: Sun May 05, 2024 8:57 am

Re: How to configure UFW on a per application basis

#8 Post by LinuxSpring1 »

davidy wrote: Thu Oct 03, 2024 3:15 am Heres a nice webpage for application blocking using ufw and ubuntu.
https://super-unix.com/ubuntu/ubuntu-ho ... plication/
You could create a "no-internet" group first and then add rules in ufw by running that process in that group with:

Code: Select all

sudo -g no-internet -c "processFullPath args"

Code: Select all

sudo iptables -I OUTPUT 1 -m owner --gid-owner no-internet -j DROP
sudo ip6tables -I OUTPUT 1 -m owner --gid-owner no-internet -j DROP # To also block IPv6 traffic
I use opensnitch which is actually pretty good at doing all that without using cmd line arguments. It can let you specify what ap and what network interface to block, or just a single host or IP.
Op should understand that ufw is an ip address/host/port manipulation application. It does not do executables. I only found that out by reading that webpage.
This is an intriguing solution, using groups and ip-tables to block access. But it can be easily bypassed if the sg command is used with some other group. This approach is a bit dated, being proposed in 2008/9 and even then there were people who had issues with this. Will evaluate OpenSnitch and use that. That seems to be a much more appropriate solution.

However using AppArmor to block the access to internet now that is worthy of being explored. Thanks for that.

User avatar
davidy
Posts: 818
Joined: Sat Jul 03, 2021 1:59 pm

Re: How to configure UFW on a per application basis

#9 Post by davidy »

Yeah, I really wish we had easier options such as in windows. Portmaster I tried (https://safing.io/) but I could not get the daemon to run so the gui never worked. I think it has something to do with sysvinit, not sure. Portmaster when I did get the gui to work seemed overly complicated and a bit hard to figure out to simply block an ap from connecting which was irritating.
Sys76 LemurPro-mx-23.4, EliteMinis HM90-mx-21.3, Deskmini UM350-phoenixLite win10, Qnap 12tb nas, Protectli FW4C-opnsense(=゜ω゜)

zero privacy = zero security . All MX'd Up
UAP = up above people

Post Reply

Return to “Security”