Skip to content

Commit 1120774

Browse files
committed
nixos-rebuild: fix SSH key security race
Make sure the ssh_key file is always 0700
1 parent ee5c39f commit 1120774

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

terraform/nixos-rebuild/deploy.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ sshOpts+=(-o StrictHostKeyChecking=no)
2222
if [[ -n ${SSH_KEY+x} && ${SSH_KEY} != "-" ]]; then
2323
sshPrivateKeyFile="$workDir/ssh_key"
2424
trap 'rm "$sshPrivateKeyFile"' EXIT
25-
echo "$SSH_KEY" >"$sshPrivateKeyFile"
26-
chmod 0700 "$sshPrivateKeyFile"
25+
# Create the file with 0700 - umask calculation: 777 - 700 = 077
26+
(
27+
umask 077
28+
echo "$SSH_KEY" >"$sshPrivateKeyFile"
29+
)
2730
unset SSH_AUTH_SOCK # don't use system agent if key was supplied
2831
sshOpts+=(-o "IdentityFile=${sshPrivateKeyFile}")
2932
fi

0 commit comments

Comments
 (0)