microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.39k stars 819 forks source link

"Access is denied." when running as LocalSystem #4803

Closed TapeWerm closed 8 months ago

TapeWerm commented 4 years ago

Download Sysinternals PsExec64.exe

.\PsExec64.exe -i -s cmd.exe
bash.exe
wsl.exe

Access is denied. 🎊

TapeWerm commented 4 years ago

logs.zip

valeriob commented 4 years ago

Hi, i'm having the same issue, running as local system account results in access denied. Did you find any solution ?

TapeWerm commented 4 years ago

I never found any solution.

valeriob commented 4 years ago

I'm trying with LOCAL SERVICE but i get the error "W i n d o w s S u b s y s t e m f o r L i n u x h a s n o i n s t a l l e d d i s t r i b u t i o n s . " instead, i guess that wsl is installed for a single users.

valp124 commented 3 years ago

Same exact issue, which prevents me from using bash in Azure DevOps pipelines. How can there be no response to this whatsoever in all this time??

valp124 commented 3 years ago

I found a workaround, by the way, for anyone interested. After much tinkering, I managed to take ownership of C:\Windows\System32\bash.exe and that allowed me to rename it (I didn't want to delete). After that, I created a symbolic link:

mklink bash.exe "c:\Program Files\Git\bin\bash.exe"

It's a poor man's bash, but at least it works, I tested it with psexec and through the Azure pipeline.

luckerby commented 3 years ago

@valp124 I'm running into the same exact problem, particularly since I need the Azure DevOps self-hosted agent to run as LOCAL SYSTEM.

However I still get "Access denied" running as LOCAL SYSTEM (via psexec -s -i cmd.exe) even after moving bash.exe and creating the symlink. Is there some additional step to be done?

valp124 commented 3 years ago

@luckerby, when you test via psexec, are you running the command as admin? Be sure to run whatever shell you're using "As Administrator." Other than that, I wouldn't know what to say, it still works for me. (You'd think that a Windows update would break it at some point.)

valp124 commented 3 years ago

You can see below that the linked bash works, but the original bash and wsl don't.

image

However:

image

luckerby commented 3 years ago

@valp124 Thank you for your quick reply! I've somehow missed the obvious, whereby the symlink has to point to an actual bash client (e.g. Git's built-in one). For some weird reason, I moved the original bash.exe and created a symlink to this one (I know, doesn't make any sense, particularly since your explicit mklink command made it clear what the end goal was; I also have a hunch that SYSTEM32's bash.exe is just a stub and expects to find a real bash client in the Linux distro installed).

So just to confirm, @valp124's solution still works perfectly with Azure DevOps, particularly when you need to run the self-hosted agent as LOCAL SYSTEM.

I did found another workaround for running the Azure DevOps self-hosted agent under a different account than the default NETWORK SERVICE, and tested this successfully on WSL1. Simply create another local user on the Azure DevOps self-hosted agent, add it to the local Administrators group, install a Linux distro by running the distribution launcher app (full procedure is here) and then configure the agent service to run as that particular user.

Unfortunately this doesn't work for the initial issue of this thread: trying to install a Linux distro while running as LOCAL SYSTEM (e.g. in the interactive window opened by psexec -s -i cmd) by using the distribution launcher app (full procedure is here) will fail with: WslRegisterDistribution failed with error: 0x80070005. Error: 0x80070005 Access is denied. Which brought me back to the same thought @TapeWerm had in the initial post, that maybe WSL is not meant to be used this way.

As a side note, using ProcMon to identify the cause of the "Access is denied" didn't lead me anywhere: all I can see what several threads created by bash.exe and then almost immediately terminated, but no operation that would result in an access denied status message.

valp124 commented 3 years ago

Right, @luckerby, I figured changing the user under which az agent runs would work, but in my case, messing with the Admin group is not an option, any changes are overwritten by the corporate policy after a short while.

@therealkenc, it would seem to me that this needs to be addressed.

valp124 commented 8 months ago

It's not ok to close an unresolved issue.

rbability commented 8 months ago

I can confirm that this is still an issue, just ran into this yesterday. It makes it difficult to use when utilized by Azure DevOps or GitHub Self-Hosted runners which run with LocalSystem permissions by default and are not meant to have more permissions in the system.

pa-0 commented 3 months ago

Was this issue addressed elsewhere? I see it's closed but I don't see any response.

valp124 commented 3 months ago

I am opening a new issue on the same subject.