Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extras/rootless/containerd-rootless-setuptool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ cmd_entrypoint_check() {
fi

INFO "Checking cgroup v2"
controllers="/sys/fs/cgroup/user.slice/user-${id}.slice/user@${id}.service/cgroup.controllers"
controllers="/sys/fs/cgroup$(systemctl --user show --value --property=ControlGroup)/cgroup.controllers"
if [ ! -f "${controllers}" ]; then
WARNING "Enabling cgroup v2 is highly recommended, see https://rootlesscontaine.rs/getting-started/common/cgroup2/ "
else
Expand Down
12 changes: 8 additions & 4 deletions pkg/infoutil/infoutil_linux.go
Comment thread
chemwolf6922 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package infoutil

import (
"context"
"fmt"
"runtime"
"strings"
Expand Down Expand Up @@ -141,9 +142,12 @@ func fulfillPlatformInfo(info *dockercompat.Info, selinuxEnabled bool) {
func mobySysInfo(info *dockercompat.Info) *sysinfo.SysInfo {
var mobySysInfoOpts []sysinfo.Opt
if info.CgroupDriver == "systemd" && info.CgroupVersion == "2" && rootlessutil.IsRootless() {
g := fmt.Sprintf("/user.slice/user-%d.slice", rootlessutil.ParentEUID())
mobySysInfoOpts = append(mobySysInfoOpts, sysinfo.WithCgroup2GroupPath(g))
groupPath, err := systemdUserManagerControlGroup(context.TODO())
if err != nil {
info.Warnings = append(info.Warnings, fmt.Sprintf("WARNING: Failed to detect rootless systemd cgroup: %v", err))
Comment thread
chemwolf6922 marked this conversation as resolved.
groupPath = fmt.Sprintf("/user.slice/user-%d.slice", rootlessutil.ParentEUID())
}
mobySysInfoOpts = append(mobySysInfoOpts, sysinfo.WithCgroup2GroupPath(groupPath))
}
mobySysInfo := sysinfo.New(mobySysInfoOpts...)
return mobySysInfo
return sysinfo.New(mobySysInfoOpts...)
}
46 changes: 46 additions & 0 deletions pkg/infoutil/rootless_cgroup_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package infoutil

import (
"context"
"fmt"
"strconv"

"github.com/coreos/go-systemd/v22/dbus"
)

// systemdUserManagerControlGroup returns the cgroup containing the systemd user
// manager. Runc asks this manager to create rootless container scopes, so its
// ControlGroup is authoritative even when nerdctl runs in another cgroup.
func systemdUserManagerControlGroup(ctx context.Context) (string, error) {
conn, err := dbus.NewUserConnectionContext(ctx)
if err != nil {
return "", fmt.Errorf("connecting to systemd user manager: %w", err)
}
defer conn.Close()

property, err := conn.GetManagerProperty("ControlGroup")
if err != nil {
return "", fmt.Errorf("getting systemd user manager ControlGroup: %w", err)
}
groupPath, err := strconv.Unquote(property)
if err != nil {
return "", fmt.Errorf("decoding systemd user manager ControlGroup property %q: %w", property, err)
}
return groupPath, nil
}
Loading