Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/actions/ssh-tunnel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: ssh-tunnel
description: SSH Reverse Tunnel

inputs:
public_key:
required: true
description: Public key to accept for reverse tunnel. Warning, this should not be the public key for the 'private_key' input.
offer:
required: true
description: RTC offer

runs:
using: composite
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install ssh
if: ${{ runner.os == 'Windows' }}
shell: powershell
run: |
python3.exe -m pip install requests
python3.exe installssh.py

- name: Start SSH
if: ${{ runner.os == 'Windows' }}
shell: powershell
run: |
Start-Service sshd

- name: Show sshd configuration
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
cat /etc/ssh/sshd_config
elif [ "$RUNNER_OS" == "macOS" ]; then
cat /private/etc/ssh/sshd_config
else
cat "C:\ProgramData\ssh\sshd_config"
fi

- name: Add ssh public key
shell: sh
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
mkdir -p /home/runner/.ssh
chmod 700 /home/runner/.ssh
touch /home/runner/.ssh/authorized_keys
echo "${{ inputs.public_key }}" | tee -a /home/runner/.ssh/authorized_keys
elif [ "$RUNNER_OS" == "macOS" ]; then
mkdir -p /Users/runner/.ssh
chmod 700 /Users/runner/.ssh
touch /Users/runner/.ssh/authorized_keys
echo "${{ inputs.public_key }}" | tee -a /Users/runner/.ssh/authorized_keys
else
echo "${{ inputs.public_key }}" | tee -a "C:\ProgramData\ssh\administrators_authorized_keys"
fi

- name: Create rtc tunnel
shell: bash
run: |
python3 -m pip install aiortc
echo '${{ inputs.offer }}' | python -m rtcforward --port 22 answer
44 changes: 44 additions & 0 deletions .github/actions/ssh-tunnel/installssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
"""

import pathlib
import subprocess
import zipfile

import requests

fwrule = """
New-NetFirewallRule `
-Name sshd `
-DisplayName 'OpenSSH SSH Server' `
-Enabled True `
-Direction Inbound `
-Protocol TCP `
-Action Allow `
-LocalPort 22 `
-Program "{}"
"""


def start_ssh_server():
"""
Pretty print the GH Actions event.
"""
resp = requests.get(
"https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.8.1.0p1-Preview/OpenSSH-Win64.zip",
allow_redirects=True,
)
with open("openssh.zip", "wb") as fp:
fp.write(resp.content)
with zipfile.ZipFile("openssh.zip") as fp:
fp.extractall()
install_script = pathlib.Path("./OpenSSH-Win64/install-sshd.ps1").resolve()
print(f"{install_script}")
subprocess.call(["powershell.exe", f"{install_script}"])
with open("fwrule.ps1", "w") as fp:
fp.write(fwrule.format(install_script.parent / "sshd.exe"))
subprocess.call(["powershell.exe", f"fwrule.ps1"])


if __name__ == "__main__":
start_ssh_server()
Loading
Loading