Skip to content

Start a reverse tunnel on the GitHub macos CI runner for debugging

mvgijssel edited this page May 26, 2020 · 1 revision
  1. Have a machine reachable (called remote machine from now on) on the internet on port 2022 for SSH
  2. Store the remote machine public ip as a GitHub secret called REMOTE_IP
  3. Store the remote machine public key, likely at ~/.ssh/id_rsa.pub, as a GitHub secret called REMOTE_PUBLIC_KEY
  4. Setup the following job as a GitHub workflow

.github/workflows/reverse_tunnel.yml

name: Reverse Tunnel
on: [push]
jobs:
  reverse_tunnel:
    name: Reverse Tunnel Job for debugging
    timeout-minutes: 120
    runs-on: macos-latest
    # install sshpass which allows you to pass password to ssh
    - run: brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

    # Enable remote access to the macos CI machine
    - run: sudo systemsetup -setremotelogin on

    # Add public key of remote machine to authorized_keys
    - run: echo $REMOTE_PUBLIC_KEY >> ~/.ssh/authorized_keys
      env:
        REMOTE_PUBLIC_KEY: ${{ secrets.REMOTE_PUBLIC_KEY }}

    # Set the correct permissions for the .ssh directory and authorized_keys
    - run: chmod 0644 ~/.ssh/authorized_keys
    - run: chmod 0700 ~/.ssh
    - run: ls -la ~/.ssh

    # Print current user information, use 
    - run: id

    # Start a reverse SSH tunnel to a remote box with username/password which listens to SSH on port 2022
    # The reverse tunnel will be started on port 19999 on the remote box.
    - run: sshpass -p vagrant ssh -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -T -R 19999:localhost:22 vagrant@$REMOTE_IP -p 2022 sleep 7200
      env:
        REMOTE_IP: ${{ secrets.REMOTE_IP }}
  1. Copy the CI runner username from the run: id step, likely will be runner
  2. On the remote machine start the SSH session
ssh <<<RUNNER USERNAME HERE>>>@localhost -p 19999