Closed llegolas closed 4 years ago
@llegolas can you try your script with a slight modification? Please try remove bash
from the last line: buildah unshare bash fedora-31-base.sh
, so it would look like buildah unshare fedora-31-base.sh
@giuseppe any other thoughts?
@TomSweeneyRedHat 'buildah unshare bash...' is not part of the script. This is how I invoke it. If i remove 'bash' from the command and call the script like
$ buildah unshare fedora-31-base.sh
ERRO exec: "fedora-31-base.sh": executable file not found in $PATH
ERRO (unable to determine exit status)
ERRO exit status 1
with bash like
$ buildah unshare bash fedora-31-base.sh
...
...
error: lsetfilecon: (/usr/share/crypto-policies/FIPS/libreswan.txt;5dd060dc, system_u:object_r:usr_t:s0) Operation not supported
error: lsetfilecon: (/usr/share/crypto-policies/FIPS/libssh.config;5dd060dc, system_u:object_r:usr_t:s0) Operation not supported
error: lsetfilecon: (/usr/share/crypto-policies/FIPS/libssh.txt;5dd060dc, system_u:object_r:usr_t:s0) Operation not supported
...
as reported
Ahh I see what you mean. Actually the whole heredoc part of the report is broken and the line you talk about indeed is not part of the script (and never was). I correct the initial post.
@llegolas thanks for the follow up, this makes a bit more sense now.
Could it be problem with fuse-overlayfs? I think I managed to reproduce it w/o buildah unvoled at all
$ ls
lower merged upper workdir
$ fuse-overlayfs -o debug,lowerdir=lower/,upperdir=upper/,workdir=workdir/,rw,nodev,noatime,user_id=0,group_id=0,default_permissions,allow_other merged/
$ chcon system_u:object_r:httpd_config_t:s0 merged/file
chcon: failed to change context of 'merged/file' to ‘system_u:object_r:httpd_config_t:s0’: Operation not supported
$
No this is not a file system issue. In the case of fuse-overlay, it is creating a fuse file system. Fuse file systems do not accept XATTRS so when you attempt to chcon on it, it gets an unsupported error since chcon can not write the XATTR.
Usually in containers we attempt to disable SELinux code, so that it does not attempt to set labels. But in the case of buildah mount and dnf install above, it is running on the host (Not in a container) and the dnf command sees that SELinux is enabled so it is attempting to lay down the SELinux labels.
Since fuse does not support them, you get the error.
I am wondering if their is a flag to dnf/rpm to tell it not to do selinux labeling.
That's easy: just added --setopt=tsflags=nocontexts to the dnf line like that (removed the docs too):
dnf install --installroot $mountpoint --releasever 31 --disablerepo=* --enablerepo=fedora glibc-minimal-langpack bash coreutils omping iproute --setopt=install_weak_deps=false --setopt=tsflags=nocontexts,nodocs -y
There are no errors now. It would be good if this gets documented somewhere.
I'm totally not sure why it worked back in the times of fedora 29. It could have been the storage driver but i can't remember for my live what the setup was before the reinstall.
I think this would work fine in Rootfull mode, but would not work in rootless. Since on Rootful, you are allowed to lay down labels on Overlayfs, but in rootless mode, you are using fuse-overlay, which would not allow labels.
I just did some tests so to recap. The above script produces errors in both rootful and rootless mode with only difference being that in rootful it is executed w/o 'buildah unshare'. the Storage.conf is basically the same for root and ordinary user just some UID/GID remapping and different containers/storage location and is using fuse-overlayfs.
Modifying the script slightly. Adding to the 'dnf install' line
..... --setopt=tsflags=nocontexts...
fixes the behaviour as now no security contexts are tried to apply at all.
fuse-overfayfs support xattrs, but it looks like it doesn't even get the request for setting the xattrs.
Probably the request is blocked by SELinux before reaching the file system
@giuseppe @rhatdan any ideas how can I try to repro? For instance I have no selinux alerts in the logs. Setting selinux mode from enforcing to permissive (setenforce 0) has no affect. I'll try disabling selinux altogether next.
On centos 8 the above script runs (rootless and rootfull) w/o the lsetfilecon errors using yum instead for dnf of course. storage.config the same as on f31.
I managed to narrow it a bit down. the script from above works fine on vanilla f29 and f30 (both updated to the latest as of today). It breaks with f31 booted with both f30 and f31 kernels kernel-core-5.3.11-100.fc29.x86_64 and kernel-core-5.3.11-300.fc31.x86_64 respectively.
Seem like problem is somewhere in userspace.
I would figure something changed in dnf/yum that is causing this. The labels will not be allowed to be applied, because the mount point has a label assigned to it. SELinux does not allow a label on a file system that that already has a label assigned via the mount context options.
merged type overlay (rw,relatime,context="system_u:object_r:container_file_t:s0:c338,c1006"
,lowerdir=/var/lib/containers/storage/overlay/880de1b82361c780df9920d3b70546c4d868659661fc7f2ad2e026fe08d1b415/empty,upperdir=/var/lib/containers/storage/overlay/880de1b82361c780df9920d3b70546c4d868659661fc7f2ad2e026fe08d1b415/diff,workdir=/var/lib/containers/storage/overlay/880de1b82361c780df9920d3b70546c4d868659661fc7f2ad2e026fe08d1b415/work)
If this works in F30 and F31, then dnf/rpm was not doing the setfilecon in those situations.
Everything ends up working, since the setfilecon is not a failure mode. Adding the --setopt=tsflags=nocontexts
turns off the noice. I do not know who on the dnf team to ask, if something changed.
@llegolas is this still an issue?
@rhatdan yes, it is still like that but as you said it has to do something with dnf/rpm. Maybe I can close this one and/or reference it in DNF github page? The no nocontexts
trick works for me, yet what bugs me on is the lack of documentation around the change of the behaviour unless it is unintentional.
I believe this is fixed by always masking over /sys/fs/selinux, Reopen if I am mistaken.
Description
OS fedora 31; selinux enforcing/targeted; using the below script with buildah in rootles mode:
Steps to reproduce the issue:
Describe the results you received: lots of lsetfilecon errors. the resulting image runs OK with podman on the same as far as I can tell.
Describe the results you expected: no errors
Output of
rpm -q buildah
orapt list buildah
:Output of
buildah version
:*Output of `cat /etc/release`:**
Output of
uname -a
:Output of
cat /etc/containers/storage.conf
: