mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
runc create/run: warn on rootless + shared pidns + no cgroup
Shared pid namespace means `runc kill` (or `runc delete -f`) have to kill all container processes, not just init. To do so, it needs a cgroup to read the PIDs from. If there is no cgroup, processes will be leaked, and so such configuration is bad and should not be allowed. To keep backward compatibility, though, let's merely warn about this for now. Alas, the only way to know if cgroup access is available is by returning an error from Manager.Apply. Amend fs cgroup managers to do so (systemd doesn't need it, since v1 can't work with rootless, and cgroup v2 does not have a special rootless case). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -580,7 +580,18 @@ func (p *initProcess) start() (retErr error) {
|
||||
// cgroup. We don't need to worry about not doing this and not being root
|
||||
// because we'd be using the rootless cgroup manager in that case.
|
||||
if err := p.manager.Apply(p.pid()); err != nil {
|
||||
return fmt.Errorf("unable to apply cgroup configuration: %w", err)
|
||||
if errors.Is(err, cgroups.ErrRootless) {
|
||||
// ErrRootless is to be ignored except when
|
||||
// the container doesn't have private pidns.
|
||||
if !p.config.Config.Namespaces.IsPrivate(configs.NEWPID) {
|
||||
// TODO: make this an error in runc 1.3.
|
||||
logrus.Warn("Creating a rootless container with no cgroup and no private pid namespace. " +
|
||||
"Such configuration is strongly discouraged (as it is impossible to properly kill all container's processes) " +
|
||||
"and will result in an error in a future runc version.")
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("unable to apply cgroup configuration: %w", err)
|
||||
}
|
||||
}
|
||||
if p.intelRdtManager != nil {
|
||||
if err := p.intelRdtManager.Apply(p.pid()); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user