二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • Nexus系列文章

  • Jenkins系列文章

  • ELK笔记

    • ELK

    • FileBeat

    • LogStash

    • ElasticSearch

      • elasticsearch高可用的探索
      • elasticsearch索引管理
      • elasticsearch配置等优化
      • elasticsearch-7-x使用xpack进行安全认证
        • 1、x-pack 演变
        • 2、安全部分免费之前,大家怎么保证基础安全?
        • 3,单机版 elk 认证
          • 1,配置 es。
          • 2,为内置账号添加密码
          • 3,配置 kibana 连接。
          • 1,明文配置
          • 2,密文配置
          • 3,logstash 配置认证。
        • 4,集群配置。
          • 1,证书。
          • 2,配置。
          • 3,为内置账号添加密码
      • elasticsearch的mapping
      • elasticsearch的日常维护参数
      • elasticsearch-ILM-索引生命周期管理探微
      • 如何优雅地下掉一台es节点
    • Kibana

  • Kubernetes笔记

  • LLM专题

  • 系列专题
  • ELK笔记
  • ElasticSearch
二丫讲梵
2019-12-14
目录

elasticsearch-7-x使用xpack进行安全认证

文章发布较早,内容可能过时,阅读注意甄别。

2019 年 5 月 21 日,Elastic 官方发布消息: Elastic Stack 新版本 6.8.0 和 7.1.0 的核心安全功能现免费提供。

这意味着用户现在能够对网络流量进行加密、创建和管理用户、定义能够保护索引和集群级别访问权限的角色,并且使用 Spaces 为 Kibana 提供全面保护。 免费提供的核心安全功能如下:

  • TLS 功能。 可对通信进行加密
  • 文件和原生 Realm。 可用于创建和管理用户
  • 基于角色的访问控制。 可用于控制用户对集群 API 和索引的访问权限
  • 通过针对 Kibana Spaces 的安全功能,还可允许在 Kibana 中实现多租户

# 1、x-pack 演变

  • 5.X 版本之前:没有 x-pack,是独立的:security 安全,watch 查看,alert 警告等独立单元。
  • 5.X 版本:对原本的安全,警告,监视,图形和报告做了一个封装,形成了 x-pack。
  • 6.3 版本之前:需要额外安装。
  • 6.3 版本及之后:已经集成在一起发布,无需额外安装,基础安全属于付费黄金版内容。 7 .1 版本:基础安全免费。

# 2、安全部分免费之前,大家怎么保证基础安全?

  • 场景一:全部“裸奔”,相信这在国内占据了非常大的比重。 内网部署,不对外提供服务。或者 ES 作为业务基础支撑,不公网开放 9200 等常用端口,开放的是业务的服务端口。 可能暴露问题:公司或团队内部开放 9200、5601 端口,基本 head 插件、kibana 都能连接,极易导致线上索引或数据可能被误删。

  • 场景二:加了简单防护。 一般使用 Nginx 身份认证+防火墙策略控制。

  • 场景三:整合使用了第三方安全认证方案。 比如:SearchGuard、ReadonlyREST。

  • 场景四:付费购买了 Elastic-Xpack 黄金版或白金版服务。 一般是银行等土豪大客户,对安全、预警、机器学习等付费功能需求迫切,如:宁波银行付费购买白金服务。

以上内容摘自:https://blog.csdn.net/laoyang360/article/details/90554761

既然新版本的 es 已经提供了基础的用户认证,那么多一层总比没有要强,因此接下来就实际配置一下单机版的 elk 和集群版的认证,两个稍微有一些不同,因此区分对待。

因为主要体现在 es 与 kibana 的认证,因此这里就只展现这两者的配置,其他 logstash 方面的,后续再完善。

# 3,单机版 elk 认证

本次实验 elk 全系版本都是基于7.4.0进行。

安装过程略过,直接来到配置阶段。

# 1,配置 es。

$ cat elasticsearch.yml

cluster.name: eryajf-search
node.name: ops-eryajf-test-1
path.data: /data/elasticsearch7/data
path.logs: /data/elasticsearch7/log
network.host: 0.0.0.0
http.port: 9200
xpack.security.enabled: true # 这条配置表示开启xpack认证机制
xpack.security.transport.ssl.enabled: true
cluster.initial_master_nodes: ["10.3.7.7"]
1
2
3
4
5
6
7
8
9
10
11
  • xpack.security.enabled:表示开启 xpack 认证机制。
  • xpack.security.transport.ssl.enabled:这条如果不配,es 将起不来,会报如下错误:Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]

配置完成,记得创建配置中涉及到的目录并授权,然后启动 es。启动成功之后,再次访问 es,就需要基于用户来访问了,但是在这之前,需要先给对应的用户创建密码才行。

# 2,为内置账号添加密码

ES 中内置了几个管理其他集成组件的账号即:apm_system, beats_system, elastic, kibana, logstash_system, remote_monitoring_user,使用之前,首先需要添加一下密码。

$ /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  • interactive:给用户一一设置密码。
  • auto:自动生成密码。

如果这个地方报如下错误:

Failed to determine the health of the cluster running at http://10.3.7.7:9200
Unexpected response code [503] from calling GET http://10.3.7.7:9200/_cluster/health?pretty
Cause: master_not_discovered_exception

It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords.
It is very likely that the password changes will fail when run against an unhealthy cluster.

Do you want to continue with the password setup process [y/N]y
1
2
3
4
5
6
7
8

可能是有脏数据导致,此时可以停掉 es,删除 data 数据目录,然后重新启动在进行操作。

配置完毕之后,可以通过如下方式访问 es 服务:

curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty'

curl 127.0.0.1:9200 -u elastic
1
2
3

# 3,配置 kibana 连接。

开启了安全认证之后,kibana 连接 es 以及访问 es 都需要认证。

变更 kibana 的配置,一共有两种方法,一种明文的,一种密文的。

# 1,明文配置

server.port: 5601
server.host: "0.0.0.0"
server.name: "es-node1"
elasticsearch.hosts: ["http://10.3.0.42:9200"]
kibana.index: ".kibana"
i18n.locale: "zh-CN"
elasticsearch.username: "kibana"
elasticsearch.password: "kibana_passwd"
xpack.reporting.encryptionKey: "a_random_string"
xpack.security.encryptionKey: "something_at_least_32_characters"
1
2
3
4
5
6
7
8
9
10
  • elasticsearch.username:连接 es 的用户名。
  • elasticsearch.password:连接 es 的密码。
  • xpack.reporting.encryptionKey:如果不添加这条配置,将会报错 Generating a random key for xpack.reporting.encryptionKey. To prevent pending reports from failing on restart, please set xpack.reporting.encryptionKey in kibana.yml。
  • xpack.security.encryptionKey:如果不配置这条,将会报错 Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml。

# 2,密文配置

当然肯定推荐使用这种密文的方式进行认证,认证之前,需要首先将用户名密码保存到内置的 ketstore 里。

/usr/share/kibana/bin/kibana-keystore --allow-root create
/usr/share/kibana/bin/kibana-keystore --allow-root add elasticsearch.username
/usr/share/kibana/bin/kibana-keystore --allow-root add elasticsearch.password
1
2
3

原封不动执行如上三条命令,用户名的时候输入 kibana,密码写入对应密码,接着调整 kibana 的配置:

server.port: 5601
server.host: "0.0.0.0"
server.name: "es-node1"
elasticsearch.hosts: ["http://10.3.0.42:9200"]
kibana.index: ".kibana"
i18n.locale: "zh-CN"
xpack.reporting.encryptionKey: "a_random_string"
xpack.security.encryptionKey: "something_at_least_32_characters"
1
2
3
4
5
6
7
8

然后重启 kibana 即可访问,访问的时候使用 elastic 的用户密码登入,将是全局管理权限,如果需要创建 kibana 的只读用户,则可以通过管理--用户--新建用户,对用户进行角色授权即可。

image

# 3,logstash 配置认证。

打开自定义的 logstash 的配置文件 logstash.conf,在 output 中增加 elasticsearch 的用户名和密码

[root@ELK1 ~]# vim /home/elk/logstash-7.2.1/config/logstash.conf

input {
  beats {
    port => 5044
  }
}

output {
  stdout {
    codec => rubydebug
  }
  elasticsearch {
    hosts => ["192.168.3.181:9200","192.168.3.182:9200","192.168.3.183:9200"]
    user => "elastic"
    password => "123456"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 4,集群配置。

在我配置过程中,发现集群认证需要首先配置秘钥才行,否则在给内置用户创建秘钥的时候将会报错。

# 1,证书。

如下操作在其中一个 node 节点执行即可,生成完证书传到集群其他节点即可。

/usr/share/elasticsearch/bin/elasticsearch-certutil ca
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
1
2

两条命令均一路回车即可,不需要给秘钥再添加密码。

证书创建完成之后,默认在 es 的数据目录,这里统一放到 etc 下:

$ ls /usr/share/elasticsearch/elastic-*
elastic-certificates.p12  elastic-stack-ca.p12

mv /usr/share/elasticsearch/elastic-* /etc/elasticsearch/
chown elasticsearch.elasticsearch elastic-*
1
2
3
4
5

同样,将如上命令生成的两个证书文件拷贝到另外两台机器作为通信依据,要注意调整权限,否则服务无法启动。

# 2,配置。

三台机器配置文件如下:

cluster.name: db-search
node.name: dc-search-es7-1
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/log
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300

discovery.seed_hosts: ["10.3.23.249:9300","10.3.23.48:9300","10.3.23.191:9300"]
cluster.initial_master_nodes: ["10.3.23.249:9300","10.3.23.48:9300","10.3.23.191:9300"]

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

除了 node.name 使用各自主机名之外,其他配置都一样。

如上配置无误,则可以启动 es。

# 3,为内置账号添加密码

ES 中内置了几个管理其他集成组件的账号即:apm_system, beats_system, elastic, kibana, logstash_system, remote_monitoring_user,使用之前,首先需要添加一下密码。

$ /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  • interactive:给用户一一设置密码。
  • auto:自动生成密码。

配置完毕之后,可以通过如下方式访问 es 服务:

curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty'

curl 127.0.0.1:9200 -u elastic
1
2
3

剩下的就是与上边的使用方式一致了,kibana 的认证,logstash 的认证等等。

其中 kibana 通过密文认证之后,配置如下:

server.port: 5601
server.host: "0.0.0.0"
server.name: "es-node3"
elasticsearch.hosts: ["http://10.3.6.30:9208"]
kibana.index: ".kibana"
i18n.locale: "zh-CN"
1
2
3
4
5
6

参考:

  • ELK 6.6.0 集群部署以及体验使用插件 X-pack (opens new window)
  • elasticsearch-certutil 官方文档 (opens new window)
  • ELASTICSEARCH 错误列表 (opens new window)
  • No Living Connections (opens new window)
  • 基于 centos 7 的 elasticsearch 7 + kibana + xpack 集群搭建 (opens new window)
  • Kibana 7.2.0 installed from rpm package does not start with error Error code EACCES: Insufficient permissions for extracting the browser archive (opens new window)
  • ELK 集群 x-pack 权限控制 (opens new window)
  • ELK 7.2 单节点开启安全认证 (opens new window)
  • Elasticsearch 教程,Elasticsearch 安全篇,通过 Nginx http basic 限制访问 (opens new window)
  • Elasticsearch 7.1 免费安全功能全景认知 (opens new window)
微信 支付宝
#elk#elasticsearch
上次更新: 2024/07/04, 22:40:37
elasticsearch配置等优化
elasticsearch的mapping

← elasticsearch配置等优化 elasticsearch的mapping→

最近更新
01
学习周刊-总第212期-2025年第21周
05-22
02
从赵心童世锦赛夺冠聊聊我的斯诺克情缘
05-16
03
学习周刊-总第211期-2025年第20周
05-15
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式