Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.timeout: timed out when running under sudo or otherwise as root? #3

Open
pmorch opened this issue Aug 4, 2021 · 3 comments
Open

Comments

@pmorch
Copy link

pmorch commented Aug 4, 2021

Is there any way I can use both wsl-sudo.pl and sudo at the same time without having to enter my linux password every time?

As I pointed out in #1, wsl-sudo works fine to edit e.g. the hosts file under WSL2, but I also need my script to have linux sudo priviledges.

If I run

wsl-sudo.py sudo ls -l

sudo asks for a password every time, presumably because wsl-sudo.py creates a new pty for each invocation.

But if I run this (where I preserve the PATH so it can find wsl-sudo.py and misc. windows binaries):

sudo env "PATH=$PATH" wsl-sudo.py ls

I'm presented with the UAC prompt but then get this, which I'd like to avoid:

Traceback (most recent call last):
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 332, in <module>
    main()
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 328, in main
    UnprivilegedClient().main(**vars(args))
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 233, in main
    self.sock, acc = listen_socket.accept()
  File "/usr/lib/python3.8/socket.py", line 292, in accept
    fd, addr = self._accept()
socket.timeout: timed out

This occurs both if I run as above, if I run sudo -i to get an interactive shell, or run wsl -u root to start a brand new WSL session.

@Chronial
Copy link
Owner

Chronial commented Aug 4, 2021

I assume you applied #2 to get wsl-sudo working on wsl2? Then I would guess that your problem with sudo env "PATH=$PATH" wsl-sudo.py ls is that sudo removes the WSL_INTEROP variable, undoing the effect of #2. You could try sudo -E wsl-sudo.py ls instead. Which is probably what you want anyways.

You could also just permanently disable the password prompt for sudo: https://askubuntu.com/a/147265. I think that is in general a sensible thing to do on WSL. Then you can do wsl-sudo.py sudo ls -l.

@pmorch
Copy link
Author

pmorch commented Aug 4, 2021

Thanks for replying.

I'm not sure I'm crazy about disabling sudo password prompting. But yes, that is a solution.

I don't understand the first part of your reply, though:

The socket.timeout: timed out occurs with or without #2 applied.

I would guess that your problem with sudo env "PATH=$PATH" wsl-sudo.py ls is that sudo removes the WSL_INTEROP variable

But:

  1. sudo runs before wsl-sudo.py so how can it possibly remove the WSL_INTEROP that hasn't been set yet?
  2. It also occurs with wsl.exe -u root starting directly as root - completely without sudo - as in:
WSL2@~» wsl.exe -u root
root@COMPANY-12D2Z0:/home/peter# /home/peter/bin/local/wsl-sudo/wsl-sudo.py ls
Traceback (most recent call last):
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 333, in <module>
    main()
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 329, in main    
    UnprivilegedClient().main(**vars(args))
  File "/home/peter/bin/local/wsl-sudo/wsl-sudo.py", line 234, in main
    self.sock, acc = listen_socket.accept()
  File "/usr/lib/python3.8/socket.py", line 292, in accept
    fd, addr = self._accept()
socket.timeout: timed out
root@COMPANY-12D2Z0:/home/peter# 

@Chronial
Copy link
Owner

Chronial commented Aug 5, 2021

#2 does not invent the WSL_INTEROP variable. The call graph of wsl-sudo is: linux wsl-sudowindows powershellwindows wsl.exe → linux wsl-sudo (see readme). #2 forwards the WSL_INTEROP variable in the first call from linux to windows. Have a look at your wsl2 env: the WSL_INTEROP variable should already be set.

You can have a look at these issues to get more understanding of the situation: microsoft/WSL#4465 and microsoft/WSL#5065. It's possible that you are encountering the latter issue here, when you run wsl.exe from within a wsl prompt. I can't really help you there – these are all undocumented WSL2 internals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants