Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Remote Procedure Call (Without the Remote Part)

I have a Python server which is not running as root, which fronts an application I am developing. However there are some application features which require access to RAW sockets which means root privileges.

Obviously I do not want to run the main server as root, and so my solution is to create a daemon process or command line script which runs as root providing guarded access to said features.

However I want put aside stdin/stdout communication and use an RPC style of interaction such as Pyro. But this exposes the RPC interface to anyone with network access to the machine, whereas I know that the process calling the RPC methods will be another process on the same machine.

Is there not a sort of inter-process procedure call standard which could be used in a similar (local machine only) fashion? I imagine the server doing something like this:

# Server not running as root
pythonically, returned, values = other_process_running_as_root.some_method()

And the process running as root exposing a method:

# Daemon running as root
@expose_this_method
def some_method():
    # Play with RAW sockets
    return pythonically, returned, values

Is anything like this possible?

like image 891
Marcus Whybrow Avatar asked Oct 13 '22 17:10

Marcus Whybrow


1 Answers

Following my comment, I was interested to see if it was possible, so I had a go at putting this together: https://github.com/takowl/ZeroRPC

Bear in mind that this is thrown together in an hour or so, so it's almost certainly inferior to any serious solution (e.g. any errors on the server side will crash it...). But it works as you suggested:

Server:

rpcserver = zerorpc.Server("ipc://myrpc.ipc")

@rpcserver.expose
def product(a, b):
    return a * b

rpcserver.run()

Client:

rpcclient = zerorpc.Client("ipc://myrpc.ipc")

print(rpcclient.product(5, 7))
rpcclient._stopserver()
like image 125
Thomas K Avatar answered Oct 18 '22 03:10

Thomas K