Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Jul 2022 12:14:08 +0100
From:      Doug Rabson <dfr@rabson.org>
To:        Gijs Peskens <gijs@peskens.net>
Cc:        freebsd-jail@freebsd.org, freebsd-net@freebsd.org,  Samuel Karp <me@samuelkarp.com>
Subject:   Re: Container Networking for jails
Message-ID:  <CACA0VUhGczi52ZbLJfr3eykZjgE89ZCXmvPVGgjppTgAtzj6LA@mail.gmail.com>
In-Reply-To: <FBE79414-8FC7-4357-A6DF-A2B4755DDF62@peskens.net>
References:  <CACA0VUgNHPaDUkzgZh48DXtB9KxkLLcWGX=HgH8-yrVYkAEQwQ@mail.gmail.com> <FBE79414-8FC7-4357-A6DF-A2B4755DDF62@peskens.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000005fdc7205e2f8d6e0
Content-Type: text/plain; charset="UTF-8"

I think it's important that configuring the container network does not rely
on any utilities from inside the container - for one thing, there are no
guarantees that these utilities even exist inside the container and as you
note, local versions may be incompatible.

On the subject of risk, with the current jail infrastructure, the only user
which can create and modify containers is root. Certain users may have
delegated authority, e.g. by using setuid on a daemon-less setup like
podman or by adjusting permissions on a unix domain socket but this is
clearly a huge risk and should be strongly discouraged (IMO). Rootless
containers using something similar to linux user namespaces would be nice
but it is probably a higher priority to get containers working well for
root first.

My concern for supporting an alternative 'tooling' image for network
utilities is that it adds complexity to the infrastructure for very little
gain. You could even make a weak argument that it adds a threat vector,
e.g. if the network utilities image is fetched from a compromised
repository (pretty far fetched IMO but possible).



On Sun, 3 Jul 2022 at 17:29, Gijs Peskens <gijs@peskens.net> wrote:

> I went with exactly the same design for the Docker port I started a while
> ago.
> The reason I went with that design is that there weren't any facilities to
> modify a jails vent network configuration from outside of the jail. So it's
> needed to enter the jail, run ifconfig et all.
> Linux jails will lack a compatible ifconfig.
> So having a parent FreeBSD based vnet jail ensures that networking can be
> configured for Linux children.
>
> There is a risk to using the / filesystem: users that might be allowed to
> setup and configure containers run standard system tools as root on the
> root filesystem, even if they might not have root permission themselves..
> If an exploit was to be ever found in any of those tools to modify files
> that could be used as a step in a privilege escalation.
>
> Imho, that risk is acceptable in a first port, but should be documented.
> And ideally an option should be provided to use an alternative root if the
> user deems the risk unacceptable.
>
>
>
>
> On 30 June 2022 09:04:24 CEST, Doug Rabson <dfr@rabson.org> wrote:
>>
>> I wanted to get a quick sanity check for my current approach to container
>> networking with buildah and podman. These systems use CNI (
>> https://www.cni.dev) to set up the network. This uses a sequence of
>> 'plugins' which are executables that perform successive steps in the
>> process - a very common setup uses a 'bridge' plugin to add one half of an
>> epair to a bridge and put the other half into the container's vnet. IP
>> addresses are managed by an 'ipam' plugin and an optional 'portmap' plugin
>> can be used to advertise container service ports on the host. All of these
>> plugins run on the host with root privileges.
>>
>> In kubernetes and podman, it is possible for more than one container to
>> share a network namespace in a 'pod'. Each container in the pod can
>> communicate with its peers directly via localhost and they all share a
>> single IP address.
>>
>> Mapping this over to jails, I am using one vnet jail to manage the
>> network namespace and child jails of this to isolate the containers. The
>> vnet jail uses '/' as its root path and the only things which run inside
>> this jail are the CNI plugins. Using the host root means that a plugin can
>> safely call host utilities such as ifconfig and route without having to
>> trust the container's version of them. An important factor here is that the
>> CNI plugins will only be run strictly before the container (to set up) or
>> strictly after (to tear down) - at no point will CNI plugins be executed at
>> the same time as container executables.
>>
>> The child jails use ip4/6=inherit to share the vnet and each will use a
>> root path to the container's contents in the same way as a normal
>> non-hierarchical jail.
>>
>> Can anyone see any potential security problems here, particularly around
>> the use of nested jails? I believe that the only difference between this
>> setup and a regular non-nested jail is that the vnet outlives the container
>> briefly before it is torn down.
>>
>
> --
> Verstuurd vanaf mijn Android apparaat met K-9 Mail. Excuseer mijn
> beknoptheid.
>

--0000000000005fdc7205e2f8d6e0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I think it&#39;s=C2=A0important that configuring the conta=
iner network does not rely on any utilities from inside the container - for=
 one thing, there are no guarantees that these utilities even exist inside =
the container and as you note, local versions may be incompatible.<div><br>=
</div><div>On the subject of risk, with the current jail infrastructure, th=
e only user which can create and modify containers is root. Certain users m=
ay have delegated authority, e.g. by using setuid on a daemon-less setup li=
ke podman or by adjusting permissions on a unix domain socket but this is c=
learly a huge risk and should be strongly discouraged (IMO). Rootless conta=
iners using something similar to linux user namespaces would be nice but it=
 is probably a higher priority to get containers working well for root firs=
t.</div><div><br></div><div>My concern for supporting an alternative &#39;t=
ooling&#39; image for network utilities is that it adds complexity to the i=
nfrastructure for very little gain. You could even make a weak argument tha=
t it adds a threat vector, e.g. if the network utilities image is fetched f=
rom a compromised repository (pretty far fetched IMO but possible).</div><d=
iv><br></div><div><br></div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">On Sun, 3 Jul 2022 at 17:29, Gijs Peskens &lt=
;<a href=3D"mailto:gijs@peskens.net">gijs@peskens.net</a>&gt; wrote:<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bord=
er-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204=
);padding-left:1ex"><div>I went with exactly the same design for the Docker=
 port I started a while ago.<br>The reason I went with that design is that =
there weren&#39;t any facilities to modify a jails vent network configurati=
on from outside of the jail. So it&#39;s needed to enter the jail, run ifco=
nfig et all.<br>Linux jails will lack a compatible ifconfig. <br>So having =
a parent FreeBSD based vnet jail ensures that networking can be configured =
for Linux children. <br><br>There is a risk to using the / filesystem: user=
s that might be allowed to setup and configure containers run standard syst=
em tools as root on the root filesystem, even if they might not have root p=
ermission themselves.. If an exploit was to be ever found in any of those t=
ools to modify files that could be used as a step in a privilege escalation=
. <br><br>Imho, that risk is acceptable in a first port, but should be docu=
mented. And ideally an option should be provided to use an alternative root=
 if the user deems the risk unacceptable.<br><br><br><br><br><div class=3D"=
gmail_quote">On 30 June 2022 09:04:24 CEST, Doug Rabson &lt;<a href=3D"mail=
to:dfr@rabson.org" target=3D"_blank">dfr@rabson.org</a>&gt; wrote:<blockquo=
te class=3D"gmail_quote" style=3D"margin:0pt 0pt 0pt 0.8ex;border-left-widt=
h:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-le=
ft:1ex">
<div dir=3D"ltr"><div>I wanted to get a quick sanity check for my current a=
pproach to container networking with buildah and podman. These systems use =
CNI (<a href=3D"https://www.cni.dev" target=3D"_blank">https://www.cni.dev<=
/a>) to set up the network. This uses a sequence of &#39;plugins&#39; which=
 are executables that perform successive steps in the process - a very comm=
on setup uses a &#39;bridge&#39; plugin to add one half of an epair=C2=A0to=
 a bridge and put the other half into the container&#39;s vnet. IP addresse=
s are managed by an &#39;ipam&#39; plugin and an optional &#39;portmap&#39;=
 plugin can be used to advertise container service ports on the host. All o=
f these plugins run on the host with root privileges.</div><div><br></div><=
div>In kubernetes and podman, it is possible for more than one container to=
 share a network namespace in a &#39;pod&#39;. Each container in the pod ca=
n communicate with its peers directly via localhost and they all share a si=
ngle IP address.</div><div><br></div><div>Mapping this over to jails, I am =
using one vnet jail to manage the network namespace and child jails of this=
 to isolate the containers. The vnet jail uses &#39;/&#39; as its root path=
 and the only things which run inside this jail are the CNI plugins. Using =
the host root means that a plugin can safely call host utilities=C2=A0such =
as ifconfig and route without having to trust the container&#39;s version o=
f them. An important factor here is that the CNI plugins will only be run s=
trictly before the container (to set up) or strictly after (to tear down) -=
 at no point will CNI plugins be executed at the same time as container exe=
cutables.</div><div><br></div><div>The child jails use ip4/6=3Dinherit to s=
hare the vnet and each will use a root path to the container&#39;s contents=
 in the same way as a normal non-hierarchical jail.</div><div><br></div><di=
v>Can anyone see any potential security problems here, particularly around =
the use of nested jails? I believe that the only difference between this se=
tup and a regular non-nested jail is that the vnet outlives the container b=
riefly before it is torn down.</div><font color=3D"#888888"></font></div>
</blockquote></div><br>-- <br>Verstuurd vanaf mijn Android apparaat met K-9=
 Mail. Excuseer mijn beknoptheid.</div></blockquote></div>

--0000000000005fdc7205e2f8d6e0--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACA0VUhGczi52ZbLJfr3eykZjgE89ZCXmvPVGgjppTgAtzj6LA>