|
| 1 | +name: RDP |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + secure-rdp: |
| 8 | + runs-on: windows-latest |
| 9 | + timeout-minutes: 3600 |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Configure Core RDP Settings |
| 13 | + run: | |
| 14 | + # Enable Remote Desktop and disable Network Level Authentication (if needed) |
| 15 | + Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' ` |
| 16 | + -Name "fDenyTSConnections" -Value 0 -Force |
| 17 | + Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' ` |
| 18 | + -Name "UserAuthentication" -Value 0 -Force |
| 19 | + Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' ` |
| 20 | + -Name "SecurityLayer" -Value 0 -Force |
| 21 | +
|
| 22 | + # Remove any existing rule with the same name to avoid duplication |
| 23 | + netsh advfirewall firewall delete rule name="RDP-Tailscale" |
| 24 | + |
| 25 | + # For testing, allow any incoming connection on port 3389 |
| 26 | + netsh advfirewall firewall add rule name="RDP-Tailscale" ` |
| 27 | + dir=in action=allow protocol=TCP localport=3389 |
| 28 | +
|
| 29 | + # (Optional) Restart the Remote Desktop service to ensure changes take effect |
| 30 | + Restart-Service -Name TermService -Force |
| 31 | +
|
| 32 | + - name: Create RDP User with Secure Password |
| 33 | + run: | |
| 34 | + Add-Type -AssemblyName System.Security |
| 35 | + $charSet = @{ |
| 36 | + Upper = [char[]](65..90) # A-Z |
| 37 | + Lower = [char[]](97..122) # a-z |
| 38 | + Number = [char[]](48..57) # 0-9 |
| 39 | + Special = ([char[]](33..47) + [char[]](58..64) + |
| 40 | + [char[]](91..96) + [char[]](123..126)) # Special characters |
| 41 | + } |
| 42 | + $rawPassword = @() |
| 43 | + $rawPassword += $charSet.Upper | Get-Random -Count 4 |
| 44 | + $rawPassword += $charSet.Lower | Get-Random -Count 4 |
| 45 | + $rawPassword += $charSet.Number | Get-Random -Count 4 |
| 46 | + $rawPassword += $charSet.Special | Get-Random -Count 4 |
| 47 | + $password = -join ($rawPassword | Sort-Object { Get-Random }) |
| 48 | + $securePass = ConvertTo-SecureString $password -AsPlainText -Force |
| 49 | + New-LocalUser -Name "RDP" -Password $securePass -AccountNeverExpires |
| 50 | + Add-LocalGroupMember -Group "Administrators" -Member "RDP" |
| 51 | + Add-LocalGroupMember -Group "Remote Desktop Users" -Member "RDP" |
| 52 | + |
| 53 | + echo "RDP_CREDS=User: RDP | Password: $password" >> $env:GITHUB_ENV |
| 54 | + |
| 55 | + if (-not (Get-LocalUser -Name "RDP")) { |
| 56 | + Write-Error "User creation failed" |
| 57 | + exit 1 |
| 58 | + } |
| 59 | +
|
| 60 | + - name: Install Tailscale |
| 61 | + run: | |
| 62 | + $tsUrl = "https://pkgs.tailscale.com/stable/tailscale-setup-1.82.0-amd64.msi" |
| 63 | + $installerPath = "$env:TEMP\tailscale.msi" |
| 64 | + |
| 65 | + Invoke-WebRequest -Uri $tsUrl -OutFile $installerPath |
| 66 | + Start-Process msiexec.exe -ArgumentList "/i", "`"$installerPath`"", "/quiet", "/norestart" -Wait |
| 67 | + Remove-Item $installerPath -Force |
| 68 | +
|
| 69 | + - name: Establish Tailscale Connection |
| 70 | + run: | |
| 71 | + # Bring up Tailscale with the provided auth key and set a unique hostname |
| 72 | + & "$env:ProgramFiles\Tailscale\tailscale.exe" up --authkey=${{ secrets.TAILSCALE_AUTH_KEY }} --hostname=gh-runner-$env:GITHUB_RUN_ID |
| 73 | + |
| 74 | + # Wait for Tailscale to assign an IP |
| 75 | + $tsIP = $null |
| 76 | + $retries = 0 |
| 77 | + while (-not $tsIP -and $retries -lt 10) { |
| 78 | + $tsIP = & "$env:ProgramFiles\Tailscale\tailscale.exe" ip -4 |
| 79 | + Start-Sleep -Seconds 5 |
| 80 | + $retries++ |
| 81 | + } |
| 82 | + |
| 83 | + if (-not $tsIP) { |
| 84 | + Write-Error "Tailscale IP not assigned. Exiting." |
| 85 | + exit 1 |
| 86 | + } |
| 87 | + echo "TAILSCALE_IP=$tsIP" >> $env:GITHUB_ENV |
| 88 | + |
| 89 | + - name: Verify RDP Accessibility |
| 90 | + run: | |
| 91 | + Write-Host "Tailscale IP: $env:TAILSCALE_IP" |
| 92 | + |
| 93 | + # Test connectivity using Test-NetConnection against the Tailscale IP on port 3389 |
| 94 | + $testResult = Test-NetConnection -ComputerName $env:TAILSCALE_IP -Port 3389 |
| 95 | + if (-not $testResult.TcpTestSucceeded) { |
| 96 | + Write-Error "TCP connection to RDP port 3389 failed" |
| 97 | + exit 1 |
| 98 | + } |
| 99 | + Write-Host "TCP connectivity successful!" |
| 100 | +
|
| 101 | + - name: Maintain Connection |
| 102 | + run: | |
| 103 | + Write-Host "`n=== RDP ACCESS ===" |
| 104 | + Write-Host "Address: $env:TAILSCALE_IP" |
| 105 | + Write-Host "Username: RDP" |
| 106 | + Write-Host "Password: $(echo $env:RDP_CREDS)" |
| 107 | + Write-Host "==================`n" |
| 108 | + |
| 109 | + # Keep runner active indefinitely (or until manually cancelled) |
| 110 | + while ($true) { |
| 111 | + Write-Host "[$(Get-Date)] RDP Active - Use Ctrl+C in workflow to terminate" |
| 112 | + Start-Sleep -Seconds 300 |
| 113 | + } |
0 commit comments