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

Make the container work on an SELinux-enforcing systems #8

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

ondrejbudai
Copy link
Member

@ondrejbudai ondrejbudai commented Nov 23, 2023

When building an image, we need to make sure that the target system is
correctly labeled. This becomes challenging if the target system contains
labels that are unknown to the host because the process setting the label
needs to have CAP_MAC_ADMIN if the host is SELinux-enforcing.

CAP_MAC_ADMIN isn't a common capability on a SELinux-enforcing system.
Even unconfined_t doesn't have it (same for spc_t - label used by
--privileged containers). Thus, we need to ensure that we transition to
a domain that actually has it.

This commit relabels osbuild as install_t, a domain that has CAP_MAP_ADMIN.
A bit of mount-dancing is needed in order to achieve that, see prepare.sh.

I decided to make prepare.sh a separate script. This is useful for debugging:

host # podman run -it
--privileged
--security-opt label=type:unconfined_t
--entrypoint bash
localhost/osbuild-deploy-container
container # ./prepare.sh

This way, you get the same environment as if you run the container the
default way.

See #6 (comment)
and links in this comment for further information.

Open questions:

  • Does this work on:
    • EL8?
    • EL9?
    • Fedora 38?
    • Fedora 39?
    • non-SELinux system (Ubuntu/Arch)?
  • Can we indeed ignore cleaning up the new mounts?
    • It looks like it
  • Can we reasonably fix the denial that happens in the ostree.container.deploy stage?
    • We think so, but as this doesn't have any effect on the resulting artifact, we can handle this in a follow-up.

Fixes #6

@achilleas-k achilleas-k changed the title Make the container working on an SELinux-enforcing systems Make the container work on an SELinux-enforcing systems Nov 23, 2023
@achilleas-k
Copy link
Member

achilleas-k commented Nov 23, 2023

Testing on the distros you listed using osbuild main and including a small loop device fix.

@achilleas-k
Copy link
Member

Manually tested the build process with this PR and it's working on:

  • Fedora 39
  • Fedora 38
  • CentOS Stream 9
  • CentOS Stream 8
  • Ubuntu 24.04 (Noble Numbat)

@teg
Copy link
Member

teg commented Nov 23, 2023

If this is meant to work on an M1, let me know and I would happily sanity check!

When building an image, we need to make sure that the target system is
correctly labeled. This becomes challenging if the target system contains
labels that are unknown to the host because the process setting the label
needs to have CAP_MAC_ADMIN if the host is SELinux-enforcing.

CAP_MAC_ADMIN isn't a common capability on a SELinux-enforcing system.
Even unconfined_t doesn't have it (same for spc_t - label used by
--privileged containers). Thus, we need to ensure that we transition to
a domain that actually has it.

This commit relabels osbuild as install_t, a domain that has CAP_MAP_ADMIN.
A bit of mount-dancing is needed in order to achieve that, see prepare.sh.

I decided to make prepare.sh a separate script. This is useful for debugging:

host # podman run -it \
  --privileged \
  --security-opt label=type:unconfined_t \
  --entrypoint bash \
  localhost/osbuild-deploy-container
container # ./prepare.sh

This way, you get the same environment as if you run the container the
default way.

See #6 (comment)
and links in this comment for further information.
@ondrejbudai
Copy link
Member Author

This is now ready to be merged.

@teg AFAIK, the container should work on ARM. Once this is merged, you can just build the container yourself (clone the repository and sudo podman build) and run a build using instructions from README.md. I don't think it's worth blocking on this now. Proper ARM builds are definitely on the roadmap.

@achilleas-k achilleas-k merged commit 7212d30 into main Nov 24, 2023
1 check passed
# Note that the transition to `install_t` must happen at this point. Osbuild stages run in `bwrap` that creates
# a nosuid, no_new_privs environment. In such an environment, we cannot transition from `unconfined_t` to `install_t`,
# because we would get more privileges.
chcon system_u:object_r:install_exec_t:s0 "${TMP}/osbuild"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would have been better to do

chcon -t install_exec_t "${TMP}/osbuild"

But this is fine.

@teg
Copy link
Member

teg commented Nov 26, 2023

@teg AFAIK, the container should work on ARM. Once this is merged, you can just build the container yourself (clone the repository and sudo podman build) and run a build using instructions from README.md. I don't think it's worth blocking on this now. Proper ARM builds are definitely on the roadmap.

Sanity tested on my M2. The container builds and runs, but we run into the (expected?) loop issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setfiles: Could not set context on SELinux-enforcing systems
4 participants