Skip to content

Commit 4a19d20

Browse files
committed
ssh tunnel
0 parents  commit 4a19d20

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Josh Larsen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

action.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Setup ngrok Tunnel
2+
description: Establishes an ngrok tunnel to the GitHub Action runner for debugging
3+
4+
branding:
5+
icon: minimize-2
6+
color: purple
7+
8+
inputs:
9+
timeout:
10+
description: Tunnel timeout
11+
required: true
12+
default: 1h
13+
port:
14+
description: Local port to forward to
15+
required: true
16+
default: 22
17+
ssh_public_key:
18+
description: Your SSH public key
19+
required: true
20+
default: 'ssh-rsa AAAA...YOUR_SSH_PUBLIC_KEY.... me@localhost'
21+
ngrok_token:
22+
description: Your ngrok auth token
23+
24+
runs:
25+
using: composite
26+
steps:
27+
- name: Download ngrok
28+
run: curl -sO https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
29+
shell: bash
30+
- name: Unzip ngrok
31+
run: unzip ngrok-stable-linux-amd64.zip
32+
shell: bash
33+
- name: Add ~/.ssh directory
34+
run: mkdir ~/.ssh
35+
shell: bash
36+
- name: Add SSH public key to authorized_keys
37+
run: echo "${{ inputs.ssh_public_key }}" >> ~/.ssh/authorized_keys
38+
shell: bash
39+
- name: Fix home directory permissions
40+
run: chmod 755 ~
41+
shell: bash
42+
- run: chmod 600 ~/.ssh/authorized_keys
43+
shell: bash
44+
- name: Set ngrok auth token
45+
run: ./ngrok authtoken ${{ inputs.ngrok_token }}
46+
shell: bash
47+
- name: Debug message
48+
run: echo "Starting ngrok tunnel..."
49+
shell: bash
50+
- name: Setup ngrok tunnel
51+
run: timeout ${{ inputs.timeout }} ./ngrok tcp ${{ inputs.port }}
52+
shell: bash

readme.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## GitHub Action SSH Tunnel via ngrok
2+
3+
A GitHub Action for connecting to the runner via SSH.
4+
5+
### Why?
6+
7+
Debugging GitHub Actions remotely can be difficult. Maybe you want to connect to the runner environment live to troubleshoot.
8+
9+
### Requirements
10+
11+
1. An [ngrok](https://ngrok.com/) account (free)
12+
2. An SSH public key (e.g. `/.ssh/id_rsa.pub`)
13+
14+
### Compatibility
15+
16+
This Action was only tested on the **Ubuntu 20.04** runner, but it may work on other Linux based runners.
17+
18+
### Setup
19+
20+
Create a YAML workflow (e.g. `ssh.yml`) in `.github/workflows` following this example:
21+
22+
```yaml
23+
name: SSH Tunnel
24+
on: push
25+
26+
jobs:
27+
deploy:
28+
name: Set up tunnel
29+
runs-on: ubuntu-20.04
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
34+
- name: Setup tunnel
35+
uses: joshlarsen/ssh-tunnel-action@main
36+
with:
37+
timeout: 1h
38+
ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }}
39+
ngrok_token: ${{ secrets.NGROK_TOKEN }}
40+
```
41+
42+
### Required Secrets
43+
44+
Create two repository secrets (Settings -> Secrets -> New repository secret)
45+
46+
`SSH_PUBLIC_KEY`: your local SSH public key (e.g. `~/.ssh/id_rsa.pub`)
47+
48+
`NGROK_TOKEN`: your ngrok auth token
49+
50+
### Deploy
51+
52+
On the next push, GitHub Actions will download the ngrok binary and set up a TLS tunnel on a random port. Check the [ngrok dashboard](https://dashboard.ngrok.com/status/tunnels) to get the hostname and port the tunnel is listening on.
53+
54+
![ngrok tunnels](https://user-images.githubusercontent.com/2565382/108560004-179c1f80-72ca-11eb-8fb1-92436b1e9024.png)
55+
56+
### Connect via SSH
57+
58+
The runner username is `runner`. Connect to the ngrok tunnel port using SSH:
59+
60+
```
61+
$ ssh -p 11785 [email protected]
62+
63+
The authenticity of host '[0.tcp.ngrok.io]:11785 ([3.134.39.220]:11785)' can't be established.
64+
ECDSA key fingerprint is SHA256:f27aouAtzHOx7rzEnrGUfKy9xhpFK5auzq6+ZY.
65+
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
66+
Warning: Permanently added '[0.tcp.ngrok.io]:11785,[3.134.39.220]:11785' (ECDSA) to the list of known hosts.
67+
68+
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-1039-azure x86_64)
69+
70+
System load: 0.0 Processes: 153
71+
Usage of /: 75.5% of 83.18GB Users logged in: 0
72+
Memory usage: 10% IPv4 address for docker0: 172.17.0.1
73+
Swap usage: 0% IPv4 address for eth0: 10.1.0.4
74+
75+
runner@fv-az214-809:~$
76+
runner@fv-az214-809:~$ curl ipinfo.io
77+
{
78+
"ip": "52.173.149.212",
79+
"city": "Des Moines",
80+
"region": "Iowa",
81+
"country": "US",
82+
"loc": "41.5878,-93.6274",
83+
"org": "AS8075 Microsoft Corporation",
84+
"postal": "50392",
85+
"timezone": "America/Chicago",
86+
"readme": "https://ipinfo.io/missingauth"
87+
}
88+
runner@fv-az214-809:~$
89+
```

0 commit comments

Comments
 (0)