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

feat: Add notification for secure boot key check #1661

Merged
merged 29 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
62e779b
feat: Add notification for secure boot key check
jardon Sep 9, 2024
4219f50
Squash: refactor to single script for motd and notify-send
jardon Sep 11, 2024
4da13af
Add quoting
jardon Sep 11, 2024
b75477f
Reverse conditional
jardon Sep 11, 2024
30c1aac
Fix grouping during quoting
jardon Sep 11, 2024
0cfbfc2
Check for file before deletion
jardon Sep 11, 2024
cfccc33
Add ~ for newline sub
jardon Sep 11, 2024
64f8a61
Clean up notify command formatting
jardon Sep 11, 2024
6517ab3
Remove fq paths to some bins
jardon Sep 11, 2024
8c3985d
Add secure boot check
jardon Sep 11, 2024
196aaa2
Add back ~ in message
jardon Sep 11, 2024
5b93743
Move motd warning outside of tips
jardon Sep 12, 2024
391e55e
Fix motd script errors
jardon Sep 12, 2024
8a49652
Bold motd warning header
jardon Sep 12, 2024
aad5db4
Fix double quoting on XDG var
jardon Sep 12, 2024
9709836
check for loginctl changes
jardon Sep 12, 2024
b2f921c
Fix linting
jardon Sep 12, 2024
1bf0a3c
Merge branch 'main' into key-dbus-notify
bsherman Sep 13, 2024
f8c31f2
Rework script check syntax
jardon Sep 13, 2024
1cc6160
Update sb key warning file location
jardon Sep 13, 2024
880d75d
Split up checking to check for sb enabled first
jardon Sep 13, 2024
edd7750
Fix json mode arg format
jardon Sep 13, 2024
3efe8f1
Merge branch 'main' into key-dbus-notify
bsherman Sep 14, 2024
87ddcf2
Rework notification to not be sent from systemd service
jardon Sep 15, 2024
bc88dc3
Update systemd service description
jardon Sep 15, 2024
306bab3
Fix execute permissions
jardon Sep 18, 2024
dbc8a65
Fix linting and update script perm
jardon Sep 18, 2024
66103e6
Squash: add missing quote closure
jardon Sep 25, 2024
40eeecf
Merge branch 'main' into key-dbus-notify
bsherman Sep 25, 2024
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 build_files/systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ systemctl enable brew-upgrade.timer
systemctl enable brew-update.timer
systemctl --global enable ublue-user-setup.service
systemctl --global enable podman-auto-update.timer
systemctl enable sb-key-notify.service
2 changes: 2 additions & 0 deletions system_files/kinoite/usr/share/ublue-os/motd/bluefin.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Let's trace the stars.
- 󰊤 [Issues](https://issues.projectbluefin.io)
- 󰈙 [Documentation](http://docs.projectbluefin.io/)
- 󰊌 [Discuss](https://community.projectbluefin.io/)

%KEY_WARN%
12 changes: 12 additions & 0 deletions system_files/shared/usr/lib/systemd/system/sb-key-notify.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Service to check for secure boot key enrollment and send notifications

[Service]
ExecStart=/usr/libexec/sb-key-notify.sh

[Install]
WantedBy=multi-user.target

[Timer]
jardon marked this conversation as resolved.
Show resolved Hide resolved
OnBootSec=1min
OnUnitActiveSec=3h
40 changes: 40 additions & 0 deletions system_files/shared/usr/libexec/sb-key-notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root." >&2
exit 1
fi

WARNING_MSG="This machine has secure boot turned on, but you haven't enrolled Universal Blue's keys. Failing to enroll these before rebooting **may cause your system to fail to boot**. Follow this link https://docs.projectbluefin.io/introduction#secure-boot ~for instructions on how to enroll the keys."
KEY_WARN_FILE="/run/user-motd-sbkey-warn.md"
KEY_DER_FILE="/etc/pki/akmods/certs/akmods-ublue.der"

mokutil --sb-state | grep -q enabled
SB_ENABLED=$?

if [ $SB_ENABLED -ne 0 ]; then
echo "Secure Boot disabled. Skipping..."
exit 0
fi

if mokutil --test-key "$KEY_DER_FILE"; then
if loginctl --help | grep -q "json=MODE"; then
JSON_ARG="--json=short"
fi
USER_ID=$(loginctl list-users --output=json ${JSON_ARG:+$JSON_ARG} | jq -r '.[] | .user')
XDG_DIR=$(loginctl show-user "$USER_ID" | grep RuntimePath | cut -c 13-)
sudo -u "$USER_ID" \
bsherman marked this conversation as resolved.
Show resolved Hide resolved
"DISPLAY=:0" \
"DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_DIR/bus" \
notify-send \
"WARNING" \
"$(echo "$WARNING_MSG" | tr -d '*~')" \
-i dialog-warning \
-u critical \
-a mokutil \
--wait

echo "**WARNING**: $WARNING_MSG" > $KEY_WARN_FILE
else
[ -e $KEY_WARN_FILE ] && rm $KEY_WARN_FILE
fi
11 changes: 10 additions & 1 deletion system_files/shared/usr/libexec/ublue-motd
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ if [[ -f "$TIP_FILE" ]]; then

TIP_ESCAPED=$(escape "$TIP")

sed -e "s/%IMAGE_NAME%/$IMAGE_NAME_ESCAPED/g" -e "s/%IMAGE_TAG%/$IMAGE_TAG_ESCAPED/g" -e "s/%TIP%/$TIP_ESCAPED/g" /usr/share/ublue-os/motd/bluefin.md | tr '~' '\n' | /usr/bin/glow -s auto -w 78 -
fi

KEY_WARN_FILE="/run/user-motd-sbkey-warn.md"
[ -e $KEY_WARN_FILE ] && KEY_WARN="$(cat $KEY_WARN_FILE)"
KEY_WARN_ESCAPED=$(escape "$KEY_WARN")

sed -e "s/%IMAGE_NAME%/$IMAGE_NAME_ESCAPED/g" \
-e "s/%IMAGE_TAG%/$IMAGE_TAG_ESCAPED/g" \
-e "s/%TIP%/$TIP_ESCAPED/g" \
-e "s/%KEY_WARN%/$KEY_WARN_ESCAPED/g" \
/usr/share/ublue-os/motd/bluefin.md | tr '~' '\n' | /usr/bin/glow -s auto -w 78 -
2 changes: 2 additions & 0 deletions system_files/silverblue/usr/share/ublue-os/motd/bluefin.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
- 󰈙 [Documentation](http://docs.projectbluefin.io/)
- 󰊌 [Discuss](https://community.projectbluefin.io/)
- 󰊌 [Leave Feedback](https://feedback.projectbluefin.io)

%KEY_WARN%
Loading