From f3307d964cdfd5e09ebf5efbc6cc0214b4dd7143 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Mon, 4 Sep 2017 17:33:21 -0300 Subject: [PATCH] Change SSH container to use SSH remoting --- Dockerfile.ssh | 13 ++++++++++--- connect.ps1 | 26 ++++++++++++++++++++++++++ ssh_config | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 connect.ps1 create mode 100644 ssh_config diff --git a/Dockerfile.ssh b/Dockerfile.ssh index 215b3d8..ac00d53 100644 --- a/Dockerfile.ssh +++ b/Dockerfile.ssh @@ -1,7 +1,14 @@ -FROM alpine +FROM ubuntu:16.04 -RUN apk add --no-cache openssh-client +RUN apt update \ + && apt install -y wget openssh-client \ + && wget -O powershell.deb https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.6/powershell_6.0.0-beta.6-1ubuntu1.16.04.1_amd64.deb \ + && dpkg -i powershell.deb; apt install -yf \ + && rm -f powershell.deb COPY ./windows /root/.ssh/id_rsa +COPY ./ssh_config /root/.ssh/config +COPY ./connect.ps1 / -CMD trap '' INT TSTP; while true; do ssh -t -L 2375:${WINDOWS_ENDPOINT}:2375 -q -o StrictHostKeyChecking=no Administrator@${WINDOWS_ENDPOINT} powershell; done + +CMD powershell -NoExit -File /connect.ps1 -endpoint ${WINDOWS_ENDPOINT} diff --git a/connect.ps1 b/connect.ps1 new file mode 100644 index 0000000..0bc3863 --- /dev/null +++ b/connect.ps1 @@ -0,0 +1,26 @@ +Param( + [Parameter(Mandatory=$True)] + [string]$endpoint +) + +function RegisterEvent { + if ($event) { + Unregister-Event $event + } + ($global:event = Register-ObjectEvent -InputObject $session.Runspace -EventName AvailabilityChanged -Action { + if ($session.State -eq "Broken") { + $global:session = New-PSSession -HostName $endpoint -UserName Administrator + RegisterEvent + } + if ($Host.Runspace -ne $session.Runspace) { + Enter-PSSession $session + } + }) | Out-Null +} + + +$global:session = New-PSSession -HostName $endpoint -UserName Administrator +Enter-PSSession $session +RegisterEvent + + diff --git a/ssh_config b/ssh_config new file mode 100644 index 0000000..f30d239 --- /dev/null +++ b/ssh_config @@ -0,0 +1,2 @@ +Host * + StrictHostKeyChecking no