Search code examples
pythonautobahnautobahnws

How to set component role in Autobahn


I'm using crossbar 0.11.1 and I want to have an autobahn component use a specific role. When I add a "role" attribute to my component, like below:

"components": [
        {
           "type": "class",
           "classname": "hello.hello.AppSession",
           "realm": "realm1",
           "role": "anonymous",
           "transport": {
              "type": "websocket",
              "endpoint": {
                 "type": "tcp",
                 "host": "127.0.0.1",
                 "port": 8080
              },
              "url": "ws://127.0.0.1:8080/ws"
           }
        }
     ]

I get this error when running crossbar start

2015-11-03T10:51:02-0600 [Controller  20933] Automatically choosing optimal Twisted reactor
2015-11-03T10:51:02-0600 [Controller  20933] Running on Linux and optimal reactor (epoll) was installed.
2015-11-03T10:51:02-0600 [Controller  20933]      __  __  __  __  __  __      __     __
2015-11-03T10:51:02-0600 [Controller  20933]     /  `|__)/  \/__`/__`|__) /\ |__)  |/  \
2015-11-03T10:51:02-0600 [Controller  20933]     \__,|  \\__/.__/.__/|__)/~~\|  \. |\__/
2015-11-03T10:51:02-0600 [Controller  20933]                                         
2015-11-03T10:51:02-0600 [Controller  20933]     Version: 0.11.1     
2015-11-03T10:51:02-0600 [Controller  20933] 
2015-11-03T10:51:02-0600 [Controller  20933] Starting from node directory /home/jaime/code/pubsub/tmp/.crossbar
2015-11-03T10:51:02-0600 [Controller  20933] Loading node configuration file '/home/jaime/code/pubsub/tmp/.crossbar/config.json'
2015-11-03T10:51:02-0600 [Controller  20933] *** Configuration validation failed ***
2015-11-03T10:51:02-0600 [Controller  20933] invalid component configuration - encountered unknown attribute 'role'

Solution

  • You may only assign the role in that way for "in-router" components (that is, the "components" list inside a worker of type "router") -- they don't really have a transport, as they're running in the same Python process as the router worker.

    For all other components, their role is assigned via the authentication for the transport they connect to. So, in your above case, you'd add an "anonymous" user that has "anonymous" role on the websocket transport you've defined at ws://127.0.0.1:8080/ws.

    For non-anonymous things, you set up one of the authentication mechanisms (e.g. WAMP-CRA) and then your component would do something like: self.join(u'admin_realm', [u'wampcra'], u'admin') in onConnect and compute the challenge in onChallenge using their secret, as per the docs: http://crossbar.io/docs/WAMP-CRA-Authentication/#python-frontend

    On the router side, the simplest for WAMP-CRA is to use static credentials where you just users + secrets in the config.json file. You can define a dynamic WAMP-CRA auth