fix(agent): Windows sandboxed commands see Beanstalk's work folder as a drive of its own #46
No reviewers
Labels
No labels
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Beanstalk!46
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Beanstalk:fix/win-work-drive"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
No Windows job gets past building
main. The compiler,clang-23.exe, starts in the sandbox and then exits at once with "<its path>: Permission denied", even for--version. That happens in LLVM's own startup code, and I've checked the source:InitLLVMcallsGetCommandLineArguments→GetExecutableName(llvm/lib/Support/Windows/Process.inc), which callsGetModuleFileNameWand thenGetLongPathNameWon the compiler's own path.InitLLVMexits throughExitOnErrorwith the bannerargv[0] + ": ", which is the line we see.#38's probe on futondestroyer's PC (rp_f4df5d54ac932b34, Longshot #799, nightly-83) shows why
GetLongPathNameWfails with error 5: the sandbox may not look up any folder above the ones it was given.UsersC:\<you>C:\UsersAppData,Local,Beanstalk,work,toolsllvm-mingw,bin,clang-23.exeC:\andC:\Userscan't be granted without an administrator, so no grant on the user's own folders alone can fix this.What changed
The agent gives sandboxed commands its data folder as a drive letter of its own. A sandboxed command then sees the compiler at
Q:\tools\llvm-mingw\bin\clang-23.exe. The only folder above the folders it was given is the drive's root, and that folder gets a listing.WinWorkDrive(Core/WindowsNative.cs): maps the data folder withDefineDosDevicefor the agent's logon session, assubstdoes, with no administrator. It reuses a mapping an earlier run left, and removes the mapping when the agent quits (AgentService.StopAsync).WinDrive(Core/WindowsPlan.cs, pure, checked on Linux):Picktakes the letter already mapped to the folder, else the last free one from Z: down.Rewriteturns each path under the data folder into the drive's path, inside arguments and path lists too, regardless of case. A folder whose name only starts the same is left alone.WinAccess.List: the drive's root gets a listing of that folder only (FILE_LIST_DIRECTORY,FILE_READ_ATTRIBUTES,SYNCHRONIZE). It's not inherited, and it gives no access to file data. The names there are the agent's own folders:tools,longshot,bases,jobs, ….WinSandbox.Preparerewrites each command's program, arguments, working folder and environment to the drive's paths. Grants still go on the real folders.cmd.exe /c if exist Q:\ …in the sandbox. If that doesn't find the drive, or no letter is free, orBEANSTALK_NO_WORK_DRIVE=1is set, commands see the real paths as before. The result is kept per sandbox mode, because the runner account is another Windows user that doesn't see the agent's mapping.BEANSTALK_WORK_DRIVE: the letter, oroff: <why>. The temp probe prints it andLONGSHOT_MINGW, so the next report says whether the drive was used. #38's lookup lines then walk the drive's path.Testing
dotnet build agent/App -c Release: 0 warnings.BEANSTALK_WORK_DRIVEin the probe lines, and the check's reason when it's off;GetLongPathNameWthen succeeds:@@probe longpath clang ok, and the spawn lines exiting 0;mainbuilds from there.