Skip to content

Commit

Permalink
Merge pull request openshift#966 from openshift-cherrypick-robot/cher…
Browse files Browse the repository at this point in the history
…ry-pick-962-to-release-4.11

[release-4.11] OCPBUGS-727: overlay: Add `rhcos-selinux-policy-upgrade.service`
  • Loading branch information
openshift-merge-robot authored Aug 31, 2022
2 parents 765d2be + 65aa57d commit 0f00144
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Upgrade fixes
enable rhcos-usrlocal-selinux-fixup.service
enable rhcos-selinux-policy-upgrade.service
# Enable the iscsi workaround
enable coreos-generate-iscsi-initiatorname.service
# Enable auditd. See https://jira.coreos.com/browse/RHCOS-536
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=RHEL CoreOS Rebuild SELinux Policy If Necessary
Documentation=https://bugzilla.redhat.com/2057497
DefaultDependencies=false
After=systemd-tmpfiles-setup.service local-fs.target
Before=sysinit.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/rhcos-rebuild-selinux-policy

[Install]
WantedBy=sysinit.target
16 changes: 16 additions & 0 deletions overlay.d/05rhcos/usr/libexec/rhcos-rebuild-selinux-policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Executed by rhcos-selinux-policy-upgrade.service
set -euo pipefail

RHEL_VERSION=$(. /usr/lib/os-release && echo ${RHEL_VERSION:-})
echo -n "RHEL_VERSION=${RHEL_VERSION:-}"
case "${RHEL_VERSION:-}" in
8.[0-6]) echo "Checking for policy recompilation";;
*) echo "Assuming we have new enough ostree"; exit 0;;
esac

ls -al /{usr/,}etc/selinux/targeted/policy/policy.31
if ! cmp --quiet /{usr/,}etc/selinux/targeted/policy/policy.31; then
echo "Recompiling policy due to local modifications as workaround for https://bugzilla.redhat.com/2057497"
semodule -B
fi
1 change: 1 addition & 0 deletions tests/kola/rebuild-selinux-policy/data/commonlib.sh
34 changes: 34 additions & 0 deletions tests/kola/rebuild-selinux-policy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Test for https://issues.redhat.com/browse/OCPBUGS-595

set -xeuo pipefail

. $KOLA_EXT_DATA/commonlib.sh

cd $(mktemp -d)
journalctl -b -u rhcos-selinux-policy-upgrade > logs.txt
RHEL_VERSION=$(. /usr/lib/os-release && echo ${RHEL_VERSION:-})
echo "RHEL_VERSION=${RHEL_VERSION:-}"
service_should_start=0
case "${RHEL_VERSION:-}" in
8.[0-6]) service_should_start=1;;
*) ;;
esac

case "${AUTOPKGTEST_REBOOT_MARK:-}" in
"")
if grep -qFe 'Recompiling policy' logs.txt; then
cat logs.txt
fatal "Recompiled policy on first boot"
fi
setsebool -P container_manage_cgroup on
/tmp/autopkgtest-reboot changed-policy
;;
"changed-policy")
if test "${service_should_start}" = "1" && ! grep -qFe 'Recompiling policy' logs.txt; then
cat logs.txt
fatal "Failed to recompile policy on first boot"
fi
;;
esac
echo ok

0 comments on commit 0f00144

Please sign in to comment.