Skip to content

Commit c6a73cf

Browse files
committed
docs: update authentication docs
Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
1 parent 9c44ae8 commit c6a73cf

File tree

2 files changed

+183
-445
lines changed

2 files changed

+183
-445
lines changed

docs/authentication.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SuperMQ uses the `access_token` provided by Google only to fetch user informatio
4545

4646
## Authentication with SuperMQ keys
4747

48-
By default, SuperMQ uses SuperMQ Thing secret for authentication. The Thing secret is a secret key that's generated at the Thing creation. In order to authenticate, the Thing needs to send its secret with the message. The way the secret is passed depends on the protocol used to send a message and differs from adapter to adapter. For more details on how this secret is passed around, please check out [messaging section][messaging]. This is the default SuperMQ authentication mechanism and this method is used if the composition is started using the following command:
48+
By default, SuperMQ uses SuperMQ Client secret for authentication. The Client secret is a secret key that's generated at the Client creation. In order to authenticate, the Client needs to send its secret with the message. The way the secret is passed depends on the protocol used to send a message and differs from adapter to adapter. For more details on how this secret is passed around, please check out [messaging section][messaging]. This is the default SuperMQ authentication mechanism and this method is used if the composition is started using the following command:
4949

5050
```bash
5151
docker-compose -f docker/docker-compose.yml up
@@ -59,52 +59,52 @@ In most of the cases, HTTPS, WSS, MQTTS or secure CoAP are secure enough. Howeve
5959
AUTH=x509 docker-compose -f docker/docker-compose.yml up -d
6060
```
6161

62-
Mutual authentication includes client-side certificates. Certificates can be generated using the simple script provided [here][ssl-makefile]. In order to create a valid certificate, you need to create SuperMQ thing using the process described in the [provisioning section][provision]. After that, you need to fetch created thing secret. Thing secret will be used to create x.509 certificate for the corresponding thing. To create a certificate, execute the following commands:
62+
Mutual authentication includes client-side certificates. Certificates can be generated using the simple script provided [here][ssl-makefile]. In order to create a valid certificate, you need to create SuperMQ client using the process described in the [provisioning section][provision]. After that, you need to fetch created client secret. Client secret will be used to create x.509 certificate for the corresponding client. To create a certificate, execute the following commands:
6363

6464
```bash
6565
cd docker/ssl
6666
make ca CN=<common_name> O=<organization> OU=<organizational_unit> emailAddress=<email_address>
6767
make server_cert CN=<common_name> O=<organization> OU=<organizational_unit> emailAddress=<email_address>
68-
make thing_cert THING_SECRET=<thing_secret> CRT_FILE_NAME=<cert_name> O=<organization> OU=<organizational_unit> emailAddress=<email_address>
68+
make client_cert CLIENT_SECRET=<client_secret> CRT_FILE_NAME=<cert_name> O=<organization> OU=<organizational_unit> emailAddress=<email_address>
6969
```
7070

7171
These commands use [OpenSSL][openssl] tool, so please make sure that you have it installed and set up before running these commands. The default values for Makefile variables are
7272

7373
```env
7474
CRT_LOCATION = certs
75-
THING_SECRET = d7cc2964-a48b-4a6e-871a-08da28e7883d
75+
CLIENT_SECRET = d7cc2964-a48b-4a6e-871a-08da28e7883d
7676
O = SuperMQ
7777
OU = supermq_ca
7878
EA = info@supermq.com
7979
CN = localhost
80-
CRT_FILE_NAME = thing
80+
CRT_FILE_NAME = client
8181
```
8282

83-
Normally, in order to get things running, you will need to specify only `THING_SECRET`. The other variables are not mandatory and the termination should work with the default values.
83+
Normally, in order to get clients running, you will need to specify only `CLIENT_SECRET`. The other variables are not mandatory and the termination should work with the default values.
8484

8585
- Command `make ca` will generate a self-signed certificate that will later be used as a CA to sign other generated certificates. CA will expire in 3 years.
8686
- Command `make server_cert` will generate and sign (with previously created CA) server cert, which will expire after 1000 days. This cert is used as a SuperMQ server-side certificate in usual TLS flow to establish HTTPS or MQTTS connection.
87-
- Command `make thing_cert` will finally generate and sign a client-side certificate and private key for the thing.
87+
- Command `make client_cert` will finally generate and sign a client-side certificate and private key for the client.
8888

89-
In this example `<thing_secret>` represents secret of the thing and `<cert_name>` represents the name of the certificate and key file which will be saved in `docker/ssl/certs` directory. Generated Certificate will expire after 2 years. The key must be stored in the x.509 certificate `CN` field. This script is created for testing purposes and is not meant to be used in production. We strongly recommend avoiding self-signed certificates and using a certificate management tool such as [Vault][vault] for the production.
89+
In this example `<client_secret>` represents secret of the client and `<cert_name>` represents the name of the certificate and key file which will be saved in `docker/ssl/certs` directory. Generated Certificate will expire after 2 years. The key must be stored in the x.509 certificate `CN` field. This script is created for testing purposes and is not meant to be used in production. We strongly recommend avoiding self-signed certificates and using a certificate management tool such as [Vault][vault] for the production.
9090

9191
Once you have created CA and server-side cert, you can spin the composition using:
9292

9393
```bash
9494
AUTH=x509 docker-compose -f docker/docker-compose.yml up -d
9595
```
9696

97-
Then, you can create user and provision things and channels. Now, in order to send a message from the specific thing to the channel, you need to connect thing to the channel and generate corresponding client certificate using aforementioned commands. To publish a message to the channel, thing should send following request:
97+
Then, you can create user and provision clients and channels. Now, in order to send a message from the specific client to the channel, you need to connect client to the channel and generate corresponding client certificate using aforementioned commands. To publish a message to the channel, client should send following request:
9898

9999
### WSS
100100

101101
```javascript
102102
const WebSocket = require("ws");
103103
// Do not verify self-signed certificates if you are using one.
104104
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
105-
// Replace <channel_id> and <thing_secret> with real values.
105+
// Replace <channel_id> and <client_secret> with real values.
106106
const ws = new WebSocket(
107-
"wss://localhost/ws/channels/<channel_id>/messages?authorization=<thing_secret>",
107+
"wss://localhost/ws/channels/<channel_id>/messages?authorization=<client_secret>",
108108
// This is ClientOptions object that contains client cert and client key in the form of string. You can easily load these strings from cert and key files.
109109
{
110110
cert: `-----BEGIN CERTIFICATE-----....`,
@@ -127,21 +127,21 @@ As you can see, `Authorization` header does not have to be present in the HTTP r
127127
### HTTPS
128128

129129
```bash
130-
curl -s -S -i --cacert docker/ssl/certs/ca.crt --cert docker/ssl/certs/<thing_cert_name>.crt --key docker/ssl/certs/<thing_cert_key>.key -X POST -H "Content-Type: application/senml+json" https://localhost/http/channels/<channel_id>/messages -d '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
130+
curl -s -S -i --cacert docker/ssl/certs/ca.crt --cert docker/ssl/certs/<client_cert_name>.crt --key docker/ssl/certs/<client_cert_key>.key -X POST -H "Content-Type: application/senml+json" https://localhost/http/channels/<channel_id>/messages -d '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
131131
```
132132

133133
### MQTTS
134134

135135
#### Publish
136136

137137
```bash
138-
mosquitto_pub -u <thing_id> -P <thing_secret> -t channels/<channel_id>/messages -h localhost -p 8883 --cafile docker/ssl/certs/ca.crt --cert docker/ssl/certs/<thing_cert_name>.crt --key docker/ssl/certs/<thing_cert_key>.key -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
138+
mosquitto_pub -u <client_id> -P <client_secret> -t channels/<channel_id>/messages -h localhost -p 8883 --cafile docker/ssl/certs/ca.crt --cert docker/ssl/certs/<client_cert_name>.crt --key docker/ssl/certs/<client_cert_key>.key -m '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
139139
```
140140

141141
#### Subscribe
142142

143143
```bash
144-
mosquitto_sub -u <thing_id> -P <thing_secret> --cafile docker/ssl/certs/ca.crt --cert docker/ssl/certs/<thing_cert_name>.crt --key docker/ssl/certs/<thing_cert_key>.key -t channels/<channel_id>/messages -h localhost -p 8883
144+
mosquitto_sub -u <client_id> -P <client_secret> --cafile docker/ssl/certs/ca.crt --cert docker/ssl/certs/<client_cert_name>.crt --key docker/ssl/certs/<client_cert_key>.key -t channels/<channel_id>/messages -h localhost -p 8883
145145
```
146146

147147
[jwt]: https://jwt.io/

0 commit comments

Comments
 (0)