-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libcontainer: allow setgroup in rootless mode #1693
libcontainer: allow setgroup in rootless mode #1693
Conversation
} | ||
return buf | ||
} | ||
|
||
func (msg *Boolmsg) Len() int { | ||
return unix.NLA_HDRLEN + 1 | ||
return unix.NLA_HDRLEN + 4 // alignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This alignment issue had not appear because no multiple Boolmsg
s had been serialized at once.
@AkihiroSuda looks like the newuidmap and newgidmap already has suid bit set, I tested on my local fedora 27 machine, so the suid bit should be ok. I wonder what all privileges these require so we can do a setcap and remove the suid bit. |
Interestingly, users do not need an entry in I raised this as an issue, but there's disagreement on how best to tackle it. It's a bit of a shame that we have a kernel-level check that's subverted by popular setuid executables. I do see the point that negative group ACLs aren't very useful, but we're kind of in the worst of both worlds now, where we have |
@craigfurman I think the logic is that you need to have
Personally I can see why it is useful to allow |
@cyphar you don't need an entry in |
And yeah tbh I totally value allowing setgroups more than I value negative group ACLs... it's certainly more useful for us container folks! :) |
I added a comment to the bug you mentioned with an idea for how we could extend |
Nice, thanks for replying to that thread. I'll continue the conversation on there. |
@cyphar @craigfurman Does this PR LGTY? |
The issue @craigfurman discussed has been fixed as part of CVE-2018-7169. So review on this has re-opened now. However it is no longer as obvious whether this actually will help with |
For single-user-being-mapped case we would use ptrace hack instead. |
But if we have more than one user being mapped then we would already fall-back to |
s/force-mapping-tools/keep-proc-setgroups-untouched/ then? |
We could do this without a CLI flag actually. You just need to figure out whether the mapping contains more than one user (because the single-user case is now the same with or without the setuid tools). If it does, then we assume we don't want to write anything to How does that sound? |
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
9e4fd2f
to
29740fe
Compare
--force-mapping-tool
is set
@cyphar updated, PTAL |
libcontainer/container_linux.go
Outdated
gidMapCount := 0 | ||
for _, m := range c.config.GidMappings { | ||
gidMapCount += m.Size | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right. It will miss if we have a single mapping of more than one group. Really, what we should do is have a helper function that does something like:
func requiresMappingTool(c *configs.Config) bool {
gidMap := []configs.IDMap{
{ContainerID: 0, HostID: os.Getegid(), Size: 1},
}
return !reflect.DeepEquals(c.GidMappings, gidMap)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will miss if we have a single mapping of more than one group.
Why? Does not gidMapCount += m.Size
catch such case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't catch if the HostID
is not os.Getegid
. Also I think the DeepEqual
is clearer (from the perspective of someone trying to understand in what case we disable setgroups).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for pointing out, updated
libcontainer/nsenter/nsexec.c
Outdated
|
||
if (config.is_setgroup) | ||
update_setgroups(child, SETGROUPS_ALLOW); | ||
if (config.is_rootless) | ||
else if (config.is_rootless) | ||
update_setgroups(child, SETGROUPS_DENY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These four lines could just be shortened to
if (config.is_rootless && !config.is_setgroup)
update_setgroups(child, SETGROUPS_DENY);
Because writing allow
is a noop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
29740fe
to
bfffaeb
Compare
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
bfffaeb
to
73f3dc6
Compare
LGTM. I've tested it out a bit and it appears to work pretty well. Thanks @AkihiroSuda! /cc @opencontainers/runc-maintainers |
@opencontainers/runc-maintainers anyone PTAL? |
/ping @opencontainers/runc-maintainers |
@AkihiroSuda, I think this example has gone broken on recent versions of runc, can you verify that? |
--force-mapping-tool is no longer needed |
Yeah, I'm aware of that, but I cannot get |
Sorry for the noise, I've figured it out, see the issue. |
Previously,
/proc/PID/setgroups
was always set to"deny"
in rootless mode, as recent Linux kernel does not allow unprivileged users to update/proc/PID/uid_map
without doing so.However, we can mitigate this limitation by using
newuidmap(1)
andnewgidmap(1)
, although it requires these binaries (notrunc
itself) to have suid bit.This PR adds a new flag
--force-mapping-tool
to use these binaries compulsory.Now
apt
works within a rootless container, without ptrace hack:Example config.json: https://gist.github.com/AkihiroSuda/0a46ad9ba6f392b27ac4c8d372721207
Demo (Tested on Ubuntu 17.10, kernel 4.13.0-25-generic x86_64):
If depending on the mapping tool is problem, we can use
ptrace(2)
hacks instead: https://github.com/AkihiroSuda/runrootless