Bug 2160391

Summary: SELinux is preventing systemd from using LoadCredentials
Product: Red Hat Enterprise Linux 9 Reporter: Nikita Uvarov <nuvarov>
Component: selinux-policyAssignee: Nikola Knazekova <nknazeko>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: low Docs Contact:
Priority: medium    
Version: CentOS StreamCC: bstinson, jwboyer, lvrabec, mmalik, sujagtap, zpytela
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-38.1.5-1.el9 Doc Type: Bug Fix
Doc Text:
Cause: systemd-creds apparently runs in a chroot where /dev/shm is backed by ramfs (ramfs_t) instead of the usual tmpfs, which is not allowed in the policy Consequence: SELinux is preventing systemd from using LoadCredentials Fix: Reuse tmpfs_t also for the ramfs filesystem Result: No SELinux denials
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 08:17:16 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 Nikita Uvarov 2023-01-12 09:02:39 UTC
Description of problem:
Current SELinux policies doesn't allow new systemd credentials feature. E.g. running a command like this:

```
sudo systemd-run -P --wait -p LoadCredential=abc:/etc/hosts systemd-creds cat abc
```

Results in:

run-u11509.service: Failed to set up credentials: Protocol error
run-u11509.service: Failed at step CREDENTIALS spawning /bin/systemd-creds: Protocol error
run-u11509.service: Main process exited, code=exited, status=243/CREDENTIALS
run-u11509.service: Failed with result 'exit-code'.

And audit.log:
type=PROCTITLE msg=audit(12/06/2022 14:32:29.129:410) : proctitle=(sd-mkdcreds)
type=SYSCALL msg=audit(12/06/2022 14:32:29.129:410) : arch=x86_64 syscall=openat success=no exit=EACCES(Permission denied) a0=0x3 a1=0x55a11385ef90 a2=O_RDWR|O_CREAT|O_EXCL|O_NOCTTY|O_NOFOLLOW|O_CLOEXEC a3=0x180 items=0 ppid=3368570 pid=3368571 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=(sd-mkdcreds) exe=/usr/lib/systemd/systemd subj=system_u:system_r:init_t:s0 key=(null)
type=AVC msg=audit(12/06/2022 14:32:29.129:410) : avc:  denied  { read write open } for  pid=3368571 comm=(sd-mkdcreds) path=/dev/shm/.#cred8d2badcefa7a5141 dev="ramfs" ino=365308391 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:ramfs_t:s0 tclass=file permissive=0

This seems to be because selinux forbids systemd process to create ramfs files. Adding such permission with semodule containing the following permissions fixes the problem:

allow init_t ramfs_t:file { create open read rename setattr write };


Version-Release number of selected component (if applicable):
CentOS Stream 9
selinux-policy-targeted: 38.1.3


How reproducible:
Everytime

Steps to Reproduce:
1. Make sure selinux is enabled
2. sudo systemd-run -P --wait -p LoadCredential=abc:/etc/hosts systemd-creds cat abc

Actual results:
Main processes terminated with: code=exited/status=243

Expected results:
Contents of /etc/hosts file

Additional info:

Compiling and installing semodule with the following permissions fixes the issue:
allow init_t ramfs_t:file { create open read rename setattr write };

Comment 1 Milos Malik 2023-01-12 13:25:56 UTC
I believe this BZ is a RHEL-9 variant of BZ#2096857.

Comment 2 Zdenek Pytela 2023-01-16 11:13:51 UTC
I thinks these two commits are needed:
021025430 Allow systemd-resolved watch tmpfs directories
8e908b8d9 Reuse tmpfs_t also for the ramfs filesystem

and there is one pr pending for cases when sockets are used.

Comment 3 Nikola Knazekova 2023-01-20 13:08:10 UTC
*** Bug 2160933 has been marked as a duplicate of this bug. ***

Comment 15 errata-xmlrpc 2023-05-09 08:17:16 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 (selinux-policy 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/RHBA-2023:2483