You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rest-server.md
+46-35Lines changed: 46 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,27 @@ Suzieq ships with a REST server. It has the same set of commands, verbs and filt
7
7
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
8
8
is via an API key and all access to the API is via SSL.
9
9
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
13
14
```
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```
15
18
16
19
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.
17
20
18
21
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:
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
26
31
```
27
32
28
33
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
31
36
32
37
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.
33
38
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.
35
41
36
-
##Creating Your Specific Key and SSL Certificate
42
+
### Setup the API KEY
37
43
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.
39
46
40
-
### SSL
47
+
If you want it to be more random, this is a good way of creating a key:
41
48
42
-
### Create a self signed cert
49
+
```shell
50
+
openssl rand -hex 20
51
+
```
43
52
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
46
54
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:
The output of the command is two files, cert.pem and key.pem, created in the directory where you ran the command.
53
62
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.
55
64
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.
57
67
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
62
69
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:
### 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.
70
77
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.
72
80
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
74
88
rest:
75
-
API_KEY: 496157e6e869ef7f3d6ecb24a6f6d847b224ee4f
76
-
rest_certfile: /suzieq/cert.pem
77
-
rest_keyfile: /suzieq/cert.pem
89
+
no-https: true
78
90
```
79
-
For more details about the configuration file, check the [Configuration](config_file.md) page
0 commit comments