OCI SELinux labeling mismatch when package only ships binary policy - greetd is broken #510
Description
Hi OSTree team,
I am trying to debug an issue that surfaced in Ublue (ublue-os/main#223). In Ublue we are making use of the OCI functionality heavily to produce custom downstream images of Fedora Silverblue. Some users have wanted to install greetd
as their greeter for simplicity but whenever they do the resulting image is slightly broken because of wrong SELinux labeling.
I have investigated the package and I see that /usr/bin/greetd
should be labeled as xdm_exec_t
(see: here) which makes sense for a display manager but in the resulting images we see that /usr/bin/greetd
is labeled as bin_t
and therefore access gets denied by SELinux when the system is booted.
This is the output of ls -lZ
in the images:
-rwxr-xr-x. 3 root root system_u:object_r:bin_t:s0 839488 Jan 1 1970 /usr/bin/greetd
this is the package source that shows the intended labeling:
I tried to trace down the issue and I found this function: sepolicy_from_base
:
1 fn sepolicy_from_base(repo: &ostree::Repo, base: &str) -> Result<tempfile::TempDir> {
2 let cancellable = gio::Cancellable::NONE;
3 let policypath = "usr/etc/selinux";
4 let tempdir = tempfile::tempdir()?;
5 let (root, _) = repo.read_commit(base, cancellable)?;
6 let policyroot = root.resolve_relative_path(policypath);
7 if policyroot.query_exists(cancellable) {
8 let policydest = tempdir.path().join(policypath);
9 std::fs::create_dir_all(policydest.parent().unwrap())?;
10 let opts = ostree::RepoCheckoutAtOptions {
11 mode: ostree::RepoCheckoutMode::User,
12 subpath: Some(Path::new(policypath).to_owned()),
13 ..Default::default()
14 };
15 repo.checkout_at(Some(&opts), ostree::AT_FDCWD, policydest, base, cancellable)?;
16 }
17 Ok(tempdir)
18 }
I am not an expert but if I understand correctly this will look for the labels defined in /usr/etc/selinux
in the resulting image and then it will restorecon
based on that. In this case the package only ships a binary policy so my theory was that this would not find the rule /usr/bin/greetd -- gen_context(system_u:object_r:xdm_exec_t,s0)
which is defined in a binary policy therefore leading to the wrong labeling we observed.
We can use this minimal Containerfile to reproduce reliably:
FROM quay.io/fedora/fedora-silverblue:39
RUN rpm-ostree install -y greetd \
&& ls -lZ /usr/bin/greetd
Activity