Skip to content

Commit 44edb4f

Browse files
committed
-wip
1 parent 61710c3 commit 44edb4f

File tree

3 files changed

+122
-18
lines changed

3 files changed

+122
-18
lines changed

en_US/security/authn/authn.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
# Introduction
22

3-
Authentication is an important part of most applications. MQTT protocol supports username/password authentication. Enabling authentication can effectively prevent illegal client connections.
3+
Authentication is an important part of most applications. MQTT protocol supports username/password authentication as
4+
well as some enhanced methods, like SCRAM authentication. Enabling authentication can effectively prevent illegal client connections.
45

5-
Authentication in EMQX Broker means that when a client connects to EMQX Broker, the server configuration is used to control the client's permission to connect to the server.
6+
Authentication in EMQX Broker means that when a client connects to EMQX Broker, the server configuration is used to control the client's permission to connect to the server.
67

78
EMQX Broker's authentication support includes two levels:
89

9-
- The MQTT protocol specifies the user name and password in the CONNECT packet by itself. EMQX Broker supports multiple forms of authentication based on Username, ClientID, HTTP, JWT, LDAP, and various databases such as MongoDB, MySQL, PostgreSQL, Redis through plugins.
10+
- The MQTT protocol itself specifies authentication primitives. EMQX Broker supports multiple variants of MQTT-level authentication:
11+
* username/password authentication with various backends (MongoDB, MySQL, PostgreSQL, Redis and built-in database);
12+
* SCRAM authentication with built-in database;
13+
* JWT authentication;
14+
* authentication via custom HTTP API.
1015
- At the transport layer, TLS guarantees client-to-server authentication using client certificates and ensures that the server verifies the server certificate to the client. PSK-based TLS/DTLS authentication is also supported.
1116

12-
This authentication methods supported by EMQX and the configuration methods of the corresponding plugins are introduced in this article.
17+
In this article we describe EMQX authentication and its configuration concepts.
1318

14-
## Authentication method
19+
## Authentication sources and authentication chains
20+
21+
Authentication source is an EMQX module that implements authentication. The following authentication sources are
22+
available by default:
23+
24+
| mechanism | backend | description |
25+
| ---- | ------------------ | ----------- |
26+
| password_based | built_in_database |
27+
| password_based | mysql |
28+
| password_based | postgresql |
29+
| password_based | mongodb |
30+
| password_based | redis |
31+
| password_based | http |
32+
| jwt | |
33+
| scram | built_in_database |
1534

1635
EMQX supports the use of built-in data sources (files, built-in databases), JWT, external mainstream databases, and custom HTTP APIs as authentication data sources.
1736

@@ -218,7 +237,7 @@ The cipher list supported by the server needs to be specified explicitly. The de
218237
listener.ssl.external.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-DES-CBC3-SHA,ECDH-ECDSA-AES256-GCM-SHA384,ECDH-RSA-AES256-GCM-SHA384,ECDH-ECDSA-AES256-SHA384,ECDH-RSA-AES256-SHA384,DHE-DSS-AES256-GCM-SHA384,DHE-DSS-AES256-SHA256,AES256-GCM-SHA384,AES256-SHA256,ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES128-SHA256,ECDHE-RSA-AES128-SHA256,ECDH-ECDSA-AES128-GCM-SHA256,ECDH-RSA-AES128-GCM-SHA256,ECDH-ECDSA-AES128-SHA256,ECDH-RSA-AES128-SHA256,DHE-DSS-AES128-GCM-SHA256,DHE-DSS-AES128-SHA256,AES128-GCM-SHA256,AES128-SHA256,ECDHE-ECDSA-AES256-SHA,ECDHE-RSA-AES256-SHA,DHE-DSS-AES256-SHA,ECDH-ECDSA-AES256-SHA,ECDH-RSA-AES256-SHA,AES256-SHA,ECDHE-ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,DHE-DSS-AES128-SHA,ECDH-ECDSA-AES128-SHA,ECDH-RSA-AES128-SHA,AES128-SHA
219238
```
220239

221-
## PSK authentication
240+
## PSK authentication
222241
If you want to use PSK authentication, you need to comment out `listener.ssl.external.ciphers` in [TLS Authentication](#auth-tls), and then configure ` listener.ssl.external.psk_ciphers`:
223242

224243
```bash

en_US/security/blacklist.md

+94-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Blacklisting/Banning ClientID, user name or IP
1+
# Blacklisting/Banning ClientDI, user name or IP
22

33
EMQX Broker provides users with a blacklisting/banning functionality.
44

@@ -7,14 +7,14 @@ to deny access of the client.
77

88
In addition to the client identifier, it also supports direct ban of user names or source IP addresses.
99

10-
For specific usage of the HTTP API, see the `/banned` API document.
11-
1210
::: tip
1311
The blacklist is only applicable to a small number of client bans.
1412
If there are a large number of clients requiring authentication management,
15-
please use the [authentication](./authn/authn.md) function.
13+
please use the [authentication](./authn/authn.md) function.
1614
:::
1715

16+
## Flapping Clients
17+
1818
Based on the blacklist function, EMQX supports automatic banning of clients that are frequently
1919
logged in for a short period of time, and rejects these clients for a period of time
2020
to prevent such clients from consuming server resources which in turn may affect other clients.
@@ -23,21 +23,103 @@ It should be noted that the automatic ban only bans the client identifier,
2323
not the user name and IP address.
2424
That is to say, a malicious client may still able to attack if they change client identifier for each attempt.
2525

26-
This feature is disabled by default, set `enable_flapping_detect` configuration item to `on` in `emqx.conf` to enable it.
26+
This feature is disabled by default, set `enable` for `flapping_detect` section to `true` in `emqx.conf` to enable it.
2727

2828
```bash
29-
zone.external.enable_flapping_detect = off
29+
flapping_detect {
30+
31+
enable = false
32+
33+
}
3034
```
3135

3236
The user can adjust the trigger threshold and the ban time with below configs
3337

3438
```bash
35-
flapping_detect_policy = "30, 1m, 5m"
39+
flapping_detect {
40+
41+
enable = true
42+
43+
## The max disconnect allowed of a MQTT Client in `window_time`
44+
max_count = 15
45+
46+
## The time window for flapping detect
47+
window_time = 1m
48+
49+
## How long the clientid will be banned
50+
ban_time = 5m
51+
52+
}
53+
```
54+
55+
These settings may be specified individually for each zone.
56+
57+
## HTTP API
58+
59+
Ban user:
60+
61+
```shell
62+
## Request
63+
curl -i \
64+
--basic \
65+
-u admin:public \
66+
-X POST \
67+
-H "Content-Type: application/json" \
68+
-d '{"as": "clientid", "who": "malicious_client"}' \
69+
http://localhost:18083/api/v5/banned
70+
71+
## Return
72+
{
73+
"as":"clientid",
74+
"at":"2022-05-17T17:07:24+03:00",
75+
"by":"mgmt_api",
76+
"reason":"",
77+
"until":"2022-05-17T17:12:24+03:00",
78+
"who":"malicious_client"
79+
}
80+
```
81+
82+
List banned users:
83+
84+
```shell
85+
## Request
86+
curl -i \
87+
--basic \
88+
-u admin:public \
89+
-X GET \
90+
http://localhost:18083/api/v5/banned?page=1&count=10
91+
92+
## Return
93+
{
94+
"data": [
95+
{
96+
"as":"clientid",
97+
"at":"2022-05-17T17:07:24+03:00",
98+
"by":"mgmt_api",
99+
"reason":"",
100+
"until":"2022-05-17T17:12:24+03:00",
101+
"who":"malicious_client"
102+
}
103+
],
104+
"meta": {
105+
"count":1,
106+
"limit":100,
107+
"page":1
108+
}
109+
}
110+
```
111+
112+
Remove banned user:
113+
114+
```shell
115+
## Request
116+
curl -i \
117+
--basic \
118+
-u admin:public \
119+
-X DELETE \
120+
http://localhost:18083/api/v5/banned/clientid/malicious_client
121+
122+
## Response: HTTP 204
36123
```
37124

38-
The value of this configuration item is separated by `,`,
39-
which repectively indicates the number of times that the client is offline,
40-
the detection time range, and the ban time.
41125

42-
In the above example, the config means that if a client goes offline 30 times in 1 minute,
43-
then this client identifie is banned for 5 minutes.

run

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docker run --rm --name emqx -p 18083:18083 -p 1883:1883 \
2+
--sysctl net.core.somaxconn=1024 \
3+
emqx/emqx:latest

0 commit comments

Comments
 (0)