crossbario / crossbar

Crossbar.io - WAMP application router
https://crossbar.io/
Other
2.05k stars 274 forks source link

Meta API: support historic session data retrieval #1996

Closed oberstet closed 2 years ago

oberstet commented 2 years ago

Extend the meta API to retrieve session (and transport) details

https://github.com/crossbario/crossbar/blob/33f48c81595427942935f66e352025674962a51a/crossbar/router/service.py#L230

to allow to retrieve closed session data.

To avoid complex state handling, and to support multi-node configurations, the session data should be persisted in a database table backed session store in case historic session data API is used.

This will also solve the following common problem: once the meta API has notified observers that a session has left, the session/transport details for that session can no longer be retrieved:

2022-04-20T19:31:39+0200 [Container   60249] <monitor.MyMonitor.onJoin.<locals>.on_session_join>: new session joined, session_info=
{'authextra': {'x_cb_node': 'intel-nuci7-60231',
               'x_cb_peer': 'tcp4:127.0.0.1:40002',
               'x_cb_pid': 60240,
               'x_cb_worker': 'test_router1'},
 'authid': 'client1',
 'authmethod': 'wampcra',
 'authprovider': 'static',
 'authrole': 'frontend',
 'session': 3338870677237213,
 'transport': {'cbtid': 'qySA297RcSEfU/Dq0/9J3j7K',
               'http_headers_received': {'cache-control': 'no-cache',
                                         'connection': 'Upgrade',
                                         'host': 'localhost:8080',
                                         'pragma': 'no-cache',
                                         'sec-websocket-extensions': 'permessage-deflate; '
                                                                     'client_no_context_takeover; '
                                                                     'client_max_window_bits',
                                         'sec-websocket-key': 'ABd7KUMRIRgo7kCr3VMnFg==',
                                         'sec-websocket-protocol': 'wamp.2.cbor.batched,wamp.2.cbor,wamp.2.msgpack.batched,wamp.2.msgpack,wamp.2.ubjson.batched,wamp.2.ubjson,wamp.2.json.batched,wamp.2.json',
                                         'sec-websocket-version': '13',
                                         'upgrade': 'WebSocket',
                                         'user-agent': 'AutobahnPython/22.4.1.dev5'},
               'http_headers_sent': {'Set-Cookie': 'cbtid=qySA297RcSEfU/Dq0/9J3j7K;max-age=604800'},
               'peer': 'tcp4:127.0.0.1:40002',
               'protocol': 'wamp.2.cbor.batched',
               'type': 'websocket',
               'websocket_extensions_in_use': []}}
2022-04-20T19:31:39+0200 [Container   60249] <monitor.MyMonitor.onJoin.<locals>.on_session_join>: ok, event data identical to getter API!
2022-04-20T19:31:39+0200 [Router      60240] add2() called with 2 and 3
2022-04-20T19:31:39+0200 [Router      60240] event received on com.foobar.topic2: hello
2022-04-20T19:31:39+0200 [Router      60240] event received on com.foobar.topic2: hello
2022-04-20T19:31:39+0200 [Router      60240] Router detached session from realm "realm1" (session=3338870677237213, detached_session_ids=1, authid="client1", authrole="frontend", authmethod="wampcra", authprovider="static") <crossbar.router.router.Router.detach>
2022-04-20T19:31:39+0200 [Container   60249] <monitor.MyMonitor.onJoin.<locals>.on_session_join>: existing session left, session_id=3338870677237213
2022-04-20T19:31:39+0200 [Router      60240] wamp.session.get: session 3338870677237213 not found
2022-04-20T19:31:39+0200 [Container   60249] 
Traceback (most recent call last):
--- <exception caught here> ---
  File "/home/oberstet/scm/crossbario/crossbar-examples/authentication/wampcra/static/monitor.py", line 72, in on_session_leave
    _session_info = yield self.call('wamp.session.get', session_id)
autobahn.wamp.exception.ApplicationError: ApplicationError(error=<wamp.error.no_such_session>, args=['no session with ID 3338870677237213 exists on this router'], kwargs={}, enc_algo=None, callee=None, callee_authid=None, callee_authrole=None, forward_for=None)

example from https://github.com/crossbario/crossbar-examples/pull/151

oberstet commented 2 years ago

depends on https://github.com/crossbario/cfxdb/pull/88

oberstet commented 2 years ago

alright, finally, crossbar 22.4.1 has this fixed. a complete test of WAMP-CRA with persistent cookie database and persistent realm store, and with a proxy-router cluster setup is here

https://github.com/crossbario/crossbar-examples/blob/852680eee646cf5479bff18ec727a8026d9bdcda/authentication/wampcra/static/Makefile#L17

here are some screenshots of the router side.

correct (proxy frontend) transport information incl. cookies is provided in the meta API event, and is identical to what is returned via meta API procedure: Bildschirmfoto von 2022-05-04 19-18-27

and data is persisted in DB, including proxy frontend and backend transport information

Bildschirmfoto von 2022-05-04 19-18-35

and the WAMP meta API info for the session is still accessible once the session is gone Bildschirmfoto von 2022-05-04 19-18-42

and it will be available in all router workers, and across router restarts.