Skip to content

Commit 8c0eb53

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 6a9ff81 commit 8c0eb53

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.github/workflows/pull_request.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ jobs:
1414
runs-on: ${{ matrix.os }}
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17-
- name: Setup SSH key
18-
uses: ./
19-
with:
20-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
21-
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
22-
log-public-key: false
2317
- name: Check known hosts file
2418
uses: pyTooling/Actions/with-post-step@9ceefdbf5dceae8c441fc393ed82344c7ca8bbdb # v3.1.1
2519
env:
@@ -29,6 +23,12 @@ jobs:
2923
sh check.sh
3024
post: |
3125
sh post_check.sh
26+
- name: Setup SSH key
27+
uses: ./
28+
with:
29+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
30+
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
31+
log-public-key: false
3232
- name: Install docker (Missing on MacOS)
3333
if: runner.os == 'macos'
3434
shell: bash

action.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ inputs:
3535
runs:
3636
using: 'composite'
3737
steps:
38-
- uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0
39-
with:
40-
ssh-private-key: ${{ inputs.ssh-private-key }}
41-
ssh-auth-sock: ${{ inputs.ssh-auth-sock }}
42-
log-public-key: ${{ inputs.log-public-key }}
43-
ssh-agent-cmd: ${{ inputs.ssh-agent-cmd }}
44-
ssh-add-cmd: ${{ inputs.ssh-add-cmd }}
45-
git-cmd: ${{ inputs.git-cmd }}
4638
- uses: pyTooling/Actions/with-post-step@9ceefdbf5dceae8c441fc393ed82344c7ca8bbdb # v3.1.1
4739
env:
4840
SSH_HOST: ${{ inputs.ssh-host }}
@@ -53,6 +45,14 @@ runs:
5345
sh "${{ github.action_path }}/action.sh"
5446
post: |
5547
sh "${{ github.action_path }}/post_action.sh"
48+
- uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0
49+
with:
50+
ssh-private-key: ${{ inputs.ssh-private-key }}
51+
ssh-auth-sock: ${{ inputs.ssh-auth-sock }}
52+
log-public-key: ${{ inputs.log-public-key }}
53+
ssh-agent-cmd: ${{ inputs.ssh-agent-cmd }}
54+
ssh-add-cmd: ${{ inputs.ssh-add-cmd }}
55+
git-cmd: ${{ inputs.git-cmd }}
5656
branding:
5757
icon: loader
5858
color: 'purple'

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)