public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: add the policykit test to upstream repo
@ 2026-09-11 13:19 Milos Malik
  0 siblings, 0 replies; only message in thread
From: Milos Malik @ 2026-09-11 13:19 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : fa8b441345d26d7d01a3c74c3ed1484df9abf489
            Author : Milos Malik <mmalik@redhat.com>
            Date   : 2021-05-20T10:21:49+00:00
            Stats  : +277/-0 in 4 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/fa8b441345d26d7d01a3c74c3ed1484df9abf489?branch=pr775-checkpolicy-revdeps

            Log:
            add the policykit test to upstream repo

The polkit component is used in various versions of RHEL and Fedora,
so it makes sense to run this TC in upstream testing too.
There are no changes in the TC functionality.
Moving the downstream TC to upstream repository.

---
diff --git a/selinux-policy/policykit-general/Makefile b/selinux-policy/policykit-general/Makefile
new file mode 100644
index 0000000..0309190
--- /dev/null
+++ b/selinux-policy/policykit-general/Makefile
@@ -0,0 +1,77 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/policykit-general
+#   Description: Test for BZ#962791 (SELinux is preventing /usr/lib/polkit-1/polkitd)
+#   Author: Michal Trunecka <mtruneck@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2013 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/policykit-general
+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:           Michal Trunecka <mtruneck@redhat.com>" > $(METADATA)
+	@echo "Name:            $(TEST)" >> $(METADATA)
+	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)
+	@echo "Path:            $(TEST_DIR)" >> $(METADATA)
+	@echo "Description:     Test for BZ#962791 (SELinux is preventing /usr/lib/polkit-1/polkitd)" >> $(METADATA)
+	@echo "Type:            Regression" >> $(METADATA)
+	@echo "TestTime:        20m" >> $(METADATA)
+	@echo "RunFor:          selinux-policy" >> $(METADATA)
+	@echo "RunFor:          polkit" >> $(METADATA)
+	@echo "Requires:        audit selinux-policy polkit glib2 libselinux libselinux-utils policycoreutils setools-console psmisc shadow-utils expect openssh-clients" >> $(METADATA)
+	@echo "RhtsRequires:    library(selinux-policy/common)" >> $(METADATA)
+	@echo "Priority:        Normal" >> $(METADATA)
+	@echo "License:         GPLv2" >> $(METADATA)
+	@echo "Confidential:    no" >> $(METADATA)
+	@echo "Destructive:     no" >> $(METADATA)
+	@echo "Environment:     AVC_ERROR=+no_avc_check" >> $(METADATA)
+	@echo "Releases:        -RHEL4 -RHEL5" >> $(METADATA)
+	@echo "Bug:             960669" >> $(METADATA) # RHEL-7
+	@echo "Bug:             962791" >> $(METADATA) # RHEL-7
+	@echo "Bug:             965143" >> $(METADATA) # RHEL-7
+	@echo "Bug:             1003799" >> $(METADATA) # RHEL-6
+	@echo "Bug:             1301561" >> $(METADATA) # RHEL-6
+	@echo "Bug:             1364513" >> $(METADATA) # RHEL-7
+	@echo "Bug:             1574389" >> $(METADATA) # RHEL-7
+	@echo "Bug:             1583082" >> $(METADATA) # RHEL-7
+	@echo "Bug:             1727902" >> $(METADATA) # RHEL-8
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/policykit-general/PURPOSE b/selinux-policy/policykit-general/PURPOSE
new file mode 100644
index 0000000..98cfd05
--- /dev/null
+++ b/selinux-policy/policykit-general/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/policykit-general
+Author: Michal Trunecka <mtruneck@redhat.com>
+
+SELinux interferes with polkitd and related programs.
+

diff --git a/selinux-policy/policykit-general/runtest.sh b/selinux-policy/policykit-general/runtest.sh
new file mode 100755
index 0000000..867f2de
--- /dev/null
+++ b/selinux-policy/policykit-general/runtest.sh
@@ -0,0 +1,175 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/selinux-policy/Regression/policykit-general
+#   Description: Test for BZ#962791 (SELinux is preventing /usr/lib/polkit-1/polkitd)
+#   Author: Michal Trunecka <mtruneck@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2013 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/bin/rhts-environment.sh || exit 1
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="selinux-policy"
+ROOT_PASSWORD="redhat"
+SERVICE_NAME="polkit"
+SERVICE_PACKAGE="polkit"
+PROCESS_NAME="polkitd"
+PROCESS_CONTEXT="policykit_t"
+if rlIsRHEL 6 7 ; then
+    ALLOWED_USERS="staff_u user_u xguest_u sysadm_u unconfined_u"
+else
+    ALLOWED_USERS="staff_u user_u guest_u xguest_u sysadm_u unconfined_u"
+fi
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlAssertRpm ${SERVICE_PACKAGE}
+
+        rlServiceStop ${SERVICE_NAME}
+        rlFileBackup /etc/shadow
+
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#960669 + bz#962791 + bz#965143"
+        if rlIsRHEL 6 ; then
+            rlSEMatchPathCon "/usr/libexec/polkit-1/polkitd" "policykit_exec_t"
+        else
+            rlSEMatchPathCon "/usr/lib/polkit-1/polkitd" "policykit_exec_t"
+            rlSESearchRule "allow policykit_t cgroup_t : dir { open read getattr lock search ioctl }"
+        fi
+        rlSESearchRule "allow initrc_t policykit_exec_t : file { getattr open read execute }"
+        rlSESearchRule "type_transition initrc_t policykit_exec_t : process policykit_t"
+        rlSESearchRule "allow initrc_t policykit_t : process { transition }"
+        rlSESearchRule "allow system_dbusd_t policykit_exec_t : file { getattr open read execute }"
+        rlSESearchRule "type_transition system_dbusd_t policykit_exec_t : process policykit_t"
+        rlSESearchRule "allow system_dbusd_t policykit_t : process { transition }"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1003799"
+        if rlIsRHEL 6 ; then
+            rlSEMatchPathCon "/usr/libexec/polkit-1/polkitd" "policykit_exec_t"
+        else
+            rlSEMatchPathCon "/usr/lib/polkit-1/polkitd" "policykit_exec_t"
+        fi
+        rlSEMatchPathCon "/var/lib/sss" "sssd_var_lib_t"
+        rlSEMatchPathCon "/var/lib/sss/mc" "sssd_public_t"
+        rlSEMatchPathCon "/var/lib/sss/mc/passwd" "sssd_public_t"
+        rlSESearchRule "allow policykit_t sssd_var_lib_t : dir { getattr open search }"
+        rlSESearchRule "allow policykit_t sssd_public_t : dir { getattr open search }"
+        rlSESearchRule "allow policykit_t sssd_public_t : file { getattr open read }"
+        rlSESearchRule "allow policykit_t sssd_var_lib_t : sock_file { getattr open write }"
+        rlSESearchRule "allow policykit_t sssd_t : unix_stream_socket { connectto }"
+    rlPhaseEnd
+
+    if ! rlIsRHEL 5 ; then
+    rlPhaseStartTest "bz#1301561"
+        rlSEMatchPathCon "/usr/libexec/polkit-1/polkitd" "policykit_exec_t"
+        rlSESearchRule "allow policykit_t fs_t : filesystem { getattr }"
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario -- DBus service"
+        rlRun "killall polkitd" 0,1
+        sleep 1
+        DESTINATION="org.freedesktop.PolicyKit1"
+        rlRun "gdbus introspect --system --object-path / --dest ${DESTINATION} >& /dev/null"
+        sleep 1
+        rlRun "ps -efZ | grep -v grep | grep ${PROCESS_NAME}"
+        rlRun "ps -efZ | grep -v grep | grep \"${PROCESS_CONTEXT}.*${PROCESS_NAME}\""
+    rlPhaseEnd
+    fi
+
+    if ! rlIsRHEL 5 6 ; then
+    rlPhaseStartTest "bz#1364513"
+        rlSESearchRule "allow dhcpc_t policykit_t : dbus { send_msg }"
+        rlSESearchRule "allow policykit_t dhcpc_t : dbus { send_msg }"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1574389 + bz#1583082"
+        rlSEMatchPathCon "/usr/bin/pkla-check-authorization" "policykit_auth_exec_t"
+        rlSESearchRule "allow policykit_t policykit_auth_exec_t : file { map } [ ]"
+    rlPhaseEnd
+    fi
+
+    if ! rlIsRHEL 5 6 7 ; then
+    rlPhaseStartTest "bz#1727902"
+        rlSEMatchPathCon "/run/dbus" "system_dbusd_var_run_t"
+        rlSEMatchPathCon "/run/dbus/system_bus_socket" "system_dbusd_var_run_t"
+        rlSESearchRule "allow guest_t system_dbusd_var_run_t : dir { search } [ ]"
+        rlSESearchRule "allow guest_t system_dbusd_var_run_t : sock_file { write } [ ]"
+        rlSESearchRule "allow guest_t system_dbusd_t : unix_stream_socket { connectto } [ ]"
+        rlSESearchRule "allow guest_t policykit_t : dbus { send_msg } [ ]"
+        rlSESearchRule "allow policykit_t guest_t : dbus { send_msg } [ ]"
+        rlSESearchRule "allow guest_t system_dbusd_t : dbus { send_msg } [ ]"
+        rlSESearchRule "allow system_dbusd_t guest_t : dbus { send_msg } [ ]"
+    rlPhaseEnd
+    fi
+
+    if ! rlIsRHEL 5 6 ; then
+    rlPhaseStartTest "real scenario -- standalone service"
+        rlRun "echo ${ROOT_PASSWORD} | passwd --stdin root"
+        if ! rlSEDefined ${PROCESS_CONTEXT} ; then
+            if rlIsRHEL 5 6 ; then
+                PROCESS_CONTEXT="initrc_t"
+            else
+                PROCESS_CONTEXT="unconfined_service_t"
+            fi
+        fi
+        rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "start status" 1
+        rlRun "restorecon -Rv /run /var"
+        rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "restart status stop status" 1
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario -- confined users"
+        rlRun "setsebool ssh_sysadm_login on"
+        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 "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost pkaction"
+            rlRun "userdel -rfZ ${USER_NAME}"
+        done
+        rlRun "setsebool ssh_sysadm_login off"
+    rlPhaseEnd
+    fi
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+
+        rlFileRestore
+        rlServiceRestore ${SERVICE_NAME}
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+

diff --git a/selinux-policy/policykit-general/ssh.exp b/selinux-policy/policykit-general/ssh.exp
new file mode 100644
index 0000000..1244013
--- /dev/null
+++ b/selinux-policy/policykit-general/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 ; sleep 5"
+expect {
+  -nocase "yes/no" { send -- "yes\r" ; exp_continue }
+  -nocase "password" { send -- "$password\r" }
+}
+log_user 1
+# send -- "\r"
+expect eof
+

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-11 13:19 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:19 [tests/selinux] pr775-checkpolicy-revdeps: add the policykit test to upstream repo Milos Malik

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