【elasticsearch】慢查询替代查询审计的尝试

【elasticsearch】慢查询替代查询审计的尝试

使用了es有两年了,突然发现一个,es没有查询审计日志,某个用户查询了某个索引的审计。

找了官方文档和社区的回复都是说使用slow log替代慢查询。

尝试一下。

参考链接1:https://discuss.elastic.co/t/does-elasticsearch-capture-audit-logs-for-query-dsl-eql-and-sql-or-not/339398/8

参考链接2:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/auditing-search-queries.html

前置条件

elasticsearch: 7.17.13

操作系统:linux7.9

es加密配置,只有加密后才可以使用audit log

yml 复制代码
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate 
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12

普通查询

bash 复制代码
 curl -u elastic:AAA320 localhost:9200/sq-20240506/_search

普通插入

bash 复制代码
curl -u elastic:AAA320 -H 'Content-Type: application/json' -X POST localhost:9200/sq-20240506/_doc/1 -d '
{
"firstname": "Krishna",
"lastname": "kumar"
}'

上述查询和插入没有任何slow log信息。

设置慢查询

这里设置trace的慢查询为0ms,会捕获所有查询。

bash 复制代码
curl -u elastic:AAA320 -H 'Content-Type: application/json'  -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
  "index.search.slowlog.threshold.fetch.debug" : "500ms",
  "index.search.slowlog.threshold.fetch.info" : "800ms",
  "index.search.slowlog.threshold.fetch.trace" : "0ms",
  "index.search.slowlog.threshold.fetch.warn" : "1s",
  "index.search.slowlog.threshold.query.debug" : "2s",
  "index.search.slowlog.threshold.query.info" : "5s",
  "index.search.slowlog.threshold.query.trace" : "0ms",
  "index.search.slowlog.threshold.query.warn" : "10s"
}'

查看日志

慢查询日志,存放再es的日志文件夹中,elasticsearch_index_search_slowlog.log,这里可以看到TRACE级别的日志,可以看到分query和fetch两种,有节点信息、索引信息、分片以及耗时,但是我还是觉得这里缺少了查询用户,查询来源信息,目前还是无法满足我的实际排查需求。

bash 复制代码
] tailf elasticsearch_index_search_slowlog.log
[2024-05-06T16:33:29,528][TRACE][i.s.s.query              ] [node-1] [sq-20240506][0] took[179.4micros], took_millis[0], total_hits[1 hits], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[1], source[{}], id[], 
[2024-05-06T16:33:29,529][TRACE][i.s.s.fetch              ] [node-1] [sq-20240506][0] took[3.3ms], took_millis[3], total_hits[1 hits], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[1], source[{}], id[],

取消慢查询

bash 复制代码
curl -u elastic:AAA320 -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/_all/_settings' -d '{
  "index.search.slowlog.threshold.fetch.debug": null,
  "index.search.slowlog.threshold.fetch.info": null,
  "index.search.slowlog.threshold.fetch.trace": null,
  "index.search.slowlog.threshold.fetch.warn": null,
  "index.search.slowlog.threshold.query.debug": null,
  "index.search.slowlog.threshold.query.info": null,
  "index.search.slowlog.threshold.query.trace": null,
  "index.search.slowlog.threshold.query.warn": null
}'
相关推荐
Eric-Ln1 小时前
大数据在 AI 时代来临下的思考与感悟
大数据·ai·bigdata
互联网江湖2 小时前
逐际动力张巍:具身智能的瓶颈在“技能”,而非“智能”
大数据·人工智能
leijiwen3 小时前
链生之境・以数据要素确权驱动智能服务的本地生活服务平台
大数据·人工智能·生活
linweidong4 小时前
Headless BI 实战:指标语义层从设计到落地的完整过程
大数据·数据挖掘·flink·数据湖·finebi·bi·chat bi
GongYeRunHuaYou4 小时前
医疗设备显示屏粘接选什么胶合适?3M VHB 4914-020薄型粘接方案
大数据·人工智能·医疗设备·工业胶粘剂·3m胶粘·结构粘接
redsea_HR4 小时前
全球化HR系统选型:本地服务网络和远程支持怎么选?
大数据·服务器·网络
用户46043852250865 小时前
关于paimon- rust的学习 --- Table(一)
大数据·rust
西木莉5 小时前
AI 落地制造的卡点:不是缺大模型,是缺可消费的业务语义资产
大数据·人工智能
smart19985 小时前
3 节点起步、5 节点封顶:边缘 AI 集群的算力、存储与K8s平台
大数据·人工智能
阿里云大数据AI技术5 小时前
宏湖负责汇聚,锦鲤负责探路:中宏保险的 DataWorks Data Agent 智能化实践之路
大数据·人工智能