Compare commits

..
2 Commits
Author SHA1 Message Date
megamiley 994b093ada Merge pull request 'Fix SSH private key leaking into step logs' (#1) from fix/env-var-secret-leak into main
Reviewed-on: #1
2026-08-06 08:47:55 +00:00
Claude 89086c4163 Fix private key leaking into step logs
Composite actions substitute ${{ inputs.* }} directly into the run:
script source before execution, and the runner echoes that resolved
script at the top of the step log. Interpolating private_key and
transfers straight into the heredocs meant the raw SSH private key
was printed in plaintext on every run. Move both through env: and
reference them as shell variables instead, matching ssh-checkout and
ssh-command.
2026-08-06 08:47:21 +00:00
+22 -20
View File
@@ -25,48 +25,50 @@ runs:
steps: steps:
- name: Execute SSH/SCP Transfers - name: Execute SSH/SCP Transfers
shell: bash shell: bash
env:
PRIVATE_KEY: ${{ inputs.private_key }}
TRANSFERS: ${{ inputs.transfers }}
HOST: ${{ inputs.host }}
PORT: ${{ inputs.port }}
USERNAME: ${{ inputs.username }}
run: | run: |
# 1. Create a secure temporary file for the SSH key # 1. Create a secure temporary file for the SSH key
SSH_KEY_PATH=$(mktemp) SSH_KEY_PATH=$(mktemp)
cat << 'EOF' > "$SSH_KEY_PATH" printf '%s\n' "$PRIVATE_KEY" > "$SSH_KEY_PATH"
${{ inputs.private_key }}
EOF
chmod 600 "$SSH_KEY_PATH" chmod 600 "$SSH_KEY_PATH"
# 2. Add Host to known_hosts to prevent verification prompts # 2. Add Host to known_hosts to prevent verification prompts
mkdir -p ~/.ssh mkdir -p ~/.ssh
ssh-keyscan -p ${{ inputs.port }} -H ${{ inputs.host }} >> ~/.ssh/known_hosts 2>/dev/null ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts 2>/dev/null
# 3. Securely write transfers input to a file for parsing # 3. Securely write transfers input to a file for parsing
cat << 'EOF' > transfers.txt printf '%s\n' "$TRANSFERS" > transfers.txt
${{ inputs.transfers }}
EOF
# 4. Loop through each line and execute commands # 4. Loop through each line and execute commands
while IFS= read -r line || [ -n "$line" ]; do while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines # Skip empty lines
[[ -z "$(echo "$line" | tr -d '[:space:]')" ]] && continue [[ -z "$(echo "$line" | tr -d '[:space:]')" ]] && continue
# Parse using the pipe | delimiter # Parse using the pipe | delimiter
IFS='|' read -r src dest <<< "$line" IFS='|' read -r src dest <<< "$line"
# Trim leading and trailing whitespace # Trim leading and trailing whitespace
src=$(echo "$src" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') src=$(echo "$src" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
dest=$(echo "$dest" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') dest=$(echo "$dest" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -n "$src" ] && [ -n "$dest" ]; then if [ -n "$src" ] && [ -n "$dest" ]; then
echo "::group::Transfer to $dest" echo "::group::Transfer to $dest"
echo "Creating remote directory: $dest" echo "Creating remote directory: $dest"
ssh -i "$SSH_KEY_PATH" -p ${{ inputs.port }} ${{ inputs.username }}@${{ inputs.host }} "mkdir -p \"$dest\"" < /dev/null ssh -i "$SSH_KEY_PATH" -p "$PORT" "$USERNAME@$HOST" "mkdir -p \"$dest\"" < /dev/null
echo "Copying $src to $dest..." echo "Copying $src to $dest..."
# Note: eval is used so wildcards or multiple space-separated files expand properly # Note: eval is used so wildcards or multiple space-separated files expand properly
eval "scp -r -i \"$SSH_KEY_PATH\" -P ${{ inputs.port }} $src \"${{ inputs.username }}@${{ inputs.host }}:$dest/\"" < /dev/null eval "scp -r -i \"$SSH_KEY_PATH\" -P $PORT $src \"$USERNAME@$HOST:$dest/\"" < /dev/null
echo "::endgroup::" echo "::endgroup::"
fi fi
done < transfers.txt done < transfers.txt
# 5. Cleanup # 5. Cleanup
rm -f "$SSH_KEY_PATH" transfers.txt rm -f "$SSH_KEY_PATH" transfers.txt