Skip to content

Commit

Permalink
Merge pull request #2725 from AkihiroSuda/fix-2724
Browse files Browse the repository at this point in the history
 systemd: fix rootful-in-userns regression
  • Loading branch information
Mrunal Patel authored Jan 26, 2021
2 parents c69ae75 + 230a46b commit be30b6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcontainer/cgroups/systemd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func DetectUID() (int, error) {
}
b, err := exec.Command("busctl", "--user", "--no-pager", "status").CombinedOutput()
if err != nil {
return -1, errors.Wrap(err, "could not execute `busctl --user --no-pager status`")
return -1, errors.Wrapf(err, "could not execute `busctl --user --no-pager status`: %q", string(b))
}
scanner := bufio.NewScanner(bytes.NewReader(b))
for scanner.Scan() {
Expand Down
19 changes: 19 additions & 0 deletions rootless_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package main
import (
"os"

"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
"github.com/opencontainers/runc/libcontainer/system"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand All @@ -28,6 +30,23 @@ func shouldUseRootlessCgroupManager(context *cli.Context) (bool, error) {
return false, nil
}
// euid = 0, in a userns.
//
// [systemd driver]
// We can call DetectUID() to parse the OwnerUID value from `busctl --user --no-pager status` result.
// The value corresponds to sd_bus_creds_get_owner_uid(3).
// If the value is 0, we have rootful systemd inside userns, so we do not need the rootless cgroup manager.
//
// On error, we assume we are root. An error may happen during shelling out to `busctl` CLI,
// mostly when $DBUS_SESSION_BUS_ADDRESS is unset.
if context.GlobalBool("systemd-cgroup") {
ownerUID, err := systemd.DetectUID()
if err != nil {
logrus.WithError(err).Debug("failed to get the OwnerUID value, assuming the value to be 0")
ownerUID = 0
}
return ownerUID != 0, nil
}
// [cgroupfs driver]
// As we are unaware of cgroups path, we can't determine whether we have the full
// access to the cgroups path.
// Either way, we can safely decide to use the rootless cgroups manager.
Expand Down

0 comments on commit be30b6e

Please sign in to comment.