Skip to content
Closed
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
@@ -0,0 +1,10 @@
[Unit]
Description=Start or stop dropbear based on SSH authorized_keys
RequiresMountsFor=/root/.ssh

[Service]
# Idempotent on purpose: the path unit may fire for any change in the watched
# directory (e.g. temporary files from atomic writes), so this must converge
# rather than toggle.
Type=oneshot
ExecStart=/bin/sh -c 'if [ -s /root/.ssh/authorized_keys ]; then systemctl start dropbear.service; else systemctl stop dropbear.service; fi'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Watch SSH authorized_keys for debug SSH access
# The watch must be armed on the bind-mounted directory (inotify events do
# not cross mount points), and before haos-config potentially imports keys.
RequiresMountsFor=/root/.ssh
Before=haos-config.service

[Path]
# Edge-triggered on purpose: PathExists= pointed at a oneshot unit that does
# not consume the file would re-trigger until the start rate limit is hit.
# Presence of keys at boot is instead handled by dropbear.service itself,
# which is enabled and gated by ConditionFileNotEmpty.
PathChanged=/root/.ssh/authorized_keys
Unit=dropbear-lifecycle.service

[Install]
WantedBy=multi-user.target
3 changes: 0 additions & 3 deletions buildroot-external/rootfs-overlay/usr/sbin/haos-config
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ if [ -f "${CONFIG_DIR}/authorized_keys" ]; then

cp -f ${CONFIG_DIR}/authorized_keys /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys

systemctl start dropbear > /dev/null 2>&1
else
echo "[Info] Stop SSH debug access"

rm -f /root/.ssh/authorized_keys
systemctl stop dropbear > /dev/null 2>&1
fi

##
Expand Down