Skip to content

Commit fc83a27

Browse files
Run as NETWORK SERVICE on Windows
Having the runner run as the SYSTEM account causes a bunch of weird issues because it's profile directory is under C:\Windows\System32 which is subject to WoW64 folder redirection. When registered using config.cmd actions-runner registers the service to run as NT AUTHORITY\NETWORK SERVICE which doesn't have this same issue. This changes GARM to also use that same service user which also requires running the service executable in a special "init" mode to register a Event Log Trace Source (without doing this the service silently does nothing).
1 parent 3fa2187 commit fc83a27

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cloudconfig/templates.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,15 @@ function Install-Runner() {
533533
534534
Update-GarmStatus -CallbackURL $CallbackURL -Message "Creating system service"
535535
$SVC_NAME=(gc -raw $serviceNameFile)
536-
New-Service -Name "$SVC_NAME" -BinaryPathName "C:\actions-runner\bin\RunnerService.exe" -DisplayName "$SVC_NAME" -Description "GitHub Actions Runner ($SVC_NAME)" -StartupType Automatic
536+
# Run as NT AUTHORITY\NETWORK SERVICE, same as what actions-runner does
537+
$servicePrincipal = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::NetworkServiceSid, $Null)
538+
$serviceUser = $servicePrincipal.Translate([System.Security.Principal.NTAccount]).Value
539+
$serviceCredential = New-Object System.Management.Automation.PSCredential ($serviceUser, (New-Object System.Security.SecureString))
540+
541+
# Have the service register itself as an Event Log Trace Source, this needs to run with elevated permissions
542+
./bin/RunnerService.exe init
543+
544+
New-Service -Name "$SVC_NAME" -BinaryPathName "C:\actions-runner\bin\RunnerService.exe" -DisplayName "$SVC_NAME" -Description "GitHub Actions Runner ($SVC_NAME)" -StartupType Automatic -Credential $serviceCredential
537545
Start-Service "$SVC_NAME"
538546
Set-SystemInfo -CallbackURL $CallbackURL -RunnerDir $runnerDir -BearerToken $Token
539547
Update-GarmStatus -Message "runner successfully installed" -CallbackURL $CallbackURL -Status "idle" | Out-Null

0 commit comments

Comments
 (0)