-
Notifications
You must be signed in to change notification settings - Fork 291
docs: api-key scopes management usage, sso user mfa #3451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-5.10
Are you sure you want to change the base?
Changes from all commits
eea6032
115978f
87c98ea
0764d20
b0071ad
1e8574a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,31 @@ For security reasons, starting from EMQX 5.0.0, you cannot use Dashboard user cr | |||||
|
|
||||||
| #### Create API Keys | ||||||
|
|
||||||
| You can manually create API keys for authentication on the Dashboard by navigating to **System** -> **API Key**. For instructions, see [System - API Keys](../dashboard/system.md#api-keys). | ||||||
| ##### Dashboard | ||||||
|
|
||||||
| You can manually create API keys on the Dashboard by navigating to **System** -> **API Key**: | ||||||
|
|
||||||
| 1. Click the **+ Create** button in the top right corner to open the Create dialog. | ||||||
| 2. Configure the API key details: | ||||||
| - **Name** (required): Enter a name for the API key. | ||||||
| - **Expire At**: Leave empty for the key to never expire. | ||||||
| - **Is Enable**: Defaults to enabled. | ||||||
| - **Role**: Select a role (optional). See [Roles and Permissions](#roles-and-permissions). | ||||||
| - **Scopes**: Select the scopes to grant (optional). Defaults to all scope permissions. See [API Scopes](#api-scopes). | ||||||
| - **Note**: Optionally enter a description for the key. | ||||||
| 3. Click **Confirm**. The API key and secret key are displayed in the **Created Successfully** dialog. | ||||||
|
|
||||||
| ::: warning Important Notice | ||||||
|
|
||||||
| Save the API key and secret key immediately. The secret key will not be shown again. | ||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| 4. Click **Close** to dismiss the dialog. | ||||||
|
|
||||||
| You can view key details by clicking its name, edit its expiration, status, or note via the **Edit** button, or remove it with the **Delete** button. | ||||||
|
|
||||||
| ##### Bootstrap File | ||||||
|
|
||||||
| You can also create API keys using the bootstrap file method. Add the following configuration file to specify the file location: | ||||||
|
|
||||||
|
|
@@ -56,23 +80,26 @@ api_key = { | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| In the specified file, add multiple API keys in the format `{API Key}:{Secret Key}:{?Role}`, separated by new lines: | ||||||
| In the specified file, add multiple API keys in the format `{API Key}:{Secret Key}:{?Role}:{?Scopes}`, separated by new lines: | ||||||
|
|
||||||
| - **API Key**: Any string as the key identifier. | ||||||
| - **Secret Key**: Use a random string as the secret key. | ||||||
| - **Role (optional)**: Specify the key's [role](#roles-and-permissions). | ||||||
| - **Scopes (optional)**: Specify the [API Scopes](#api-scopes) the key is allowed to access, as a comma-separated list. When omitted, the key receives all user-visible scopes by default (administrative all-allow, for backward compatibility with earlier releases). | ||||||
|
|
||||||
| For example: | ||||||
|
|
||||||
| ```bash | ||||||
| my-app:AAA4A275-BEEC-4AF8-B70B-DAAC0341F8EB | ||||||
| ec3907f865805db0:Ee3taYltUKtoBVD9C3XjQl9C6NXheip8Z9B69BpUv5JxVHL:viewer | ||||||
| foo:3CA92E5F-30AB-41F5-B3E6-8D7E213BE97E:publisher | ||||||
| integration-svc:6f1a9f2d09c84e6b:viewer:monitoring,cluster_operations | ||||||
| rules-mgr:2b8e4a1c9d7e4f3b:administrator:data_integration,access_control | ||||||
| ``` | ||||||
|
|
||||||
| API keys created this way are valid indefinitely. | ||||||
|
|
||||||
| Each time EMQX starts, it will add the data set in the file to the API key list. If an API key already exists, its Secret Key and Role will be updated. | ||||||
| Each time EMQX starts, it will add the data set in the file to the API key list. If an API key already exists, its Secret Key, Role, and Scopes will be updated. | ||||||
|
|
||||||
| #### Roles and Permissions | ||||||
|
|
||||||
|
|
@@ -82,6 +109,80 @@ The REST API implements role-based access control. When creating an API key, you | |||||
| - **Viewer**: This role can only view resources and data, corresponding to all GET requests in the REST API. The corresponding role identifier is `viewer`. | ||||||
| - **Publisher**: Designed specifically for MQTT message publishing, this role is limited to accessing APIs related to message publishing. The corresponding role identifier is `publisher`. | ||||||
|
|
||||||
| #### API Scopes | ||||||
|
|
||||||
| Scopes are a per-key permission dimension introduced in EMQX 5.10 that declare which business areas of the REST API a key is allowed to reach. Scopes and [Roles and Permissions](#roles-and-permissions) are independent of each other and enforced together, forming two separate layers of access control: | ||||||
|
|
||||||
| | Dimension | Purpose | Granularity | | ||||||
|
Meggielqk marked this conversation as resolved.
|
||||||
| | --------- | ------- | ----------- | | ||||||
| | **Role** | Limits HTTP verbs (read-only vs. writes, publish-only, etc.) | Request action | | ||||||
| | **Scope** | Limits the API domain (clients, rules, monitoring, ...) | Resource area | | ||||||
|
|
||||||
| Every request is checked against both dimensions: the role check and the scope check. A request is accepted only when both checks pass. | ||||||
|
|
||||||
| ##### Why Scopes | ||||||
|
|
||||||
| In microservice and integration scenarios, external systems typically need access to only a subset of EMQX's management surface: | ||||||
|
|
||||||
| - A monitoring platform only needs the `monitoring` scope (`/metrics`, `/stats`, `/prometheus`, ...); | ||||||
| - A rules-publishing service only needs `data_integration` (`/rules`, `/connectors`, `/actions`, ...); | ||||||
| - A cluster operator tool only needs `cluster_operations` (`/cluster`, `/nodes`, `/load_rebalance`, ...). | ||||||
|
|
||||||
| With only `administrator` / `viewer` / `publisher` available, granularity is coarse: the only way to grant a service write access to rules is to hand it `administrator`, which effectively gives it full control over the whole system. | ||||||
|
|
||||||
| Scopes let you assign keys using the principle of least privilege: grant only the scopes required for the task, and minimize the blast radius if a key is ever leaked. | ||||||
|
|
||||||
| ##### Built-in Scopes | ||||||
|
|
||||||
| EMQX 5.10 ships with 10 scopes that you can combine freely when creating a key: | ||||||
|
|
||||||
| | Scope | Name | Typical API areas | | ||||||
| | --- | --- | --- | | ||||||
| | `connections` | Connection management | `/clients`, `/subscriptions`, `/topics`, `/banned`, `/retainer`, `/file_transfer`, `/mqtt/delayed`, `/mqtt/topic_rewrite`, ... | | ||||||
| | `publish` | Message publishing | `/publish`, `/publish/bulk` | | ||||||
| | `data_integration` | Data integration | `/rules`, `/connectors`, `/actions`, `/schema_registry`, `/schema_validations`, `/message_transformations`, `/exhooks`, `/ai/*` | | ||||||
| | `access_control` | Access control | `/authentication`, `/authorization/*` | | ||||||
| | `gateways` | Protocol gateways | `/gateways`, `/coap/*`, `/lwm2m/*`, `/gcp_devices`, ... | | ||||||
| | `monitoring` | Monitoring data | `/metrics`, `/stats`, `/monitor*`, `/alarms`, `/trace`, `/slow_subscriptions`, `/telemetry`, `/prometheus/{auth,stats,data_integration,...}`, ... | | ||||||
| | `cluster_operations` | Cluster operations | `/cluster*`, `/nodes`, `/load_rebalance`, `/node_eviction`, `/mt/*`, ... | | ||||||
| | `system` | System configuration | `/configs*`, `/listeners*`, `/plugins*`, `/ds/*`, `/data/*`, `/status`, `/relup`, `/opentelemetry*`, `/prometheus`, ... | | ||||||
| | `audit` | Audit log | `/audit` | | ||||||
| | `license` | License | `/license*` | | ||||||
|
|
||||||
| ::: tip | ||||||
| Scope names are stable identifiers that do not change across EMQX upgrades. Even if a route's OpenAPI tag is renamed, a key configured with the same scope keeps working. | ||||||
| ::: | ||||||
|
|
||||||
| Dashboard login, SSO callbacks and the API key self-management endpoints (for example `/login` and `/api_key`) can **never** be reached via API keys, regardless of the key's `scopes` configuration. This is a built-in Dashboard security boundary, unrelated to the scope model. | ||||||
|
||||||
| Dashboard login, SSO callbacks and the API key self-management endpoints (for example `/login` and `/api_key`) can **never** be reached via API keys, regardless of the key's `scopes` configuration. This is a built-in Dashboard security boundary, unrelated to the scope model. | |
| Dashboard login, SSO callbacks, and API key self-management endpoints (for example `/api_key`) do not accept API-key authentication, regardless of the key's `scopes` configuration. This is a built-in Dashboard security boundary, unrelated to the scope model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field label "Is Enable" is ungrammatical and doesn’t match common UI wording. Consider renaming it to something like "Enabled" / "Enable" (or whatever the Dashboard actually shows) and keep the navigation label consistent with the rest of the docs (System -> API Keys vs API Key).