blob: d7e1ec7d4eb67db634f331e26ad454aed6ae9364 [file] [log] [blame]
Jeremy Kerrf403c422018-07-26 12:14:56 +08001nbd-proxy
2=========
3
4Prototype javascript+websocket NBD server; this code demonstrates a javascript
5NBD implementation connected to the kernel nbd device over a websocket.
6
7There are two components here:
8
9 nbd-proxy: a little binary to initialise a nbd client, connected to a
10 unix domain socket, then proxy data between that socket and
11 stdio. This can be used with a websocket proxy to expose
12 that stdio as a websocket.
13
14 nbd.js: a javascript implementation of a NBD server.
15
16Running
17-------
18
19You'll need a websocket proxy This connects the nbd-proxy
20component to a websocket endpoint.
21
22For experimentation, I use the `websocketd` infrastrcture to expose the
23websocket endpoint, plus serve the static HTML+js client:
24
25 git clone https://github.com/joewalnes/websocketd
26 (cd websocketd && make)
27
Jeremy Kerr19527352018-08-03 15:04:38 +080028 sudo websocketd/websocketd --port=8000 --staticdir=web --binary ./nbd-proxy <config>
29
30- where <config> is a name of a configuration in the config.json file.
Jeremy Kerrf403c422018-07-26 12:14:56 +080031
32Note that this type of invocation is very insecure, and intended just for
33experimentation. See the Security section below.
34
35For real deployments, you want your websocket-enabled service to run
36nbd-proxy, and connect its stdio to a websocket, running in binary mode. Your
37web interface will interact with this using an instance of the NBDServer object
38(defined in web/js/nbd.js):
39
40 var server = NBDServer(endpoint, file);
41 server.start();
42
43- where endpoint is the websocket URL (ws://...) and file is a File object. See
44web/index.html for an example.
45
46Security
47--------
48
49This code allows potentially-untrusted clients to export arbitrary block
50device data to your kernel. Therefore, you should ensure that only trusted
51clients can connect as NBD servers.
52
53There is no authentication or authorisation implemented in the nbd proxy. Your
54websocket proxy should implement proper authentication before nbd-proxy is
55connected to the websocket endpoint.
Jeremy Kerrc6134c12018-08-09 13:03:33 +080056
Jeremy Kerra87af842018-08-13 11:48:23 +080057State hook
58----------
Jeremy Kerrc6134c12018-08-09 13:03:33 +080059
Jeremy Kerra87af842018-08-13 11:48:23 +080060The nbd-proxy has a facility to run an program on state change. When a nbd
61session is established or shut down, the proxy will run the executable at
62/etc/nbd-proxy/state.
Jeremy Kerrc6134c12018-08-09 13:03:33 +080063
Jeremy Kerra87af842018-08-13 11:48:23 +080064This executable is called with two arguments: the action ("start" or "stop"),
Jeremy Kerrc6134c12018-08-09 13:03:33 +080065and the name of the configuration (as specified in the config.json file).