wsl2-ssh-pageant icon indicating copy to clipboard operation
wsl2-ssh-pageant copied to clipboard

new wsl2-ssh-pageant.exe instance is create for every gpg communication

Open davidshen84 opened this issue 3 years ago • 10 comments

Describe the bug This is how I start the process in WSL 2:

setsid socat UNIX-LISTEN:$GPG_AGENT_SOCK,fork EXEC:"$HOME/.ssh/wsl2-ssh-pageant.exe --verbose --gpgConfigBasepath 'C:/Users/user-name/AppData/Local/gnupg' --gpg S.gpg-agent" >/dev/null 2>&1 &

To Reproduce Steps to reproduce the behavior:

  1. Start a WSL 2 terminal
  2. Start the socat process like above
  3. Repeat gpg --card-status 3 times
  4. Check the wsl2-ssh-pageant.exe process in Windows Task Manager

Expected behavior

No wsl2-ssh-pageant.exe process should be found in the Task Manager

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context

  • Gpg4win v4.0.0
  • wsl2-ssh-pageant v1.4.0

davidshen84 avatar Mar 01 '22 08:03 davidshen84

That is actually intended, each connection attempt opens a new binary. The agent itself is not long lived. The question in this case is: why is the connection held open. The part about gpg is that it's not the main purpose of wsl2-ssh-pageant and was more or less hacked into it. As I'm not using it as my daily driver there needs to be someone who is willing to investigate that issue. Maybe I will find some time to have a look into it myself.

tobiaskohlbau avatar Mar 01 '22 09:03 tobiaskohlbau

Even if I kill the socat process in WSL, the wsl2-ssh-pageant process on the Windows side is still alive. But if I kill the gpg-agent process on the Windows side, the wsl2-ssh-pageant processes are gone.

davidshen84 avatar Mar 01 '22 10:03 davidshen84

Even if I kill the socat process in WSL, the wsl2-ssh-pageant process on the Windows side is still alive. But if I kill the gpg-agent process on the Windows side, the wsl2-ssh-pageant processes are gone.

I must admit that I never noticed that the wsl2-ssh-pageant proccesses are lacked behind. But I can indeed confirm it's happening for me too. I would assume there ist something in the teardown process which results in this behavior. I've tried to look into it but did not find any obvious reasons. I totally understand that this is not the expected behavior but on the other hand on most modern computers this shouldn't make a huge difference. If the computer is rebooted frequently. Nevertheless I will mark this as an issue which needs to be addressed, but I have no concrete timeframe.

tobiaskohlbau avatar Mar 02 '22 08:03 tobiaskohlbau

Well, in my case, my desktop is usually on throughout the day and went to hibernation during the night. I rarely restart or shut down my computer unless I have to.

While reading the code, I noticed you opened a connection here. But I wonder if you need to manually close it. I don't have much knowledge of go.

davidshen84 avatar Mar 05 '22 01:03 davidshen84

I tried in ssh mode. I observed that the wsl2-ssh-pageant process appeared on Windows for a short time, then exited.

davidshen84 avatar Mar 06 '22 04:03 davidshen84

@davidshen84 I download wsl2-ssh-pageant file from your repository and run 3 times gpg --card-status. wsl2-ssh-pageant.ext processes not closes

FFxSquall avatar Mar 29 '22 13:03 FFxSquall

@FFxSquall

Thanks, I just tested the one from the github artifactory and I can reproduce the issue. However, the one compiled on my local does not have this issue.

I think the real problem the the -H=windowsgui option which, according to this, creates a GUI binary. I don't think we need a GUI binary for this tool. I will update my PR to build a console binary.

Thanks

davidshen84 avatar Mar 29 '22 22:03 davidshen84

@FFxSquall

Please give it another try. https://github.com/davidshen84/wsl2-ssh-pageant/actions/runs/2063498454

davidshen84 avatar Mar 30 '22 08:03 davidshen84

@davidshen84 It's works. Thanks

FFxSquall avatar Mar 30 '22 09:03 FFxSquall

@davidshen84 I've tried this on my system as well, and it appears to resolve the issue. The added Close handler doesn't seem to be called with our without the windows gui option. One note, might want to also remove the compile option from the Makefile. Much appreciated!

tofupup avatar Jul 19 '22 20:07 tofupup