fix: identify APT local-file handoff failure and verify Windows admin tunnel
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -5,14 +5,14 @@ param([switch]$MaintainTunnel)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$statePath = Join-Path $env:ProgramData 'RmmDevAccess'
|
||||
|
||||
function Protect-AdminFile([string]$Path) {
|
||||
function Protect-AdminFile([string]$Path, [switch]$SystemOwner) {
|
||||
$directory = (Get-Item -LiteralPath $Path).PSIsContainer
|
||||
if ($directory) { $acl = New-Object Security.AccessControl.DirectorySecurity }
|
||||
else { $acl = New-Object Security.AccessControl.FileSecurity }
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$admins = New-Object Security.Principal.SecurityIdentifier 'S-1-5-32-544'
|
||||
$system = New-Object Security.Principal.SecurityIdentifier 'S-1-5-18'
|
||||
$acl.SetOwner($admins)
|
||||
if ($SystemOwner) { $acl.SetOwner($system) } else { $acl.SetOwner($admins) }
|
||||
foreach ($sid in @($admins, $system)) {
|
||||
if ($directory) {
|
||||
$rule = New-Object Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
|
||||
@@ -109,19 +109,24 @@ Add-LocalGroupMember -Group $adminGroup -Member $account
|
||||
|
||||
$sshData = Join-Path $env:ProgramData 'ssh'
|
||||
[void](New-Item -ItemType Directory -Path $sshData -Force)
|
||||
Protect-AdminFile $sshData -SystemOwner
|
||||
$sshdConfig = Join-Path $sshData 'sshd_config'
|
||||
if (Test-Path -LiteralPath $sshdConfig) { Copy-Item -LiteralPath $sshdConfig -Destination (Join-Path $statePath 'sshd_config.before') }
|
||||
$authorized = Join-Path $sshData 'administrators_authorized_keys'
|
||||
if (Test-Path -LiteralPath $authorized) { Copy-Item -LiteralPath $authorized -Destination (Join-Path $statePath 'administrators_authorized_keys.before') }
|
||||
Write-Utf8 $authorized ($config.notebook_public_key + "`n"); Protect-AdminFile $authorized
|
||||
Write-Utf8 $authorized ($config.notebook_public_key + "`n"); Protect-AdminFile $authorized -SystemOwner
|
||||
$serverConfig = @('Port 22222', 'ListenAddress 127.0.0.1', 'PubkeyAuthentication yes',
|
||||
'PasswordAuthentication no', 'AuthenticationMethods publickey', 'AllowUsers rmm-dev',
|
||||
'AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys',
|
||||
'AllowTcpForwarding no', 'AllowAgentForwarding no', 'PermitTTY yes',
|
||||
'Subsystem sftp sftp-server.exe') -join "`n"
|
||||
Write-Utf8 $sshdConfig ($serverConfig + "`n"); Protect-AdminFile $sshdConfig
|
||||
Write-Utf8 $sshdConfig ($serverConfig + "`n"); Protect-AdminFile $sshdConfig -SystemOwner
|
||||
& $keygen -A | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw 'SSH host key generation failed' }
|
||||
foreach ($name in @('ssh_host_rsa_key', 'ssh_host_ecdsa_key', 'ssh_host_ed25519_key')) {
|
||||
$hostPrivatePath = Join-Path $sshData $name
|
||||
if (Test-Path -LiteralPath $hostPrivatePath) { Protect-AdminFile $hostPrivatePath -SystemOwner }
|
||||
}
|
||||
& (Join-Path $sshDirectory 'sshd.exe') -t
|
||||
if ($LASTEXITCODE -ne 0) { throw 'SSH configuration rejected; retained files require inspection' }
|
||||
[void](New-Item -Path 'HKLM:\SOFTWARE\OpenSSH' -Force)
|
||||
|
||||
Reference in New Issue
Block a user