fix: normalize CD ssh key with literal backslash-n

Secret paste dang 1 dong voi backslash-n chu (thay vi newline that) lam key hong. Tu dung lai newline, giu nguyen dang chuan, validate bang ssh-keygen -lf.
This commit is contained in:
hailt 2026-11-02 11:10:14 +07:00
parent 8ce9a600dd
commit 5f362ec7d3

View file

@ -51,8 +51,17 @@ jobs:
run: |
set -euo pipefail
install -m 700 -d ~/.ssh
# Loc ky tu CR (secret paste tu Windows/chat hay dinh CRLF lam hong key).
printf '%s\n' "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_ed25519
# Chuan hoa secret truoc khi ghi key:
# - Loc ky tu CR (paste tu Windows/chat hay dinh CRLF).
# - Neu secret bi paste dang 1 dong voi \n chu (thay vi xuong
# dong that) thi dung lai newline that.
KEY="$SSH_PRIVATE_KEY"
if [ "$(printf '%s' "$KEY" | wc -l)" -eq 0 ]; then
case "$KEY" in
*\\n*) KEY="$(printf '%b' "$KEY")" ;;
esac
fi
printf '%s\n' "$KEY" | tr -d '\r' > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
# Fail som neu key hong: in armor + fingerprint (khong lo secret) de doi chieu.
head -n 1 ~/.ssh/id_ed25519