Skip to content

rootless: support --pid=host#41893

Merged
AkihiroSuda merged 2 commits into
moby:masterfrom
AkihiroSuda:fix-41457
Apr 6, 2021
Merged

rootless: support --pid=host#41893
AkihiroSuda merged 2 commits into
moby:masterfrom
AkihiroSuda:fix-41457

Conversation

@AkihiroSuda

Copy link
Copy Markdown
Member

- What I did
rootless: support --pid=host

Fix #41457

Also port TestRunModePIDHost from CLI test to API test

- How I did it
By substituting procfs mount with rbind (https://github.com/containers/podman/blob/v3.0.0-rc1/pkg/specgen/generate/oci.go#L248-L257)

- How to verify it
DOCKER_ROOTLESS=1 TEST_SKIP_INTEGRATION_CLI=1 TESTFLAGS='-test.run TestPidHost' make test-integration

- Description for the changelog

rootless: support --pid=host

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

🐧

@AkihiroSuda AkihiroSuda added area/rootless Rootless Mode kind/bugfix PR's that fix bugs labels Jan 19, 2021
Comment thread rootless/specconv/specconv_linux.go Outdated
Comment thread rootless/specconv/specconv_linux.go Outdated
Comment thread rootless/specconv/specconv_linux.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can use path.Clean as well (instead of filepath. Do we want a fast-path here in case no cleaning is needed?

Suggested change
if filepath.Clean(m.Destination) == "/proc" {
if m.Destination == "/proc" || path.Clean(m.Destination) == "/proc" {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That makes the code longer and I feel less readable, but just my feeling

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Too bad we don't have a spec requirement that the paths should be absolute and cleaned.

Hmm, a somewhat similar code in buildkit do not have path.Clean():

https://github.com/moby/buildkit/blob/master/util/rootless/specconv/specconv_linux.go#L28-L29

So I'm not sure whether it is needed here.

Comment thread rootless/specconv/specconv_linux.go Outdated
Comment thread integration/internal/container/ns.go Outdated
Comment thread integration/container/pidmode_linux_test.go Outdated

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM

@thaJeztah

Copy link
Copy Markdown
Member

@cpuguy83 ptal

@AkihiroSuda AkihiroSuda added this to the 21.xx milestone Feb 25, 2021
@AkihiroSuda
AkihiroSuda requested a review from tonistiigi March 24, 2021 05:38

daemonCgroup := d.CgroupNamespace(t)
containerCgroup := containerCgroupNamespace(ctx, t, client, cID)
containerCgroup := container.GetContainerNS(ctx, t, client, cID, "cgroup")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the code from reading /proc/1/ns/cgroup to /proc/self/ns/cgroup but the end result should be the same, so no issue here (just noticing).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I know.

if err != nil {
return false, err
}
return pidNS == selfPidNS, nil

@kolyshkin kolyshkin Mar 26, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A little bit faster way would be to run stat on both paths and return (st1.Dev == st2.Dev) && (st1.Ino == st2.Ino), nil. Comparing symlinks is OK, too.

@kolyshkin kolyshkin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda

Copy link
Copy Markdown
Member Author

Mergeable? @kolyshkin @thaJeztah

@AkihiroSuda

Copy link
Copy Markdown
Member Author

I see two LGTMs, so merging

@AkihiroSuda
AkihiroSuda merged commit c8ff730 into moby:master Apr 6, 2021
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Apr 11, 2023
The `docker/bash.sh` script should omit the `--pid=host` argument and
`docker/with_the_same_user` arguments when the host's docker daemon is
running in [rootless
mode](https://docs.docker.com/engine/security/rootless/).  The
`with_the_same_user` script is unnecessary in this mode, as rootless
docker daemons already use the privileges of the user.

The `--pid=host` flag is required when running in CI, and while it may
be useful when running tests locally, it is only supported for
rootless docker in versions docker versions 22.06 or
greater ([requires this
commit](moby/moby#41893)).
Lunderberg added a commit to apache/tvm that referenced this pull request Apr 18, 2023
The `docker/bash.sh` script should omit the `--pid=host` argument and
`docker/with_the_same_user` arguments when the host's docker daemon is
running in [rootless
mode](https://docs.docker.com/engine/security/rootless/).  The
`with_the_same_user` script is unnecessary in this mode, as rootless
docker daemons already use the privileges of the user.

The `--pid=host` flag is required when running in CI, and while it may
be useful when running tests locally, it is only supported for
rootless docker in versions docker versions 22.06 or
greater ([requires this
commit](moby/moby#41893)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rootless: docker run --pid=host fails with mounting "proc" to rootfs at "/proc" caused: operation not permitted

4 participants