在不安全的集群上启用 Elasticsearch Xpack 安全性

这篇具有很好参考价值的文章主要介绍了在不安全的集群上启用 Elasticsearch Xpack 安全性。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

在不安全的集群上启用 Elasticsearch Xpack 安全性,Elasticsearch,Elastic,elasticsearch,大数据,搜索引擎,安全

本博文详细描述如何把一个没有启动安全的 Elasticsearch 集群升级为一个带有 HTTPS 访问的启用 Elasticsearch xpack 安全的集群。

为了增强 Elasticsearch 集群的安全性,你需要执行完全集群重启,并在客户端进行一些更改。 启用身份验证后,所有索引和搜索数据的请求都将需要用户名和密码或 token。

安装

如果你还不知道如何安装一个不含有安全的 Elasticsearch 8.x 集群,那么请参考之前的文章:

  • Elasticsearch:如何在 Docker 上运行 Elasticsearch 8.x 进行本地开发

  • Elastic Stack 8.0 安装 - 保护你的 Elastic Stack 现在比以往任何时候都简单 (参考文章的 “如何配置 Elasticsearch 不带安全性” 部分)

在本显示中,我们将参考上面的第二篇文章在本地部署一个不带安全的 Elasticsearch 集群。在第一次启动 Elasticsearch 之前,我们必须修改 elasticsearch.yml 文件如下:

xpack.security.enabled: false
xpack.security.http.ssl.enabled: false

只有这样的配置,我们才可以安装出一个没有任何安全的 Elasticsearch 集群。安装完毕后,我们可以在 http://localhost:9200 来访问 Elasticsearch 集群。

$ curl http://localhost:9200
{
  "name" : "liuxgm.local",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "hHUucYL9Q0GhcC9QivRlDg",
  "version" : {
    "number" : "8.10.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "e338da74c79465dfdc204971e600342b0aa87b6b",
    "build_date" : "2023-09-07T08:16:21.960703010Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

在不安全的集群上启用 Elasticsearch Xpack 安全性,Elasticsearch,Elastic,elasticsearch,大数据,搜索引擎,安全

一旦安装完毕,我们在下面的步骤中来进行展示。

启动 xpack 安全

步骤:

  • 创建 SSL Elastic 证书
  • 将 SSL 证书复制到所有节点
  • 更新 elasticsearch.yml
  • 停止所有 Elasticsearch 节点
  • 启动所有 Elasticsearch 节点
  • 创建/重置内置用户密码

下面,我们分别进行展示各个步骤。

1. 创建 SSL Elastic 证书

  • 要启用 TLS 通信,需要 SSL 证书。 首先创建 SSL 证书。 注意:只需创建一次证书并将其复制到所有节点。
  • 创建 CA 证书。

./bin/elasticsearch-certutil ca --days 3650
[Press Enter]
[Press Enter]
$ pwd
/Users/liuxg/test/elasticsearch-8.10.0
$ ./bin/elasticsearch-certutil ca --days 3650
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.

Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority

By default the 'ca' mode produces a single PKCS#12 output file which holds:
    * The CA certificate
    * The CA's private key

If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key

Please enter the desired output file [elastic-stack-ca.p12]: 
Enter password for elastic-stack-ca.p12 : 
$ ls
LICENSE.txt          bin                  elastic-stack-ca.p12 logs
NOTICE.txt           config               jdk.app              modules
README.asciidoc      data                 lib                  plugins

在上面,我们可以看到生产的 elastic-stack-ca.p12 文件。如果你是针对 Linux 的安装,那么你的证书必须是位于 /usr/share/elasticsearch 目录下。

  • 在单个节点上,为集群中的所有节点生成证书和私钥。
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 --days 3650
[Press Enter]
[Press Enter]
$ ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 --days 3650
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires an SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.


    * All certificates generated by this tool will be signed by a certificate authority (CA)
      unless the --self-signed command line option is specified.
      The tool can automatically generate a new CA for you, or you can provide your own with
      the --ca or --ca-cert command line options.


By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files

Enter password for CA (elastic-stack-ca.p12) : 
Please enter the desired output file [elastic-certificates.p12]: 
Enter password for elastic-certificates.p12 : 

Certificates written to /Users/liuxg/test/elasticsearch-8.10.0/elastic-certificates.p12

This file should be properly secured as it contains the private key for 
your instance.
This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.

For client applications, you may only need to copy the CA certificate and
configure the client to trust this certificate.
$ ls
LICENSE.txt              data                     logs
NOTICE.txt               elastic-certificates.p12 modules
README.asciidoc          elastic-stack-ca.p12     plugins
bin                      jdk.app
config                   lib

从上面的输出中我们可以看出来有一个新的文件 elastic-certificates.p12 被生成。

2. 拷贝 SSL 证书到所有的节点

针对子家压缩包进行安装的 Elasticsearch 来说,我们可以把刚生产的证书拷贝到相应的 config 目录下:

$ pwd
/Users/liuxg/test/elasticsearch-8.10.0
$ cp elastic-certificates.p12 config/

针对 Linux 环境,我们可以使用如下的命令来进行拷贝。必须在 “/usr/share/elasticsearch” 下创建 “elastic-certificates.p12” 文件。 创建 SSL 证书 (elastic-certificates.p12) 后,将其复制并粘贴到所有节点上。

mv /usr/share/elasticsearch/elastic-certificates.p12 /etc/elasticsearch/
chown elasticsearch:elasticsearch /etc/elasticsearch/ -R

3. 更新 elasticsearch.yml 文件

编辑 elasticsearch.yml 文件并添加或更新以下设置:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

xpack.security.http.ssl:
  enabled: true
  keystore.path: elastic-certificates.p12

如果你是按照本教程安装的没有设置任何安全的 Elasticsearch 集群,那么请删之前在安装时的如下两行,再进行粘贴上面的代码:

注意:证书的默认路径是 “/etc/elasticsearch/elastic-certificates.p12”。 还有:确保没有重复设置。

4. 停止所有的 Elasticsearch 节点

Linux:

service elasticsearch stop

如果是字节压缩的安装,你可以使用 Ctrl + C 来终止集群的运行。

5. 启动所有 Elasticsearch 节点

从主节点开始,启动所有 Elasticsearch 节点。

Linux:

service elasticsearch start

针对自解压的安装,你可以使用:

./bin/elasticsearch

从主节点开始可确保 Elasticsearch 集群的核心在数据节点上线之前启动并运行。 此顺序对于维护集群稳定性和数据完整性非常重要。

6. 创建/重置内置用户密码

bin/elasticsearch-reset-password -u -i elastic
$ pwd
/Users/liuxg/test/elasticsearch-8.10.0
$ ./bin/elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This       command will be removed in a future release.
******************************************************************************

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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_system]: 
Reenter password for [kibana_system]: 
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_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
passwordChanged password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

为方便说明,我们在上面把密码都设置为 “password”。

7. 测试

我们使用如下的命令来进行测试:

curl -k -u elastic:password  https://localhost:9200
$ curl -k -u elastic:password  https://localhost:9200
{
  "name" : "liuxgm.local",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "hHUucYL9Q0GhcC9QivRlDg",
  "version" : {
    "number" : "8.10.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "e338da74c79465dfdc204971e600342b0aa87b6b",
    "build_date" : "2023-09-07T08:16:21.960703010Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

常见问题及解决方案:

  • SSL 证书路径:确保 “elastic-certificates.p12” 路径正确。 在 Debian 或 RPM 安装中,默认路径是 “/etc/elasticsearch”。
  • SSL 证书权限:验证所有 Elasticsearch 节点是否具有 SSL 证书和足够的访问权限。
  • SSL 证书密码:在证书创建过程中,未定义密码,但 Elasticsearch v8 可能有默认密码。 检查 “./bin/elasticsearch-keystore list” 并删除为“xpack.security.transport.ssl.*”定义的任何密码。
  • Elasticsearch-Reset-Password 命令(1):确保您可以通过 localhost 访问 Elasticsearch。 如果没有,请在命令末尾添加 “—url”。 检查是否有任何代理问题。
  • Elasticsearch-Reset-Password命令(2):该命令需要数据节点连接到集群,因为它需要将 elastic 用户密码添加到 '.security' 索引中。 在运行命令之前确保数据节点已连接。
  • Kibana 不工作:Elasticsearch v8 之后,你无法在 Kibana 中使用 elastic 超级用户。 使用 “kibana_system” 用户。
  • Kibana 系统无法登录:使用 elastic 用户登录 Kibana; “kibana_system” 用户保留用于 Kibana 和 Elasticsearch 之间的通信。

更多阅读:Security:如何安装 Elastic SIEM 和 EDR文章来源地址https://www.toymoban.com/news/detail-734475.html

到了这里,关于在不安全的集群上启用 Elasticsearch Xpack 安全性的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Elasticsearch的安全性与权限管理

    Elasticsearch是一个基于分布式搜索和分析引擎,它可以处理大量数据并提供实时搜索功能。在现代企业中,Elasticsearch被广泛应用于日志分析、搜索引擎、实时数据处理等场景。然而,随着数据的增长和使用范围的扩展,数据安全和权限管理也成为了关键问题。 在本文中,我们

    2024年04月13日
    浏览(29)
  • ElasticSearch的安全性和权限管理

    ElasticSearch是一个开源的搜索和分析引擎,用于处理大量数据并提供实时搜索功能。在现代应用中,ElasticSearch广泛应用于日志分析、搜索引擎、实时数据处理等场景。然而,随着ElasticSearch的应用越来越广泛,数据安全和权限管理也成为了关键的问题。 本文将深入探讨ElasticS

    2024年03月16日
    浏览(35)
  • elasticsearch8.9.1部署及配置基本安全性以及安全的 HTTPS 流量

    1、官网下载elasticsearch8.9.1安装包,上传至服务器并解压 官网地址 解压 2、修改elasticsearch配置文件elasticsearch.yml(支持ipv4以及ipv6双栈),文件权限修改成非root的应用程序账号 1、进入elasticsearch根目录 注:1、输出文件名称(默认)2、CA密码设置(可留空直接回车,生产环境建议

    2024年02月03日
    浏览(27)
  • Elasticsearch(实践2)链接库产生TLS验证安全性报错

    问题:   File \\\"/home/server/miniconda3/envs/rag/lib/python3.8/site-packages/elastic_transport/_transport.py\\\", line 328, in perform_request     meta, raw_data = node.perform_request(   File \\\"/home/server/miniconda3/envs/rag/lib/python3.8/site-packages/elastic_transport/_node/_http_urllib3.py\\\", line 202, in perform_request     raise err from None elas

    2024年01月18日
    浏览(29)
  • 加密数据安全性的两大安全护盾-前向安全性与后向安全性详解

    在数字安全的世界里,加密技术是用来保护数据不被未经授权访问的重要机制。然而,即使使用了最强的加密算法,也不能保证永远是安全的。攻击者可能会在未来某个时间点获得了解密密钥,从而能够解密拦截的密文。为了解决这个问题,密码学引入了前向安全性(Forwar

    2024年02月04日
    浏览(41)
  • elasticsearch配置xpack集群间加密认证时报错:

    通过证书配置集群间节点通信认证: 报错信息: 各种尝试:授权文件777、把文件放在config/certs下、放在/opt/elaticsearch/certs下,都想不通,然后猜测可能是路径问题,于是不写绝对路径,指定相对路径,看看es从那个目录下获取,改了之后包如下错误,发现是从/etc/elasticsearch

    2024年02月13日
    浏览(31)
  • 云计算:云计算安全性有哪些?_云计算技术的安全性,这些知识你必须拿下

    先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7 深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前! 因此收集整理了一份《2024年最新网络安全全套学习资料》

    2024年04月23日
    浏览(36)
  • 什么是前端安全性(front-end security)?列举一些前端安全性的最佳实践

    聚沙成塔·每天进步一点点 前端入门之旅:探索Web开发的奇妙世界 欢迎来到前端入门之旅!感兴趣的可以订阅本专栏哦!这个专栏是为那些对Web开发感兴趣、刚刚踏入前端领域的朋友们量身打造的。无论你是完全的新手还是有一些基础的开发者,这里都将为你提供一个系统而

    2024年02月05日
    浏览(39)
  • 《网络安全0-100》低层协议安全性

    对于网络层,IP协议是其中一个非常重要的协议。网络层的IP地址相当于数据链路层的Mac地址。协议字段如下,每行4字节,总共4*5=20字节。   IP协议安全性:IP协议不能保证数据就是从数据包中给定的源地址发出的,你绝对不能靠对源地址的有效性检验来判断数据包的好坏。

    2024年02月11日
    浏览(33)
  • 线程的安全性

    你或许会感到奇怪,线程或者锁在并发编程中的作用,类似于铆钉和工字梁在土木工程中的作用。要建筑一座坚固的桥梁,必须正确地使用大量的铆钉和工字梁。同理,在构建稳健的并发程序时,必须正确地使用线程和锁。但这些终归只是一些机制。要编写线程安全的代码,

    2024年02月07日
    浏览(55)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包