Skip to content

Instantly share code, notes, and snippets.

@thom-vend
Last active November 15, 2022 22:18
Show Gist options
  • Save thom-vend/d09763efee62972355c4489234e43c77 to your computer and use it in GitHub Desktop.
Save thom-vend/d09763efee62972355c4489234e43c77 to your computer and use it in GitHub Desktop.

Debug your github action build via ssh

  • Store action.yml into .github/actions/debugviassh/action.yml
  • Add your ngrok.com token in an env var NGROK_TOKEN
  • Add your public ssh key in another env var SSH_PUBLIC_KEY
  • Add the action call in your workflow where you want to stop and get ssh access
  • Find host/port to connect in https://dashboard.ngrok.com/cloud-edge/endpoints
  • ssh -l runner -p $ngrok_port $ngrok_host

note:

  • eventually resolve manually the ngrok dns if it's blocked using dig dig -t A $ngrokhost +short @1.1.1.1
  • ssh username is runner on official runner or could be anything like ubuntu,debian,etc on self hosted

source (wasn't working out of the box): https://github.com/marketplace/actions/ssh-tunnel-over-ngrok

Action usage to be added in .github/workflows/${your-workflow-name}.yml

      - name: Setup SSH tunnel
        uses: "./.github/actions/debugviassh"
        with:
          timeout: 2h
          ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }}
          ngrok_token: ${{ secrets.NGROK_TOKEN }}
---
# .github/actions/debugviassh/action.yml
name: SSH tunnel over ngrok
description: Establishes an ngrok tunnel to the GitHub Action runner for debugging
branding:
icon: minimize-2
color: purple
inputs:
timeout:
description: Tunnel timeout
required: true
default: 1h
port:
description: Local port to forward to
required: true
default: 22
ssh_public_key:
description: Your SSH public key
required: true
ngrok_token:
description: Your ngrok auth token
required: true
runs:
using: composite
steps:
- name: Download ngrok
run: curl -sO https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
shell: bash
- name: Unzip ngrok
run: unzip ngrok-stable-linux-amd64.zip
shell: bash
- name: Add ~/.ssh directory
run: mkdir -p ~/.ssh
shell: bash
- name: Add SSH public key to authorized_keys
run: echo "${{ inputs.ssh_public_key }}" >> ~/.ssh/authorized_keys
shell: bash
- name: Fix home directory permissions
run: chmod 755 ~
shell: bash
- run: chmod 600 ~/.ssh/authorized_keys
shell: bash
- name: Set ngrok auth token
run: ./ngrok authtoken "${{ inputs.ngrok_token }}"
shell: bash
- name: Debug message
run: echo "Starting ngrok tunnel..."
shell: bash
- name: Setup ngrok tunnel
run: timeout ${{ inputs.timeout }} ./ngrok tcp ${{ inputs.port }}
shell: bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment