Skip to content

Commit b6cd42f

Browse files
authored
Merge pull request #2547 from emqx/0618-jwt-authz-update
docs(authz & jwt): Update topic placeholders and acl example
2 parents ca518bd + d5cf927 commit b6cd42f

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

en_US/access-control/authn/jwt.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ Example:
6969
"topic": "t/${clientid}"
7070
},
7171
{
72-
// Allows the client to subscribe to the topic t/1 with QoS 1, while QoS 0 or 2 is allowed
73-
"permission": "deny",
72+
"permission": "allow",
7473
"action": "subscribe",
75-
"topic": "t/1",
74+
// The 'eq' prefix means the rule matches 't/1/#', but not 't/1/x' or 't/1/y'
75+
"topic": "eq t/1/#",
76+
// Matches QoS 1, but not QoS 0 or 2
7677
"qos": [1]
7778
},
7879
{

en_US/access-control/authz/authz.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ EMQX also allows placeholders to be used in topics to support dynamic themes. Th
102102

103103
Placeholders can be used as topic segments, like `a/b/${username}/c/d`.
104104

105-
To avoid placeholder interpolation, one may use special `eq` syntax: `eq a/b/${username}/c/d`. This topic is treated as `a/b/${username}/c/d` literally, without interpolation.
105+
To avoid placeholder interpolation, starting from EMQX 5.4, you can escape `$` as `${$}`. For example, `t/${$}{username}` is treated as `t/${username}` literally without interpolation, rather than the topic name with `username` replaced.
106+
107+
::: tip
108+
109+
If you use the `eq` syntax in query statements, note that the topic following `eq` does not support placeholder interpolation. This behavior can change in future versions.
110+
111+
The `eq` syntax is to match exactly a topic filter, but not any topic that matches the filter. For example, `eq t/#` matches `t/#`, not `t/1` or `t/2`.
112+
113+
:::
106114

107115
### Authorization Check Priority
108116

zh_CN/access-control/authn/jwt.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@
6565
"topic": "t/${clientid}"
6666
},
6767
{
68-
// 允许客户端以 QoS 1 订阅 t/1 主题,使用 QoS 0 或 2 则是允许的
69-
"permission": "deny",
68+
"permission": "allow",
7069
"action": "subscribe",
71-
"topic": "t/1",
70+
// `eq` 前缀意味着该规则仅适用于主题过滤器 t/1/#,但不适用于 t/1/x 或 t/1/y 等
71+
"topic": "eq t/1/#",
72+
// 该规则只匹配 QoS 1 但不匹配 QoS 0 或 2
7273
"qos": [1]
7374
},
7475
{

zh_CN/access-control/authz/authz.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ EMQX 还允许在主题中使用占位符,在匹配规则时将当前客户端
116116

117117
<!-- TODO 调查与 4.x 版本是否存在差异-->
118118

119-
为了避免占位符跟想要的主题冲突的问题,EMQX 5.0 中引入了一个 `eq` 语法,例如 `eq a/b/${username}/c/d`
119+
为了避免占位符跟想要的主题冲突的问题,从 EMQX 5.4 开始,可以使用 `${$}` 来对 `$` 进行转义。例如 `t/${$}{username}` 表示 `t/${username}` 本身,而不是将 username 替换进去之后的主题名称。
120+
121+
::: tip
122+
123+
如果在查询语句中使用`eq` 语法,需要注意,`eq` 后面的主题不支持占位符替换,这个行为可能会在后续版本中改变。
124+
125+
`eq` 语法用于精确匹配一个订阅主题通配符,而不是匹配该通配符的其他主题。 例如 `eq t/#` 精确匹配 `t/#` 但不匹配 `t/1``t/2` 等等。
126+
127+
:::
120128

121129
### 授权检查优先级
122130

zh_CN/access-control/authz/file.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EMQX 支持基于 ACL 文件中存储的规则进行授权检查。您可在文
1212
## 文件格式
1313
基于文件的授权权限列表简单轻量,适合配置通用的规则。对于上百条或者更面向客户端的规则,推荐使用其他授权来源。基于文件的权限列表可以作为防护置于授权链末端。
1414

15-
基于文件进行授权检查前,您需要将授权规则以 [Erlang 元组](https://www.erlang.org/doc/reference_manual/data_types.html#tuple) 数据列表的形式存储在文件中。
15+
基于文件进行授权检查前,您需要将授权规则以 [Erlang 元组](https://www.erlang.org/doc/reference_manual/data_types.html#tuple)数据列表的形式存储在文件中。
1616

1717
基本语法和概念如下:
1818

0 commit comments

Comments
 (0)