Keep the key of the website away from the Administrator account
The key that the website logs in with was written into the authorized_keys of the Administrator, which would have given everyone who has the website administrator rights on the box. It only gets access as the root user. The deploy script logs in as Administrator with the personal key of the deployer instead, from the agent or from -i. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
ac98212fa2
commit
fc7b75b930
1 changed files with 30 additions and 42 deletions
|
|
@ -5,6 +5,9 @@
|
|||
#
|
||||
# The job runs on the box as SYSTEM, never as the root user. The Administrator account sets it up; its shell is a
|
||||
# Windows one, so the commands we run there are Windows commands.
|
||||
#
|
||||
# The Administrator logs in with the personal key of the deployer, from the agent or from -i. The key of the website
|
||||
# never gets administrator rights: it only logs in as the root user.
|
||||
set -euo pipefail
|
||||
|
||||
HOST=nowhere.wirs.ing
|
||||
|
|
@ -27,23 +30,6 @@ remote='C:\Users\Administrator\kik' # where the installer is put, in the home
|
|||
remotePath='/c/Users/Administrator/kik' # the same place, as the file transfer sees it
|
||||
temporary=()
|
||||
|
||||
if [ -z "$KEYFILE" ]; then
|
||||
# The key the website uses is authorized for the Administrator account as well.
|
||||
KEYFILE=$(mktemp)
|
||||
chmod 600 "$KEYFILE"
|
||||
temporary+=("$KEYFILE")
|
||||
boring=$(sed -n "s/.*const boringData = '\([^']*\)'.*/\1/p" "$repo/src/scripts/terminal.ts")
|
||||
printf '%s' "$boring" | base64 -d | tr 'A-Za-z' 'N-ZA-Mn-za-m' > "$KEYFILE"
|
||||
fi
|
||||
|
||||
# The site logs in with the key in the authorized_keys of the user, so the two have to be the same.
|
||||
public=$(ssh-keygen -y -f "$KEYFILE" | awk 'NF {print $1" "$2}')
|
||||
authorized=$(awk 'NF {print $1" "$2; exit}' "$server/resources/.ssh/authorized_keys")
|
||||
if [ "$public" != "$authorized" ]; then
|
||||
echo "the key in server/resources/.ssh/authorized_keys is not the one the website uses" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The host key is the one the website pins, so that the deployment cannot be intercepted.
|
||||
expected=$(sed -n "s/.*const HOST_KEY = '\([^']*\)'.*/\1/p" "$repo/src/scripts/terminal.ts")
|
||||
known=$(mktemp)
|
||||
|
|
@ -56,8 +42,23 @@ if [ "$actual" != "$expected" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
ssh=(ssh -i "$KEYFILE" -o UserKnownHostsFile="$known" -o StrictHostKeyChecking=yes "$USER@$HOST")
|
||||
scp=(scp -i "$KEYFILE" -o UserKnownHostsFile="$known" -o StrictHostKeyChecking=yes)
|
||||
# The site logs in with the key in the authorized_keys of the user on the box, so the two have to be the same.
|
||||
site=$(mktemp)
|
||||
chmod 600 "$site"
|
||||
temporary+=("$site")
|
||||
boring=$(sed -n "s/.*const boringData = '\([^']*\)'.*/\1/p" "$repo/src/scripts/terminal.ts")
|
||||
printf '%s' "$boring" | base64 -d | tr 'A-Za-z' 'N-ZA-Mn-za-m' > "$site"
|
||||
public=$(ssh-keygen -y -f "$site" | awk 'NF {print $1" "$2}')
|
||||
authorized=$(awk 'NF {print $1" "$2; exit}' "$server/resources/.ssh/authorized_keys")
|
||||
if [ "$public" != "$authorized" ]; then
|
||||
echo "the key in server/resources/.ssh/authorized_keys is not the one the website uses" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
options=(-o "UserKnownHostsFile=$known" -o StrictHostKeyChecking=yes)
|
||||
if [ -n "$KEYFILE" ]; then options+=(-i "$KEYFILE"); fi
|
||||
ssh=(ssh "${options[@]}" "$USER@$HOST")
|
||||
scp=(scp "${options[@]}")
|
||||
|
||||
if [ "$UNINSTALL" = 1 ]; then
|
||||
"${ssh[@]}" "if exist $remote\\scripts\\install_restore_task.ps1 (powershell -NoProfile -ExecutionPolicy Bypass -File $remote\\scripts\\install_restore_task.ps1 -Uninstall) else (echo Nothing is installed.)"
|
||||
|
|
|
|||
Loading…
Reference in a new issue