r/Gentoo•
useless_it

Wrong context with KDE systemdBoot and systemd+SELinux profile

Tip

Hi!

I've been toying around with a desktop/plasma/systemd profile with features hardened and selinux enabled. SELinux is in permissive mode for the time being.

Using the systemBoot feature (to be default in plasma 5.25) with SELINUXTYPE=mcs (needed for podman) the user session has the wrong context system_u:system_r:initrc_t instead of staff_u:staff_r:staff_t, so the role transition to sysadm_r is not allowed (no sudo if you follow [1]). Reverting to the old startup scripts [2] resolves the issue.

Upon searching for a solution to use KDE with systemdBoot, I came across this RedHat bugzilla entry [3] where it's stated that some changes are needed in /etc/pam.d/systemd-user:

# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so nottys open

Now the proceses started in the session have the right context. A truncated output of ps uxZ --forest shows:

staff_u:staff_r:staff_t:s0-s0:c0.c1023 username 7982 0.0  0.2 198848 40360 tty8    Ssl+ 09:11   0:00 /usr/bin/startplasma-wayland
staff_u:staff_r:staff_t:s0-s0:c0.c1023 username 7981 0.0  0.2 356092 44376 ?       Sl   09:11   0:00 /usr/bin/kwalletd5 --pam-login 7 8
staff_u:staff_r:staff_gkeyringd_t:s0-s0:c0.c1023 username 7974 0.0  0.0 245096 10076 ? Sl 09:11   0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
staff_u:staff_r:staff_systemd_t:s0-s0:c0.c1023 username 7962 0.0  0.1 28432 21196 ? Ss  09:11   0:00 /lib/systemd/systemd --user

and everything else underneath /lib/systemd/systemd --user (so KDE startup using systemd is working).

Just a small tip. Feel free to correct anything wrong in what I've posted.

[1] SELinux/Installation

[2] Plasma and the systemd boot

[3] systemd user sessions running with the wrong context. #7 comment

EDIT: Grammar and typos.

Posted Jul 30, 2022, 12:36 PM UTC · edited

30

No comments yet

Nobody commented on this post, or the comments weren't captured.