Skip to content

Commit c5c0cc8

Browse files
committed
Introduce SELinux policy module for kiwi
This simple policy module ensures that the kiwi executable is labeled such that it works properly in SELinux enforcing mode.
1 parent 5af510a commit c5c0cc8

File tree

6 files changed

+489
-0
lines changed

6 files changed

+489
-0
lines changed

package/python-kiwi-spec-template

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
%global develsuffix devel
5656
%endif
5757

58+
%if 0%{?fedora} || 0%{?rhel} || 0%{?suse_version} >= 1600
59+
%bcond_without selinux
60+
%else
61+
%bcond_with selinux
62+
%endif
63+
5864
Name: python-kiwi
5965
Version: %%VERSION
6066
Provides: kiwi-schema = 8.1
@@ -445,6 +451,9 @@ Requires: python%{python3_pkgversion}-lxml
445451
Requires: python%{python3_pkgversion}-requests
446452
Requires: python%{python3_pkgversion}-setuptools
447453
Requires: python%{python3_pkgversion}-xmltodict
454+
%if %{with selinux}
455+
Requires: (kiwi-selinux = %{version}-%{release} if selinux-policy)
456+
%endif
448457
%if ! (0%{?rhel} && 0%{?rhel} < 8)
449458
Recommends: kiwi-man-pages
450459
%endif
@@ -684,6 +693,21 @@ BuildArch: noarch
684693
Bash command line completion support for python-kiwi - completion
685694
of subcommands, parameters and keywords for the kiwi-ng command.
686695

696+
%if %{with selinux}
697+
%package -n kiwi-selinux
698+
Summary: SELinux module for kiwi-ng
699+
License: GPL-2.0-or-later
700+
BuildArch: noarch
701+
BuildRequires: selinux-policy
702+
BuildRequires: selinux-policy-devel
703+
BuildRequires: make
704+
%{?selinux_requires}
705+
706+
%description -n kiwi-selinux
707+
This package provides the SELinux policy module to ensure kiwi-ng
708+
runs properly under an environment with SELinux enabled.
709+
%endif
710+
687711
%prep
688712
%setup -q -n kiwi-%{version}
689713

@@ -705,6 +729,11 @@ sed -e "s|#!/usr/bin/env python||" -i kiwi/xml_parse.py
705729
# Build documentation
706730
make -C doc man
707731

732+
%if %{with selinux}
733+
# Build SELinux module
734+
make -C selinux SHARE="%{_datadir}" TARGETS="kiwi"
735+
%endif
736+
708737
# Build application wheel
709738
%{__python3} -m build --no-isolation --wheel
710739

@@ -731,6 +760,11 @@ make buildroot=%{buildroot}/ docdir=%{_defaultdocdir}/ python=%{__python3} insta
731760
ln -sr %{buildroot}%{_bindir}/kiwi-ng %{buildroot}%{_bindir}/kiwi
732761
ln -sr %{buildroot}%{_bindir}/kiwi-ng %{buildroot}%{_bindir}/kiwi-ng-3
733762

763+
%if %{with selinux}
764+
# Install SELinux module
765+
install -t %{buildroot}%{_datadir}/selinux/packages -Dpm 0644 selinux/kiwi.pp.bz2
766+
%endif
767+
734768
%if "%{_vendor}" != "debbuild"
735769
# kiwi pxeboot directory structure to be packed in kiwi-pxeboot
736770
%ifarch %{ix86} x86_64
@@ -759,6 +793,24 @@ fi
759793
%endif
760794
%endif
761795

796+
%if %{with selinux}
797+
%pre -n kiwi-selinux
798+
%selinux_relabel_pre
799+
800+
%post -n kiwi-selinux
801+
%selinux_modules_install %{_datadir}/selinux/packages/kiwi.pp.bz2
802+
%selinux_relabel_post
803+
804+
%posttrans -n kiwi-selinux
805+
%selinux_relabel_post
806+
807+
%postun -n kiwi-selinux
808+
%selinux_modules_uninstall kiwi
809+
if [ $1 -eq 0 ]; then
810+
%selinux_relabel_post
811+
fi
812+
%endif
813+
762814
%files -n kiwi-systemdeps-core
763815
# Empty metapackage
764816

@@ -838,4 +890,11 @@ fi
838890
%endif
839891
%endif
840892

893+
%if %{with selinux}
894+
%files -n kiwi-selinux
895+
%license selinux/LICENSE
896+
%doc selinux/README.md
897+
%{_datadir}/selinux/packages/kiwi.pp.bz2
898+
%endif
899+
841900
%changelog

0 commit comments

Comments
 (0)