跳到主要内容

Elasticsearch 账号权限

网关专用 Elasticsearch 账号的角色定义,在 Kibana 中或通过 API 创建账号的方法,以及改用 API key 连接。

网关对日志索引只读,自身状态写入 .rst_copilot_* 前缀下的隐藏索引。为网关创建专用账号,不使用 elastic 超级用户。

角色权限

集群权限

权限用途是否必需
monitor连通检查(/readyz 的 es)、平台健康 的集群级检查和索引列表必需
manage_ilm、manage_index_templates审计写入 ILM 数据流设置 RST_ILM_BOOTSTRAP=true 时

缺少 monitor 时 /readyz 返回 not_ready,es 一项为 ping returned False,平台健康各项显示为未知。

索引权限

索引模式权限用途是否必需
日志索引,例如 logs-*、filebeat-*、winlogbeat-*read、view_index_metadata智能查询、字段字典、调查取证必需
.rst_copilot_*create_index、read、write、manage审计、会话、知识库、学习库、报告、分析记录、告警、游标、通知配置与队列、资产、用户状态必需
.alerts-security.alerts-*、.internal.alerts-security.alerts-*read、view_index_metadata实时告警 拉取、批量分诊使用告警功能时
logs-osquery_manager.result-*read、view_index_metadata基线巡检使用基线功能时
baseline-*、eol-catalogcreate_index、read、write、manage基线的规则、结果、轮次,以及由网关创建的软件生命周期目录使用基线功能时

baseline-* 与 eol-catalog 不带 .rst_copilot_ 前缀,不在上一行的通配范围内。缺少这两项时基线页没有规则,执行返回 403。

Kibana 功能权限

空间功能权限用途是否必需
defaultDiscover:Read在 Kibana 中打开配置 KIBANA_URL 且 Kibana 沿用网关账号时

缺少该权限时网关查不到数据视图,在 Kibana 中打开 提示「在 Kibana 中找不到匹配索引 <索引> 的 Data View」,即使 Kibana 中已有该数据视图。

在 Kibana 中创建账号

步骤

  1. 在 Kibana 中打开 Stack Management > Security > Roles,选择 Create role,角色名为 rst_copilot_gateway。
  2. 在 Cluster privileges 中添加 monitor。设置了 RST_ILM_BOOTSTRAP=true 时再添加 manage_ilm、manage_index_templates。
  3. 在 Index privileges 中按上表逐行添加索引模式和权限。
  4. 配置了 KIBANA_URL 时,在 Kibana 一栏选择 Add Kibana privilege,空间选 default,在功能列表中把 Discover 设为 Read。
  5. 在 Users 中选择 Create user,用户名为 rst_copilot_gateway,分配该角色。
  6. 把账号写入 .env 的 ES_USER 和 ES_PASSWORD,或在 系统设置 中测试连接后保存。改用 API key 见 使用 API key。

.alerts-security.alerts-* 等隐藏索引不出现在索引下拉的自动补全中。直接输入模式即可,不需要打开包含受限索引的开关。

通过 API 创建账号

PUT _security/role/rst_copilot_gateway
{
  "cluster": ["monitor"],
  "indices": [
    { "names": ["logs-*", "filebeat-*", "winlogbeat-*"], "privileges": ["read", "view_index_metadata"] },
    { "names": [".rst_copilot_*", "baseline-*", "eol-catalog"], "privileges": ["create_index", "read", "write", "manage"] },
    { "names": [".alerts-security.alerts-*", ".internal.alerts-security.alerts-*", "logs-osquery_manager.result-*"], "privileges": ["read", "view_index_metadata"] }
  ]
}

PUT _security/user/rst_copilot_gateway
{ "password": "<强密码>", "roles": ["rst_copilot_gateway"] }

设置了 RST_ILM_BOOTSTRAP=true 时,cluster 改为 ["monitor", "manage_ilm", "manage_index_templates"]。

Kibana 功能权限只能通过 Kibana 的角色 API 设置。该请求会整体覆盖同名角色,elasticsearch 一段要把上面的集群和索引权限一起带上,否则这些权限会被清空:

curl -u elastic -X PUT "https://<Kibana 地址>/api/security/role/rst_copilot_gateway" \
  -H "kbn-xsrf: true" -H "Content-Type: application/json" -d '
{
  "elasticsearch": {
    "cluster": ["monitor"],
    "indices": [
      { "names": ["logs-*", "filebeat-*", "winlogbeat-*"], "privileges": ["read", "view_index_metadata"] },
      { "names": [".rst_copilot_*", "baseline-*", "eol-catalog"], "privileges": ["create_index", "read", "write", "manage"] },
      { "names": [".alerts-security.alerts-*", ".internal.alerts-security.alerts-*", "logs-osquery_manager.result-*"], "privileges": ["read", "view_index_metadata"] }
    ]
  },
  "kibana": [
    { "base": [], "feature": { "discover": ["read"] }, "spaces": ["default"] }
  ]
}'

使用 API key

网关可以用 API key 代替用户名和密码连接 Elasticsearch。API key 的权限等于签发它的账号的权限,所以仍然先按上文创建 rst_copilot_gateway 账号和角色,再为该账号签发 key。

步骤

  1. 用管理员账号为 rst_copilot_gateway 签发 key:

    POST _security/api_key/grant
    {
      "grant_type": "password",
      "username": "rst_copilot_gateway",
      "password": "<强密码>",
      "api_key": { "name": "rst-copilot-gateway" }
    }

    也可以用 rst_copilot_gateway 登录 Kibana,在 Stack Management > Security > API keys 中创建。

  2. 把返回中的 encoded 值写入 .env 的 ES_API_KEY。

  3. 重启网关。

ES_API_KEY 优先于 ES_USER / ES_PASSWORD。未配置 KIBANA_* 凭据时,Kibana 调用也使用这个 key。ES_API_KEY 只能在 .env 中设置,系统设置 中没有这一项。

验证权限

curl -k https://<域名>/readyz

返回中的 es_write 应为 ok。为 denied 时,账号缺少 .rst_copilot_* 的建索引或写权限,网关日志中出现 es_write_denied。返回 not_ready 且 es 为 ping returned False 时,账号缺少集群权限 monitor,或地址、证书、凭据有误。

系统设置中测试连接提示「连接成功,但这个账号列不出索引」时,账号缺少 monitor 或目标索引的 read。

索引白名单

账号权限决定网关能读取哪些索引,索引白名单(RST_INDEX_WHITELIST,或系统设置中的 索引白名单)决定网关实际查询哪些索引。两层都要设置:账号只授予必要的索引,白名单再收窄一层。模型查询白名单外的索引时请求被拒绝,拒绝记录显示在 告警调查 的检索过程中。

本页内容