From 32517999f30e7a85a88c2ef047aa0b349e16332b Mon Sep 17 00:00:00 2001 From: Reditus <33814724+ReditusDraco@users.noreply.github.com> Date: Mon, 1 Jun 2026 05:47:04 +0100 Subject: [PATCH] fix: wrap Set-Acl in try/catch to avoid SeSecurityPrivilege error on SSH key rotate --- launcher.ps1 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/launcher.ps1 b/launcher.ps1 index 5360658..1c35afd 100644 --- a/launcher.ps1 +++ b/launcher.ps1 @@ -2821,13 +2821,17 @@ function Rotate-SSHKey { } else { Copy-Item $newestKey.Path $TargetKey -Force - $acl = Get-Acl $TargetKey - $acl.SetAccessRuleProtection($true, $false) - $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$env:USERNAME", "FullControl", "Allow") - $acl.SetAccessRule($rule) - $adminRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators", "FullControl", "Allow") - $acl.SetAccessRule($adminRule) - Set-Acl -Path $TargetKey -AclObject $acl + try { + $acl = Get-Acl $TargetKey -ErrorAction SilentlyContinue + if ($acl) { + $acl.SetAccessRuleProtection($true, $false) + $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$env:USERNAME", "FullControl", "Allow") + $acl.SetAccessRule($rule) + $adminRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators", "FullControl", "Allow") + $acl.SetAccessRule($adminRule) + Set-Acl -Path $TargetKey -AclObject $acl -ErrorAction SilentlyContinue + } + } catch {} Write-Host "" Write-Host " Rotated: $($newestKey.Path)" -ForegroundColor Green