librelist archives

« back to archive

Connect to remote unix domain socket

Connect to remote unix domain socket

From:
Lars Kruse
Date:
2014-05-31 @ 01:46
Hi,

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:
 https://docs.python.org/2.7/library/socketserver.html.
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
manually.

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()
 client.load_system_host_keys()
 client.connect(hostname=dest_host)
 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 "blocksync.py", line 432, in <module>
    process_args(args)
  File "blocksync.py", line 408, in process_args
    slave_channel = get_slave_channel(args.dest_host)
  File "blocksync.py", line 174, in get_slave_channel
    remote_socket = client.open_sftp().file(SOCKET_DEFAULT_LOCATION, "r+")
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 245, in
open t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 635, in
_request return self._read_response(num)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 682, in
_read_response self._convert_status(msg)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", 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.

Cheers,
Lars