dotcloud/zerorpc-python — pull request #46 by adieu (2012-12-13 13:59:44+00:00)
Title: Add authentication support

I'm not quite sure if this patch should be merged. But I'd like to bring up a discussion about whether should zerorpc have authentication support built-in.

The need of authentication support start from day one when I use zerorpc to build some internal service since I have to expose this service to the internet.

When I heard the release of stack.io, I though I might use stack.io as a gateway doing the authentication work. But I couldn't find the authentication method for clients connected through zerorpc.

So I begin to add authentication support by myself.

This patch consists two commits. The first one patches current zerorpc code base to support custom Event class for Server and Client. And the second one add signed requests based authentication using custom Event class and proper middleware.

When I was modifying current zerorpc code base, I tried to change as less as possible and I put authentication related code in a separate file as kind of extension.

Here are some example code shows about how to use authentication:

# server
import time
import zerorpc
from zerorpc.auth import SignedEvent, SharedSecretMiddleware

zerorpc.Context.get_instance().register_middleware(SharedSecretMiddleware('some_random_key'))
server = zerorpc.Server(time, event_class=SignedEvent)
server.bin("tcp://0.0.0.0:4242")
server.run()

# client
import zerorpc
from zerorpc.auth import SignedEvent, SharedSecretMiddleware

zerorpc.Context.get_instance().register_middleware(SharedSecretMiddleware('some_random_key'))
client = zerorpc.Client(event_class=SignedEvent)
client.connect('tcp://127.0.0.1:4242')
print client.strftime('%Y/%m/%d')

I don't know the design decisions about authentication. If we decided not to include authentication in zerorpc, could we just merge the first commit and give the developers ability to change the default behavior of events so that they could implement their own authentication mechanism in their own code base?

Btw, I really enjoyed writing services with zerorpc. Thank you for this wonderful project.