From: Topi Miettinen <toiwoton@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: Support for loading firewall rules with cgroup(v2) expressions early
Date: Tue, 29 Mar 2022 21:20:25 +0300 [thread overview]
Message-ID: <5b850d67-92c1-9ece-99d2-390e8a5731b3@gmail.com> (raw)
In-Reply-To: <YkHOuprHwwuXjWrm@salvia>
On 28.3.2022 18.05, Pablo Neira Ayuso wrote:
> On Mon, Mar 28, 2022 at 05:08:32PM +0300, Topi Miettinen wrote:
>> On 28.3.2022 0.31, Pablo Neira Ayuso wrote:
>>> On Sat, Mar 26, 2022 at 12:09:26PM +0200, Topi Miettinen wrote:
> [...]
>>>> Another possibility would be to hook into cgroup directory creation logic in
>>>> kernel so that when the cgroup is created, part of the path checks are
>>>> performed or something else which would allow non-existent cgroups to be
>>>> used. Then the NFT syntax would not need changing, but the expressions would
>>>> "just work" even when loaded early.
>>>
>>> Could you use inotify/dnotify/eventfd to track these updates from
>>> userspace and update the nftables sets accordingly? AFAIK, this is
>>> available to cgroupsv2.
>>
>> It's possible, there's for example:
>> https://github.com/mk-fg/systemd-cgroup-nftables-policy-manager
>
> This one seems to be adding one rule per cgroupv2, it would be better
> to use a map for this purpose for scalability reasons.
>
>> https://github.com/helsinki-systems/nft_cgroupv2/
>
> This approach above takes us back to the linear ruleset evaluation
> problem, this is basically looking like iptables, this does not scale up.
>
>> But I think that with this approach, depending on system load, there could
>> be a vulnerable time window where the rules aren't loaded yet but the
>> process which is supposed to be protected by the rules has already started
>> running. This isn't desirable for firewalls, so I'd like to have a way for
>> loading the firewall rules as early as possible.
>
> You could define a static ruleset which creates the table, basechain
> and the cgroupv2 verdict map. Then, systemd updates this map with new
> entries to match on cgroupsv2 and apply the corresponding policy for
> this process, and delete it when not needed anymore. You have to
> define one non-basechain for each cgroupv2 policy.
Actually this seems to work:
table inet filter {
set cg {
typeof socket cgroupv2 level 0
}
chain y {
socket cgroupv2 level 2 @cg accept
counter drop
}
}
Simulating systemd adding the cgroup of a service to the set:
# nft add element inet filter cg "system.slice/systemd-resolved.service"
Cgroup ID (inode number of the cgroup) has been successfully added:
# nft list set inet filter cg
set cg {
typeof socket cgroupv2 level 0
elements = { 6032 }
}
# ls -id /sys/fs/cgroup/system.slice/systemd-resolved.service
6032 /sys/fs/cgroup/system.slice/systemd-resolved.service/
-Topi
> To address the vulnerable time window, the static ruleset defines a
> default policy to allow nothing until an explicit policy based on
> cgroupv2 for this process is in place.
>
> The cgroupv2 support for nftables was designed to be used with maps.
next prev parent reply other threads:[~2022-03-29 18:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-26 10:09 Support for loading firewall rules with cgroup(v2) expressions early Topi Miettinen
2022-03-27 21:31 ` Pablo Neira Ayuso
2022-03-28 14:08 ` Topi Miettinen
2022-03-28 15:05 ` Pablo Neira Ayuso
2022-03-28 17:46 ` Topi Miettinen
2022-03-29 18:20 ` Topi Miettinen [this message]
2022-03-29 22:25 ` Pablo Neira Ayuso
2022-03-30 2:53 ` Pablo Neira Ayuso
2022-04-02 8:12 ` Topi Miettinen
2022-04-03 18:32 ` Topi Miettinen
2022-04-05 22:00 ` Pablo Neira Ayuso
2022-04-06 13:57 ` Topi Miettinen
2022-03-30 16:37 ` Topi Miettinen
2022-03-30 21:47 ` Pablo Neira Ayuso
2022-03-31 15:10 ` Topi Miettinen
2022-04-05 22:18 ` Pablo Neira Ayuso
2022-04-06 14:02 ` Topi Miettinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5b850d67-92c1-9ece-99d2-390e8a5731b3@gmail.com \
--to=toiwoton@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).