Skip to content

Commit 72ad89d

Browse files
committed
selinux: run the GNU test too
1 parent e147063 commit 72ad89d

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

.github/workflows/GnuTests.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,44 @@ jobs:
8282
submodules: false
8383
persist-credentials: false
8484

85+
- name: Selinux - Setup Lima
86+
uses: lima-vm/lima-actions/setup@v1
87+
id: lima-actions-setup
88+
89+
- name: Selinux - Cache ~/.cache/lima
90+
uses: actions/cache@v4
91+
with:
92+
path: ~/.cache/lima
93+
key: lima-${{ steps.lima-actions-setup.outputs.version }}
94+
95+
- name: Selinux - Start Fedora VM with SELinux
96+
run: limactl start --plain --name=default --cpus=2 --disk=40 --memory=8 --network=lima:user-v2 template://fedora
97+
98+
- name: Selinux - Setup SSH
99+
uses: lima-vm/lima-actions/ssh@v1
100+
101+
- name: Selinux - Verify SELinux Status and Configuration
102+
run: |
103+
lima getenforce
104+
lima ls -laZ /etc/selinux
105+
lima sudo sestatus
106+
107+
# Ensure we're running in enforcing mode
108+
lima sudo setenforce 1
109+
lima getenforce
110+
111+
# Create test files with SELinux contexts for testing
112+
lima sudo mkdir -p /var/test_selinux
113+
lima sudo touch /var/test_selinux/test_file
114+
lima sudo chcon -t etc_t /var/test_selinux/test_file
115+
lima ls -Z /var/test_selinux/test_file # Verify context
116+
117+
- name: Selinux - Install dependencies in VM
118+
run: |
119+
lima sudo dnf -y update
120+
lima sudo dnf -y install git autoconf autopoint bison texinfo gperf gcc g++ gdb jq libacl-devel libattr-devel libcap-devel libselinux-devel attr rustup clang-devel texinfo-tex wget automake patch quilt
121+
lima rustup-init -y --default-toolchain stable
122+
85123
- name: Override submodule URL and initialize submodules
86124
# Use github instead of upstream git server
87125
run: |
@@ -125,12 +163,42 @@ jobs:
125163
sudo update-locale
126164
echo "After:"
127165
locale -a
166+
167+
- name: Selinux - Copy the sources to VM
168+
run: |
169+
rsync -a -e ssh . lima-default:~/work/
170+
128171
- name: Build binaries
129172
shell: bash
130173
run: |
131174
## Build binaries
132175
cd '${{ steps.vars.outputs.path_UUTILS }}'
133176
bash util/build-gnu.sh --release-build
177+
178+
- name: Selinux - Generate selinux tests list
179+
run: |
180+
# Find and list all tests that require SELinux
181+
lima bash -c "cd ~/work/gnu/ && grep -l 'require_selinux_' -r tests/ > ~/work/uutils/selinux-tests.txt"
182+
lima bash -c "cd ~/work/uutils/ && cat selinux-tests.txt"
183+
184+
# Count the tests
185+
lima bash -c "cd ~/work/uutils/ && echo 'Found SELinux tests:'; wc -l selinux-tests.txt"
186+
187+
- name: Selinux - Build for selinux tests
188+
run: |
189+
lima bash -c "cd ~/work/uutils/ && bash util/build-gnu.sh"
190+
191+
- name: Selinux - Run selinux tests
192+
run: |
193+
lima sudo setenforce 1
194+
lima getenforce
195+
lima cat /proc/filesystems
196+
lima bash -c "cd ~/work/uutils/ && bash util/run-gnu-test.sh \$(cat selinux-tests.txt)"
197+
198+
- name: Selinux - Run selinux tests as root
199+
run: |
200+
lima bash -c "cd ~/work/uutils/ && CI=1 bash util/run-gnu-test.sh run-root \$(cat selinux-tests.txt)"
201+
134202
- name: Run GNU tests
135203
shell: bash
136204
run: |

GNUmakefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ TOYBOX_ROOT := $(BASEDIR)/tmp
5757
TOYBOX_VER := 0.8.8
5858
TOYBOX_SRC := $(TOYBOX_ROOT)/toybox-$(TOYBOX_VER)
5959

60-
ifeq ($(SELINUX_ENABLED),)
61-
SELINUX_ENABLED := 0
60+
61+
ifdef SELINUX_ENABLED
62+
override SELINUX_ENABLED := 0
63+
# Now check if we should enable it (only on non-Windows)
6264
ifneq ($(OS),Windows_NT)
63-
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
64-
SELINUX_ENABLED := 1
65+
ifeq ($(shell if [ -x /sbin/selinuxenabled ] && /sbin/selinuxenabled 2>/dev/null; then echo 0; else echo 1; fi),0)
66+
override SELINUX_ENABLED := 1
67+
$(info /sbin/selinuxenabled successful)
68+
else
69+
$(info SELINUX_ENABLED=1 but /sbin/selinuxenabled failed)
6570
endif
6671
endif
6772
endif

util/build-gnu.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ sed -i "s/ {ERR_SUBST=>\"s\/(unrecognized|unknown) option \[-' \]\*foobar\[' \]
240240

241241
# Remove the check whether a util was built. Otherwise tests against utils like "arch" are not run.
242242
sed -i "s|require_built_ |# require_built_ |g" init.cfg
243+
244+
# exit early for the selinux check. The first is enough for us.
245+
sed -i "s|# Independent of whether SELinux|return 0\n #|g" init.cfg
246+
243247
# Some tests are executed with the "nobody" user.
244248
# The check to verify if it works is based on the GNU coreutils version
245249
# making it too restrictive for us

0 commit comments

Comments
 (0)