librelist archives

« back to archive

Connect to remote unix domain socket

Connect to remote unix domain socket

Lars Kruse
2014-05-31 @ 01:46

I have a service running on a remote system. It is communicating with its
clients via a unix domain socket. Local access via socat is working fine.
The service uses Python's SocketServer module:
I choose a unix domain socket instead of an inet socket in order to be able
to rely on local user permissions instead of authenticating remote users

I feel that paramiko would be the right tool for an ssh-based connection to a
remote unix socket, thus I went through the API documentation of paramiko. But I
failed to find a way to read to and write from a socket on the remote system.

I just asked this question on paramiko's irc channel today. "Mennis" mentioned
that an sftp file object could be the way to go. Thus I tried the following:
 client = paramiko.SSHClient()
 remote_socket = client.open_sftp().file(SOCKET_DEFAULT_LOCATION, "r+")

Sadly the last line fails (with any mode setting):
Traceback (most recent call last):
  File "", line 432, in <module>
  File "", line 408, in process_args
    slave_channel = get_slave_channel(args.dest_host)
  File "", line 174, in get_slave_channel
    remote_socket = client.open_sftp().file(SOCKET_DEFAULT_LOCATION, "r+")
  File "/usr/lib/python2.7/dist-packages/paramiko/", line 245, in
open t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
  File "/usr/lib/python2.7/dist-packages/paramiko/", line 635, in
_request return self._read_response(num)
  File "/usr/lib/python2.7/dist-packages/paramiko/", line 682, in
_read_response self._convert_status(msg)
  File "/usr/lib/python2.7/dist-packages/paramiko/", line 712, in
_convert_status raise IOError(text)
IOError: Failure

I am not sure what else I could try.
Maybe paramiko is not suitable for this specific need?
Or maybe my current approach ist just pointing at the wrong direction?

I would be very thankful for any advice.