【问题标题】:ejabberd rest API without authentication, 403 Forbidden (error code 32)ejabberd rest API 没有身份验证,403 Forbidden(错误代码 32)
【发布时间】:2017-10-31 14:39:53
【问题描述】:

我正在尝试在没有身份验证的情况下访问 ejabberd rest api,但总是得到带有此正文的 403 Forbidden 响应:

{
    "status": "error",
    "code": 32,
    "message": "AccessRules: Account does not have the right to perform the operation."
}

我无法在 /api/status 端点上得到 OK 响应,这是来自 127.0.0.1 的所有用户都应该能够使用的命令(请参阅 ejabberd.yml 中 api_permissions 下的“公共命令”部分)。

这是请求详细信息(通过 Insomnia REST 客户端):

> POST /api/status HTTP/1.1
> User-Agent: insomnia/5.1.0
> Host: localhost:5280
> Accept: */*
> Accept-Encoding: deflate, gzip
> Content-Type: application/json
> Content-Length: 2
| {}

Ejabberd 版本为 17.04,从下载的 deb 包安装并以 ejabberd 用户身份在 Debian 8.8 (jessie) x86_64 上运行。 安装后,我只是添加了主机“localhost”,为 localhost 注册了一个新用户“admin”并将其添加到 ACL。

我对 ejabberd.yml 所做的唯一更改:

hosts:
  - "localhost"
acl:
  admin:
    user:
      - "admin": "localhost"

否则,我可以访问运行良好的 webadmin 界面...
我该怎么做才能得到 200 OK 响应?

【问题讨论】:

    标签: rest ejabberd ejabberd-api


    【解决方案1】:

    好的,我找到了解决方案。就像消息说的那样,这是一个权限问题。
    这是默认配置:

    api_permissions:
    ## ...
      "public commands":
        who:
          - ip: "127.0.0.1/8"
        what:
          - "status"
          - "connected_users_number"
    

    不允许访问statusconnected_users_number命令有或没有身份验证(我三重检查)。

    如果不使用身份验证,请使用-all

      "public commands":
        who:
    ## This allows to use both commands without having to authenticate
          - all
        what:
          - "status"
          - "connected_users_number"
    

    如果您需要有效用户(使用基本身份验证),请将 - all 替换为 - access: local

      "public commands":
        who:
    ## This allows to use both commands with basic authentication for local users
          - access: local
        what:
          - "status"
          - "connected_users_number"
    

    【讨论】:

    • 工作就像一个魅力,我怎么能也强​​制IP限制?
    • 你用的是什么版本?在 17.04 中,它不适用于 - ip: "127.0.0.1/8" 对我来说。但在后来的版本中,它似乎工作正常。
    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多