Skip to content

Commit 8b60a76

Browse files
committed
fix(scripts): correct known_hosts validation logic
- Updated `check.sh` to verify that the SSH fingerprint exists in the `known_hosts` file using `grep`. - Adjusted `post_check.sh` to confirm the SSH fingerprint is removed from the `known_hosts` file after the job. - Added proper cleanup of `SSH_KNOWN_HOSTS_FILE` variable in both scripts for better environment management.
1 parent 726b8e3 commit 8b60a76

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

check.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env sh
22

3-
if [ ! -s "${HOME}/.ssh/known_hosts" ]; then
3+
SSH_KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts"
4+
5+
if ! grep -q "${SSH_KNOWN_HOSTS}" "${SSH_KNOWN_HOSTS_FILE}"; then
46
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
5-
~/.ssh/known_hosts is missing or empty."
7+
${SSH_KNOWN_HOSTS_FILE} file should contain the ssh fingerprint."
68
exit 1
7-
fi
9+
fi
10+
11+
unset SSH_KNOWN_HOSTS_FILE

post_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SSH_KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts"
44

5-
if ! grep -q "${SSH_KNOWN_HOSTS}" "${SSH_KNOWN_HOSTS_FILE}" ; then
5+
if grep -q "${SSH_KNOWN_HOSTS}" "${SSH_KNOWN_HOSTS_FILE}" ; then
66
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
77
${SSH_KNOWN_HOSTS_FILE} file should not contain the ssh fingerprint after the job."
88
exit 1

0 commit comments

Comments
 (0)