0

我正在尝试遵循API 权限 | ejabberd 文档配置 ejabberd | ejabberd 文档

然而在尝试注册用户时:

# curl -sk -d '{"user":"test", "password":"testing", "host":"localhost"}' -H 'Content-Type: application/json' https://localhost:5443/api/register 

我得到以下信息ejabberd.log

# tail -2 ./home/ejabberd/logs/ejabberd.log 
2019-10-04 21:41:47.079 [info] <0.663.0>@mod_http_api:log:509 API call register [{<<"user">>,<<"test">>},{<<"password">>,<<"testing">>},{<<"host">>,<<"localhost">>}] from ::ffff:172.19.0.1:53740
2019-10-04 21:41:47.079 [info] <0.521.0>@ejabberd_listener:accept:256 (<0.663.0>) Accepted connection [::ffff:172.19.0.1]:53740 -> [::ffff:172.19.0.6]:5443
# 

ejabberd.yml' acl&api_permissions块:

acl:
  local:
    user_regexp: ""
  loopback:
    ip:
      - 127.0.0.0/8
      - ::1/128
      - ::FFFF:127.0.0.1/128
  admin:
    user:
      - "admin@localhost"
    ip:
      - ::/0
      - ::FFFF:10.0.0.0/8
      - ::FFFF:172.16.0.0/12
      - ::FFFF:172.19.0.0/12
      - ::FFFF:192.168.0.0/16

&

api_permissions:
  "console commands":
    from:
      - ejabberd_ctl
    who: all
    what: "*"
  "admin access":
    who: 
      access:
        allow:
          acl: loopback
          acl: admin
          ip:
            - ::/0
            - ::FFFF:10.0.0.0/8
            - ::FFFF:172.16.0.0/12
            - ::FFFF:172.19.0.0/12
            - ::FFFF:192.168.0.0/16
      oauth:
        scope: "ejabberd:admin"
        access:
          allow:
            acl: loopback
            acl: admin
    what:
      - "*"
      - "!stop"
      - "!start"
  "public commands":
    who:
      ip: 127.0.0.1/8
    what:
      - status
      - connected_users_number

请指教。

4

2 回答 2

3

我将ip/range 添加到admin AND loopback块:

acl:
  local:
    user_regexp: ""
  loopback:
    ip:
      - 127.0.0.0/8
      - ::1/128
      - ::FFFF:127.0.0.1/128
      - ::FFFF:172.19.0.0/16
  admin:
    user:
      - "admin@localhost"
    ip:
      - ::FFFF:172.19.0.0/16

并且错误消失了)

于 2019-10-11T20:48:25.390 回答
0

使用此最小配置:

listen:
  -
    port: 5443
    ip: "::"
    module: ejabberd_http
    tls: true
    request_handlers:
      "/api": mod_http_api

acl:
  admin:
    ip:
      - "127.0.0.1"

api_permissions:
  "admin commands":
    who: admin
    what:
      - register

如果我在机器 127.0.0.1 中执行它,它会起作用:

$ curl -sk -d '{"user":"test", "password":"testing", "host":"localhost"}' -H 'Content-Type: application/json' https://localhost:5443/api/register

"User test@localhost successfully registered"
于 2019-10-07T11:02:50.277 回答