Mnesia ACL

    插件:

    1. "username":"emqx",
    2. "clientid":"client1",
    3. "topic":"testtopic/1",
    4. "action":"pub",
    5. "access": "allow"
    6. }

    规则字段说明:

    • clientid:客户端的 Client ID.
    • username: 客户端的 Username.
    • topic:控制的主题,可以使用通配符,并且可以在主题中加入占位符来匹配客户端信息,例如 t/%c 则在匹配时主题将会替换为当前客户端的 Client ID
      • %u:用户名
      • %c:Client ID
    • action:操作行为,可选值:pub | sub | pubsub
    • Access:是否允许,可选值:allow | deny

    usernameclientid是可选的,当两个都没有提供时,该规则适用于所有的客户端

    Mnesia ACL 默认不设规则,你可以使用 HTTP API 和 emqx_ctl 管理 ACL 规则。

    使用 HTTP API 管理 ACL 规则

      1. # Request
      2. POST api/v4/acl
      3. {
      4. "clientid":"emqx_c",
      5. "topic":"Topic/A",
      6. "action":"pub",
      7. "access": "allow"
      8. }
      9. # Response
      10. {
      11. "data": {
      12. "clientid":"emqx_c",
      13. "topic":"Topic/A",
      14. "action":"pub",
      15. "access": "allow"
      16. "result": "ok"
      17. },
      18. "code": 0
      19. }
    • Username ACL:

      1. # Request
      2. POST api/v4/acl
      3. {
      4. "username":"emqx_u",
      5. "topic":"Topic/A",
      6. "action":"pub",
      7. "access": "allow"
      8. }
      9. # Response
      10. {
      11. "data": {
      12. "username":"emqx_u",
      13. "topic":"Topic/A",
      14. "action":"pub",
      15. "access": "allow"
      16. "result": "ok"
      17. },
      18. "code": 0
      19. }
    • $all ACL:

    1. # Request
    2. POST api/v4/acl
    3. [
    4. {
    5. "clientid":"emqx_c_1",
    6. "topic":"Topic/A",
    7. "action":"pub",
    8. "access": "allow"
    9. },
    10. {
    11. "username":"emqx_u_1",
    12. "topic":"Topic/A",
    13. "action":"sub",
    14. "access": "allow"
    15. },
    16. {
    17. "action":"pubsub",
    18. "access": "deny"
    19. }
    20. ]
    21. {
    22. "data": [
    23. {
    24. "clientid":"emqx_c_1",
    25. "topic":"Topic/A",
    26. "action":"pub",
    27. "access": "allow",
    28. "result": "ok"
    29. },
    30. {
    31. "username":"emqx_u_1",
    32. "topic":"Topic/A",
    33. "action":"pub",
    34. "access": "allow"
    35. "result": "ok"
    36. },
    37. {
    38. "all": "$all",
    39. "topic":"Topic/+",
    40. "action":"pubsub",
    41. "access": "deny"
    42. },
    43. ],
    44. "code": 0
    45. }
    • Clientid ACL:

      1. # Request
      2. GET api/v4/acl/clientid
      3. # Response
      4. {
      5. "meta": {
      6. "page": 1,
      7. "limit": 10,
      8. "count": 1
      9. },
      10. "data": [
      11. {
      12. "clientid": "emqx_c",
      13. "topic": "Topic/A",
      14. "action": "pub",
      15. "access": "allow"
      16. },
      17. {
      18. "clientid": "emqx_c_1",
      19. "topic": "Topic/A",
      20. "action": "pub",
      21. "access": "allow"
      22. },
      23. {
      24. "clientid": "emqx_c_2",
      25. "topic": "Topic/A",
      26. "action": "pub",
      27. "access": "allow"
      28. }
      29. ],
      30. "code": 0
      31. }
    • Username ACL:

      1. # Request
      2. GET api/v4/acl/username
      3. # Response
      4. {
      5. "meta": {
      6. "page": 1,
      7. "limit": 10,
      8. "count": 1
      9. },
      10. "data": [
      11. {
      12. "username": "emqx_u",
      13. "topic": "Topic/A",
      14. "action": "pub",
      15. },
      16. {
      17. "username": "emqx_u_1",
      18. "topic": "Topic/A",
      19. "action": "pub",
      20. "access": "allow"
      21. },
      22. {
      23. "username": "emqx_u_2",
      24. "topic": "Topic/A",
      25. "action": "pub",
      26. "access": "allow"
      27. }
      28. ],
      29. "code": 0
      30. }
    • Clientid ACL:

      1. # Request
      2. GET api/v4/acl/clientid/emqx_c
      3. # Response
      4. {
      5. "data": [
      6. {
      7. "topic": "Topic/A",
      8. "clientid": "emqx_c",
      9. "access": "allow",
      10. "action": "pub"
      11. },
      12. {
      13. "topic": "Topic/B",
      14. "clientid": "emqx_c",
      15. "access": "allow",
      16. "action": "pub"
      17. }
      18. ],
      19. "code": 0
      20. }
    • Username ACL:

      1. # Request
      2. GET api/v4/acl/username/emqx_u
      3. # Response
      4. {
      5. "data": [
      6. {
      7. "topic": "Topic/A",
      8. "username": "emqx_u",
      9. "access": "allow",
      10. "action": "pub"
      11. },
      12. {
      13. "topic": "Topic/B",
      14. "username": "emqx_u",
      15. "access": "allow",
      16. "action": "pub"
      17. }
      18. ],
      19. "code": 0
      20. }
    • Client ACL

      1. # Request
      2. # 请注意 ${topic} 需要使用 UrlEncode 编码
      3. DELETE api/v4/acl/clientid/${clientid}/topic/${topic}
      4. # Response
      5. {
      6. "code": 0
      7. }
    • Username ACL

      1. # Request
      2. # 请注意 ${topic} 需要使用 UrlEncode 编码
      3. DELETE api/v4/acl/$all/topic/${topic}
      4. # Response
      5. {
      6. }