我有一个不以 root 身份运行的 Python 服务器,它面向我正在开发的应用程序。然而,有一些应用程序功能需要访问 RAW 套接字,这意味着 root 权限。
显然,我不想以 root 身份运行主服务器,因此我的解决方案是创建一个守护进程进程或命令行脚本,以 root 身份运行,提供对所述功能的受保护访问。
但是我想搁置 stdin/stdout 通信并使用 RPC 风格的交互,例如Pyro http://www.xs4all.nl/~irmen/pyro3/index.html。但这会将 RPC 接口暴露给任何可以通过网络访问该计算机的人,而我知道调用 RPC 方法的进程将是同一台计算机上的另一个进程。
难道没有一种进程间过程调用标准哪个可以以类似的(仅限本地机器)方式使用?我想象服务器会做这样的事情:
# Server not running as root
pythonically, returned, values = other_process_running_as_root.some_method()
以 root 身份运行的进程公开了一个方法:
# Daemon running as root
@expose_this_method
def some_method():
# Play with RAW sockets
return pythonically, returned, values
这样的事情可能吗?
在我发表评论后,我很想看看这是否可能,所以我尝试将其放在一起:https://github.com/takowl/ZeroRPC https://github.com/takowl/ZeroRPC
请记住,这是在一个小时左右的时间内拼凑而成的,因此它几乎肯定不如任何严重的解决方案(例如,服务器端的任何错误都会使其崩溃......)。但它按照你的建议工作:
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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)