Skip to content

Commit a14ccf4

Browse files
committed
update(authn): Add "Precondition" Dashboard config field
1 parent c6251e4 commit a14ccf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+564
-494
lines changed
Loading
Loading
5.96 KB
Loading
-43.6 KB
Loading
64.8 KB
Loading
-47.6 KB
Loading
Loading
-5.71 KB
Loading
Loading

en_US/access-control/authn/authn.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ When an authentication chain is configured, EMQX processes authenticators in the
8989
Here’s how it works, using password-based authentication as an example:
9090

9191
1. **Evaluate Preconditions (if configured):**
92-
If the authenticator has a [precondition](#authenticator-preconditions), EMQX first evaluates the expression based on client information (e.g., `listener`, `clientid`, `username`).
92+
If the authenticator has a [precondition](#authenticator-preconditions), EMQX first evaluates the expression based on client attributes information (e.g., `listener`, `clientid`, `username`).
9393
- If the expression evaluates to `true`, the authenticator is invoked.
9494
- If not, the authenticator is skipped.
9595
2. **Execute the Authenticator:**
@@ -106,11 +106,23 @@ Here’s how it works, using password-based authentication as an example:
106106

107107
### Authenticator Preconditions
108108

109-
Starting from EMQX 5.9, you can assign a precondition to each authenticator to control whether it should be invoked for a given client.
109+
Starting from EMQX 5.9, you can assign a precondition to each authenticator to control whether it should be invoked for a given client. A precondition is a [Variform expression](../../configuration/configuration.md#variform-expressions) that evaluates client attributes (such as `listener`, `username`, `clientid`, etc.). If the expression does not evaluate to `true`, the authenticator is skipped.
110110

111-
A precondition is a [Variform expression](../../configuration/configuration.md#variform-expressions) that evaluates client metadata (such as `listener`, `username`, `clientid`, etc.). If the expression does not evaluate to `true`, the authenticator is skipped.
111+
This feature enables conditional logic in the authentication chain. It allows for fine-grained control over authentication logic, such as applying different authenticators for clients connecting through different listeners or based on client attributes. EMQX can then invoke authenticators only when appropriate and avoid unnecessary requests to external systems.
112112

113-
This feature enables conditional logic in the authentication chain, allowing EMQX to invoke authenticators only when appropriate and avoid unnecessary requests to external systems.
113+
#### Supported Client Attributes in Precondition
114+
115+
Supported client attributes in a precondition include:
116+
117+
- `username`: The username of the client
118+
- `password`: The password of the client
119+
- `clientid`: The client ID of the client
120+
- `client_attrs.*`: The client attributes of the client
121+
- `cert_common_name`: The subject field from the client's TLS certificate
122+
- `cert_subject`: The Common Name (CN) from the client's TLS certificate
123+
- `peersni`: The SNI (Server Name Indication) sent by the TLS client
124+
- `listener`: The listener ID (e.g. `tcp:default`)
125+
- `zone`: The associated config zone
114126

115127
#### Precondition Examples
116128

en_US/access-control/authn/cinfo.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@ Client-Info authentication (`cinfo` type) is a lightweight authentication mechan
1010

1111
## Configure Client-Info Authentication via Dashboard
1212

13-
In the EMQX Dashboard, navigate to **Access Control** -> **Authentication** in the left menu to enter the **Authentication** page. Click **Create** at the top right corner, then select **Client Info** as the **Mechanism**, Client-Info authentication does not require selecting a backend, so you can proceed by clicking **Next** to enter the **Configure Parameters** step.
14-
15-
1. Click **Add** in the **Checks**.
16-
- In the **Match Conditions** input box, enter the Variform expression used to match client information. If there are multiple expressions, enter each on a new line. When all expressions return `true`, the authenticator will return the relevant result; otherwise, the current check will be skipped. The following variables are supported in the expressions:
17-
- `username`: Username
18-
- `clientid`: Client ID
19-
- `client_attrs.*`: Client Attributes
20-
- `peerhost`: Client IP
21-
- `cert_subject`: TLS Certificate Subject
22-
- `cert_common_name`: TLS Certificate Common Name
23-
- Select `allow`, `ignore`, or `deny` from the **Result** dropdown menu.
24-
2. Click **Create** to complete the authentication configuration.
13+
1. In the EMQX Dashboard, navigate to **Access Control** -> **Authentication** in the left menu to enter the **Authentication** page.
14+
2. Click **Create** at the top right corner, then select **Client Info** as the **Mechanism**. Client-Info authentication does not require selecting a backend, so you can proceed by clicking **Next** to enter the **Configure Parameters** step.
15+
3. Follow the instructions below to configure the backend:
16+
- **Precondition**: A [Variform expression](../../configuration/configuration.md#variform-expressions) used to control whether this Client Info authenticator should be applied to a client connection. The expression is evaluated against attributes from the client (such as `username`, `clientid`, `listener`, etc.). The authenticator will only be invoked if the expression evaluates to the string `"true"`. Otherwise, it will be skipped. For more information about the precondition, see [Authentication Preconditions](./authn.md#authentication-preconditions).
17+
- Click **Add** in the **Checks**.
18+
- In the **Match Conditions** input box, enter the Variform expression used to match client information. If there are multiple expressions, enter each on a new line. When all expressions return `true`, the authenticator will return the relevant result; otherwise, the current check will be skipped. The following variables are supported in the expressions:
19+
- `username`: Username
20+
- `clientid`: Client ID
21+
- `client_attrs.*`: Client Attributes
22+
- `peerhost`: Client IP
23+
- `cert_subject`: TLS Certificate Subject
24+
- `cert_common_name`: TLS Certificate Common Name
25+
- From the **Result** dropdown menu, select the result to return if the match condition is true:
26+
- `allow`: Allow the client to connect.
27+
- `ignore`: Defer the authentication to the next authenticator in the chain.
28+
- `deny`: Deny the client to connect.
29+
4. Click **Create** to complete the authentication configuration.
2530

2631
## Configure Client-Info Authentication via Configuration Items
2732

en_US/access-control/authn/http.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,36 @@ Due to the lack of expressiveness, it has been redesigned to make use of HTTP bo
6363

6464
You can use EMQX Dashboard to finish the relevant configuration.
6565

66-
On [EMQX Dashboard](http://127.0.0.1:18083/#/authentication), click **Access Control** -> **Authentication** on the left navigation tree to enter the **Authentication** page. Click **Create** at the top right corner, then click to select **Password-Based** as **Mechanism**, and **HTTP Server** as **Backend**, this will lead us to the **Configuration** tab, as shown below.
66+
1. In the EMQX Dashboard, click **Access Control** -> **Authentication** from the left navigation menu.
67+
2. On the **Authentication** page, click **Create** in the top right corner.
68+
3. Click to select **Password-Based** as **Mechanism**, and **HTTP Server** as **Backend** to go to the **Configuration** tab, as shown below.
6769

6870
<img src="./assets/authn-http.png" alt="HTTP" style="zoom:67%;" />
6971

70-
Follow the instructions below on how to configure the authentication:
72+
4. Follow the instructions below to configure the authentication backend:
7173

72-
- **Method**: Select HTTP request method, optional values: `get`, `post`
74+
- **Method**: Select HTTP request method, optional values: `get`, `post`
7375

74-
:::tip
76+
:::tip
7577

76-
The `POST` method is recommended. When using the `GET` method, some sensitive information (such as plain text passwords) may be exposed via HTTP server logs. Also, for untrusted environments, please use HTTPS.
77-
:::
78+
The `POST` method is recommended. When using the `GET` method, some sensitive information (such as plain text passwords) may be exposed via HTTP server logs. Also, for untrusted environments, please use HTTPS.
79+
:::
7880

79-
- **URL**: Enter the URL address of the HTTP service.
80-
- **Headers** (optional): HTTP request header. You can add several headers. Keys and values support using [placeholders](./authn.md#authentication-placeholders).
81-
- **Enable TLS**: Turn on the toggle switch if you want to enable TLS. For more information on enabling TLS, see [Network and TLS](../../network/overview.md).
81+
- **URL**: Enter the URL address of the HTTP service.
82+
- **Precondition**: A [Variform expression](../../configuration/configuration.md#variform-expressions) used to control whether this HTTP Server authenticator should be applied to a client connection. The expression is evaluated against attributes from the client (such as `username`, `clientid`, `listener`, etc.). The authenticator will only be invoked if the expression evaluates to the string `"true"`. Otherwise, it will be skipped. For more information about the precondition, see [Authentication Preconditions](./authn.md#authentication-preconditions).
83+
- **Headers** (optional): HTTP request header. You can add several headers. Keys and values support using [placeholders](./authn.md#authentication-placeholders).
84+
- **Enable TLS**: Turn on the toggle switch if you want to enable TLS. For more information on enabling TLS, see [Network and TLS](../../network/overview.md).
85+
- **Body**: Request template; for `POST` requests, it is sent as a JSON in the request body; for `GET` requests, it is encoded as a Query String in the URL. Mapping keys and values support using [placeholders](./authn.md#authentication-placeholders).
86+
- **Advanced Settings**:
87+
- **Pool size** (optional): Input an integer value to define the number of concurrent connections from an EMQX node to an HTTP server. Default: `8`.
8288

83-
- **Body**: Request template; for `POST` requests, it is sent as a JSON in the request body; for `GET` requests, it is encoded as a Query String in the URL. Mapping keys and values support using [placeholders](./authn.md#authentication-placeholders).
89+
- **Connect Timeout** (optional): Specify the waiting period before EMQX assumes the connection is timed out. Units supported include milliseconds, second, minute, and hour.
8490

85-
- **Advanced Settings**:
91+
- **HTTP Pipelining** (optional): Input a positive integer to specify the maximum number of HTTP requests that can be sent without waiting for a response; default value: `100`.
8692

87-
- **Pool size** (optional): Input an integer value to define the number of concurrent connections from an EMQX node to an HTTP server. Default: `8`.
93+
- **Request Timeout** (optional): Specify the waiting period before EMQX assumes the request is timed out. Units supported include milliseconds, second, minute, and hour.
8894

89-
- **Connect Timeout** (optional): Specify the waiting period before EMQX assumes the connection is timed out. Units supported include milliseconds, second, minute, and hour.
90-
91-
- **HTTP Pipelining** (optional): Input a positive integer to specify the maximum number of HTTP requests that can be sent without waiting for a response; default value: `100`.
92-
93-
- **Request Timeout** (optional): Specify the waiting period before EMQX assumes the request is timed out. Units supported include milliseconds, second, minute, and hour.
94-
95-
After you finish the settings, click **Create**.
95+
5. After you finish the settings, click **Create**.
9696

9797
## Configure with Configuration Items
9898

en_US/access-control/authn/jwt.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Example:
5757

5858
1. Select **Access Control** -> **Authentication** from the left navigation menu.
5959

60-
2. On the **Authentication** page, click **Create** at the top right corner. Click to select **JWT** as **Mechanism**, and click **Next**. Skip the Backend selection and go to the **Configuration** tab.
60+
2. On the **Authentication** page, click **Create** in the top right corner. Click to select **JWT** as the **Mechanism**, and click **Next**. Skip the Backend selection and go to the **Configuration** tab.
6161

6262
<img src="./assets/authn-jwt.png" alt="JWT" style="zoom:67%;" />
6363

@@ -74,6 +74,7 @@ Example:
7474
- `public-key`: Uses a private key to generate the JWT's signature and a public key for verification. Supported algorithms are RS256, RS384, RS512, ES256, ES384, and ES512. Configuration must include:
7575
- `Public Key`: Specify the public key in PEM format used to verify the signature.
7676

77+
- **Precondition**: A [Variform expression](../../configuration/configuration.md#variform-expressions) used to control whether this JWT authenticator should be applied to a client connection. The expression is evaluated against attributes from the client (such as `username`, `clientid`, `listener`, etc.). The authenticator will only be invoked if the expression evaluates to the string `"true"`. Otherwise, it will be skipped. For more information about the precondition, see [Authentication Preconditions](./authn.md#authentication-preconditions).
7778
- **Disconnect After Expiration**: Configures whether to disconnect clients after their JWT expires, enabled by default.
7879
- **Payload**: Specify additional claims checks that the user wants to perform. Users can define multiple key-value pairs with the **Claim** and **Expacted Value** fields, where the key is used to find the corresponding claim in the JWT, so it needs to have the same name as the JWT claim to be checked, and the value is used to compare with the actual value of the claim. Currently, the placeholders supported are `${clientid}` and `${username}`.
7980

en_US/access-control/authn/kerberos.md

+15-8
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,30 @@ To configure the Kerberos authenticator, you need a running KDC (Key Distributio
5656

5757
EMQX can only support keytab files at the default location. You can configure the system default value by using the environment variable `KRB5_KTNAME` or by setting `default_keytab_name` in `/etc/krb5.conf`.
5858

59-
## Configure via Dashboard
59+
::: tip Note
6060

61-
In the EMQX Dashboard, navigate to **Access Control** -> **Authentication** in the left menu to enter the **Authentication** page. Click **Create** at the top right corner, then select **GSSAPI** as the **Mechanism**, and **Kerberos** as the **Backend**. Click **Next** to go to the **Configuration** step.
61+
The keytab file `/etc/krb5.conf` must be located on the EMQX nodes, and the user running the EMQX service must have read permissions for the file.
6262

63-
1. Configure the following fields:
63+
:::
6464

65-
- **Principal**: Set Kerberos principal for the server to define the server's identity within the Kerberos authentication system. For example, `mqtt/[email protected]`.
65+
## Configure via Dashboard
6666

67-
Note: The realm in use must be configured in `/etc/krb5.conf` on EMQX nodes.
67+
1. In the EMQX Dashboard, navigate to **Access Control** -> **Authentication** in the left menu to enter the **Authentication** page.
6868

69+
2. Click **Create** at the top right corner, then select **GSSAPI** as the **Mechanism**, and **Kerberos** as the **Backend**.
6970

70-
- **Keytab File**: Specify the path to the Kerberos keytab file.
71+
3. Click **Next** to go to the **Configuration** step.
7172

72-
Note: The keytab file must be located on the EMQX nodes, and the user running the EMQX service must have read permissions for the file.
73+
4. Configure the following fields:
74+
75+
- **Principal**: Set Kerberos principal for the server to define the server's identity within the Kerberos authentication system. For example, `mqtt/[email protected]`.
76+
77+
Note: The realm in use must be configured in `/etc/krb5.conf` on EMQX nodes.
78+
79+
- **Precondition**: A [Variform expression](../../configuration/configuration.md#variform-expressions) used to control whether this Kerberos authenticator should be applied to a client connection. The expression is evaluated against attributes from the client (such as `username`, `clientid`, `listener`, etc.). The authenticator will only be invoked if the expression evaluates to the string `"true"`. Otherwise, it will be skipped. For more information about the precondition, see [Authentication Preconditions](./authn.md#authentication-preconditions).
7380

7481

75-
2. Click **Create** to complete the configuration.
82+
5. Click **Create** to complete the configuration.
7683

7784
## Configure via Configuration Items
7885

0 commit comments

Comments
 (0)