Bug 2229722

Summary: SELinux policy blocks FDO servers and FDO client
Product: Red Hat Enterprise Linux 9 Reporter: Xiaofeng Wang <xiaofwan>
Component: selinux-policyAssignee: Nikola Knazekova <nknazeko>
Status: ASSIGNED --- QA Contact: Milos Malik <mmalik>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 9.3CC: amurdaca, elpereir, idiez, lvrabec, mcattamo, miabbott, mmalik, nknazeko, perobins, qzhang, yih, zpytela
Target Milestone: rcKeywords: TestBlocker, Triaged
Target Release: 9.3Flags: nknazeko: needinfo? (xiaofwan)
nknazeko: needinfo? (idiez)
nknazeko: needinfo? (xiaofwan)
nknazeko: needinfo? (amurdaca)
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 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:
Attachments:
Description Flags
FDO client avc log none

Description Xiaofeng Wang 2023-08-07 13:01:36 UTC
Created attachment 1982118 [details]
FDO client avc log

Description of problem:
selinux-policy-38.1.18-1.el9.noarch blocked fdo-manufacturing-server, fdo-rendezvous-server, fdo-client-linuxapp, and some fdo operations related with FDO.

Version-Release number of selected component (if applicable):
selinux-policy-38.1.18-1.el9.noarch
fdo-rendezvous-server-0.4.12-1.el9_2.x86_64
fdo-owner-onboarding-server-0.4.12-1.el9_2.x86_64
fdo-owner-cli-0.4.12-1.el9_2.x86_64
fdo-manufacturing-server-0.4.12-1.el9_2.x86_64
fdo-admin-cli-0.4.12-1.el9_2.x86_64
fdo-client-0.4.12-1.el9_2.x86_64

How reproducible:

Steps to Reproduce:
1. Deploy a RHEL 9.3 VM.
2. git clone https://github.com/virt-s1/rhel-edge.git
3. DOWNLOAD_NODE=download-node-02.eng.bos ./ostree-simplified-installer.sh 

Actual results:
FDO services and FDO client operations are blocked by selinux

Expected results:
FDO services and FDO client work without error.

Additional info:
FDO service and FDO client log attached.

Comment 3 idiez 2023-08-07 13:23:51 UTC
These other fdo operations affected by selinux denials are the manufacturing-client.service being terminated, see attachment.

We cannot add the selinux denials for this event since the service runs in the dracut stage and there is no ausearch in the emergency shell.

Comment 5 Peter Robinson 2023-08-08 10:26:41 UTC
> We cannot add the selinux denials for this event since the service runs in
> the dracut stage and there is no ausearch in the emergency shell.

To recreate the problem most easily I suggest we:
1) boot with SELinux in permissive mode
2) run the manufacturing process from standard userspace manually from the cli in the same way you'd run it from the initrd
3) collect logs/denials etc

There's no reason the manufacturing client can't be run from standard linux run level for debug even though we usually run it in the initrd.

Comment 9 Nikola Knazekova 2023-08-10 15:52:31 UTC
PR for tracking fix: https://github.com/fedora-selinux/selinux-policy/pull/1831

Comment 11 Nikola Knazekova 2023-08-11 13:45:45 UTC
Thank you Irene, 

can you please reproduce the issue with SELinux in permissive?
# setenforce 0

Comment 12 Nikola Knazekova 2023-08-11 13:55:18 UTC
How is created /etc/device-credentials ? 
because there is also unlabeled type, which is invalid type and it might happen when a file was created in SELinux disabled state. 

If the system is seriously mislabeled, you may need to boot in SELinux permissive mode which changes in /etc/selinux/config, 
and replace enforcing for permissive

Then

  # fixfiles -F onboot
  # reboot

Comment 13 idiez 2023-08-11 14:57:40 UTC
(In reply to Nikola Knazekova from comment #12)
> How is created /etc/device-credentials ? 
> because there is also unlabeled type, which is invalid type and it might
> happen when a file was created in SELinux disabled state. 
> 

/etc/device-credentials is the result of running the binary at /usr/libexec/fdo/fdo-manufacturing-client with the systemd unit /usr/lib/dracut/modules.d/52fdo/manufacturing-client.service during the dracut stage at system installation time.

> If the system is seriously mislabeled, you may need to boot in SELinux
> permissive mode which changes in /etc/selinux/config, 
> and replace enforcing for permissive
> 
> Then
> 
>   # fixfiles -F onboot
>   # reboot

We cannot do that because the the binary that generates the file runs once during the system installation, it is part of a dracut module that it is then removed at first boot.
At first boot /boot/device-credentials must have been copied from /etc/device-credentials, or the installation fails.


(In reply to Nikola Knazekova from comment #11)
> Thank you Irene, 
> 
> can you please reproduce the issue with SELinux in permissive?
> # setenforce 0

The issue is not reproducible if I set enforcing=0 as the kernel parameters.

Comment 14 Nikola Knazekova 2023-08-14 13:43:17 UTC
Can you add this line in the service where is used device credentials?:
ExecStartPre=/usr/sbin/restorecon /boot/device-credentials

Comment 15 Antonio Murdaca 2023-08-15 10:09:02 UTC
(In reply to Nikola Knazekova from comment #14)
> Can you add this line in the service where is used device credentials?:
> ExecStartPre=/usr/sbin/restorecon /boot/device-credentials

I'll try this although I want to understand why "it used to work" before and now it doesn't

Comment 16 Nikola Knazekova 2023-08-15 11:03:37 UTC
Hi Antonio,

the fdo module was added to SELinux policy version 38.1.17-1.
SELinux policy for FDO module was created and tested in the bz#2026795, and nothing has changed since that time, so maybe there were some changes in the test?

Comment 17 Antonio Murdaca 2023-08-15 14:31:18 UTC
created a test PR here https://github.com/fedora-iot/fido-device-onboard-rs/pull/543

Comment 18 Antonio Murdaca 2023-08-16 14:52:47 UTC
Nikola, can you please take a look at https://github.com/fedora-selinux/selinux-policy/pull/1831#discussion_r1294696018 - I'm pretty sure we're missing something within the policy at this point

Comment 19 Nikola Knazekova 2023-08-17 10:21:51 UTC
Fixed, waiting for the test results