Skip to content

Commit

Permalink
less dirty hack
Browse files Browse the repository at this point in the history
Temporarily setting ErrorActionPreference to 'Continue' in order to avoid the following error that we also got with the entrypoint.ps1 script:

  [*] C:\Program Files\OpenSSH-Win64\moduli
Inheritance is removed from 'C:\Program Files\OpenSSH-Win64\moduli'.
'BUILTIN\Users' now has Read access to 'C:\Program Files\OpenSSH-Win64\moduli'.
      Repaired permissions

  [*] C:\ProgramData\ssh
Inheritance is removed from 'C:\ProgramData\ssh'.
New-Object: Exception calling ".ctor" with "5" argument(s): "The value '268435456' is not
valid for this usage of the type FileSystemRights. (Parameter
'fileSystemRights')"
MethodInvocationException: Exception calling "RemoveAccessRule" with "1" argument(s): "Value cannot be
null. (Parameter 'rule')"
'BUILTIN\Users' has no more access to 'C:\ProgramData\ssh'.
'BUILTIN\Users' has no more access to 'C:\ProgramData\ssh'.
      Repaired permissions

  [*] C:\ProgramData\ssh\sshd_config
Inheritance is removed from 'C:\ProgramData\ssh\sshd_config'.
      looks good

[SC] SetServiceObjectSecurity SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
sshd and ssh-agent services successfully installed
Updated Machine PATH to include OpenSSH directory, restart/re-login required to take effect globally
  • Loading branch information
lemeurherve committed Apr 29, 2024
1 parent 2f59fa5 commit 1239b46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 0 additions & 8 deletions entrypoint.ps1

This file was deleted.

9 changes: 5 additions & 4 deletions windows/nanoserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl
Expand-Archive c:/openssh.zip 'C:/Program Files' ; `
Remove-Item C:/openssh.zip ; `
$env:PATH = '{0};{1}' -f $env:PATH,'C:\Program Files\OpenSSH-Win64' ; `
& 'C:/Program Files/OpenSSH-Win64/Install-SSHd.ps1' ; `
if(!(Test-Path 'C:\ProgramData\ssh')) { New-Item -Type Directory -Path 'C:\ProgramData\ssh' | Out-Null } ; `
Copy-Item 'C:\Program Files\OpenSSH-Win64\sshd_config_default' 'C:\ProgramData\ssh\sshd_config' ; `
$content = Get-Content -Path "C:\ProgramData\ssh\sshd_config" ; `
Expand All @@ -111,7 +110,10 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value ('Match User {0}' -f $env:JENKINS_AGENT_USER) ; `
Add-Content -Path "C:\ProgramData\ssh\sshd_config" -Value (' AuthorizedKeysFile C:/Users/{0}/.ssh/authorized_keys' -f $env:JENKINS_AGENT_USER) ; `
New-Item -Path HKLM:\SOFTWARE -Name OpenSSH -Force | Out-Null ; `
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Program Files\Powershell\pwsh.exe' -PropertyType string -Force | Out-Null
New-ItemProperty -Path HKLM:\SOFTWARE\OpenSSH -Name DefaultShell -Value 'C:\Program Files\Powershell\pwsh.exe' -PropertyType string -Force | Out-Null ; `
$ErrorActionPreference = 'Continue' ; `
& 'C:\Program Files\OpenSSH-Win64\install-sshd.ps1' ; `
$ErrorActionPreference = 'Stop'

COPY CreateProfile.psm1 C:/

Expand All @@ -124,7 +126,6 @@ VOLUME "${JENKINS_AGENT_WORK}" "C:/Users/${user}/AppData/Local/Temp"
WORKDIR "${JENKINS_AGENT_WORK}"

COPY setup-sshd.ps1 C:/ProgramData/Jenkins/setup-sshd.ps1
COPY entrypoint.ps1 C:/ProgramData/Jenkins/entrypoint.ps1

EXPOSE 22

Expand All @@ -136,4 +137,4 @@ LABEL `
org.opencontainers.image.source="https://github.com/jenkinsci/docker-ssh-agent" `
org.opencontainers.image.licenses="MIT"

ENTRYPOINT ["pwsh.exe", "-NoExit", "-Command", "& C:/ProgramData/Jenkins/entrypoint.ps1"]
ENTRYPOINT ["pwsh.exe", "-NoExit", "-Command", "& C:/ProgramData/Jenkins/setup-sshd.ps1"]

0 comments on commit 1239b46

Please sign in to comment.