Skip to content

Commit 40c6637

Browse files
claudiolorddutt
authored andcommitted
docs: update the REST apis page
Signed-off-by: Claudio Lorina <[email protected]>
1 parent b9510c8 commit 40c6637

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

docs/rest-server.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@ Suzieq ships with a REST server. It has the same set of commands, verbs and filt
77
The REST server is bundled with the Suzieq Docker image. It already has an API key and a self-signed SSL certificate to get you going without further ado. Real deployment of course involves changing these defaults with something specific to your enterprise. At this time it's only authentication
88
is via an API key and all access to the API is via SSL.
99

10-
You must launch the Suzieq docker container as follows:
11-
```
12-
docker run -it -p 8000:8000 --name suzieq netenglabs/suzieq:latest
10+
You can launch the Suzieq docker container as follows:
11+
12+
```shell
13+
docker run -it -p 8000:8000 --name suzieq netenglabs/suzieq:latest
1314
```
14-
This assumes that you're using port 8000 to connect to the REST server. If you wish to use a different port for the REST server, say 7000, you can launch it as ```docker run -it -p 7000:8000 --name suzieq netenglabs/suzieq:latest```.
15+
16+
!!! info
17+
This assumes that you're using port 8000 to connect to the REST server. If you wish to use a different port for the REST server, say 7000, you can launch it as ```docker run -it -p 7000:8000 --name suzieq netenglabs/suzieq:latest```
1518

1619
You then launch the server with ```sq-rest-server.py &```. You can then exit the container using the usual Docker container escape sequence CTRL-p CTRL-q to leave the docker container running.
1720

1821
The server is now accessible via [https://localhost:8000/api/docs](https://localhost:8000/api/docs) (or whatever port you've mapped the server to on the host). You need to pass the API_KEY in the request to be able to access the server. A simple example using the default API key and certificate is to use curl as follows:
19-
```
20-
curl --insecure 'https://localhost:8000/api/v2/device/show?&access_token=496157e6e869ef7f3d6ecb24a6f6d847b224ee4f'
22+
23+
```shell
24+
curl --insecure 'https://localhost:8000/api/v2/device/show?access_token=496157e6e869ef7f3d6ecb24a6f6d847b224ee4f'
2125
```
2226

2327
The Suzieq docker container of course serves the data available under `/home/suzieq/parquet` inside the container. You can mount the parquet data you've already gathered via the `-v` option. So an example of mounting the parquet directory with data would be to launch the container as follows:
24-
```
25-
docker run -it -p 8000:8000 -v /path/to/you/suzieq-data:/home/suzieq/parquet --name suzieq netenglabs/suzieq:latest
28+
29+
```shell
30+
docker run -it -p 8000:8000 -v /path/to/you/suzieq-data:/home/suzieq/parquet --name suzieq netenglabs/suzieq:latest
2631
```
2732

2833
The REST server has been implemented using the [fastapi](https://fastapi.tiangolo.com/) server.
@@ -31,49 +36,55 @@ The REST server has been implemented using the [fastapi](https://fastapi.tiangol
3136

3237
In keeping with the modern REST server design model, the rest server comes bundled with automatic documentation. You can point the browser at [https://localhost:8000/api/docs](https://localhost:8000/api/docs) for the classical Swagger-based documentation. This also allows you to try out the API from within the browser itself. You can also use the fastapi's alternative documentation at [https://localhost:8000/api/redoc](https://localhost:8000/api/redoc). The openapi.json URL is [https://localhost:8000/api/openapi.json](https://localhost:8000/api/openapi.json). We changed the default URLs for the Swagger and Redoc API as well as OpenAPI to make it easier for reverse proxies such as Caddy.
3338

34-
If you do decide to try out the API from within the browser, you need to authenticate it first using the Authorize button and adding the API Key.
39+
!!! warning
40+
If you do decide to try out the API from within the browser, you need to authenticate it first using the Authorize button and adding the API Key.
3541

36-
## Creating Your Specific Key and SSL Certificate
42+
### Setup the API KEY
3743

38-
If you wish to create your own self-signed certificate and API key, you can do so using the instructions in this section, in case you don't already know how to do so.
44+
You do need a entry called API_KEY in your suzieq config file, which is usually in ~/.suzieq/suzieq.cfg.
45+
It can be anything you want it to be. This will be the same key that you need to use from the client.
3946

40-
### SSL
47+
If you want it to be more random, this is a good way of creating a key:
4148

42-
### Create a self signed cert
49+
```shell
50+
openssl rand -hex 20
51+
```
4352

44-
The easiest way to go about getting a cert is a self signed cert. You can create this
45-
via openssl.
53+
## Configure SSL Key and Certificate
4654

47-
The easiest way is:
55+
It is possible to secure connections to the REST server via SSL. You can specify the full path of your SSL key and certificate via the ```rest_keyfile``` and ```rest_certfile``` variables under the `rest` section of the suzieq config file, typically at `~/.suzieq/suzieq-cfg.yml`. Here is an example of a config file with these two parameters defined:
4856

49-
``` bash
50-
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
57+
```yaml
58+
rest:
59+
rest_certfile: /home/suzieq/cert.pem
60+
rest_keyfile: /home/suzieq/cert.pem
5161
```
52-
The output of the command is two files, cert.pem and key.pem, created in the directory where you ran the command.
5362
54-
It's not likely that you'd want to use this in production. This certificate will expire in 365 days.
63+
For more details about the configuration file, check the [configuration](config_file.md) file documentation.
5564
56-
The REST server requires two files in ~/.suzieq, key.pem and cert.pem. Put these files in ~/.suzieq. Without those two files the REST server will not work.
65+
!!! warning
66+
By default the rest server has HTTPS enabled with some default self-signed certificates, to let users play with SuzieQ without further ado. Please, always provide your own certificates.
5767
58-
### Setup API KEY
59-
60-
You do need a entry called API_KEY in your suzieq config file, which is usually in ~/.suzieq/suzieq.cfg.
61-
It can be anything you want it to be. This will be the same key that you need to use from the client.
68+
### Create a self signed cert
6269
63-
If you want it to be more random, this is a good way of creating a key:
70+
The easiest way to go about getting a cert is a self signed cert. You can create this via openssl:
6471
65-
``` bash
66-
openssl rand -hex 20
72+
```shell
73+
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
6774
```
6875

69-
### Changing the Location And Name of the Key/Cert Files
76+
The command above generates two files: `cert.pem` and `key.pem`, created in the directory where you ran the command. The certificate will expire after 365 days.
7077

71-
The default location for the key and certificate files needed for REST is `~/.suzieq`, and the file names are `key.pem` and `cert.pem`. If you wish these to be different, you can specify the full path of each of the files (or any one) via the ```rest_keyfile``` and ```rest_certfile``` variables under the `rest` section of the suzieq config file, typically at ~/.suzieq/suzieq-cfg.yml. Here is an example of a config file with these two parameters defined:
78+
!!! danger
79+
Self-signed certificates should never be used in production.
7280

73-
```
81+
82+
### Disable HTTP on the rest server
83+
84+
In same cases you might want to disable HTTPS from the REST server, for example when TLS connections are terminated by a reverse proxy.
85+
HTTPS can be disabled by setting to `true` the `no-https` field under the `rest` section of the config file, as in the following example:
86+
87+
```yaml
7488
rest:
75-
API_KEY: 496157e6e869ef7f3d6ecb24a6f6d847b224ee4f
76-
rest_certfile: /suzieq/cert.pem
77-
rest_keyfile: /suzieq/cert.pem
89+
no-https: true
7890
```
79-
For more details about the configuration file, check the [Configuration](config_file.md) page

0 commit comments

Comments
 (0)