rootless: fix running with /proc/self/setgroups set to deny
This is a regression from 06f789cf26
when the user namespace was configured without a privileged helper.
To allow a single mapping in an user namespace, it is necessary to set
/proc/self/setgroups to "deny".
For a simple reproducer, the user namespace can be created with
"unshare -r".
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
e93996674f
commit
869add3318
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -300,11 +301,18 @@ func setupUser(config *initConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setgroups, err := ioutil.ReadFile("/proc/self/setgroups")
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// This isn't allowed in an unprivileged user namespace since Linux 3.19.
|
// This isn't allowed in an unprivileged user namespace since Linux 3.19.
|
||||||
// There's nothing we can do about /etc/group entries, so we silently
|
// There's nothing we can do about /etc/group entries, so we silently
|
||||||
// ignore setting groups here (since the user didn't explicitly ask us to
|
// ignore setting groups here (since the user didn't explicitly ask us to
|
||||||
// set the group).
|
// set the group).
|
||||||
if !config.RootlessEUID {
|
allowSupGroups := !config.RootlessEUID && strings.TrimSpace(string(setgroups)) != "deny"
|
||||||
|
|
||||||
|
if allowSupGroups {
|
||||||
suppGroups := append(execUser.Sgids, addGroups...)
|
suppGroups := append(execUser.Sgids, addGroups...)
|
||||||
if err := unix.Setgroups(suppGroups); err != nil {
|
if err := unix.Setgroups(suppGroups); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue