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: test if `sudo dnf` works for confined administrators
Date: Fri, 11 Sep 2026 13:21:08 GMT	[thread overview]
Message-ID: <178913286820.1.10765176716910583149.tests-selinux-d5c1f98be652@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : d5c1f98be6527d07064a12161c000af2bc951a70
            Author : Milos Malik <mmalik@redhat.com>
            Date   : 2023-11-01T12:07:41+00:00
            Stats  : +218/-0 in 5 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/d5c1f98be6527d07064a12161c000af2bc951a70?branch=pr775-checkpolicy-revdeps

            Log:
            test if `sudo dnf` works for confined administrators

A recently filed customer report revealed that SELinux prevents the
confined administrator (derived from sysadm_u, having sysadm_r role)
from running the "sudo dnf update" command. The TC reproduces the
situation.

Because BZ#1910077 was not fixed on the sudo side, various commands
end up triggering SELinux denials and consequently, they need to be
fixed on the selinux-policy side. It is an unfortunate solution, but
a necessary one if we want to achieve a successful run of such commands.

The TC covers BZ#2233065 and RHEL-1679.

---
diff --git a/selinux-policy/sudo-and-dnf/Makefile b/selinux-policy/sudo-and-dnf/Makefile
new file mode 100644
index 0000000..d1cc3ca
--- /dev/null
+++ b/selinux-policy/sudo-and-dnf/Makefile
@@ -0,0 +1,69 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/selinux-policy/Regression/sudo-and-dnf
+#   Description: SELinux interferes with the dnf command executed via sudo
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2023 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/sudo-and-dnf
+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 the dnf command executed via sudo" >> $(METADATA)
+	@echo "Type:            Regression" >> $(METADATA)
+	@echo "TestTime:        10m" >> $(METADATA)
+	@echo "RunFor:          selinux-policy" >> $(METADATA)
+	@echo "Requires:        audit libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools-console expect openssh-clients shadow-utils sudo dnf" >> $(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:             2233065" >> $(METADATA) # RHEL-8
+	@echo "Bug:             RHEL-9947" >> $(METADATA) # RHEL-8
+
+	rhts-lint $(METADATA)
+

diff --git a/selinux-policy/sudo-and-dnf/PURPOSE b/selinux-policy/sudo-and-dnf/PURPOSE
new file mode 100644
index 0000000..a3b1b5c
--- /dev/null
+++ b/selinux-policy/sudo-and-dnf/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Regression/sudo-and-dnf
+Author: Milos Malik <mmalik@redhat.com>
+
+SELinux interferes with the dnf command executed via sudo
+

diff --git a/selinux-policy/sudo-and-dnf/main.fmf b/selinux-policy/sudo-and-dnf/main.fmf
new file mode 100644
index 0000000..c46b178
--- /dev/null
+++ b/selinux-policy/sudo-and-dnf/main.fmf
@@ -0,0 +1,45 @@
+summary: SELinux interferes with the dnf command executed via sudo
+description: |+
+    SELinux interferes with the dnf command executed via sudo.
+
+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
+  - expect
+  - openssh-clients
+  - shadow-utils
+  - sudo
+  - dnf
+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=2233065
+  - verifies: https://issues.redhat.com/browse/RHEL-1679
+adjust:
+  - enabled: false
+    when: distro == rhel-4, rhel-5, rhel-6, rhel-7
+    continue: false
+extra-summary: /CoreOS/selinux-policy/Regression/sudo-and-dnf
+extra-task: /CoreOS/selinux-policy/Regression/sudo-and-dnf
+extra-nitrate: TC#0615928
+id: 5d15cec5-e128-4e5c-9f60-80e852df3936

diff --git a/selinux-policy/sudo-and-dnf/runtest.sh b/selinux-policy/sudo-and-dnf/runtest.sh
new file mode 100755
index 0000000..716001d
--- /dev/null
+++ b/selinux-policy/sudo-and-dnf/runtest.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/selinux-policy/Regression/sudo-and-dnf
+#   Description: SELinux interferes with the dnf command executed via sudo
+#   Author: Milos Malik <mmalik@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2023 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"
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlRun "rlImport 'selinux-policy/common'"
+        rlSESatisfyRequires
+        rlAssertRpm ${PACKAGE}
+        rlAssertRpm ${PACKAGE}-targeted
+        rlAssertRpm dnf
+        rlAssertRpm sudo
+
+        rlSESetEnforce
+        rlSEStatus
+        rlSESetTimestamp
+        sleep 2
+    rlPhaseEnd
+
+    rlPhaseStartTest "real scenario -- bz#2233065 + RHEL-9947"
+        rlSEConfigureSSH
+        rlRun "setsebool ssh_sysadm_login on"
+        USER_NAME="sysadm${RANDOM}"
+        USER_SECRET="S3kr3t${RANDOM}"
+        rlRun "useradd -Z sysadm_u ${USER_NAME}"
+        rlRun "echo ${USER_SECRET} | passwd --stdin ${USER_NAME}"
+        rlRun "echo \"${USER_NAME} ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/dnf-test"
+        rlRun "ls -dlZ /var/lib/rpm"
+
+        rlRun -s "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost sudo dnf clean all"
+        rlRun "grep -i 'rpmdb open failed' $rlRun_LOG" 1
+        rm -f $rlRun_LOG
+        rlRun -s "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost sudo dnf update -y"
+        rlRun "grep -i 'rpmdb open failed' $rlRun_LOG" 1
+        rm -f $rlRun_LOG
+
+        rlRun "rm -f /etc/sudoers.d/dnf-test"
+        rlRun "userdel -rfZ ${USER_NAME}"
+        rlRun "setsebool ssh_sysadm_login off"
+        rlFileRestore
+        rlRun "service sshd restart"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+        sleep 2
+        rlSECheckAVC
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd
+

diff --git a/selinux-policy/sudo-and-dnf/ssh.exp b/selinux-policy/sudo-and-dnf/ssh.exp
new file mode 100755
index 0000000..096b9b8
--- /dev/null
+++ b/selinux-policy/sudo-and-dnf/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 "id -Z ; $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=178913286820.1.10765176716910583149.tests-selinux-d5c1f98be652@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