大网数据广告活动
服务器运维问答

iptables match output rule for supplementary groups

· 52CE 我爱测

The iptables utility allows for rules to match based on the process's uid or gid with the following: sudo iptables -A OUTPUT -m owner --uid-owner root -j ACCEPT I also want to add a rule to allow all members of a group called "ne…

问题原文

原帖链接 · C0deH4cker · CC BY-SA 3.0

The iptables utility allows for rules to match based on the process's uid or gid with the following:

sudo iptables -A OUTPUT -m owner --uid-owner root -j ACCEPT

I also want to add a rule to allow all members of a group called "netaccess" to use outbound traffic. I tried the following:

sudo groupadd -r netaccess # This created the group with gid 999
sudo usermod -aG netaccess <myUser>
sudo iptables -A OUTPUT -m owner --gid-owner netaccess -j ACCEPT

However, my outbound traffic is still being blocked. I have verified that the iptables rule was created above the final REJECT rule, so that isn't the issue. Rather, it appears that when using iptables -m owner with the --gid-owner option, it compares the exact gid of the process rather than checking if the gid is in the owner's list of supplementary groups (as defined in /etc/group). I found this by looking at this page (Ctrl+F for "owner"): http://ipset.netfilter.org/iptables-extensions.man.html

Is there any way to use iptables to match rules to all members of a supplementary group? I'd like something like the following to work:

sudo iptables -A OUTPUT -m owner --gid-member netaccess -j ACCEPT

I am running on Ubuntu 14.04 and have iptables v1.4.21.

已采纳解答

原帖链接 · forest · CC BY-SA 4.0

Support for supplementary groups was added in ea6cc2fd in 2019:

netfilter: xt_owner: Add supplementary groups option

The XT_OWNER_SUPPL_GROUPS flag causes GIDs specified with XT_OWNER_GID
to be also checked in the supplementary groups of a process.

f_cred->group_info cannot be modified during its lifetime and f_cred
holds a reference to it so it's safe to use.

Signed-off-by: Lukasz Pawelczyk 
Signed-off-by: Pablo Neira Ayuso 

The corresponding iptables feature is documented in iptables-extensions(8):

--suppl-groups
       Causes group(s) specified with --gid-owner to be also checked in
       the supplementary groups of a process.

To do what you want, you would use this:

iptables -A OUTPUT -m owner --gid-owner netaccess --suppl-groups -j ACCEPT

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-12-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。