Skip to content

Commit b7a8917

Browse files
authored
Merge branch 'master' into revert-495-helpesk4557-disable-failing-test-for-now
2 parents 93ae985 + 2ab6cba commit b7a8917

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

alpine/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ RUN apk add --no-cache \
8888
musl-locales \
8989
netcat-openbsd \
9090
openssh \
91-
patch
91+
patch \
92+
# Cleanup SSH host keys if any
93+
&& rm -f /etc/ssh/ssh_host*_key*
9294

9395
# setup SSH server
9496
RUN sed -i /etc/ssh/sshd_config \

debian/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ RUN apt-get update \
8787
netcat-traditional \
8888
openssh-server \
8989
patch \
90-
&& rm -rf /var/lib/apt/lists/*
90+
# Cleanup APT cache
91+
&& rm -rf /var/lib/apt/lists/* \
92+
# Cleanup SSH host keys if any
93+
&& rm -f /etc/ssh/ssh_host*_key*
9194

9295
# setup SSH server
9396
RUN sed -i /etc/ssh/sshd_config \

tests/sshAgent.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ Describe "[$global:IMAGE_NAME] image has setup-sshd.ps1 in the correct location"
8686
}
8787
}
8888

89+
Describe "[$global:IMAGE_NAME] image has no pre-existing SSH host keys" {
90+
BeforeAll {
91+
$exitCode, $stdout, $stderr = Run-Program 'docker' "run --detach --tty --name=`"$global:CONTAINERNAME`" --publish-all `"$global:IMAGE_NAME`" `"$global:CONTAINERSHELL`""
92+
$exitCode | Should -Be 0
93+
Is-ContainerRunning $global:CONTAINERNAME | Should -BeTrue
94+
}
95+
96+
It 'has has no SSH host key present in C:\ProgramData\ssh' {
97+
$exitCode, $stdout, $stderr = Run-Program 'docker' "exec $global:CONTAINERNAME $global:CONTAINERSHELL -C `"if(Test-Path C:/ProgramData/ssh/ssh_host*_key*) { exit 0 } else { exit 1 }`""
98+
$exitCode | Should -Be 1
99+
}
100+
101+
AfterAll {
102+
Cleanup($global:CONTAINERNAME)
103+
}
104+
}
105+
89106
Describe "[$global:IMAGE_NAME] checking image metadata" {
90107
It 'has correct volumes' {
91108
$exitCode, $stdout, $stderr = Run-Program 'docker' "inspect --format '{{.Config.Volumes}}' $global:IMAGE_NAME"

tests/tests.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ docker_run_opts=('--detach' '--publish-all' '--health-cmd=echo | nc -w1 localhos
5252
clean_test_container "${test_container_name}"
5353
}
5454

55+
@test "[${SUT_IMAGE}] image has no pre-existing SSH host keys" {
56+
local test_container_name=${AGENT_CONTAINER}-ssh-hostkeys
57+
clean_test_container "${test_container_name}"
58+
docker run --name="${test_container_name}" --name="${test_container_name}" "${docker_run_opts[@]}" "${PUBLIC_SSH_KEY}"
59+
60+
run docker exec "${test_container_name}" ls -l /etc/ssh/ssh_host*_key*
61+
assert_failure
62+
63+
clean_test_container "${test_container_name}"
64+
}
65+
5566
@test "[${SUT_IMAGE}] create agent container with pubkey as argument" {
5667
local test_container_name=${AGENT_CONTAINER}-pubkey-arg
5768
clean_test_container "${test_container_name}"

windows/nanoserver/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl
124124
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value ('Match User {0}' -f $env:JENKINS_AGENT_USER) ; `
125125
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value (' AuthorizedKeysFile C:/Users/{0}/.ssh/authorized_keys' -f $env:JENKINS_AGENT_USER) ; `
126126
New-Item -Path HKLM:\SOFTWARE -Name OpenSSH -Force | Out-Null ; `
127-
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Program Files\Powershell\pwsh.exe' -PropertyType string -Force | Out-Null
127+
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Program Files\Powershell\pwsh.exe' -PropertyType string -Force | Out-Null ; `
128+
Remove-Item -Path "C:\ProgramData\ssh\ssh_host*_key*
128129
129130
COPY CreateProfile.psm1 C:/
130131

windows/windowsservercore/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl
110110
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value ('Match User {0}' -f $env:JENKINS_AGENT_USER) ; `
111111
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value (' AuthorizedKeysFile C:/Users/{0}/.ssh/authorized_keys' -f $env:JENKINS_AGENT_USER) ; `
112112
New-Item -Path HKLM:\SOFTWARE -Name OpenSSH -Force | Out-Null ; `
113-
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -PropertyType string -Force | Out-Null
113+
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -PropertyType string -Force | Out-Null ; `
114+
Remove-Item -Path "C:\ProgramData\ssh\ssh_host*_key*"
114115

115116
COPY CreateProfile.psm1 C:/
116117

0 commit comments

Comments
 (0)