Re: [PATCH 0/8] userns: per-namespace capability bounding set and opt-in netns loopback
From: Christian Brauner
Date: Tue Nov 17 2026 - 12:11:04 EST
On Mon, Nov 16, 2026 at 09:15:18AM -0800, Andy Lutomirski wrote:
> On Wed, Nov 11, 2026 at 7:20 AM Christian Brauner <brauner@xxxxxxxxxx> wrote:
> > * a task that setns()es in later gets
> > ns->cap_bset & (cred->cap_userns | cred->cap_permitted)
>
> I'm not sure this is ideal. If a task has cap_userns & CAP_NET_ADMIN,
> then there is no attack surface issue with allowing it to enter a
> namespace and be NET_ADMIN there even if the namespace itself has
> CAP_NET_ADMIN cleared from cap_bset. But any exemption here would
> need to be a new API so that it isn't used by accident.
>
> I'm mostly saying this because container managers might want to
> restrict cap_userns within their containers but still have it
> themselves for management. But maybe there isn't any need to enter
> the userns for this purpose.
I don't think there is. A manager that holds the capabilities itself can
just do most things from the outside. I think it's nice that once you're
inside a namespace you're bound by its capabiltiy set. Otherwise the set
isn't a property of the namespace anymore. If someone comes up with a
real need to enter we can add an explicit opt-in later?
> > * Root in a container has caps as well so for containers the exemption
> > would be wrong.
> >
> > So here we need a a lockable SECURE_NO_USERNS_CAP_RAISE bit thingy.
> > This turns off the exemption and prevents raising the mask.
> >
> > Docker lowers the mask, sets and locks the bit, and
> > unshare(CLONE_NEWUSER) in the container doesn't hand out CAP_NET_ADMIN
> > anymore.
>
> Can you clarify this part a bit? I'm not seeing why Docker should be
> special. Shouldn't the inside of a Docker container work as much like
> a normal non-container system as possible? What's the use case?
I picked Docker because you brought it up, and your goal of allowing
user namespaces even in Docker is kinda the use case. Docker can only
drop the CLONE_NEWUSER block from its seccomp profile if nested user
namespaces can't get more caps than root/Docker wants to give them.
But the bit isn't at all Docker specific. Any privileged task that wants the
mask to apply to itself would benefit. With just the exemption this wouldn't be
possible:
(1) A runtime that holds full capabilities gives a
user namespace it creates all bits.
It can just set the bit before creating it.
(2) In a container without a user namespace container root has host-level
capabilities. Any user namespace it creates gets them through this
exemption thing. So it can also add them back to its mask. And the mask is
inherited. So every process it starts can then create user namespaces with
them.
by raising the bit we stop both. The locked bit keeps container root which
also has CAP_SETPCAP from clearing it.
On the host none of that matters as the mask is root's own policy there.
> In any event, the ptrace access checks also need to be updated. If
> we're adding cap_userns, then one should not be able to
> PTRACE_MODE_ATTACH a task with higher cap_userns.
Yeah, I mentioned that in my reply earlier.