Skip to content

Commit b419ffa

Browse files
committed
feat: Refactor Tailscale deployment workflow to sanitize SSH target and simplify SSH command usage
1 parent fe2fe14 commit b419ffa

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

.github/workflows/deploy-tailscale.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,27 @@ jobs:
4242
echo "::error::TAILSCALE_SSH_TARGET contains unsupported characters" >&2
4343
exit 1
4444
fi
45-
echo "target=$target" >> "$GITHUB_OUTPUT"
46-
47-
- name: Configure SSH known hosts
48-
shell: bash
49-
run: |
50-
mkdir -p "$HOME/.ssh"
51-
touch "$HOME/.ssh/tailscale_known_hosts"
52-
chmod 600 "$HOME/.ssh/tailscale_known_hosts"
53-
echo "TAILSCALE_KNOWN_HOSTS=$HOME/.ssh/tailscale_known_hosts" >> "$GITHUB_ENV"
45+
user_prefix=""
46+
host_port="$target"
47+
if [[ "$host_port" == *@* ]]; then
48+
user_prefix="${host_port%%@*}@"
49+
host_port="${host_port#*@}"
50+
fi
51+
host_only="$host_port"
52+
port_suffix=""
53+
if [[ "$host_only" == *:* ]]; then
54+
host_only="${host_only%%:*}"
55+
port_suffix=":${host_port#*:}"
56+
fi
57+
while [[ "$host_only" == *"." ]] && [ -n "$host_only" ]; do
58+
host_only="${host_only%?}"
59+
done
60+
if [ -z "$host_only" ]; then
61+
echo "::error::TAILSCALE_SSH_TARGET host portion resolved to empty after sanitization" >&2
62+
exit 1
63+
fi
64+
sanitized_target="${user_prefix}${host_only}${port_suffix}"
65+
echo "target=$sanitized_target" >> "$GITHUB_OUTPUT"
5466
5567
- name: Validate deployment secrets
5668
run: |
@@ -66,16 +78,16 @@ jobs:
6678
- name: Test Tailscale connectivity
6779
run: |
6880
echo "Testing connection to target host..."
69-
tailscale ssh --ssh-flag "-oStrictHostKeyChecking=accept-new" --ssh-flag "-oUserKnownHostsFile=$TAILSCALE_KNOWN_HOSTS" "${{ steps.prepare.outputs.target }}" "echo 'Connected successfully' && whoami"
81+
tailscale ssh "${{ steps.prepare.outputs.target }}" "echo 'Connected successfully' && whoami"
7082
7183
- name: Deploy through Tailscale SSH
7284
run: |
7385
echo "🚀 Starting deployment..."
74-
tailscale ssh --ssh-flag "-oStrictHostKeyChecking=accept-new" --ssh-flag "-oUserKnownHostsFile=$TAILSCALE_KNOWN_HOSTS" "${{ steps.prepare.outputs.target }}" "${TAILSCALE_DEPLOY_COMMAND}"
86+
tailscale ssh "${{ steps.prepare.outputs.target }}" "${TAILSCALE_DEPLOY_COMMAND}"
7587
echo "✅ Deployment completed"
7688
7789
- name: Post-deployment verification (optional)
7890
if: success()
7991
run: |
8092
echo "Verifying deployment..."
81-
tailscale ssh --ssh-flag "-oStrictHostKeyChecking=accept-new" --ssh-flag "-oUserKnownHostsFile=$TAILSCALE_KNOWN_HOSTS" "${{ steps.prepare.outputs.target }}" "systemctl status your-app || echo 'Status command not available'"
93+
tailscale ssh "${{ steps.prepare.outputs.target }}" "systemctl status your-app || echo 'Status command not available'"

0 commit comments

Comments
 (0)