Skip to content

Commit b0b61f8

Browse files
committed
Adjusted RPM packaging to be avoid failed installs when selinux-policy version is not sufficient
As a workaround, if the cfengine-enterprise selinux module fails to install we set binaries to unconfined domain with bin_t type. Ticket: ENT-12980 Changelog: title
1 parent c3387a3 commit b0b61f8

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

packaging/cfengine-community/cfengine-community.spec.in

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ Requires: coreutils
1717
Recommends: gzip
1818
%endif
1919

20-
# we require selinux-policy package version that matches or exceeds our build system version
21-
# this guarantees that our compiled selinux policy will work.
20+
# We add a recommends for the selinux-policy package version that matches or exceeds our build system version.
21+
# This increases the likelihood that our compiled selinux policy will work.
22+
# By making this a weak dependency we allow the package to install on systems with an older selinux-policy version.
2223
%if %{?rhel}%{!?rhel:0} >= 8
23-
Requires: selinux-policy >= @@SELINUX_POLICY_VERSION@@
24+
Recommends: selinux-policy >= @@SELINUX_POLICY_VERSION@@
2425
%endif
2526

2627
AutoReqProv: no
@@ -147,6 +148,7 @@ done
147148
%prefix/selinux/cfengine-enterprise.pp
148149
%prefix/selinux/cfengine-enterprise.te
149150
%prefix/selinux/cfengine-enterprise.fc
151+
%prefix/selinux/label-binaries-unconfined.sh
150152
%endif
151153

152154
# Globally installed configs, scripts

packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ Recommends: gzip
2525
Requires(pre): /usr/sbin/useradd, /usr/sbin/userdel, /usr/bin/getent
2626
Requires(post): /usr/sbin/usermod, /bin/sed
2727

28-
# we require selinux-policy package version that matches or exceeds our build system version
29-
# this guarantees that our compiled selinux policy will work.
28+
# We add a recommends for the selinux-policy package version that matches or exceeds our build system version.
29+
# This increases the likelihood that our compiled selinux policy will work.
30+
# By making this a weak dependency we allow the package to install on systems with an older selinux-policy version.
3031
%if %{?rhel}%{!?rhel:0} >= 8
31-
Requires: selinux-policy >= @@SELINUX_POLICY_VERSION@@
32+
Recommends: selinux-policy >= @@SELINUX_POLICY_VERSION@@
3233
%endif
3334

35+
3436
# we don't bundle OpenSSL on RHEL 8 (and newer in the future)
3537
%if %{?rhel}%{!?rhel:0} == 8
3638
Requires: libssl.so.1.1()(64bit) libssl.so.1.1(OPENSSL_1_1_0)(64bit) libssl.so.1.1(OPENSSL_1_1_1)(64bit)
@@ -413,6 +415,7 @@ exit 0
413415
%prefix/selinux/cfengine-enterprise.pp
414416
%prefix/selinux/cfengine-enterprise.te
415417
%prefix/selinux/cfengine-enterprise.fc
418+
%prefix/selinux/label-binaries-unconfined.sh
416419
%endif
417420

418421
# Documentation

packaging/cfengine-nova/cfengine-nova.spec.in

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ Requires: coreutils
1717
Recommends: gzip
1818
%endif
1919

20-
# we require selinux-policy package version that matches or exceeds our build system version
21-
# this guarantees that our compiled selinux policy will work.
20+
# We add a recommends for the selinux-policy package version that matches or exceeds our build system version.
21+
# This increases the likelihood that our compiled selinux policy will work.
22+
# By making this a weak dependency we allow the package to install on systems with an older selinux-policy version.
2223
%if %{?rhel}%{!?rhel:0} >= 8
23-
Requires: selinux-policy >= @@SELINUX_POLICY_VERSION@@
24+
Recommends: selinux-policy >= @@SELINUX_POLICY_VERSION@@
2425
%endif
2526

2627
# We don't bundle OpenSSL on RHEL >= 8 and SuSE >= 15
@@ -173,6 +174,7 @@ exit 0
173174
%prefix/selinux/cfengine-enterprise.pp
174175
%prefix/selinux/cfengine-enterprise.te
175176
%prefix/selinux/cfengine-enterprise.fc
177+
%prefix/selinux/label-binaries-unconfined.sh
176178
%endif
177179

178180
# Globally installed configs, scripts

packaging/common/cfengine-hub/postinstall.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ then
1111
test -x /usr/sbin/restorecon || cf_console echo "warning! selinuxenabled exists and returns 0 but restorecon not found"
1212
fi
1313
if ! cf_console semodule -n -i "$PREFIX/selinux/cfengine-enterprise.pp"; then
14-
cf_console echo "warning! semodule import failed, examine /var/log/CFE*log and \
15-
consider installing selinux-policy-devel package and \
16-
rebuilding policy with: \
17-
\
18-
cd $PREFIX/selinux \
19-
make -f /usr/share/selinux/devel/Makefile -j1 \
20-
semodule -n -i $PREFIX/selinux/cfengine-enterprise.pp \
21-
\
22-
and then restarting services with \
23-
\
24-
systemctl restart cfengine3"
14+
cf_console echo "warning! semodule import failed, as a fallback all binaries in $PREFIX will be labeled bin_t aka unconfined. \
15+
The semodule import failure should be examined in /var/log/CFE*log and reported so that properly confined CFEngine can be setup."
16+
if ! command -v semodule; then
17+
cf_console echo "warning! semodule import failed and semodule command is not available. Please install the package policycoreutils and run $PREFIX/selinux/label-binaries-unconfined.sh manually immediately after install and restart services with systemctl restart cfengine3."
18+
else
19+
if ! "$PREFIX"/selinux/label-binaries-unconfined.sh "$PREFIX"; then
20+
cf_console echo "warning! fallback to label all binaries unconfined has failed. CFEngine may not properly operate with selinux set to enforcing."
21+
fi
22+
fi
2523
fi
2624
if /usr/sbin/selinuxenabled; then
2725
/usr/sbin/load_policy

packaging/common/cfengine-non-hub/postinstall.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,15 @@ then
127127

128128
fi
129129
if ! cf_console semodule -n -i "$PREFIX/selinux/cfengine-enterprise.pp"; then
130-
cf_console echo "warning! semodule import failed, examine /var/log/CFE*log and \
131-
consider installing selinux-policy-devel package and \
132-
rebuilding policy with: \
133-
\
134-
cd $PREFIX/selinux \
135-
make -f /usr/share/selinux/devel/Makefile -j1 \
136-
semodule -n -i $PREFIX/selinux/cfengine-enterprise.pp \
137-
\
138-
and then restarting services with \
139-
\
140-
systemctl restart cfengine3"
130+
cf_console echo "warning! semodule import failed, as a fallback all binaries in $PREFIX will be labeled bin_t aka unconfined. \
131+
The semodule import failure should be examined in /var/log/CFE*log and reported so that properly confined CFEngine can be setup."
132+
if ! command -v semodule; then
133+
cf_console echo "warning! semodule import failed and semodule command is not available. Please install the package policycoreutils and run $PREFIX/selinux/label-binaries-unconfined.sh manually immediately after install and restart services with systemctl restart cfengine3."
134+
else
135+
if ! "$PREFIX"/selinux/label-binaries-unconfined.sh "$PREFIX"; then
136+
cf_console echo "warning! fallback to label all binaries unconfined has failed. CFEngine may not properly operate with selinux set to enforcing."
137+
fi
138+
fi
141139
fi
142140
if /usr/sbin/selinuxenabled; then
143141
/usr/sbin/load_policy

0 commit comments

Comments
 (0)