public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: add new test which covers various virtualization daemons
@ 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 : d25c4ccdfca94f69b453cfba7b14c44ddbfa2941
            Author : Milos Malik <mmalik@redhat.com>
            Date   : 2023-04-22T11:20:49+00:00
            Stats  : +242/-0 in 4 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/d25c4ccdfca94f69b453cfba7b14c44ddbfa2941?branch=pr775-checkpolicy-revdeps

            Log:
            add new test which covers various virtualization daemons

Recently, the libvirt daemon was restructured into several smaller
daemons. Each of them will be confined by SELinux. This test
case should test if these smaller daemons cooperate with SELinux
policy and looks for any SELinux denials.

This TC runs only basic scenarios like start, restart, stop on
various virtualization services. It also tests SELinux contexts of
those virtualization processes and their file context patterns.

---
diff --git a/selinux-policy/virtualization-daemons/Makefile b/selinux-policy/virtualization-daemons/Makefile
new file mode 100644
index 0000000..48867c8
--- /dev/null
+++ b/selinux-policy/virtualization-daemons/Makefile
@@ -0,0 +1,68 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/virtualization-daemons
+#   Description: Various virtualization daemons are confined by SELinux
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2020 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/virtualization-daemons
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE
+
+.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:     Various virtualization daemons are confined by SELinux" >> $(METADATA)
+	@echo "Type:            Regression" >> $(METADATA)
+	@echo "TestTime:        15m" >> $(METADATA)
+	@echo "RunFor:          libvirt" >> $(METADATA)
+	@echo "RunFor:          selinux-policy" >> $(METADATA)
+	@echo "Requires:        audit libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools-console initscripts libvirt-daemon libvirt-client libvirt-daemon-driver-interface libvirt-daemon-driver-libxl libvirt-daemon-driver-lxc libvirt-daemon-driver-network libvirt-daemon-driver-nodedev libvirt-daemon-driver-nwfilter libvirt-daemon-driver-qemu libvirt-daemon-driver-secret libvirt-daemon-driver-storage-core libvirt-daemon-driver-vbox">> $(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)
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/virtualization-daemons/PURPOSE b/selinux-policy/virtualization-daemons/PURPOSE
new file mode 100644
index 0000000..e3776a9
--- /dev/null
+++ b/selinux-policy/virtualization-daemons/PURPOSE
@@ -0,0 +1,6 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/virtualization-daemons
+Author: Milos Malik <mmalik@redhat.com>
+
+Various virtualization daemons are confined by SELinux. Do they work
+as expected?
+

diff --git a/selinux-policy/virtualization-daemons/main.fmf b/selinux-policy/virtualization-daemons/main.fmf
new file mode 100644
index 0000000..acad013
--- /dev/null
+++ b/selinux-policy/virtualization-daemons/main.fmf
@@ -0,0 +1,48 @@
+summary: SELinux interferes with various virtualization daemons.
+description: |+
+    SELinux interferes with various virtualization daemons.
+
+contact: Milos Malik <mmalik@redhat.com>
+component:
+  - selinux-policy
+test: ./runtest.sh
+framework: beakerlib
+require:
+  - library(selinux-policy/common)
+recommend:
+  - audit
+  - libselinux
+  - libselinux-utils
+  - policycoreutils
+  - selinux-policy
+  - selinux-policy-targeted
+  - setools-console
+  - /usr/sbin/service
+  - libvirt-client
+  - libvirt-daemon
+  - libvirt-daemon-driver-interface
+  - libvirt-daemon-driver-libxl
+  - libvirt-daemon-driver-lxc
+  - libvirt-daemon-driver-network
+  - libvirt-daemon-driver-nodedev
+  - libvirt-daemon-driver-nwfilter
+  - libvirt-daemon-driver-qemu
+  - libvirt-daemon-driver-secret
+  - libvirt-daemon-driver-storage-core
+  - libvirt-daemon-driver-vbox
+environment:
+    AVC_ERROR: +no_avc_check
+duration: 15m
+enabled: true
+tag:
+  - NoRHEL4
+  - NoRHEL5
+  - NoRHEL6
+  - NoRHEL7
+  - NoRHEL8
+  - targeted
+adjust:
+-  enabled: false
+   when: distro < rhel-9
+   because: the virtualization daemons are not available there
+

diff --git a/selinux-policy/virtualization-daemons/runtest.sh b/selinux-policy/virtualization-daemons/runtest.sh
new file mode 100755
index 0000000..9df58e5
--- /dev/null
+++ b/selinux-policy/virtualization-daemons/runtest.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/selinux-policy/Regression/virtualization-daemons
+#   Description: Various virtualization daemons are confined by SELinux
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2020 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"
+ROOT_PASSWORD="redhat"
+SERVICE_NAMES="libvirtd virtinterfaced virtlockd virtlogd virtlxcd virtnetworkd virtnodedevd virtnwfilterd virtproxyd virtqemud virtsecretd virtstoraged virtvboxd virtxend"
+ALL_TUPLES="libvirtd:libvirtd:virtd_t \
+            virtinterfaced:virtinterfaced:virtd_t \
+            virtlockd:virtlockd:virtlogd_t \
+            virtlogd:virtlogd:virtlogd_t \
+            virtlxcd:virtlxcd:virtd_t \
+            virtnetworkd:virtnetworkd:virtd_t \
+            virtnodedevd:virtnodedevd:virtd_t \
+            virtnwfilterd:virtnwfilterd:virtd_t \
+            virtproxyd:virtproxyd:virtd_t \
+            virtqemud:virtqemud:virtd_t \
+            virtsecretd:virtsecretd:virtd_t \
+            virtstoraged:virtstoraged:virtd_t \
+            virtvboxd:virtvboxd:virtd_t"
+#            virtxend:virtxend:virtd_t
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlRun "rpm -qa libvirt\*"
+
+        rlRun "sed -i 's/^.*task.*never.*$//' /etc/audit/rules.d/audit.rules"
+        rlRun "echo '-w /etc/shadow -p w' >> /etc/audit/rules.d/audit.rules"
+        rlRun "service auditd restart"
+
+        rlServiceStop ${SERVICE_NAMES}
+        rlFileBackup /etc/shadow
+
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "SELinux contexts and rules"
+        rlSEMatchPathCon "/usr/sbin/virtinterfaced" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtlxcd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtnetworkd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtnodedevd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtnwfilterd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtproxyd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtqemud" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtsecretd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtstoraged" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtvboxd" "virtd_exec_t"
+        rlSEMatchPathCon "/usr/sbin/virtxend" "virtd_exec_t"
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario -- standalone service"
+        rlRun "echo ${ROOT_PASSWORD} | passwd --stdin root"
+        # start all the services
+        for TUPLE in ${ALL_TUPLES} ; do
+            SERVICE_NAME=`echo ${TUPLE} | cut -d : -f 1`
+            PROCESS_NAME=`echo ${TUPLE} | cut -d : -f 2`
+            PROCESS_CONTEXT=`echo ${TUPLE} | cut -d : -f 3`
+            rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "start status" 1
+        done
+        rlRun "restorecon -Rv /etc /run /var"
+        # restart all the services
+        for TUPLE in ${ALL_TUPLES} ; do
+            SERVICE_NAME=`echo ${TUPLE} | cut -d : -f 1`
+            PROCESS_NAME=`echo ${TUPLE} | cut -d : -f 2`
+            PROCESS_CONTEXT=`echo ${TUPLE} | cut -d : -f 3`
+            rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "restart status" 1
+        done
+        # stop all the services
+        for TUPLE in ${ALL_TUPLES} ; do
+            SERVICE_NAME=`echo ${TUPLE} | cut -d : -f 1`
+            PROCESS_NAME=`echo ${TUPLE} | cut -d : -f 2`
+            PROCESS_CONTEXT=`echo ${TUPLE} | cut -d : -f 3`
+            rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "stop status" 1
+        done
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+
+        rlFileRestore
+        rlServiceRestore ${SERVICE_NAMES}
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+

^ 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 various virtualization daemons Milos Malik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox