📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

适用版本: 6.8-8.x

1. 错误说明 #

报错 failed to parse indices privileges for role [<role>]. <field1> requires <field2> if <field3> is given 表示字段级权限配置存在依赖关系:你设置了排除字段,但没有提供允许字段集合。

从附录逻辑可见,只要 deniedFields 存在而 grantedFields 为空,解析器就会拒绝该配置。

2. 常见触发场景 #

  • 角色里只写了 except,没写 grant
  • 把旧版本字段安全模板迁移到新环境时,遗漏了白名单字段。
  • 程序合并权限配置时,grant_fields 被条件分支意外删除。

错误示例:

{
  "indices": [
    {
      "names": ["logs-*"],
      "privileges": ["read"],
      "field_security": {
        "except": ["secret"]
      }
    }
  ]
}

3. 排查方法 #

  1. 检查报错对应的索引权限对象是否包含 field_security.except
  2. 确认同一对象中是否同时存在 field_security.grant
  3. 如果 grant 是由默认模板注入,核对模板变量是否在某些场景下为空。
  4. 进一步检查 except 是否真的是 grant 的子集,避免修完后出现下一类字段权限错误。

4. 修复方法 #

  • except 配置对应的 grant 字段集合。
  • 如果不需要字段级过滤,直接移除整个 field_security 配置。

修正示例:

{
  "indices": [
    {
      "names": ["logs-*"],
      "privileges": ["read"],
      "field_security": {
        "grant": ["message", "host", "secret"],
        "except": ["secret"]
      }
    }
  ]
}

5. 预防建议 #

  • grantexcept 视为一组联动字段,在配置层做联合校验。
  • 对角色模板增加字段安全单元测试,覆盖“只有 except”“只有 grant”“两者同时存在”等情况。
  • 尽量使用可复用模板管理字段级权限,减少手工编辑。

相关错误 #

附:日志上下文 #

if (privileges == null) {
 throw new ElasticsearchParseException("failed to parse indices privileges for role [{}]. missing required [{}] field";
 roleName; Fields.PRIVILEGES.getPreferredName());
 }
 if (deniedFields != null && grantedFields == null) {
 throw new ElasticsearchParseException("failed to parse indices privileges for role [{}]. {} requires {} if {} is given";
 roleName; Fields.FIELD_PERMISSIONS; Fields.GRANT_FIELDS; Fields.EXCEPT_FIELDS);
 }
 checkIfExceptFieldsIsSubsetOfGrantedFields(roleName; grantedFields; deniedFields);
 return RoleDescriptor.IndicesPrivileges.builder()
 .indices(names)