-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now that the kernel supports relabeling from the initrd, we can clean up some hacks here. After running `systemd-tmpfiles`, immediately relabel what we just wrote using `setfiles`. This allows us to drop the `Z /var` tmpfiles.d dropin, and hacking around `systemd-random-seed.service` ordering. For compatibility with RHCOS, I added a fallback in `coreos-relabel` so that if initrd relabeling isn't supported, we just use tmpfiles.d dropins. (RHCOS today sources the `05core` overlay directly, and I think doing it this way is cleaner than splitting things out into a separate overlay). I've also snuck in a fix for the live case with persistent `/var` so we don't always relabel everything in there.
- Loading branch information
Showing
3 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
overlay.d/05core/usr/lib/dracut/modules.d/40ignition-ostree/coreos-relabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
err() { | ||
echo "$@" >&2 | ||
} | ||
|
||
fatal() { | ||
err "$@" | ||
exit 1 | ||
} | ||
|
||
if [ $# -eq 0 ]; then | ||
err "Usage: $0 [PATTERN...]" | ||
err " e.g.: $0 /etc/passwd '/etc/group*'" | ||
fi | ||
|
||
if [ ! -f /sysroot/etc/selinux/config ]; then | ||
exit 0 | ||
fi | ||
|
||
source /sysroot/etc/selinux/config | ||
|
||
if [ -z "${SELINUXTYPE:-}" ]; then | ||
fatal "Couldn't find SELINUXTYPE in /sysroot/etc/selinux/config" | ||
fi | ||
|
||
file_contexts="/sysroot/etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts" | ||
|
||
# feature detection until RHEL8 kernel has | ||
# https://lore.kernel.org/selinux/20190912133007.27545-1-jlebon@redhat.com/T/#m5f950ca9fc3ed374cb793fc9aed0435602b1b6ad | ||
can_setfiles() { | ||
CAN_SETFILES_STAMP=/run/.coreos-relabel-can-setfiles | ||
if [ ! -f ${CAN_SETFILES_STAMP} ]; then | ||
touch /sysroot/etc/.setfiles-test | ||
trap 'rm /sysroot/etc/.setfiles-test' EXIT | ||
if setfiles -Fr /sysroot "$file_contexts" /sysroot/etc/.setfiles-test &>/dev/null; then | ||
echo 1 > ${CAN_SETFILES_STAMP} | ||
else | ||
echo 0 > ${CAN_SETFILES_STAMP} | ||
fi | ||
fi | ||
grep -q 1 ${CAN_SETFILES_STAMP} | ||
} | ||
|
||
if can_setfiles; then | ||
prefixed_patterns=() | ||
while [ $# -ne 0 ]; do | ||
pattern=$1; shift | ||
prefixed_patterns+=("/sysroot/$pattern") | ||
done | ||
setfiles -vFi0 -r /sysroot "$file_contexts" "${prefixed_patterns[@]}" | ||
else | ||
while [ $# -ne 0 ]; do | ||
pattern=$1; shift | ||
# Really, we could handle /etc files here earlier by spitting out a | ||
# separate unit service like ignition-relabel.service was. But let's not | ||
# do that until the need arises. | ||
echo "Z $pattern - - -" >> /run/tmpfiles.d/var-relabel.conf | ||
done | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters