Debian Codegraph @

doc/sources/admin/websocketapplications.rst

raw
1 WebSocket Applications
2 ======================
3
4 Presentation
5 ------------
6
7 WebSocket is a protocol defined in :rfc:`6455`.
8
9 It allows bi-directional communication on top of TCP. See diagram below.
10
11 |image0|
12
13 The communication starts with an HTTP request from the client, asking for a connection upgrade to websocket. This request contains a challenge (the key).
14
15 The server response contains the answer to this challenge.
16
17 Then, if everything is successful, the communication continues on top of TCP. The client and server can send requests from both side.
18
19
20 Webserver configuration
21 -----------------------
22
23 Nginx does not require any specific configuration to handle WebSocket connections.
24
25 If you use Apache, you need a recent version (2.4.47), and you need to add ``upgrade=websocket`` to the ``ProxyPass`` directive ::
26
27 ProxyPass / http://private-name/ upgrade=websocket
28
29 Refer to :ref:`vhostapachereverse` for more details
30
31 Protection by LemonLDAP::NG
32 ---------------------------
33
34 You can protect your websocket application with the classic :doc:`LemonLDAP::NG handler<presentation>`.
35
36 The handler is set up as an HTTP/TCP reverse-proxy in front of the websocket application.
37
38 |image1|
39
40 You can configure the :doc:`access rules and headers<writingrulesand_headers>` as usual.
41
42 - Only the initial HTTP handshake (request and response) is protected by LemonLDAP::NG. Later TCP traffic pass directly through Nginx reverse-proxy
43 - LemonLDAP::NG access rules are evaluated during the initial HTTP handshake (request and response) that upgrades the communication to websocket
44 - LemonLDAP::NG headers are sent during the initial HTTP handshake (request and response) that upgrades the communication to websocket
45
46 Be careful of the following scenario :
47
48 * an unprotected page with a button that connect to the websocket endpoint with ajax requests
49 * the websocket endpoint is protected by LemonLDAP
50 * user clicks the button, but the SSO session has expired at this moment
51
52 The unprotected page must manage the 302 return code sent by the SSO portal
53
54
55 Load-testing
56 ------------
57
58 * when passing by the LemonLDAP Nginx handler, there is about ~30% overload for the initial HTTP websocket request and response
59 * when passing by the Nginx reverse-proxy, there is no significant overload of TCP websocket requests
60
61
62 .. |image0| image:: /websocket.png
63 :class: align-center
64
65 .. |image1| image:: /websocket-sso.png
66 :class: align-center
67