Skip to content

Commit da23bbe

Browse files
committed
feat: windows desktop allow ssh to issue full admin token
Signed-off-by: Adrian Riobo <[email protected]>
1 parent 703a5b0 commit da23bbe

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/provider/azure/action/windows/rhqp-ci-setup.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule([Sys
9191
$acl.SetAccessRule($AccessRule)
9292
Set-Acl C:\Users\$user\.ssh\authorized_keys $acl
9393
Set-Acl -Path "C:\ProgramData\ssh\*key" $acl
94+
# Adminuser
95+
$adminKeysPath = "$env:ProgramData\ssh\administrators_authorized_keys"
96+
New-Item -ItemType Directory -Path (Split-Path $adminKeysPath) -Force | Out-Null
97+
if (-not (Test-Path $adminKeysPath)) {
98+
New-Item -ItemType File -Path $adminKeysPath -Force | Out-Null
99+
}
100+
Add-Content -Path $adminKeysPath -Value $authorizedKey
101+
$acl = Get-Acl $adminKeysPath
102+
$acl.SetOwner([System.Security.Principal.NTAccount] "Administrators")
103+
$acl.SetAccessRuleProtection($true, $false)
104+
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
105+
[System.Security.Principal.NTAccount] "Administrators",
106+
"FullControl",
107+
"Allow"
108+
)
109+
$acl.SetAccessRule($AccessRule)
110+
$AccessRuleSystem = New-Object System.Security.AccessControl.FileSystemAccessRule(
111+
[System.Security.Principal.NTAccount] "SYSTEM",
112+
"FullControl",
113+
"Allow"
114+
)
115+
$acl.AddAccessRule($AccessRuleSystem)
116+
Set-Acl -Path $adminKeysPath -AclObject $acl
117+
94118
# Create bat script to start sshd as a user process on startup
95119
# New-Item -Path "C:\Users\$Env:USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" -Name start-openssh.bat -ItemType "file" -Value 'powershell -command "sshd -f C:\ProgramData\ssh\sshd_config"'
96120
New-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp" -Name start-openssh.bat -ItemType "file" -Value 'powershell -command "sshd -f C:\ProgramData\ssh\sshd_config"'
@@ -112,6 +136,13 @@ curl.exe -LO https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/P
112136
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList '/qb /i PowerShell-7.4.2-win-x64.msi ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1' -wait
113137
# Set powershell as default shell on openssh
114138
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
139+
# Allow SSH to issue a full admin token
140+
New-ItemProperty `
141+
-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" `
142+
-Name "LocalAccountTokenFilterPolicy" `
143+
-Value 1 `
144+
-PropertyType DWord `
145+
-Force
115146

116147
# Remove curl alias
117148
$profilePath="C:\Users\$user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"

0 commit comments

Comments
 (0)