Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TEST-06-SELINUX to mkosi integration tests #32588

Merged
merged 4 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ Packages=
selinux-policy
selinux-policy-targeted
setools-console

# We relabel on first boot instead of at build time because it is only possible to label without root
# if the labels exist in the host system, and we want to be able to cross-build to other distributions.
SELinuxRelabel=no

InitrdPackages=
selinux-policy
selinux-policy-targeted
5 changes: 5 additions & 0 deletions test/TEST-06-SELINUX/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

test_params += {
'mkosi_args' : ['--kernel-command-line-extra=apparmor=0 selinux=1 enforcing=0 lsm=selinux systemd.wants=autorelabel.service systemd.wants=firstboot-autorelabel.service'],
}
2 changes: 1 addition & 1 deletion test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ integration_tests = {
'03': 'TEST-03-JOBS',
# '04': 'TEST-04-JOURNAL', # Extremely flaky
'05': 'TEST-05-RLIMITS',
# '06': 'TEST-06-SELINUX',
'06': 'TEST-06-SELINUX',
# '07': 'TEST-07-PID1',
# '08': 'TEST-08-INITRD',
'09': 'TEST-09-REBOOT',
Expand Down
11 changes: 8 additions & 3 deletions test/units/autorelabel.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
Description=Relabel all filesystems
DefaultDependencies=no
Requires=local-fs.target
Conflicts=shutdown.target
After=local-fs.target
Before=sysinit.target shutdown.target
Conflicts=shutdown.target
Before=shutdown.target
Before=multi-user.target
# Needs to access /var, which may not have been populated yet
After=systemd-tmpfiles-setup.service
# Must wait for systemd-machine-id-commit or firstboot-autorelabel will reactivate autorelabel
After=systemd-machine-id-commit.service
ConditionSecurity=selinux
ConditionPathExists=|/.autorelabel

Expand All @@ -16,4 +21,4 @@ TimeoutSec=infinity
RemainAfterExit=yes

[Install]
WantedBy=basic.target
WantedBy=multi-user.target
20 changes: 20 additions & 0 deletions test/units/firstboot-autorelabel.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Unit]
Description=Activate relabelling on firstboot only
DefaultDependencies=no
Wants=first-boot-complete.target
Requires=local-fs.target
After=local-fs.target
Conflicts=shutdown.target
Before=shutdown.target
Before=first-boot-complete.target sysinit.target autorelabel.service
ConditionPathIsReadWrite=/etc
ConditionFirstBoot=yes

[Service]
ExecStart=touch /.autorelabel
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=sysinit.target
6 changes: 6 additions & 0 deletions test/units/testsuite-06.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
set -eux
set -o pipefail

. /etc/os-release
if ! [[ "$ID" =~ centos|fedora ]]; then
echo "Skipping because only CentOS and Fedora support SELinux tests" >>/skipped
exit 77
fi

# Note: ATTOW the following checks should work with both Fedora and upstream reference policy
# (with or without MCS/MLS)

Expand Down