Bug 1484699 - nspawn does not work with selinux enabled
Summary: nspawn does not work with selinux enabled
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 28
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Lukas Vrabec
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-08-24 07:24 UTC by Petr Sklenar
Modified: 2019-06-05 13:12 UTC (History)
19 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-05-28 18:58:55 UTC
Type: Bug


Attachments (Terms of Use)

Description Petr Sklenar 2017-08-24 07:24:36 UTC
Description of problem:
nspawn does not work much with selinux enabled

Version-Release number of selected component (if applicable):
systemd-233-6.fc26.x86_64

How reproducible:
always

Steps to Reproduce:
1, prepare machine:

dnf -y install --nogpgcheck --setopt=install_weak_deps=False --installroot /opt/chroot_bash_1503496751.028378 --allowerasing --disablerepo=* --enablerepo=bash*  --repofrompath bash1,https://kojipkgs.fedoraproject.org/compose/latest-Fedora-Modular-26/compose/Server/x86_64/os/ --repofrompath bash2,https://kojipkgs.fedoraproject.org/compose/latest-Fedora-Modular-26/compose/Server/x86_64/os/ systemd microdnf glibc-minimal-langpack coreutils-single shadow-utils filesystem util-linux rpm bash libcrypt

systemd-nspawn --machine=bash_1503496751.028378 -bD /opt/chroot_bash_1503496751.028378

2, 

16:05 $ sudo machinectl status  bash_2
bash_2(5ef82a93d7e84efbb9012fe9f75f0d95)
           Since: Wed 2017-08-23 16:07:46 CEST; 5s ago
          Leader: 6076 (systemd)
         Service: systemd-nspawn; class container
            Root: /opt/chroot_bash_1
              OS: Fedora Modular 26 (Twenty Six)
            Unit: machine-bash_2.scope
                  ├─init.scope
                  │ └─6076 /usr/lib/systemd/systemd
                  └─system.slice
                    ├─console-getty.service
                    │ └─6108 /sbin/agetty --noclear --keep-baud console 115200,38400,9600 xterm-256color
                    ├─dbus.service
                    │ └─6106 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
                    ├─systemd-journald.service
                    │ └─6093 /usr/lib/systemd/systemd-journald
                    └─systemd-logind.service
                      └─6107 /usr/lib/systemd/systemd-logind

Aug 23 16:07:46 localhost.localdomain systemd[1]: Started Container bash_2.

16:07 $ getenforce 
Enforcing

16:08 $ machinectl shell root@bash_2
Failed to get shell PTY: Access denied

16:08 $ sudo machinectl shell  bash_2
Failed to get shell PTY: Message recipient disconnected from message bus without replying

16:08 $ sudo machinectl shell  bash_2
Failed to get shell PTY: Failed to activate service 'org.freedesktop.machine1': timed out (service_start_timeout=25000ms)

16:09 $ sudo machinectl status  bash_2
Could not get path to machine: Failed to activate service 'org.freedesktop.machine1': timed out (service_start_timeout=25000ms)

and now its totally out of order even you turn off selinux. Only what can I do is systemd-machined restart.

Actual results:
Could not get path to machine: Failed to activate service 'org.freedesktop.machine1': timed out (service_start_timeout=25000ms)


Expected results:
no timeout

Additional info:

Comment 1 Petr Sklenar 2017-08-24 07:27:15 UTC
we would like this feature for 
https://github.com/fedora-modularity/meta-test-family/issues/53

Comment 2 Petr Sklenar 2017-08-28 13:50:04 UTC
tried in rawhide with packages:
systemd-container-234-5.fc27.x86_64
selinux-policy-3.13.1-276.fc28.noarch
---
[root@kvm-02-guest13 ~]# machinectl list
MACHINE                CLASS     SERVICE        OS             VERSION ADDRESSES
bash_1503496751.028378 container systemd-nspawn fedora-modular 26      -

1 machines listed.
[root@kvm-02-guest13 ~]# machinectl shell bash_1503496751
Failed to get shell PTY: No machine 'bash_1503496751' known
[root@kvm-02-guest13 ~]# getenforce 
Enforcing
[root@kvm-02-guest13 ~]# setenforce 0
[root@kvm-02-guest13 ~]# machinectl shell bash_1503496751.028378
Connected to machine bash_1503496751.028378. Press ^] three times within 1s to exit session.
sh-4.4# 
Connection to machine bash_1503496751.028378 terminated.
[root@kvm-02-guest13 ~]# setenforce 1
[root@kvm-02-guest13 ~]# machinectl shell bash_1503496751.028378
Failed to get shell PTY: Message recipient disconnected from message bus without replying
---------
its blocked by selinux:

[root@kvm-02-guest13 ~]# cat /var/log/audit/audit.log | grep den
type=AVC msg=audit(1503925459.191:525): avc:  denied  { map } for  pid=1348 comm="restorecon" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:setfiles_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925868.863:533): avc:  denied  { map } for  pid=1459 comm="unix_chkpwd" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:chkpwd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925868.870:535): avc:  denied  { map } for  pid=1460 comm="unix_chkpwd" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:chkpwd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925868.988:542): avc:  denied  { map } for  pid=1462 comm="unix_chkpwd" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:chkpwd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925964.211:556): avc:  denied  { map } for  pid=1668 comm="nfs-server-gene" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:nfsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925964.240:557): avc:  denied  { map } for  pid=1675 comm="systemd-gpt-aut" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:systemd_gpt_generator_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=1
type=AVC msg=audit(1503925991.493:564): avc:  denied  { map } for  pid=1691 comm="unix_chkpwd" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:chkpwd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503925991.499:566): avc:  denied  { map } for  pid=1692 comm="unix_chkpwd" path="/etc/ld.so.cache" dev="dm-0" ino=9832865 scontext=system_u:system_r:chkpwd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=0
type=AVC msg=audit(1503927926.221:175): avc:  denied  { read } for  pid=1285 comm="systemd-machine" name="ptmx" dev="tmpfs" ino=24483 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=lnk_file permissive=1
type=AVC msg=audit(1503927926.221:176): avc:  denied  { open } for  pid=1285 comm="systemd-machine" path="/dev/pts/ptmx" dev="devpts" ino=2 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503927926.223:177): avc:  denied  { open } for  pid=1286 comm="systemd-machine" path="/dev/pts/0" dev="devpts" ino=3 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=system_u:object_r:devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503927926.230:178): avc:  denied  { write } for  pid=1290 comm="systemd-machine" name="system_bus_socket" dev="tmpfs" ino=25130 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=sock_file permissive=1
type=AVC msg=audit(1503927926.230:179): avc:  denied  { connectto } for  pid=1290 comm="systemd-machine" path="/run/dbus/system_bus_socket" scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1503927975.525:192): avc:  denied  { read } for  pid=1354 comm="systemd-machine" name="ptmx" dev="tmpfs" ino=24483 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=lnk_file permissive=1
type=AVC msg=audit(1503927975.526:193): avc:  denied  { open } for  pid=1354 comm="systemd-machine" path="/dev/pts/ptmx" dev="devpts" ino=2 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503927975.528:194): avc:  denied  { open } for  pid=1355 comm="systemd-machine" path="/dev/pts/0" dev="devpts" ino=3 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=system_u:object_r:devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503927975.534:195): avc:  denied  { write } for  pid=1359 comm="systemd-machine" name="system_bus_socket" dev="tmpfs" ino=25130 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=sock_file permissive=1
type=AVC msg=audit(1503927975.535:196): avc:  denied  { connectto } for  pid=1359 comm="systemd-machine" path="/run/dbus/system_bus_socket" scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1503928006.231:210): avc:  denied  { read } for  pid=1412 comm="systemd-machine" name="ptmx" dev="tmpfs" ino=24483 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=lnk_file permissive=1
type=AVC msg=audit(1503928006.231:211): avc:  denied  { open } for  pid=1412 comm="systemd-machine" path="/dev/pts/ptmx" dev="devpts" ino=2 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503928006.233:212): avc:  denied  { open } for  pid=1413 comm="systemd-machine" path="/dev/pts/0" dev="devpts" ino=3 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=system_u:object_r:devpts_t:s0 tclass=chr_file permissive=1
type=AVC msg=audit(1503928006.239:213): avc:  denied  { write } for  pid=1417 comm="systemd-machine" name="system_bus_socket" dev="tmpfs" ino=25130 scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=sock_file permissive=1
type=AVC msg=audit(1503928006.239:214): avc:  denied  { connectto } for  pid=1417 comm="systemd-machine" path="/run/dbus/system_bus_socket" scontext=system_u:system_r:systemd_machined_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=unix_stream_socket permissive=1

Comment 4 Fedora End Of Life 2018-02-20 15:25:41 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 28 development cycle.
Changing version to '28'.

Comment 5 George Nikandrov 2018-04-15 17:54:53 UTC
Still there with:
systemd-container-234-10.git5f8984e.fc27.x86_64
selinux-policy-3.13.1-283.30.fc27.noarch

Anyone?

Comment 6 Daniel Walsh 2018-04-16 12:41:57 UTC
What AVC's are you seeing now?

The original one seemed to be around a mislabled /etc/ld.so.cache file and machine not able to communicate with the unconfined process.

Have you played around with container-selinux and attempted to run a nspawn container with a container label?  (No I have not tried, but it might work).  I mainly work with podman and docker.

Comment 7 Lukas Vrabec 2018-04-16 13:53:59 UTC
Dan, 

I tried it, if you use -Z parameter, it should work like in podman:

# systemd-nspawn -Z system_u:system_r:container_t:s0 -D /var/lib/machines/container1/ --machine test_container

However, It would be cool if in systemd-nswpawn will be implemented object manager so every container started via systemd-nspawn will have container_t domain. 

Lukas.

Comment 8 Daniel Walsh 2018-04-16 16:19:16 UTC
Sure.

Comment 9 Germano Massullo 2018-05-14 13:03:10 UTC
Petr could you please test also
https://bugzilla.redhat.com/show_bug.cgi?id=1416540
I no longer have a working systemd container based stack, so I cannot any longer do tests

Comment 10 Ben Cotton 2019-05-02 19:36:01 UTC
This message is a reminder that Fedora 28 is nearing its end of life.
On 2019-May-28 Fedora will stop maintaining and issuing updates for
Fedora 28. It is Fedora's policy to close all bug reports from releases
that are no longer maintained. At that time this bug will be closed as
EOL if it remains open with a Fedora 'version' of '28'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 28 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 11 Ben Cotton 2019-05-28 18:58:55 UTC
Fedora 28 changed to end-of-life (EOL) status on 2019-05-28. Fedora 28 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.