public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Jan Zarsky <jzarsky@redhat.com>
To: git-commits@fedoraproject.org
Subject: [tests/selinux] pr775-checkpolicy-revdeps: test basic module functionality
Date: Fri, 11 Sep 2026 13:17:18 GMT	[thread overview]
Message-ID: <178913263845.1.5473793771958243224.tests-selinux-604c93034453@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : tests/selinux
            Branch : pr775-checkpolicy-revdeps
            Commit : 604c9303445303fdec68b5b786b87febe05faaf0
            Author : Jan Zarsky <jzarsky@redhat.com>
            Date   : 2018-07-31T21:22:12+02:00
            Stats  : +279/-0 in 4 file(s)
            URL    : https://src.fedoraproject.org/tests/selinux/c/604c9303445303fdec68b5b786b87febe05faaf0?branch=pr775-checkpolicy-revdeps

            Log:
            test basic module functionality

The test compiles a TE module, loads it via semodule, and checks that
the rules are enforced. The same is done with a CIL module. Module
overriding using priorities and module disabling is also tested.

This test requires policycoreutils and selinux-policy-devel packages.

---
diff --git a/policycoreutils/modules/Makefile b/policycoreutils/modules/Makefile
new file mode 100644
index 0000000..4689f27
--- /dev/null
+++ b/policycoreutils/modules/Makefile
@@ -0,0 +1,64 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Makefile of /CoreOS/policycoreutils/Sanity/modules
+#   Description: Test module compiling and loading
+#   Author: Jan Zarsky <jzarsky@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2018 Red Hat, Inc.
+#
+#   This program is free software: you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation, either version 2 of
+#   the License, or (at your option) any later version.
+#
+#   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, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/policycoreutils/Sanity/modules
+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)
+	test -x runtest.sh || chmod a+x runtest.sh
+
+clean:
+	rm -f *~ $(BUILT_FILES)
+
+
+include /usr/share/rhts/lib/rhts-make.include
+
+$(METADATA): Makefile
+	@echo "Owner:           Jan Zarsky <jzarsky@redhat.com>" > $(METADATA)
+	@echo "Name:            $(TEST)" >> $(METADATA)
+	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)
+	@echo "Path:            $(TEST_DIR)" >> $(METADATA)
+	@echo "Description:     Test module compiling and loading" >> $(METADATA)
+	@echo "Type:            Sanity" >> $(METADATA)
+	@echo "TestTime:        10m" >> $(METADATA)
+	@echo "RunFor:          policycoreutils" >> $(METADATA)
+	@echo "Requires:        policycoreutils" >> $(METADATA)
+	@echo "Requires:        selinux-policy-devel" >> $(METADATA)
+	@echo "Priority:        Normal" >> $(METADATA)
+	@echo "License:         GPLv2+" >> $(METADATA)
+	@echo "Confidential:    no" >> $(METADATA)
+	@echo "Destructive:     no" >> $(METADATA)
+	@echo "Releases:        -RHEL4 -RHELClient5 -RHELServer5 -RHEL6" >> $(METADATA)
+
+	rhts-lint $(METADATA)

diff --git a/policycoreutils/modules/PURPOSE b/policycoreutils/modules/PURPOSE
new file mode 100644
index 0000000..5f2d254
--- /dev/null
+++ b/policycoreutils/modules/PURPOSE
@@ -0,0 +1,3 @@
+PURPOSE of /CoreOS/policycoreutils/Sanity/modules
+Description: Test module compiling and loading
+Author: Jan Zarsky <jzarsky@redhat.com>

diff --git a/policycoreutils/modules/main.fmf b/policycoreutils/modules/main.fmf
new file mode 100644
index 0000000..3b5d389
--- /dev/null
+++ b/policycoreutils/modules/main.fmf
@@ -0,0 +1,11 @@
+path: /policycoreutils/modules
+summary: test basic module functionality
+description: |
+    The test compiles a TE module, loads it via semodule, and checks
+    that the rules are enforced. The same is done with a CIL module.
+    Module overriding using priorities and module disabling is also
+    tested. This test requires policycoreutils and selinux-policy-devel
+    packages.
+relevancy:
+    - "distro = rhel-4, rhel-5, rhel-6: False"
+duration: 10m

diff --git a/policycoreutils/modules/runtest.sh b/policycoreutils/modules/runtest.sh
new file mode 100755
index 0000000..0d7a704
--- /dev/null
+++ b/policycoreutils/modules/runtest.sh
@@ -0,0 +1,201 @@
+#!/bin/bash
+# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   runtest.sh of /CoreOS/policycoreutils/Sanity/modules
+#   Description: Test module compiling and loading
+#   Author: Jan Zarsky <jzarsky@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#   Copyright (c) 2018 Red Hat, Inc.
+#
+#   This program is free software: you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation, either version 2 of
+#   the License, or (at your option) any later version.
+#
+#   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, see http://www.gnu.org/licenses/.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include Beaker environment
+. /usr/bin/rhts-environment.sh || exit 1
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="policycoreutils"
+
+rlJournalStart
+    rlPhaseStartSetup
+        rlAssertRpm $PACKAGE
+        rlAssertRpm "selinux-policy-devel"
+    rlPhaseEnd
+
+    rlPhaseStartTest "TE module using Makefile"
+        rlRun "mkdir test"
+        rlRun "pushd test"
+
+        # create new type, allow reading, do not allow writing
+        rlRun "cat << EOF >test_module.te
+module test_module 1.0;
+
+require {
+    type unconfined_t;
+    type fs_t;
+    class file { getattr ioctl lock open read relabelto write };
+    class filesystem { associate };
+}
+
+type test_t;
+
+allow test_t fs_t:filesystem { associate };
+allow unconfined_t test_t:file { getattr ioctl lock open read relabelto};
+dontaudit unconfined_t test_t:file { write };
+EOF"
+        # compile the module
+        rlRun "make -f /usr/share/selinux/devel/Makefile test_module.pp"
+
+        # load it
+        rlRun "semodule -i test_module.pp"
+
+        # test that the rules are enforced
+        rlRun "touch test_file"
+        rlRun "chcon -t test_t test_file"
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 1
+
+        # unload the module
+        rlRun "semodule -r test_module"
+
+        rlRun "popd"
+        rlRun "rm -rf test"
+    rlPhaseEnd
+
+    rlPhaseStartTest "CIL module"
+        rlRun "mkdir test"
+        rlRun "pushd test"
+
+        # create new type, allow reading, do not allow writing
+        rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+
+        # load the module
+        rlRun "semodule -i test_module.cil"
+
+        # test that the rules are enforced
+        rlRun "touch test_file"
+        rlRun "chcon -t test_t test_file"
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 1
+
+        # unload the module
+        rlRun "semodule -r test_module"
+
+        rlRun "popd"
+        rlRun "rm -rf test"
+    rlPhaseEnd
+
+    rlPhaseStartTest "Priorities"
+        rlRun "mkdir test"
+        rlRun "pushd test"
+
+        # create new type, allow reading and writing
+        rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto
+    write)))
+EOF"
+
+        # load the module at priority 400
+        rlRun "semodule -i test_module.cil -X 400"
+
+        # test that both reading and writing is allowed
+        rlRun "touch test_file"
+        rlRun "chcon -t test_t test_file"
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 0
+
+        # create new type, allow only reading
+        rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+
+        # load the module at priority 500
+        rlRun "semodule -i test_module.cil -X 500"
+
+        # test that only reading is allowed
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 1
+
+        # unload both modules
+        rlRun "semodule -r test_module -X 400"
+        rlRun "semodule -r test_module -X 500"
+
+        rlRun "popd"
+        rlRun "rm -rf test"
+    rlPhaseEnd
+
+    rlPhaseStartTest "Disabling modules"
+        rlRun "mkdir test"
+        rlRun "pushd test"
+
+        # create new type, allow reading
+        rlRun "cat << EOF >test_module.cil
+(type test_t)
+(allow test_t fs_t (filesystem (associate)))
+(allow unconfined_t test_t (file (getattr ioctl lock open read relabelto)))
+(dontaudit unconfined_t test_t (file (write)))
+EOF"
+        # allow writing
+        rlRun "cat << EOF >test_module_writing.cil
+(allow unconfined_t test_t (file (write)))
+EOF"
+
+        # load the modules
+        rlRun "semodule -i test_module.cil test_module_writing.cil"
+
+        # test that reading and writing is allowed
+        rlRun "touch test_file"
+        rlRun "chcon -t test_t test_file"
+        rlRun "cat test_file"
+        rlRun "echo asdf >test_file"
+
+        # disable writing
+        rlRun "semodule -d test_module_writing"
+
+        # test that writing is not allowed
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 1
+
+        # enable the module
+        rlRun "semodule -e test_module_writing"
+
+        # test that writing is allowed
+        rlRun "cat test_file" 0
+        rlRun "echo asdf >test_file" 0
+
+        # unload the modules
+        rlRun "semodule -r test_module test_module_writing"
+
+        rlRun "popd"
+        rlRun "rm -rf test"
+    rlPhaseEnd
+
+    rlPhaseStartCleanup
+    rlPhaseEnd
+rlJournalPrintText
+rlJournalEnd

                 reply	other threads:[~2026-09-11 13:17 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=178913263845.1.5473793771958243224.tests-selinux-604c93034453@fedoraproject.org \
    --to=jzarsky@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