Skip to content

cgroup2: unshare cgroupns by default regardless to API version#41072

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
AkihiroSuda:fix-41071
Oct 1, 2020
Merged

cgroup2: unshare cgroupns by default regardless to API version#41072
cpuguy83 merged 1 commit intomoby:masterfrom
AkihiroSuda:fix-41071

Conversation

@AkihiroSuda
Copy link
Member

- What I did
Fix #41071

cgroup2 mode sets cgroupns=private by default , but the default was overridden to host when API < 1.41.

- How to verify it

$ sudo ls -l /proc/1/ns/cgroup
lrwxrwxrwx 1 root root 0 Jun  5 18:04 /proc/1/ns/cgroup -> 'cgroup:[4026531835]'
$ DOCKER_API_VERSION=1.40 docker run --rm alpine ls -l /proc/1/ns/cgroup
lrwxrwxrwx    1 root     root             0 Jun  5 09:04 /proc/1/ns/cgroup -> cgroup:[4026532639]

- A picture of a cute animal (not mandatory but encouraged)
🐧

@thaJeztah thaJeztah added this to the 20.03.0 milestone Jun 11, 2020
@thaJeztah
Copy link
Member

ping @kolyshkin PTAL

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify it a lot by using cgroups.IsCgroup2UnifiedMode() in place

Fix moby#41071

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

@kolyshkin That package only compiles on Linux and cannot be imported in cmd/dockerd/daemon.go.

@AkihiroSuda
Copy link
Member Author

@kolyshkin @thaJeztah @cpuguy83 PTAL

@cpuguy83
Copy link
Member

Should this be in the router? If we are doing this regardless of API version, seems like the router doesn't need to know about v2.

@thaJeztah
Copy link
Member

^ good point

@kolyshkin
Copy link
Contributor

Should this be in the router? If we are doing this regardless of API version, seems like the router doesn't need to know about v2.

It's the router who resets the cgroupns=private (default for cgroupv2) setting for older clients. Chances are, older clients don't know/care about cgroupv2, so the reset should only be done for cgroupv1, thus the need for router to know whether its v1 or v2.

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83
Copy link
Member

I don't think we should contort the router to have system level information because we can't tell if a value passed from the router is a default value or not.

@kolyshkin
Copy link
Contributor

I don't think we should contort the router to have system level information

So, you are suggesting we should perform the change somewhere else. Fine, but...

we can't tell if a value passed from the router is a default value or not

...this is exactly what the problem is. We do not know if a cgroupns value that comes from the router is default or not, so we don't know if we need to change it or not :-\

IOW, if you don't like the way how it's currently done, can you please propose an alternative way to do the same thing?

@cpuguy83
Copy link
Member

Maybe not perfect for future (albeit highly unlikely to have changes around this case), but telling the router what the default should be seems cleaner.

I also opened #41129 to discuss how to handle this across the board because it is problematic in other places as well.

@AkihiroSuda
Copy link
Member Author

Can we merge this PR and discuss the router design in #41129 ?

@cpuguy83
Copy link
Member

I would rather not add extra compexity like this just to get the change in.
I think it's also a bit of a stretch to make this change to older API versions.

@justincormack
Copy link
Contributor

Its not safe to run cgroupsv2 unnamespaced it appears, so I think we have to make this change for previous API versions.

@cpuguy83
Copy link
Member

@justincormack I was curious about that. Good catch.

So we can implement this totally in the daemon and not touch the API side.

@AkihiroSuda
Copy link
Member Author

not touch the API side.

API server has if hostConfig.CgroupnsMode.IsEmpty() { hostConfig.CgroupnsMode = container.CgroupnsMode("host") } , so this PR modifies API server to disable this block for cgroup v2

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It'd be nice to rework this a bit, but we need this in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cgroup2: cgroupns is not unshared when DOCKER_API_VERSION < 1.41

5 participants