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

Don't mount /dev/ inside privileged containers running systemd #15895

Merged

Conversation

dcermak
Copy link
Contributor

@dcermak dcermak commented Sep 21, 2022

According to https://systemd.io/CONTAINER_INTERFACE/, systemd will try take control over /dev/tty if exported, which can cause conflicts with the host's tty in privileged containers. Thus we will not expose these to privileged containers in systemd mode, as this is a bad idea according to systemd's maintainers.

This fixes #15878

Does this PR introduce a user-facing change?

- don't expose `/dev/tty*` to privileged containers in systemd mode

@rhatdan
Copy link
Member

rhatdan commented Sep 22, 2022

Please repush your PR. I added [NO NEW TESTS NEEDED]
/approve
LGTM
@giuseppe PTAL

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 22, 2022
@dcermak dcermak force-pushed the don-expose-dev-for-privileged branch 3 times, most recently from 78d0925 to af24c04 Compare September 22, 2022 11:42
@dcermak
Copy link
Contributor Author

dcermak commented Sep 22, 2022

Please repush your PR. I added [NO NEW TESTS NEEDED]

I have removed that and added a bats test, because my initial fix was actually broken (it got late yesterday…).

@dcermak dcermak force-pushed the don-expose-dev-for-privileged branch 2 times, most recently from 67db995 to cefd583 Compare September 22, 2022 14:10
Copy link
Collaborator

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

Please squash your commits - no need for separate code + test commits. And please update your commit message to reflect the new state of the code. A few test suggestions inline.

Thank you, and thanks for contributing!

test/system/030-run.bats Outdated Show resolved Hide resolved
test/system/030-run.bats Outdated Show resolved Hide resolved
According to https://systemd.io/CONTAINER_INTERFACE/, systemd will try take
control over /dev/ttyN if exported, which can cause conflicts with the host's tty
in privileged containers. Thus we will not expose these to privileged containers
in systemd mode, as this is a bad idea according to systemd's maintainers.

Additionally, this commit adds a bats regression test to check that no /dev/ttyN
are present in a privileged container in systemd mode

This fixes containers#15878

Signed-off-by: Dan Čermák <dcermak@suse.com>
@dcermak
Copy link
Contributor Author

dcermak commented Sep 22, 2022

@edsantiago Thanks for the review, I've squashed the commits and applied your suggested changes.


if [[ $TTYs = "" ]]; then
die "Did not find any /dev/ttyN devices on local host"
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a little bit confusing to use else after die, since by definition die terminates execution... but not worth re-pushing for, especially given our flaky CI today. I'll fix it in one of my periodic cleanup PRs.

LGTM, but I'll let other more systemd-savvy team members give final approval. Thanks again!

@mheon
Copy link
Member

mheon commented Sep 22, 2022

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 22, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 22, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dcermak, edsantiago, mheon, rhatdan

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:
  • OWNERS [edsantiago,mheon,rhatdan]

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 0899351 into containers:main Sep 22, 2022
edsantiago added a commit to edsantiago/libpod that referenced this pull request Sep 22, 2022
Followup to containers#15895:
 - add a normal-case test, to ensure that --privileged without
   systemd continues to pass through /dev/ttyN devices
 - explain why we die() if host has no ttyN devices
 - I find grep -vx slightly easier to read than sed backslash-slash
 - run cleanup with '-t 0', to shave ten seconds from CI run

Signed-off-by: Ed Santiago <santiago@redhat.com>
edsantiago added a commit to edsantiago/libpod that referenced this pull request Sep 27, 2022
Followup to containers#15895:
 - add a normal-case test, to ensure that --privileged without
   systemd continues to pass through /dev/ttyN devices
 - explain why we die() if host has no ttyN devices
 - I find grep -vx slightly easier to read than sed backslash-slash
 - run cleanup with '-t 0', to shave ten seconds from CI run

Signed-off-by: Ed Santiago <santiago@redhat.com>
@dcermak dcermak deleted the don-expose-dev-for-privileged branch January 24, 2023 07:38
@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 Sep 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 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.

podman exposes /dev/tty* to privileged containers when run as root
5 participants