From 5f362ec7d389c93830e713c81fcea21e84c6bb17 Mon Sep 17 00:00:00 2001 From: hailt Date: Mon, 2 Nov 2026 11:10:14 +0700 Subject: [PATCH] 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. --- .github/workflows/cd.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c37ee2a..a7f680d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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