Skip to content

opendi/action-sshd-cloudflared

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘©β€πŸ’» action-sshd-cloudflared

GitHub Action to debug via SSH over a Cloudflare Tunnel.

Overview

This GitHub Action starts an ad hoc SSH server (inspired by sshd on the go), and creates a Cloudflare Tunnel to expose it (because we can't directly open ports on a public IP address from the runner VM).

Then by using the cloudflared command you can bind that tunnel to a local port and SSH there.

It's similar to the debugging with SSH action (action-upterm), but instead of using Upterm, it's simply backed by /usr/sbin/sshd, cloudflared and 100 lines of commented shell script.

The main difference is that the community uptermd server on uptermd.upterm.dev (the default if you don't specify your own server) technically has full visibility on your unencrypted SSH traffic, whereas thanks to cloudflared allowing to tunnel raw TCP traffic, action-sshd-cloudflared is end-to-end encrypted.

Usage

name: CI
on:
  - push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: valeriangalliat/action-sshd-cloudflared@v1

Example output:

Downloading `cloudflared` from <https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64>...
Configured SSH key(s) for user: valeriangalliat
Creating SSH server key...
Creating SSH server config...
Starting SSH server...
Starting tmux session...
Starting Cloudflare tunnel...

Run the following command to connect:

    ssh-keygen -R action-sshd-cloudflared && echo 'action-sshd-cloudflared ssh-rsa (public key goes here)' >> ~/.ssh/known_hosts && ssh -o ProxyCommand='cloudflared access tcp --hostname https://recycling-currently-enjoy-pregnant.trycloudflare.com' runner@action-sshd-cloudflared

What the one-liner does:

    # Remove old SSH server public key for `action-sshd-cloudflared`
    ssh-keygen -R action-sshd-cloudflared

    # Trust the public key for this session
    echo 'action-sshd-cloudflared ssh-rsa (public key goes here)' >> ~/.ssh/known_hosts

    # Connect using `cloudflared` as a transport (SSH is end-to-end encrpted over this tunnel)
    ssh -o ProxyCommand='cloudflared access tcp --hostname https://recycling-currently-enjoy-pregnant.trycloudflare.com' runner@action-sshd-cloudflared

    # Alternative if you don't want to verify the host key
    ssh -o ProxyCommand='cloudflared access tcp --hostname https://recycling-currently-enjoy-pregnant.trycloudflare.com' -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new runner@action-sshd-cloudflared

You can download cloudflared from here or here.

When logging in, you'll be automatically attached to a tmux session. Whenever you exit the session, the action will stop the tunnel and SSH server and continue its steps.

More details

If you want to know everything about this program, you can read the detailed blog posts I wrote about the client and server parts of action-sshd-cloudflared. Enjoy!

Troubleshooting

GitHub Action hangs without logs

All you see in your workflow output is the SSH step running but you can't expand the live logs.

Step with unavailable logs

This is quite annoying because the logs is where we output the host to connect to. 😬

This is a recurring bug with GitHub Actions: if you open the action logs page after the step started running, it won't be able to show logs until the command completes. Or if you're lucky it will show logs from the moment you "joined", but that might not include the part you want to see like the SSH host.

This is more likely to happen if this is one of the first actions in your workflow.

At that point you need to cancel the action and restart it, making sure to open the logs right away, and reload the page aggressively in the beginning before a runner was found, e.g. when you see this:

Waiting for a runner to pick up this job...
Job is waiting for a hosted runner to come online.

If you want to add a bit of a delay to get a chance to catch the logs in time, you can add the following in your steps:

      - run: sleep 5

About

GitHub Action to debug via SSH over a Cloudflare Tunnel. πŸ‘©β€πŸ’»

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%