Skip to content

Commit

Permalink
Merge pull request #119 from cirros-dev/fix-dropbear
Browse files Browse the repository at this point in the history
Fix handling of /etc/dropbear
  • Loading branch information
osfrickler authored Aug 6, 2024
2 parents 4e72d2e + 53b102b commit 4ceb60c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/etc/init.d/S50dropbear
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ start() {
umask 077
local dropbear_key_dir="/etc/dropbear"

# Handle symlinked directories
if [ -L "$dropbear_key_dir" ]; then
dropbear_key_dir=$(readlink -f "$dropbear_key_dir")
# If /etc/dropbear is not a directory, and
# - the filesystem is RO (i.e. we can not rm the symlink),
# create the directory pointed to by the symlink.
# - the filesystem is RW (i.e. we can rm the symlink),
# replace the symlink with an actual directory
if ! [ -d /etc/dropbear ]; then
if ! rm -f /etc/dropbear; then
dropbear_key_dir=$(readlink "$dropbear_key_dir")
fi
fi

# Ensure host keys are changed when instance ID changes
Expand All @@ -26,7 +32,7 @@ start() {

# Regenerate invalid or missing keys
local ktype file
for ktype in rsa ecdsa; do
for ktype in rsa ecdsa ed25519; do
file="${dropbear_key_dir}/dropbear_${ktype}_host_key"
# -f = input file, -y = validate and print pubkey info
if ! dropbearkey -f "$file" -y &>/dev/null; then
Expand Down

0 comments on commit 4ceb60c

Please sign in to comment.