Skip to content

Commit a25fb7f

Browse files
authored
Merge pull request #2810 from OSInside/fix_use_of_setfiles_on_read_only_root
Apply security context on writable root only
2 parents aafd752 + 6be96e0 commit a25fb7f

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

build-tests/x86/tumbleweed/test-image-overlayroot/appliance.kiwi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<type
4747
image="oem"
4848
filesystem="xfs"
49-
kernelcmdline="console=ttyS0 rd.systemd.verity=1"
49+
kernelcmdline="console=ttyS0 rd.systemd.verity=1 security=selinux selinux=1 enforcing=1"
5050
firmware="uefi"
5151
format="vmdk"
5252
overlayroot="true"
@@ -69,7 +69,7 @@
6969
<type
7070
image="oem"
7171
filesystem="btrfs"
72-
kernelcmdline="console=ttyS0 rd.systemd.verity=1"
72+
kernelcmdline="console=ttyS0 rd.systemd.verity=1 security=selinux selinux=1 enforcing=1"
7373
firmware="efi"
7474
format="vmdk"
7575
overlayroot="true"
@@ -95,6 +95,12 @@
9595
<packages type="image" profiles="sdboot_verity_erofs,grub_verity_erofs">
9696
<package name="cryptsetup"/>
9797
<package name="dracut-kiwi-verity"/>
98+
<package name="restorecond"/>
99+
<package name="policycoreutils"/>
100+
<package name="setools-console"/>
101+
<package name="selinux-policy-targeted"/>
102+
<package name="selinux-policy-devel"/>
103+
<package name="selinux-autorelabel"/>
98104
</packages>
99105
<packages type="image">
100106
<package name="patterns-base-minimal_base"/>

kiwi/system/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ def set_selinux_file_contexts(self, security_context_file: str) -> None:
553553
:param str security_context_file: path file name
554554
"""
555555
log.info('Processing SELinux file security contexts')
556+
if not os.access(self.root_dir, os.W_OK):
557+
log.info('System is read-only, security context unchanged')
558+
return
556559
exclude = []
557560
for devname in Defaults.get_exclude_list_for_non_physical_devices():
558561
exclude.append('-e')

test/unit/system/setup_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,20 @@ def test_set_selinux_file_contexts_new_version(
16591659
]
16601660
)
16611661

1662+
@patch('kiwi.system.setup.CommandCapabilities.has_option_in_help')
1663+
@patch('kiwi.system.setup.Command.run')
1664+
@patch('os.scandir')
1665+
@patch('os.access')
1666+
def test_set_selinux_file_contexts_read_only_root(
1667+
self, mock_os_access, mock_os_scandir, mock_command,
1668+
mock_has_option_in_help
1669+
):
1670+
mock_os_access.return_value = False
1671+
mock_has_option_in_help.return_value = False
1672+
mock_os_scandir.return_value = self.selinux_policies
1673+
self.setup.set_selinux_file_contexts('security_context_file')
1674+
assert not mock_command.called
1675+
16621676
@patch('kiwi.system.setup.CommandCapabilities.has_option_in_help')
16631677
@patch('kiwi.system.setup.Command.run')
16641678
@patch('os.scandir')

0 commit comments

Comments
 (0)