Skip to content

Commit

Permalink
Merge pull request #211 from matttbe/sshd-overlayfs
Browse files Browse the repository at this point in the history
sshd: look for overlayfs before modifying auth keys
  • Loading branch information
arighi authored Dec 30, 2024
2 parents 6e7dc3e + 6577bd1 commit f53c692
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions virtme/guest/virtme-sshd-script
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ fi
#
# Overwriting authorized_keys is considered safe only when the guest rootfs
# is mounted as read-only, with an overlayfs on top to handle writes within
# the guest environment (`--rw` not specified as argument).
if grep ' / ' /proc/mounts | grep -q ' ro,'; then
cat "${SSH_HOME}"/.ssh/id_*.pub >> "${SSH_HOME}/.ssh/authorized_keys" 2>/dev/null
chown "${virtme_ssh_user}" "${SSH_HOME}/.ssh/authorized_keys" 2>/dev/null
# the guest environment (e.g. `--rw` or `--rwdir` not specified as argument).
OVERLAYFS="794c7630" # OVERLAYFS_SUPER_MAGIC in include/uapi/linux/magic.h
SSH_AUTH_KEYS="${SSH_HOME}/.ssh/authorized_keys"
if [ "$(stat -f -c "%t" "${SSH_AUTH_KEYS}")" = "${OVERLAYFS}" ]; then
cat "${SSH_HOME}"/.ssh/id_*.pub >> "${SSH_AUTH_KEYS}" 2>/dev/null
chown "${virtme_ssh_user}" "${SSH_AUTH_KEYS}" 2>/dev/null
fi

# Generate ssh host keys (if they don't exist already).
Expand Down

0 comments on commit f53c692

Please sign in to comment.