Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relabel / and /rw if needed #541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ install-init:
install -m 0644 init/functions $(DESTDIR)$(LIBDIR)/qubes/init/
ifneq ($(ENABLE_SELINUX),1)
rm -f $(DESTDIR)$(LIBDIR)/qubes/init/relabel-root.sh
rm -f $(DESTDIR)$(LIBDIR)/qubes/init/relabel-rw.sh
endif

# Systemd service files
Expand Down
12 changes: 12 additions & 0 deletions init/relabel-rw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash --
Copy link
Member

Choose a reason for hiding this comment

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

What bash features you use here? I'd prefer /bin/sh (and consequently shellcheck noticing non-POSIX features) in scritpts that don't absolutely need bash (for example to have proper arrays).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-nt is not part of POSIX.

set -eu
unset SELINUXTYPE
if [ -f /etc/selinux/config ]; then
# shellcheck disable=SC1091
. /etc/selinux/config
fi
ctx_file=/etc/selinux/${SELINUXTYPE:-targeted}/contexts/files/file_contexts
if [ "$ctx_file" -nt /rw/.autorelabel ]; then
restorecon -R /rw
touch "--reference=$ctx_file" /rw/.autorelabel
fi
1 change: 1 addition & 0 deletions rpm_spec/core-agent.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ a VM with SELinux enforcing, as is the default on Red Hat-family distributions.
%dir %_unitdir/selinux-autorelabel.service.d
%_unitdir/selinux-autorelabel.service.d/30_qubes.conf
/usr/lib/qubes/init/relabel-root.sh
/usr/lib/qubes/init/relabel-rw.sh

%postun selinux
if [ "$1" -eq 0 ]; then
Expand Down
3 changes: 2 additions & 1 deletion vm-systemd/qubes-relabel-root.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Description=Relabel /
After=qubes-sysinit.service
Requires=qubes-sysinit.service
ConditionSecurity=selinux
ConditionPathExists=!/.qubes-relabeled
ConditionPathExists=|/.autorelabel
ConditionPathExists=|!/.qubes-relabeled
ConditionPathExists=/run/qubes/persistent-full
DefaultDependencies=no
Conflicts=shutdown.target
Expand Down
8 changes: 3 additions & 5 deletions vm-systemd/qubes-relabel-rw.service
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[Unit]
Description=Relabel /rw and /home
After=qubes-mount-dirs.service qubes-sysinit.service
Requires=qubes-mount-dirs.service qubes-sysinit.service
After=qubes-mount-dirs.service qubes-sysinit.service qubes-relabel-root.service
Requires=qubes-mount-dirs.service qubes-sysinit.service qubes-relabel-root.service
ConditionSecurity=selinux
ConditionPathExists=!/rw/.autorelabel
DefaultDependencies=no
Conflicts=selinux-autorelabel.service
Before=local-fs.target rw.mount home.mount qubes-gui-agent.service qubes-qrexec-agent.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/restorecon -RF /rw /home /usr/local
ExecStart=/bin/touch /rw/.autorelabel
ExecStart=/usr/lib/qubes/init/relabel-rw.sh

[Install]
WantedBy=multi-user.target