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

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : 1cdc4059919ddee7a577ce3e3f02e72bf5a9aa18
            Author : Milos Malik <mmalik@redhat.com>
            Date   : 2021-03-04T11:08:52+00:00
            Stats  : +223/-0 in 5 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/1cdc4059919ddee7a577ce3e3f02e72bf5a9aa18?branch=pr775-checkpolicy-revdeps

            Log:
            add the journalctl test to upstream repo

The journalctl command is frequently used by various users on Fedora
and RHEL, 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 repo.

---
diff --git a/selinux-policy/journalctl-and-similar/Makefile b/selinux-policy/journalctl-and-similar/Makefile
new file mode 100644
index 0000000..255fcdf
--- /dev/null
+++ b/selinux-policy/journalctl-and-similar/Makefile
@@ -0,0 +1,72 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/journalctl-and-similar
+#   Description: SELinux interferes with journalctl executed by various users
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2012 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/journalctl-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 journalctl executed by various users" >> $(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 expect openssh-clients systemd 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" >> $(METADATA)
+	@echo "Bug:             1176713" >> $(METADATA) # Fedora 21
+	@echo "Bug:             1288255" >> $(METADATA) # RHEL-7
+	@echo "Bug:             1685689" >> $(METADATA) # RHEL-8
+	@echo "Bug:             1825894" >> $(METADATA) # RHEL-8
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/journalctl-and-similar/PURPOSE b/selinux-policy/journalctl-and-similar/PURPOSE
new file mode 100644
index 0000000..806f597
--- /dev/null
+++ b/selinux-policy/journalctl-and-similar/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/journalctl-and-similar
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with journalctl executed by various users.
+

diff --git a/selinux-policy/journalctl-and-similar/main.fmf b/selinux-policy/journalctl-and-similar/main.fmf
new file mode 100644
index 0000000..cf8103f
--- /dev/null
+++ b/selinux-policy/journalctl-and-similar/main.fmf
@@ -0,0 +1,2 @@
+path: /selinux-policy/journalctl-and-similar
+tier: 2

diff --git a/selinux-policy/journalctl-and-similar/runtest.sh b/selinux-policy/journalctl-and-similar/runtest.sh
new file mode 100755
index 0000000..7a53398
--- /dev/null
+++ b/selinux-policy/journalctl-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/journalctl-and-similar
+#   Description: SELinux interferes with journalctl executed by various users
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2012 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"
+FILE_PATH="/usr/bin/journalctl"
+FILE_CONTEXT="journalctl_exec_t"
+SERVICE_PACKAGE="systemd"
+SERVICE_NAME=""
+PROCESS_NAME="journalctl"
+PROCESS_CONTEXT="journalctl_t"
+ALLOWED_USERS=${ALLOWED_USERS:-"staff_u user_u sysadm_u unconfined_u"}
+DENIED_USERS=${DENIED_USERS:-"guest_u xguest_u"}
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlAssertRpm ${SERVICE_PACKAGE}
+
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1176713"
+        rlSEMatchPathCon "/usr/bin/journalctl" "journalctl_exec_t"
+        rlSEMatchPathCon "/dev/urandom" "urandom_device_t"
+        rlSESearchRule "allow journalctl_t urandom_device_t : chr_file { getattr open read } [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1288255"
+        rlSEMatchPathCon "${FILE_PATH}" "${FILE_CONTEXT}"
+        rlSESearchRule "allow staff_t ${FILE_CONTEXT} : file { getattr open read execute } [ ]"
+        rlSESearchRule "allow sysadm_t ${FILE_CONTEXT} : file { getattr open read execute } [ ]"
+        rlSESearchRule "allow user_t ${FILE_CONTEXT} : file { getattr open read execute } [ ]"
+        rlSESearchRule "allow staff_t ${PROCESS_CONTEXT} : process { transition } [ ]"
+        rlSESearchRule "allow sysadm_t ${PROCESS_CONTEXT} : process { transition } [ ]"
+        rlSESearchRule "allow user_t ${PROCESS_CONTEXT} : process { transition } [ ]"
+        rlSESearchRule "type_transition staff_t ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} [ ]"
+        rlSESearchRule "type_transition sysadm_t ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} [ ]"
+        rlSESearchRule "type_transition user_t ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1685689"
+        rlSEMatchPathCon "/usr/bin/journalctl" "journalctl_exec_t"
+        rlSEMatchPathCon "/run/log/journal/bfd37efc55db4f44a0f350821db2b810/system.journal" "syslogd_var_run_t"
+        if rlIsRHEL 7 ; then
+            # the domain_can_mmap_files boolean is enabled by default
+            rlSESearchRule "allow journalctl_t syslogd_var_run_t : file { map }"
+        else
+            # the domain_can_mmap_files boolean is disabled by default
+            rlSESearchRule "allow journalctl_t syslogd_var_run_t : file { map } [ ]"
+        fi
+    rlPhaseEnd
+
+    rlPhaseStartTest "bz#1825894"
+        rlSEMatchPathCon "/usr/bin/journalctl" "journalctl_exec_t"
+        rlSESearchRule "allow journalctl_t journalctl_t : process { setrlimit } [ ]"
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario -- confined users"
+        rlFileBackup /etc/ssh/sshd_config
+        rlRun "sed -i 's/^.*PermitRootLogin.*$/PermitRootLogin yes/' /etc/ssh/sshd_config"
+        rlRun "sed -i 's/^.*PasswordAuthentication.*$/PasswordAuthentication yes/' /etc/ssh/sshd_config"
+        rlRun "service sshd restart"
+
+        rlRun "setsebool ssh_sysadm_login on"
+        rlLog "configuration says not to test SELinux users: ${DENIED_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 "usermod -G systemd-journal ${USER_NAME}"
+            rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost journalctl -n 10 --no-pager --user"
+            rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost journalctl -n 10 --no-pager --system"
+            rlRun "userdel -rfZ ${USER_NAME}"
+            sleep 10
+        done
+        rlRun "setsebool ssh_sysadm_login off"
+
+        rlFileRestore
+        rlRun "service sshd restart"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+

diff --git a/selinux-policy/journalctl-and-similar/ssh.exp b/selinux-policy/journalctl-and-similar/ssh.exp
new file mode 100755
index 0000000..58c9647
--- /dev/null
+++ b/selinux-policy/journalctl-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
+

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

only message in thread, other threads:[~2026-09-11 13:18 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:18 [tests/selinux] pr775-checkpolicy-revdeps: add the journalctl 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