public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: add new test which covers systemd-machined
@ 2026-09-11 13:20 Milos Malik
0 siblings, 0 replies; only message in thread
From: Milos Malik @ 2026-09-11 13:20 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : tests/selinux
Branch : pr775-checkpolicy-revdeps
Commit : de80db37fed2901ae5fb90db580359d080ed9d09
Author : Milos Malik <mmalik@redhat.com>
Date : 2022-12-02T08:41:50+00:00
Stats : +252/-0 in 5 file(s)
URL : https://src.fedoraproject.org/tests/selinux/c/de80db37fed2901ae5fb90db580359d080ed9d09?branch=pr775-checkpolicy-revdeps
Log:
add new test which covers systemd-machined
The use of systemd-machined and systemd-nspawn services revealed that
SELinux still prevents various actions they do. The TC reproduces the
situation.
In order to support the documented functionality of systemd-machine,
I believe that SELinux policy should allow these actions. The TC
looks for appropriate policy rules and file context patterns.
The TC covers BZ#1847545, BZ#1900869, BZ#1900888 and their duplicates.
---
diff --git a/selinux-policy/systemd-machined-and-similar/Makefile b/selinux-policy/systemd-machined-and-similar/Makefile
new file mode 100644
index 0000000..35c7767
--- /dev/null
+++ b/selinux-policy/systemd-machined-and-similar/Makefile
@@ -0,0 +1,71 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Makefile of /CoreOS/selinux-policy/Regression/systemd-machined-and-similar
+# Description: SELinux interferes with systemd-machined and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2022 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-machined-and-similar
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE testpolicy.cil
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+ ./runtest.sh
+
+build: $(BUILT_FILES)
+ chmod a+x runtest.sh
+ chcon -t bin_t runtest.sh
+
+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-machined and related programs" >> $(METADATA)
+ @echo "Type: Regression" >> $(METADATA)
+ @echo "TestTime: 10m" >> $(METADATA)
+ @echo "RunFor: selinux-policy" >> $(METADATA)
+ @echo "RunFor: systemd" >> $(METADATA)
+ @echo "Requires: audit libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools-console systemd-container /usr/sbin/service" >> $(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: 1847545" >> $(METADATA) # Fedora 32
+ @echo "Bug: 1900869" >> $(METADATA) # Fedora 33
+ @echo "Bug: 1900888" >> $(METADATA) # Fedora 35
+
+ rhts-lint $(METADATA)
+
diff --git a/selinux-policy/systemd-machined-and-similar/PURPOSE b/selinux-policy/systemd-machined-and-similar/PURPOSE
new file mode 100644
index 0000000..1734b44
--- /dev/null
+++ b/selinux-policy/systemd-machined-and-similar/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/systemd-machined-and-similar
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with systemd-machined and related programs.
+
diff --git a/selinux-policy/systemd-machined-and-similar/main.fmf b/selinux-policy/systemd-machined-and-similar/main.fmf
new file mode 100644
index 0000000..dc0ec37
--- /dev/null
+++ b/selinux-policy/systemd-machined-and-similar/main.fmf
@@ -0,0 +1,41 @@
+summary: SELinux interferes with systemd-machined and related programs
+description: |+
+ SELinux interferes with systemd-machined and related programs.
+
+contact: Milos Malik <mmalik@redhat.com>
+component:
+ - selinux-policy
+ - systemd
+require:
+ - library(selinux-policy/common)
+recommend:
+ - audit
+ - libselinux
+ - libselinux-utils
+ - policycoreutils
+ - selinux-policy
+ - selinux-policy-targeted
+ - setools-console
+ - systemd-container
+ - /usr/sbin/service
+environment:
+ AVC_ERROR: +no_avc_check
+duration: 10m
+enabled: true
+tag:
+ - NoRHEL4
+ - NoRHEL5
+ - NoRHEL6
+ - NoRHEL7
+ - targeted
+link:
+ - verifies: https://bugzilla.redhat.com/show_bug.cgi?id=1847545
+ - verifies: https://bugzilla.redhat.com/show_bug.cgi?id=1900869
+ - verifies: https://bugzilla.redhat.com/show_bug.cgi?id=1900888
+adjust:
+ - enabled: false
+ when: distro == rhel-4, rhel-5, rhel-6, rhel-7, rhel-alt-7
+ because: the systemd-machined program is not available there
+extra-summary: /CoreOS/selinux-policy/Regression/systemd-machined-and-similar
+extra-task: /CoreOS/selinux-policy/Regression/systemd-machined-and-similar
+extra-nitrate: TC#0614355
diff --git a/selinux-policy/systemd-machined-and-similar/runtest.sh b/selinux-policy/systemd-machined-and-similar/runtest.sh
new file mode 100755
index 0000000..9063972
--- /dev/null
+++ b/selinux-policy/systemd-machined-and-similar/runtest.sh
@@ -0,0 +1,124 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# runtest.sh of /CoreOS/selinux-policy/Regression/systemd-machined-and-similar
+# Description: SELinux interferes with systemd-machined and related programs
+# Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2022 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"
+FILE_PATH="/usr/lib/systemd/systemd-machined"
+FILE_CONTEXT="systemd_machined_exec_t"
+SERVICE_PACKAGE="systemd-container"
+SERVICE_NAME="systemd-machined"
+PROCESS_NAME="systemd-machined"
+PROCESS_CONTEXT="systemd_machined_t"
+
+rlJournalStart
+ if [ ! -f ${FILE_PATH} ] ; then
+ rlLog "The required program is not installed. Quitting..."
+ rlJournalEnd
+ exit 0
+ fi
+
+ rlPhaseStartSetup
+ rlRun "rlImport 'selinux-policy/common'"
+ rlSESatisfyRequires
+ rlAssertRpm ${PACKAGE}
+ rlAssertRpm ${PACKAGE}-targeted
+ rlAssertRpm ${SERVICE_PACKAGE}
+
+ rlServiceStop ${SERVICE_NAME}
+
+ rlSESetEnforce
+ rlSEStatus
+ rlSESetTimestamp
+ sleep 2
+ rlPhaseEnd
+
+ rlPhaseStartTest "SELinux contexts and rules"
+ rlSEMatchPathCon "${FILE_PATH}" "${FILE_CONTEXT}"
+ SOURCE_TYPE="init_t" # systemd runs the process
+ rlSESearchRule "allow ${SOURCE_TYPE} ${FILE_CONTEXT} : file { getattr open read execute } $BOOLEANS"
+ rlSESearchRule "allow ${SOURCE_TYPE} ${PROCESS_CONTEXT} : process { transition } $BOOLEANS"
+ rlSESearchRule "type_transition ${SOURCE_TYPE} ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} $BOOLEANS"
+ rlPhaseEnd
+
+ rlPhaseStartTest "bz#1847545"
+ rlSESearchRule "allow systemd_machined_t unconfined_service_t : dir { search } [ ]"
+ rlPhaseEnd
+
+ rlPhaseStartTest "bz#1900869 + bz#1900888"
+ rlSESearchRule "allow system_dbusd_t devpts_t : chr_file { read write } [ ]"
+ rlSESearchRule "allow systemd_machined_t devpts_t : chr_file { open read write ioctl } [ ]"
+ rlSESearchRule "allow systemd_machined_t systemd_machined_t : cap_userns { sys_ptrace sys_admin setgid setuid } [ ]"
+ rlSESearchRule "allow systemd_machined_t tmpfs_t : lnk_file { getattr read } [ ]"
+ rlSESearchRule "allow systemd_machined_t tmpfs_t : sock_file { write } [ ]"
+ rlSESearchRule "allow systemd_machined_t unconfined_service_t : dir { search } [ ]"
+ rlSESearchRule "allow systemd_machined_t unconfined_service_t : file { getattr open read ioctl } [ ]"
+ rlSESearchRule "allow systemd_machined_t unconfined_service_t : lnk_file { getattr read } [ ]"
+ rlSESearchRule "allow systemd_machined_t unconfined_service_t : unix_stream_socket { connectto } [ ]"
+ rlPhaseEnd
+
+ rlPhaseStartTest "real scenario -- standalone service"
+ if ! rlSEDefined ${PROCESS_CONTEXT} ; then
+ PROCESS_CONTEXT="unconfined_service_t"
+ fi
+ rlSEService - ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "start status" 1
+ rlRun "restorecon -Rv /run /var -e /var/ARTIFACTS" 0-255
+ rlSEService - ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "restart status stop status" 1
+ rlPhaseEnd
+
+ rlPhaseStartTest "real scenario -- bz#1900869 + bz#1900888"
+ rlRun "mkdir -pZ /var/lib/machines/test"
+ rlRun "dnf -y --installroot=/var/lib/machines/test/ install dhcp-client dnf filesystem glibc glibc-langpack-en glibc-langpack-de iproute iputils less passwd systemd vim-minimal"
+ rlRun "du -sh /var/lib/machines/test"
+ # TODO: remove next 2 lines once the BZs are fixed
+ rlRun "semodule -i testpolicy.cil"
+ rlRun "semodule -lfull | grep testpolicy"
+ rlRun "systemctl start systemd-nspawn@test"
+ rlRun "systemctl status systemd-nspawn@test"
+ rlRun "ps -efZ | grep -e ${PROCESS_CONTEXT} -e unconfined_service_t"
+ rlRun "machinectl list"
+ rlRun "machinectl status test"
+ rlWatchdog "machinectl login test" 20
+ rlRun "machinectl terminate test"
+ rlRun "systemctl stop systemd-nspawn@test"
+ # TODO: remove next 2 lines once the BZs are fixed
+ rlRun "semodule -r testpolicy"
+ rlRun "semodule -lfull | grep testpolicy" 1
+ rlRun "rm -rf /var/lib/machines/test"
+ rlPhaseEnd
+
+ rlPhaseStartCleanup
+ sleep 2
+ rlSECheckAVC
+
+ rlServiceRestore ${SERVICE_NAME}
+ rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+
diff --git a/selinux-policy/systemd-machined-and-similar/testpolicy.cil b/selinux-policy/systemd-machined-and-similar/testpolicy.cil
new file mode 100644
index 0000000..9fa2ced
--- /dev/null
+++ b/selinux-policy/systemd-machined-and-similar/testpolicy.cil
@@ -0,0 +1,11 @@
+( allow systemd_machined_t unconfined_service_t ( dir ( search )))
+( allow systemd_machined_t unconfined_service_t ( file ( getattr open read ioctl )))
+( allow systemd_machined_t unconfined_service_t ( lnk_file ( getattr read )))
+( allow systemd_machined_t systemd_machined_t ( cap_userns ( sys_ptrace sys_admin setgid setuid )))
+( allow systemd_machined_t tmpfs_t ( lnk_file ( getattr read )))
+( allow systemd_machined_t devpts_t ( chr_file ( open read write ioctl )))
+( allow systemd_machined_t tmpfs_t ( sock_file ( write )))
+( allow system_dbusd_t devpts_t ( chr_file ( read write )))
+( allow systemd_machined_t unconfined_service_t ( unix_stream_socket ( connectto )))
+( allow systemd_machined_t systemd_unit_file_t ( service ( stop )))
+
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-11 13:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 13:20 [tests/selinux] pr775-checkpolicy-revdeps: add new test which covers systemd-machined Milos Malik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox