Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions modules/BOSH.SSH/BOSH.SSH.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ Describe "BOSH.SSH" {
Assert-VerifiableMock
}

It "calls Protect-Dir only after install-sshd.ps1 has run" {
$script:installRanFirst = $false
Mock -ModuleName BOSH.SSH Protect-Dir {
$script:installRanFirst = (Test-Path $INSTALL_SCRIPT_SPY_STATUS)
}

Install-SSHD -SSHZipFile $FAKE_ZIP

$script:installRanFirst | Should -Be $true
}

It "calls Invoke-CACL with expected files" {
Mock Invoke-CACL { } -Verifiable -ModuleName BOSH.SSH -ParameterFilter {
@(
Expand Down
21 changes: 16 additions & 5 deletions modules/BOSH.SSH/BOSH.SSH.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@
Move-Item -Force "$env:PROGRAMFILES\SSHTemp\OpenSSH-Win64" "$env:PROGRAMFILES\OpenSSH"
Remove-Item -Force "$env:PROGRAMFILES\SSHTemp"

# Remove users from 'OpenSSH' before installing. The install process
# will add back permissions for the NT AUTHORITY\Authenticated Users for some files
Protect-Dir -path "$env:PROGRAMFILES\OpenSSH"

# Run the OpenSSH service installer before locking down the directory.
# install-sshd.ps1 needs read access to its own files (the WinRM provisioning session
# runs with a UAC-filtered token where BUILTIN\Administrators is disabled, so only
# inherited permissions from C:\Program Files allow access at this point).
# The script also grants NT AUTHORITY\Authenticated Users on some files, which
# Protect-Dir will remove in the next step.
Push-Location "$env:PROGRAMFILES\OpenSSH"
powershell -ExecutionPolicy Bypass -File install-sshd.ps1
if ($LASTEXITCODE -ne 0)
{
throw "install-sshd.ps1 exited with $LASTEXITCODE"
}
Pop-Location

# # Grant NT AUTHORITY\Authenticated Users access to .EXEs and the .DLL in OpenSSH
# Lock down the directory now that the service installer has completed.
# This removes all inherited ACEs (including Authenticated Users added by the
# installer) and leaves only SYSTEM and Administrators with full control.
Protect-Dir -path "$env:PROGRAMFILES\OpenSSH"

# Grant NT AUTHORITY\Authenticated Users read access to .EXEs and the .DLL in OpenSSH
$FileNames = @(
"libcrypto.dll",
"scp.exe",
Expand Down
Loading