Bug 2113941

Summary: podman did not set selinux labels to symbolic links
Product: Red Hat Enterprise Linux 8 Reporter: dominik.holler
Component: podmanAssignee: Jindrich Novy <jnovy>
Status: CLOSED ERRATA QA Contact: Alex Jia <ajia>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.6CC: bbaude, dwalsh, jligon, jnovy, lsm5, mheon, pthomas, tsweeney, umohnani, ypu
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: podman-4.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 09:16:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description dominik.holler 2022-08-02 11:28:12 UTC
Description of problem:
Running a command like 
`podman run -p 22:22 --name rsync6e -m 512m -h rsync   --uidmap 0:100000:500000   -v $RSYNC_BASE/home:/home:Z,ro   -v $RSYNC_BASE/etc/ssh/:/etc/ssh:Z,ro  -v $RSYNC_DATA:/mnt/data2:Z rsync6 `
as root,  the files in $RSYNC_DATA got relabeld as expected, except symbol links, e.g.:
```
[root@ship ~]# ls -lZ /srv/rsync/data/bak/xxx/Programme/xxx/jre/lib/i386/client/                                                               
total 18916                                                                                                                   
-r--r--r--. 87 101001 101001 system_u:object_r:container_file_t:s0:c277,c298 14008320 Sep 15  2011 classes.jsa                                                                                                    
lrwxrwxrwx. 87 101001 101001 system_u:object_r:container_file_t:s0:c527,c785       13 Sep 15  2011 libjsig.so -> ../libjsig.so                                                                                 
-rwxr-xr-x. 87 101001 101001 system_u:object_r:container_file_t:s0:c277,c298  5355014 Mar 25  2008 libjvm.so
-rw-r--r--. 87 101001 101001 system_u:object_r:container_file_t:s0:c277,c298     1423 Mar 25  2008 Xusage.txt 
```
and from inside the container:
```
root@rsync:/mnt/data2/bak/xxx# ls -lsh /mnt/data2/bak/xxx/Programme/xxx/jre/lib/i386/client/                                                                                                         
ls: cannot access '/mnt/data2/bak/xxx/Programme/xxx/jre/lib/i386/client/libjsig.so': Permission denied                                                                                                 
total 19M
4.0K -rw-r--r--. 87 xxx xxx 1.4K Mar 25  2008 Xusage.txt
 14M -r--r--r--. 87 xxx xxx  14M Sep 15  2011 classes.jsa
   ? l??????????  ? ?       ?          ?            ? libjsig.so
5.2M -rwxr-xr-x. 87 xxx xxx 5.2M Mar 25  2008 libjvm.so

```

Version-Release number of selected component (if applicable):
podman-4.0.2-6.module+el8.6.0+14877+f643d2d6.x86_64


How reproducible:
only happend a single time


Actual results:
The container has no permissions to access symbolic links.

Expected results:
The container has permissions to access symbolic links.

Additional info:
Setting the context manually worked as expected:
` chcon -R  system_u:object_r:container_file_t:s0:c277,c298 /srv/rsync/data/bak`
No relevant information in journalctl

Comment 1 Daniel Walsh 2022-08-02 12:22:00 UTC
This is fixed in podman 4.1

Comment 3 Tom Sweeney 2022-08-02 18:52:35 UTC
Assigning to Jindrich for any further BZ/packaging needs

Comment 5 Daniel Walsh 2022-08-17 18:39:29 UTC
https://github.com/opencontainers/selinux/pull/173
Which was released in v1.10.1

Which should have come into Podman here:

https://github.com/containers/podman/pull/13689

Comment 6 Tom Sweeney 2022-08-18 21:05:24 UTC
@jnovy Can this BZ be moved into ON_QA state?  This was fixed in Podman 4.1.0 and beyond, maybe a bit earlier.

Comment 9 Alex Jia 2022-08-19 09:52:06 UTC
I can reproduce this bug on podman-4.0.2-6.module+el8.6.0+14877+f643d2d6.x86_64
and verified it on podman 4.1.

Reproducer

[root@sweetpig-11 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 ls -lZ /mnt/data
ls: cannot access /mnt/data/ls: Permission denied
?---------  ?    ?                                     ls
-rw-r--r--. root root system_u:object_r:container_file_t:s0:c539,c772 test.txt

[root@sweetpig-11 ~]# rpm -q podman runc
podman-4.0.2-6.module+el8.6.0+14877+f643d2d6.x86_64
runc-1.0.3-2.module+el8.6.0+14877+f643d2d6.x86_64

On 8.6

[root@sweetpig-11 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.6 (Ootpa)

[root@sweetpig-11 ~]# rpm -q podman runc
podman-4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64
runc-1.1.3-2.module+el8.6.0+15917+093ca6f8.x86_64

[root@sweetpig-11 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 ls -lZ /mnt/data
lrwxrwxrwx. root root system_u:object_r:container_file_t:s0:c481,c637 ls -> /usr/bin/ls
-rw-r--r--. root root system_u:object_r:container_file_t:s0:c481,c637 test.txt

[root@sweetpig-11 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 /mnt/data/ls
bin  boot  dev	etc  home  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var

[root@sweetpig-11 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 cat /mnt/data/test.txt
test

On 8.7

[root@ibm-x3650m4-01-vm-16 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.7 Beta (Ootpa)

[root@ibm-x3650m4-01-vm-16 ~]# rpm -q podman runc
podman-4.1.1-6.module+el8.7.0+15895+a6753917.x86_64
runc-1.1.3-2.module+el8.7.0+15895+a6753917.x86_64

[root@ibm-x3650m4-01-vm-16 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 ls -lZ /mnt/data
lrwxrwxrwx. root root system_u:object_r:container_file_t:s0:c535,c760 ls -> /usr/bin/ls
-rw-r--r--. root root system_u:object_r:container_file_t:s0:c535,c760 test.txt

[root@ibm-x3650m4-01-vm-16 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 /mnt/data/ls
bin  boot  dev	etc  home  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var

[root@ibm-x3650m4-01-vm-16 ~]# podman run -it -v /foo/data:/mnt/data:Z rhel7 cat /mnt/data/test.txt
test

Comment 11 errata-xmlrpc 2022-11-08 09:16:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: container-tools:rhel8 security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:7457

Comment 12 Red Hat Bugzilla 2023-09-18 04:43:38 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days