masahide / OmniSSHAgent

Integrated ssh-agent for windows. (pageant compatible. openSSH ssh-agent etc ..)
Apache License 2.0
127 stars 9 forks source link

WSL2 "error fetching identities: communication with agent failed" #44

Closed RAnders00 closed 8 months ago

RAnders00 commented 8 months ago

When I run ssh-add -l, I get the following error:

error fetching identities: communication with agent failed

I've read the previous issue on this (#16), here are my command outputs for the same commands you wanted the other issue reporter to run:

$ ps axuw | grep socat
ruben       15  0.0  0.0  10304  3016 ?        Ss   10:40   0:00 socat UNIX-LISTEN:/home/ruben/.ssh/agent.sock,fork EXEC:/home/ruben/omni-socat/omni-socat.exe,nofork
ruben     1434  0.0  0.0   6332  2004 pts/0    S+   10:47   0:00 grep socat
> Get-ChildItem \\.\pipe\|findstr open
    Directory: \\.\pipe\openvpn
------        1601-01-01     01:00              1 openvpn\service
------        1601-01-01     01:00              2 openssh-ssh-agent

Using pageant apps and OpenSSH apps on Windows works just fine.

I'm not sure if this is the problem, but when I run omni-socat.exe manually from WSL2, I get:

$ strace -ff -o st ./omni-socat.exe
./omni-socat.exe: Invalid argument

I ran strace on omni-socat:

execve("./omni-socat.exe", ["./omni-socat.exe"], 0x7fff43d828e8 /* 29 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x406b40)       = 0
set_tid_address(0x406ae0)               = 1744
gettid()                                = 1744
gettid()                                = 1744
gettid()                                = 1744
gettid()                                = 1744
brk(NULL)                               = 0x1622000
brk(0x1624000)                          = 0x1624000
mmap(0x1622000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x1622000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77cb000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77ca000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c9000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c8000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c7000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c6000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c5000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c4000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c3000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77c1000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77bf000
sched_getaffinity(0, 128, [0 1 2 3 4 5 6 7 8 9 10 11]) = 32
getpid()                                = 1744
getpid()                                = 1744
uname({sysname="Linux", nodename="RANDERS01", ...}) = 0
getcwd("/home/ruben/omni-socat", 4096)  = 23
readlink("omni-socat.exe", 0x7ffe1a3fa570, 4096) = -1 EINVAL (Invalid argument)
getcwd("/home/ruben/omni-socat", 4097)  = 23
open("/proc/self/mountinfo", O_RDONLY|O_LARGEFILE) = 3
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77be000
read(3, "64 68 0:26 / /mnt/wsl rw,relatim"..., 1024) = 1024
read(3, "me shared:21 - devpts devpts rw,"..., 1024) = 1024
read(3, "e shared:34 - cgroup cgroup rw,c"..., 1024) = 1024
read(3, "oup/rdma rw,nosuid,nodev,noexec,"..., 1024) = 721
read(3, "", 1024)                       = 0
close(3)                                = 0
munmap(0x7fb2a77be000, 4096)            = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77bb000
getcwd("/home/ruben/omni-socat", 4096)  = 23
munmap(0x7fb2a77bb000, 16384)           = 0
getcwd("/home/ruben/omni-socat", 4096)  = 23
open("/proc/self/mountinfo", O_RDONLY|O_LARGEFILE) = 3
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77be000
read(3, "64 68 0:26 / /mnt/wsl rw,relatim"..., 1024) = 1024
read(3, "me shared:21 - devpts devpts rw,"..., 1024) = 1024
read(3, "e shared:34 - cgroup cgroup rw,c"..., 1024) = 1024
read(3, "oup/rdma rw,nosuid,nodev,noexec,"..., 1024) = 721
read(3, "", 1024)                       = 0
close(3)                                = 0
munmap(0x7fb2a77be000, 4096)            = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb2a77bd000
ioctl(0, TCGETS, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(1, TCGETS, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(2, TCGETS, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TIOCGPGRP, [1741])             = 0
getpgid(0)                              = 1741
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
fstat(2, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=69, ws_col=270, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {c_iflag=, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ECHOE|ECHOK|ECHOCTL|ECHOKE, ...}) = 0
dup(0)                                  = 3
socket(AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0) = 4
bind(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_ANY, svm_port=VMADDR_PORT_ANY, svm_flags=0}, 16) = 0
getsockname(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_ANY, svm_port=0xe00a7bed, svm_flags=0}, [16]) = 0
listen(4, 4)                            = 0
access("/run/WSL/8_interop", F_OK)      = 0
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 5
connect(5, {sa_family=AF_UNIX, sun_path="/run/WSL/8_interop"}, 110) = 0
write(5, "\7\0\0\0I\1\0\0\355{\n\340\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 329) = 329
poll([{fd=4, events=POLLIN}], 1, 10000) = 1 ([{fd=4, revents=POLLIN}])
accept4(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_HOST, svm_port=0xa5ebd9da, svm_flags=0}, [16], SOCK_CLOEXEC) = 6
poll([{fd=4, events=POLLIN}], 1, 10000) = 1 ([{fd=4, revents=POLLIN}])
accept4(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_HOST, svm_port=0xa5ebd9db, svm_flags=0}, [16], SOCK_CLOEXEC) = 7
poll([{fd=4, events=POLLIN}], 1, 10000) = 1 ([{fd=4, revents=POLLIN}])
accept4(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_HOST, svm_port=0xa5ebd9dc, svm_flags=0}, [16], SOCK_CLOEXEC) = 8
poll([{fd=4, events=POLLIN}], 1, 10000) = 1 ([{fd=4, revents=POLLIN}])
accept4(4, {sa_family=AF_VSOCK, svm_cid=VMADDR_CID_HOST, svm_port=0xa5ebd9dd, svm_flags=0}, [16], SOCK_CLOEXEC) = 9
close(4)                                = 0
rt_sigprocmask(SIG_BLOCK, [INT WINCH], NULL, 8) = 0
signalfd4(-1, [INT WINCH], 8, 0)        = 4
poll([{fd=0, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=4, events=POLLIN}], 5, -1) = 1 ([{fd=9, revents=POLLIN}])
recvfrom(9, "\n\0\0\0 \0\0\0", 8, MSG_WAITALL, NULL, NULL) = 8
recvfrom(9, "\26\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 24, 0, NULL, NULL) = 24
writev(2, [{iov_base="./omni-socat.exe: Invalid argume"..., iov_len=35}, {iov_base=NULL, iov_len=0}], 2) = 35
close(4)                                = 0
close(5)                                = 0
close(9)                                = 0
close(8)                                = 0
close(7)                                = 0
close(6)                                = 0
munmap(0x7fb2a77bd000, 8192)            = 0
ioctl(3, SNDCTL_TMR_START or TCSETS, {c_iflag=ICRNL|IXON, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
close(3)                                = 0
munmap(0x7fb2a77c1000, 8192)            = 0
munmap(0x7fb2a77c3000, 4096)            = 0
munmap(0x7fb2a77c5000, 4096)            = 0
munmap(0x7fb2a77c6000, 4096)            = 0
munmap(0x7fb2a77c7000, 4096)            = 0
munmap(0x7fb2a77c8000, 4096)            = 0
munmap(0x7fb2a77c9000, 4096)            = 0
munmap(0x7fb2a77ca000, 4096)            = 0
munmap(0x7fb2a77cb000, 4096)            = 0
exit_group(1)                           = ?
+++ exited with 1 +++
masahide commented 8 months ago

Sorry for the late reply. Does this error always occur?

RAnders00 commented 8 months ago

I've not gotten it to work even once, so yes, always. Thank you for taking the time to look into this. Let me know if you need any more details.

masahide commented 8 months ago

To isolate the cause, could you try replacing omni-socat with npiperelay to see if it works? (npiperelay is a software similar to omni-socat that can proxy named-pipes via socat.) Please perform the following operations on WSL2.

# download npiperelay_windows_amd64
$ wget https://github.com/jstarks/npiperelay/releases/download/v0.1.0/npiperelay_windows_amd64.zip
$ unzip npiperelay_windows_amd64.zip

$ ps axuw|grep socat
masahide 99065  0.0  0.0   6976  1832 ?        Ss   19:35   0:00 socat UNIX-LISTEN:/home/masahide/.ssh/agent.sock,fork EXEC:/home/masahide/omni-socat/omni-socat.exe -debug,nofork
masahide 99107  0.0  0.0   8172   660 pts/1    S+   19:36   0:00 grep --color=auto socat
# kill omni-socat.exe
$  killall socat

# start $HOME/npiperelay.exe
$ setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$HOME/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork
$ ps axuw|grep npi
masahide 98717  0.0  0.0   6976  1836 ?        Ss   19:29   0:00 socat UNIX-LISTEN:/home/masahide/.ssh/agent.sock,fork EXEC:/home/masahide/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent,nofork
masahide 98740  0.0  0.0   8172   724 pts/1    S+   19:29   0:00 grep --color=auto npi

# list ssh agent keys
$ ssh-add -l
256 SHA256:...............
RAnders00 commented 8 months ago

While tinkering around, I was able to find out what went wrong:

In omni-socat/ubuntu-bash.setup.sh, I replaced the socat start line with this to get the output:

(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$OMNISOCATCMD",nofork &) >$HOME/omni-socat/socat-output 2>&1

Which shows the following output:

2024/01/07 15:35:04 socat[89] E exactly 2 addresses required (there are 0); use option "-h" for help

Which, I found out, is caused by me not having a .ssh directory.

mkdir $HOME/.ssh

fixes everything.

masahide commented 8 months ago

@RAnders00 Thank you for the pull request.