Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rootless: support joining containers that use host ns #18344

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Apr 25, 2023

The problem right now is that --ns contianer: syntax causes use to add the namespace path to the spec which means the runtime will try to call setns on that. This works fine for private namespaces but when the host namspace is used by the container a rootless user is not allowed to join that namespace so the setns call will return with permission denied.

The fix is to effectively switch the container to the host mode instead of container: when the mention container used the host ns. I tried to fix this deep into the libpod call when we assign these namespaces but the problem is that this does not work correctly because these namespace require much more setup. Mainly different kind of mount points to work correctly.

We already have similar work-arounds in place for pods because they also need this.

For some reason this does not work with the user namespace, I don't know why and I don't think it is really needed so I left this out just to get at least the rest working. The original issue only reported this for the network namespace.

Fixes #18027

Does this PR introduce a user-facing change?

Podman run `--network container:XXX` now also works when the target container uses the host network mode. The same also works for the other namespace options (`--pid`, `--uts`, `--cgroupns`, `--ipc`). 

The problem right now is that --ns contianer: syntax causes use to add
the namespace path to the spec which means the runtime will try to call
setns on that. This works fine for private namespaces but when the host
namspace is used by the container a rootless user is not allowed to
join that namespace so the setns call will return with permission
denied.

The fix is to effectively switch the container to the `host` mode
instead of `container:` when the mention container used the host ns. I
tried to fix this deep into the libpod call when we assign these
namespaces but the problem is that this does not work correctly because
these namespace require much more setup. Mainly different kind of mount
points to work correctly.

We already have similar work-arounds in place for pods because they also
need this.

For some reason this does not work with the user namespace, I don't know
why and I don't think it is really needed so I left this out just to get
at least the rest working. The original issue only reported this for the
network namespace.

Fixes containers#18027

Signed-off-by: Paul Holzinger <[email protected]>
@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 25, 2023
@Luap99
Copy link
Member Author

Luap99 commented Apr 25, 2023

@giuseppe @mheon PTAL

@mheon
Copy link
Member

mheon commented Apr 25, 2023

LGTM

@edsantiago edsantiago changed the title rootless: support joining contianers that use host ns rootless: support joining containers that use host ns Apr 25, 2023
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 26, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 26, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 931447b into containers:main Apr 26, 2023
@Luap99 Luap99 deleted the container-ns branch April 26, 2023 08:53
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Aug 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

network mode container fails if container use host mode
4 participants