public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Milos Malik <mmalik@redhat.com>
To: git-commits@fedoraproject.org
Subject: [tests/selinux] pr775-checkpolicy-revdeps: add a basic test which covers systemd-tmpfiles
Date: Fri, 11 Sep 2026 13:21:46 GMT [thread overview]
Message-ID: <178913290642.1.10067114986068236241.tests-selinux-ba1ba298ba92@fedoraproject.org> (raw)
A new commit has been pushed.
Repo : tests/selinux
Branch : pr775-checkpolicy-revdeps
Commit : ba1ba298ba9205da7d06205ef126af2c87ce9068
Author : Milos Malik <mmalik@redhat.com>
Date : 2024-06-27T07:40:50+00:00
Stats : +225/-0 in 5 file(s)
URL : https://src.fedoraproject.org/tests/selinux/c/ba1ba298ba9205da7d06205ef126af2c87ce9068?branch=pr775-checkpolicy-revdeps
Log:
add a basic test which covers systemd-tmpfiles
A recently filed Jira issue revealed that SELinux prevents staff_u
users from executing the systemd-tmpfiles program (via the following
service: /usr/lib/systemd/user/systemd-tmpfiles-setup.service).
The TC reproduces the situation.
In order to support the systemd-tmpfiles-setup.service functions
for confined users, I believe that SELinux policy should allow
the access described above. The TC looks for appropriate policy
rules and file context patterns.
The TC covers RHEL-40374 and RHEL-44191.
---
diff --git a/selinux-policy/systemd-tmpfiles-and-similar/Makefile b/selinux-policy/systemd-tmpfiles-and-similar/Makefile
new file mode 100644
index 0000000..fd16134
--- /dev/null
+++ b/selinux-policy/systemd-tmpfiles-and-similar/Makefile
@@ -0,0 +1,69 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Makefile of /CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+# Description: SELinux interferes with systemd-tmpfiles and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2024 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE ssh.exp
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+ ./runtest.sh
+
+build: $(BUILT_FILES)
+ chmod a+x runtest.sh ssh.exp
+ chcon -t bin_t runtest.sh ssh.exp
+
+clean:
+ rm -f *~ $(BUILT_FILES)
+
+include /usr/share/rhts/lib/rhts-make.include
+
+$(METADATA): Makefile
+ @echo "Owner: Milos Malik <mmalik@redhat.com>" > $(METADATA)
+ @echo "Name: $(TEST)" >> $(METADATA)
+ @echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
+ @echo "Path: $(TEST_DIR)" >> $(METADATA)
+ @echo "Description: SELinux interferes with systemd-tmpfiles and related programs" >> $(METADATA)
+ @echo "Type: Regression" >> $(METADATA)
+ @echo "TestTime: 10m" >> $(METADATA)
+ @echo "RunFor: selinux-policy" >> $(METADATA)
+ @echo "Requires: audit expect libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools-console systemd /usr/sbin/service shadow-utils" >> $(METADATA)
+ @echo "RhtsRequires: library(selinux-policy/common)" >> $(METADATA)
+ @echo "Environment: AVC_ERROR=+no_avc_check" >> $(METADATA)
+ @echo "Priority: Normal" >> $(METADATA)
+ @echo "License: GPLv2" >> $(METADATA)
+ @echo "Confidential: no" >> $(METADATA)
+ @echo "Destructive: no" >> $(METADATA)
+ @echo "Releases: -RHEL4 -RHEL5 -RHEL6 -RHEL7" >> $(METADATA)
+ @echo "Bug: RHEL-40374" >> $(METADATA) # RHEL-9
+ @echo "Bug: RHEL-44191" >> $(METADATA) # RHEL-10
+
+ rhts-lint $(METADATA)
+
diff --git a/selinux-policy/systemd-tmpfiles-and-similar/PURPOSE b/selinux-policy/systemd-tmpfiles-and-similar/PURPOSE
new file mode 100644
index 0000000..6f0cf3c
--- /dev/null
+++ b/selinux-policy/systemd-tmpfiles-and-similar/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with systemd-tmpfiles and related programs.
+
diff --git a/selinux-policy/systemd-tmpfiles-and-similar/main.fmf b/selinux-policy/systemd-tmpfiles-and-similar/main.fmf
new file mode 100644
index 0000000..37bd8f2
--- /dev/null
+++ b/selinux-policy/systemd-tmpfiles-and-similar/main.fmf
@@ -0,0 +1,48 @@
+summary: SELinux interferes with systemd-tmpfiles and related programs
+description: |+
+ SELinux interferes with systemd-tmpfiles and related programs
+
+contact: Milos Malik <mmalik@redhat.com>
+component:
+ - selinux-policy
+test: ./runtest.sh
+framework: beakerlib
+require:
+ - library(selinux-policy/common)
+recommend:
+ - audit
+ - expect
+ - libselinux
+ - libselinux-utils
+ - policycoreutils
+ - selinux-policy
+ - selinux-policy-targeted
+ - setools-console
+ - systemd
+ - /usr/sbin/service
+ - shadow-utils
+environment:
+ AVC_ERROR: +no_avc_check
+duration: 10m
+enabled: true
+tag:
+ - NoRHEL4
+ - NoRHEL5
+ - NoRHEL6
+ - NoRHEL7
+ - Tier2
+ - Tier2se
+ - targeted
+ - NoRHIVOS
+tier: '2'
+link:
+ - verifies: https://issues.redhat.com/browse/RHEL-40374
+ - verifies: https://issues.redhat.com/browse/RHEL-44191
+adjust:
+ - enabled: false
+ when: distro == rhel-4, rhel-5, rhel-6, rhel-7
+ continue: false
+extra-summary: /CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+extra-task: /CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+extra-nitrate: TC#0617577
+id: 03d8e784-9026-46ef-a48b-0bbed63f7f95
diff --git a/selinux-policy/systemd-tmpfiles-and-similar/runtest.sh b/selinux-policy/systemd-tmpfiles-and-similar/runtest.sh
new file mode 100755
index 0000000..7f2e944
--- /dev/null
+++ b/selinux-policy/systemd-tmpfiles-and-similar/runtest.sh
@@ -0,0 +1,83 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# runtest.sh of /CoreOS/selinux-policy/Regression/systemd-tmpfiles-and-similar
+# Description: SELinux interferes with systemd-tmpfiles and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2024 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include Beaker environment
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="selinux-policy"
+SERVICE_PACKAGE="systemd"
+ALLOWED_USERS="staff_u sysadm_u unconfined_u"
+
+rlJournalStart
+ rlPhaseStartSetup
+ rlRun "rlImport 'selinux-policy/common'" 0,1
+ rlSESatisfyRequires
+ rlAssertRpm ${PACKAGE}
+ rlAssertRpm ${PACKAGE}-targeted
+ rlAssertRpm ${SERVICE_PACKAGE}
+
+ rlSEConfigureSSH
+
+ rlSESetEnforce
+ rlSEStatus
+ rlSESetTimestamp
+ sleep 2
+ rlPhaseEnd
+
+ rlPhaseStartTest "RHEL-40374 + RHEL-44191"
+ rlSEMatchPathCon "/usr/bin/systemd-tmpfiles" "systemd_tmpfiles_exec_t"
+ rlSESearchRule "allow staff_t systemd_tmpfiles_exec_t : file { getattr open read map execute execute_no_trans } [ ]"
+ rlRun "setsebool ssh_sysadm_login on"
+ CREATED_USERS=""
+ for SELINUX_USER in ${ALLOWED_USERS} ; do
+ USER_NAME="user${RANDOM}"
+ USER_SECRET="S3kr3t${RANDOM}"
+ rlRun "useradd -Z ${SELINUX_USER} ${USER_NAME}"
+ rlRun "echo ${USER_SECRET} | passwd --stdin ${USER_NAME}"
+ rlRun "restorecon -Rv /home/${USER_NAME}"
+ rlRun -s "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost systemctl --no-pager --user status systemd-tmpfiles-setup.service"
+ rlRun "grep -i failed $rlRun_LOG" 1
+ rm -f $rlRun_LOG
+ rlRun -s "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost systemctl --no-pager --user --failed"
+ rlRun "grep '0 loaded units listed' $rlRun_LOG"
+ rm -f $rlRun_LOG
+ CREATED_USERS="${USER_NAME} ${CREATED_USERS}"
+ done
+ rlRun "setsebool ssh_sysadm_login off"
+ for USER_NAME in ${CREATED_USERS} ; do
+ rlRun "userdel -rfZ ${USER_NAME}"
+ done
+ rlPhaseEnd
+
+ rlPhaseStartCleanup
+ sleep 2
+ rlSECheckAVC
+ rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+
diff --git a/selinux-policy/systemd-tmpfiles-and-similar/ssh.exp b/selinux-policy/systemd-tmpfiles-and-similar/ssh.exp
new file mode 100755
index 0000000..58c9647
--- /dev/null
+++ b/selinux-policy/systemd-tmpfiles-and-similar/ssh.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+# Expect script for SSH logging as $username to $hostname using $password and executing $command.
+# Usage:
+# ./ssh.exp username password hostname command
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set hostname [lrange $argv 2 2]
+set command [lrange $argv 3 10]
+set timeout 15
+# connect to remote host and execute given command
+log_user 1
+spawn ssh -t $username@$hostname $command
+expect {
+ -nocase "yes/no" { send -- "yes\r" ; exp_continue }
+ -nocase "password" { send -- "$password\r" }
+}
+log_user 1
+# send -- "\r"
+expect eof
+
reply other threads:[~2026-09-11 13:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178913290642.1.10067114986068236241.tests-selinux-ba1ba298ba92@fedoraproject.org \
--to=mmalik@redhat.com \
--cc=git-commits@fedoraproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox