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

Unable to run systemd container with custom SELinux policy #11100

Closed
darrenfoong opened this issue Jun 11, 2021 · 6 comments · Fixed by #11101
Closed

Unable to run systemd container with custom SELinux policy #11100

darrenfoong opened this issue Jun 11, 2021 · 6 comments · Fixed by #11101
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@darrenfoong
Copy link

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

I've been playing around with podman and udica, and it seems that while it is possible to run most containers with custom policy modules (--security-opt label=type:my_policy.process), it is not possible for containers running systemd. This is because containers running systemd are run with the container_init_t label, and it cannot be overwritten (to the best of my knowledge) with --security-opt label.

This is a limitation for those who'd like to run a systemd container with a custom SELinux policy. Some ideas:

  1. Add a init_container.cil template to udica (this should be under the udica project).
  2. Make podman allow a custom policy when running systemd containers.

Steps to reproduce the issue:

  1. Run podman run -d --name init_ctr --systemd always registry.access.redhat.com/ubi8/ubi-init

  2. Use udica to generate a policy module: podman inspect init_ctr | sudo udica test_policy. The actual contents of the module are irrelevant.

  3. Load the policy module: sudo semodule -i test_policy.cil /usr/share/udica/templates/base_container.cil.

  4. Stop the container: podman stop init_ctr && podman rm init_ctr.

  5. Run the container with the new policy: podman run -d --name init_ctr --systemd always --security-opt label=type:test_policy.process registry.access.redhat.com/ubi8/ubi-init.

Describe the results you received:

ps -efZ | grep init shows that the init process runs with the container_init_t label. systemd is running in the container.

Describe the results you expected:

Expected the test_policy.process label with systemd running in the container.

Additional information:

Running podman 3.2.0 on Fedora 34 Workstation.

@rhatdan rhatdan transferred this issue from containers/podman Jun 11, 2021
@rhatdan
Copy link
Member

rhatdan commented Jun 11, 2021

This is an issue with udica not with Podman. Transfering to udica repo.

@rhatdan
Copy link
Member

rhatdan commented Jun 11, 2021

@wrabcak PTAL

@wrabcak
Copy link
Member

wrabcak commented Jun 17, 2021

Hi All,

This needs to be solved on both sides, udica and also podman. It looks like container_init_t label is hard coded in the podman code. Correct, @rhatdan ?

From udica POV, it should be simple to catch if systemd is inside the container. We'll look "--systemd always" parameter is used. But how to fix it from podman side? @rhatdan WDYT?

FYI: @vmojzis

@vmojzis
Copy link

vmojzis commented Jul 16, 2021

@rhatdan Is there any way to override the "container_init_t" label for init containers?

@rhatdan
Copy link
Member

rhatdan commented Jul 16, 2021

--security-opt label=type:foo_t should work.

@darrenfoong
Copy link
Author

Hi @rhatdan, I've repeated "Steps to reproduce the issue" on podman 3.2.3 on Fedora 34 Workstation, and --security-opt label=type:foo_t does not work:

podman run -d --name init_ctr --systemd always --security-opt label=type:test_policy.process registry.access.redhat.com/ubi8/ubi-init

ps -efZ | grep init shows that the init process runs with the container_init_t label, and not the test_policy.process label that I had expected.

On the other hand, I managed to run another container (without systemd) with the expected test_policy.process label:

# differences:
# - removed "--systemd always"
# - changed ubi-init to ubi-minimal (non-systemd)
# - added "sleep 60" to keep it running

podman run -d --name init_ctr --security-opt label=type:test_policy.process registry.access.redhat.com/ubi8/ubi-minimal sleep 60

This time, ps -efZ | grep sleep shows the sleep process running with the test_policy.process label as expected.

So it seems like if I run with --systemd always (or if podman detects a systemd container?), I cannot overwrite the container_init_t label.

@rhatdan rhatdan transferred this issue from containers/udica Aug 2, 2021
@openshift-ci openshift-ci bot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 2, 2021
@rhatdan rhatdan self-assigned this Aug 2, 2021
rhatdan added a commit to rhatdan/podman that referenced this issue Aug 2, 2021
Currently we override the SELinux labels specified by the user
if the container is runing a kata container or systemd container.

This PR fixes to use the label specified by the user.

Fixes: containers#11100

Signed-off-by: Daniel J Walsh <[email protected]>
mheon pushed a commit to mheon/libpod that referenced this issue Aug 11, 2021
Currently we override the SELinux labels specified by the user
if the container is runing a kata container or systemd container.

This PR fixes to use the label specified by the user.

Fixes: containers#11100

Signed-off-by: Daniel J Walsh <[email protected]>
@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 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants