Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this is stable across all of our releases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just above this, we exit if the OS isn't RHEL 8.[0-6]. This code very intentionally will not run on RHEL9, because we don't need it there.

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