LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2020, 12:11 PM   #1
sJjohn
LQ Newbie
 
Registered: Mar 2020
Posts: 4

Rep: Reputation: Disabled
Angry IPTABLES rule using --gid-owner


I have 2 groups created: groupA groupB
I have 4 users: uA, uB, uC, uD

groupA = uA and uB, groupB = uC and uD.

I am trying to block groupB from accessing OUTSIDE network.
groupA can access.

I want to be able to return the packets once the connection is established.

I tried:

iptables -A OUTPUT -o eth0 -m owner --gid-owner groupA -j ACCEPT
iptables -A OUTPUT -o eth0 -m owner --gid-owner groupB -j REJECT

But this does not work. when I su - uC, I can still ping google.com.
I am a bit confused on the return after established connection rule.

Can anyone please assist.
 
Old 03-09-2020, 12:23 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
Welcome.

Where are these rules in relation to other rules in the OUTPUT chain? The --append or -A option will put these two new rules after any that are already in place. So if one of the previous rules lets everyone out, that's what'll happen. Can you show the whole OUTPUT chain?
 
Old 03-09-2020, 12:52 PM   #3
sJjohn
LQ Newbie
 
Registered: Mar 2020
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you,
I did not add any rules yet.
Here is the default output chain I see:

[root@c12-19 ~]# iptables -nL
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
[root@c12-19 ~]#


Quote:
Originally Posted by Turbocapitalist View Post
Welcome.

Where are these rules in relation to other rules in the OUTPUT chain? The --append or -A option will put these two new rules after any that are already in place. So if one of the previous rules lets everyone out, that's what'll happen. Can you show the whole OUTPUT chain?

Last edited by sJjohn; 03-09-2020 at 12:58 PM.
 
Old 03-09-2020, 01:06 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
Ok. That means those would be the only two rules in the chain. Perhaps --gid-owner only addresses primary groups. Have you looked at using --suppl-groups also?
 
Old 03-09-2020, 01:19 PM   #5
sJjohn
LQ Newbie
 
Registered: Mar 2020
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you,
No I have not tried that before. I did now, here is what I got:

[root@c12-19 ~]# iptables -A OUTPUT -o eth0 -m owner --gid-owner 59931 --suppl-groups groupB -j REJECT
iptables v1.4.21: unknown option "--suppl-groups"
Try `iptables -h' or 'iptables --help' for more information.

[root@c12-19 ~]# iptables -A OUTPUT -o eth0 -m owner --suppl-groups groupB -j REJECT
iptables v1.4.21: unknown option "--suppl-groups"
Try `iptables -h' or 'iptables --help' for more information.



Quote:
Originally Posted by Turbocapitalist View Post
Ok. That means those would be the only two rules in the chain. Perhaps --gid-owner only addresses primary groups. Have you looked at using --suppl-groups also?
 
Old 03-09-2020, 02:04 PM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
I tried a few things and searched a little but gave up quickly on iptables. Reading about it, there seem to be some longstanding issues about how iptables handles groups. nftables is much better and iptables will be deprecated in the near future so, have you considered nftables instead?

I get the expected behavior with nftables:

Code:
$ nft list ruleset
table ip output {
        chain filter4 {
                type filter hook output priority 0; policy accept;
                ip protocol tcp skgid "groupB" reject                            
        }
}
You'd have to install nftables, uninstall iptables, and then reboot for the new filter interface to take effect.

https://wiki.nftables.org/wiki-nftab....php/Main_Page
 
Old 03-09-2020, 02:45 PM   #7
sJjohn
LQ Newbie
 
Registered: Mar 2020
Posts: 4

Original Poster
Rep: Reputation: Disabled
Never tried that.

We were considering iptables for this though.



Quote:
Originally Posted by Turbocapitalist View Post
I tried a few things and searched a little but gave up quickly on iptables. Reading about it, there seem to be some longstanding issues about how iptables handles groups. nftables is much better and iptables will be deprecated in the near future so, have you considered nftables instead?

I get the expected behavior with nftables:

Code:
$ nft list ruleset
table ip output {
        chain filter4 {
                type filter hook output priority 0; policy accept;
                ip protocol tcp skgid "groupB" reject                            
        }
}
You'd have to install nftables, uninstall iptables, and then reboot for the new filter interface to take effect.

https://wiki.nftables.org/wiki-nftab....php/Main_Page
 
Old 03-09-2020, 03:16 PM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
I wouldn't hold my breath about problems with iptables getting fixed any time soon. That one with the groups seems to be an old one, too.

Myself, I've run into enough problems with iptables that I don't consider it for any projects any more and just use nftables nowadays. Back before nftables, I did recompile some kernels with ipchains support because of problems with iptables. So maybe I just never got along with iptables.

Either way, nftables is the future of packet filters for Linux. So you might give it a quick try. The syntax is quite different from ipchains and iptables, and is a bit more complex. However, the complexity on the user side is supposed to be in exchange for gains in performance once the rules are inside the kernel.

You have two ways of building the rules out:

Code:
nft flush ruleset
nft add table ip foobar

nft add chain foobar input  { type filter hook input priority 0 \; policy drop \; }
nft add rule ip foobar input ct state related,established counter accept

nft add chain foobar output  { type filter hook output priority 0 \; policy accept \; }
nft add rule ip foobar output ip protocol tcp skgid groupb reject
Or

Code:
#!/usr/bin/nft -f

flush ruleset

table ip foobar {
        chain input {
                type filter hook input priority 0; policy drop;
                ct state established,related counter accept
        }

        chain output {
                type filter hook output priority 0; policy accept;
                ip protocol tcp skgid "groupb" reject
        }
}
The latter format is what you can put in /etc/nftables.conf for persistence.

The wiki in the earlier link seems to be the best guide, though the manual page serves as a reminder once it nft becomes familiar.

Last edited by Turbocapitalist; 03-10-2020 at 12:51 AM. Reason: packets and bytes not needed in rule
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
“ls” shows group owner as “root”, but real gid is different ranshalit Linux - Security 3 11-24-2018 03:11 PM
[SOLVED] iptables "-m owner --uid-owner" option Besl621 Linux - Security 4 09-25-2015 10:13 AM
Owner of a directory different than file owner problems Guardian-Mage Linux - Server 4 04-24-2009 10:26 AM
difference between gid and effective gid zahidul Linux - Newbie 1 10-01-2008 10:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration