Elasticsearch 设置基本安全性
创始人
2025-06-01 05:02:43
0

为 Elastic Stack 设置基本安全性

在最小安全配置中添加密码保护后,您将需要配置传输层安全性 (TLS)。传输层处理集群中节点之间的所有内部通信。

最小安全配置请参考 :Elasticsearch 设置最低安全性

  • 如果您的集群有多个节点,那么您必须在节点之间配置 TLS。如果您不启用 TLS,生产模式集群将不会启动。

  • 传输层依赖于双向 TLS 来加密和验证节点。正确应用 TLS 可确保恶意节点无法加入集群并与其他节点交换数据。虽然在 HTTP 层实现用户名和密码身份验证对于保护本地集群很有用,但节点之间通信的安全性需要 TLS。

- 在节点之间配置 TLS 是防止未经授权的节点访问您的集群的基本安全设置。

先决条件

完成Elastic Stack 的最低安全性中的步骤,以在集群中的每个节点上启用 Elasticsearch 安全功能。然后,您可以使用 TLS 加密节点之间的通信。

生成证书颁发机构

您可以在集群中添加任意数量的节点,但它们必须能够相互通信。集群中节点之间的通信由传输模块处理。为了保护您的集群,您必须确保节点间通信经过加密和验证,这是通过双向 TLS 实现的

  • 在安全集群中,Elasticsearch 节点在与其他节点通信时使用证书来标识自己。

  • 集群必须验证这些证书的真实性。推荐的方法是信任特定的证书颁发机构 (CA)。将节点添加到集群时,它们必须使用由同一 CA 签名的证书。

  • 对于传输层,我们建议使用单独的专用 CA 而不是现有的、可能共享的 CA,以便严格控制节点成员资格。使用该elasticsearch-certutil工具为您的集群生成 CA。

在任何单个节点上,使用该elasticsearch-certutil工具为您的集群生成 CA。
你也可以指定 --days 参数 : number of days that the generated certificates are valid

  • 出现提示时,接受默认文件名,即elastic-stack-ca.p12,此文件包含您的 CA 的公共证书和用于为每个节点签署证书的私钥。
  • 输入您的 CA 的密码。如果您不部署到生产环境,则可以选择将密码留空。
root@ubuntu-x64_02:/usr/local/elasticsearch9201# ./bin/elasticsearch-certutil ca
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 authorityBy default the 'ca' mode produces a single PKCS#12 output file which holds:* The CA certificate* The CA's private keyIf 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 keyPlease enter the desired output file [elastic-stack-ca.p12]: 
Enter password for elastic-stack-ca.p12 : 
  • 执行成功后,在当前目录下可以看到CA证书文件: elastic-stack-ca.p12
root@ubuntu-x64_02:/usr/local/elasticsearch9201# ls -tlh 
total 656K
-rw-------  1 root root 2.7K Mar 21 14:31 elastic-stack-ca.p12
  • 在任何单个节点上,为集群中的节点生成证书和私钥。使用在上一步中生成的CA输出文件elastic-stack-ca.p12。

  • –ca

  • 用于签署证书的 CA 文件的名称。该工具的默认文件名elasticsearch-certutil是elastic-stack-ca.p12.

  • 输入您的 CA 的密码,或者如果您在上一步中没有配置密码, 请按Enter 。

  • 为证书创建密码并接受默认文件名。

  • 输出文件是一个名为elastic-certificates.p12. 此文件包含节点证书、节点密钥和 CA 证书。

  • 你也可以指定 --days 参数 : number of days that the generated certificates are valid

root@ubuntu-x64_02:/usr/local/elasticsearch9201# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
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 useon a single instance.* The '-multiple' option will prompt you to enter details for multipleinstances and will generate a certificate and key for each one* The '-in' option allows for the certificate generation to be automated by describingthe 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 Beatsmay all require a certificate and private key.* The minimum required value for each instance is a name. This can simply be thehostname, which will be used as the Common Name of the certificate. A fulldistinguished name may also be used.* A filename value may be required for each instance. This is necessary when thename would result in an invalid file or directory name. The name provided hereis used as the directory name (within the zip) and the prefix for the key andcertificate files. The filename is required if you are prompted and the nameis not displayed in the prompt.* IP addresses and DNS names are optional. Multiple values can be specified as acomma separated string. If no IP addresses or DNS names are provided, you maydisable 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 withthe --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 certificateIf you specify any of the following options:* -pem (PEM formatted output)* -keep-ca-key (retain generated CA key)* -multiple (generate multiple certificates)* -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key filesEnter 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 /usr/local/elasticsearch9201/elastic-certificates.p12This 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.
  • 生成之后的证书文件 如下:
root@ubuntu-x64_02:/usr/local/elasticsearch9201# ls -tlh 
total 660K
-rw-------  1 root root 3.6K Mar 21 14:37 elastic-certificates.p12
-rw-------  1 root root 2.7K Mar 21 14:31 elastic-stack-ca.p12
  • 在集群中的每个节点 上,将elastic-certificates.p12文件复制到$ES_PATH_CONF目录中。并修改文件所有者为 elk
root@ubuntu-x64_02:/usr/local/elasticsearch9201#cp elastic-certificates.p12  /usr/local/elasticsearch9201/config/ ;  chown elk:elk /usr/local/elasticsearch9201/config/elastic-certificates.p12
root@ubuntu-x64_02:/usr/local/elasticsearch9201#cp elastic-certificates.p12  /usr/local/elasticsearch9202/config/ ;  chown elk:elk /usr/local/elasticsearch9202/config/elastic-certificates.p12
root@ubuntu-x64_02:/usr/local/elasticsearch9201#cp elastic-certificates.p12  /usr/local/elasticsearch9203/config/ ;  chown elk:elk /usr/local/elasticsearch9203/config/elastic-certificates.p12

使用 TLS 加密节点间通信

  • 传输网络层用于集群中节点之间的内部通信。启用安全功能后,您必须使用 TLS 来确保节点之间的通信是加密的。

  • 现在您已经生成了证书颁发机构和证书,您将更新集群以使用这些文件。

  • 为集群中的每个节点完成以下步骤。要加入同一个集群,所有节点必须共享相同的cluster.name值。

  • 打开$ES_PATH_CONF/elasticsearch.yml文件并进行以下更改:

  • 添加cluster-name设置并为集群输入名称:

root@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9201/config/elasticsearch.yml | grep "cluster.name"
cluster.name: my-clusterroot@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9202/config/elasticsearch.yml | grep "cluster.name"
cluster.name: my-clusterroot@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9203/config/elasticsearch.yml | grep "cluster.name"
cluster.name: my-cluster
  • 添加node.name设置并输入节点名称。当 Elasticsearch 启动时,节点名称默认为机器的主机名。
root@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9201/config/elasticsearch.yml | grep "node.name"
node.name: node-1root@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9202/config/elasticsearch.yml | grep "node.name"
node.name: node-2root@ubuntu-x64_02:/usr/local/elasticsearch9201# cat /usr/local/elasticsearch9203/config/elasticsearch.yml | grep "node.name"
node.name: node-3
  • 添加以下设置以启用节点间通信并提供对节点证书的访问。

  • 因为您在集群中的每个节点上都使用相同的elastic-certificates.p12文件,所以将验证模式设置为certificate:


root@ubuntu-x64_02:/usr/local/elasticsearch9201# cat >> /usr/local/elasticsearch9201/config/elasticsearch.yml  <> /usr/local/elasticsearch9202/config/elasticsearch.yml  <> /usr/local/elasticsearch9203/config/elasticsearch.yml  <
  • 在集群中的每个节点上,重新启动 Elasticsearch。启动和停止Elasticsearch的方法 因安装方式而异。

  • 您必须执行完整的集群重启。配置为使用 TLS 进行传输的节点无法与使用未加密传输连接的节点通信(反之亦然)。

root@ubuntu-x64_02:/usr/local/elasticsearch9201# systemctl restart elasticsearch9201
root@ubuntu-x64_02:/usr/local/elasticsearch9201# systemctl restart elasticsearch9202
root@ubuntu-x64_02:/usr/local/elasticsearch9201# systemctl restart elasticsearch9203
  • REST请求缺少身份验证凭据
root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# curl "http://127.0.0.1:9201/_cat/health/?v"
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/health/?v]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/health/?v]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# 
root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# 
  • 你要先添加用户后,可以对来自该用户的请求进行身份验证。这里测试,我们使用超级用户,如下:
root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# curl -u elastic:G9******nG http://127.0.0.1:9201/_cat/health/?v; 
epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1679389771 09:09:31  my-cluster green           3         3     39  18    0    0        0             0                  -                100.0%root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# curl -u elastic:G9******nG  http://127.0.0.1:9201/_cat/nodes/?v; 
ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
127.0.0.1           41          90   5    1.10    0.51     0.25 cdfhilmrstw *      node-1
127.0.0.1           66          90   5    1.10    0.51     0.25 cdfhilmrstw -      node-3
127.0.0.1           52          90   5    1.10    0.51     0.25 cdfhilmrstw -      node-2
root@ubuntu-x64_02:/db_data/elasticsearch9201/logs# 

小结

  • 基本安全性(Elasticsearch 产品)

  • 此场景通过为节点之间的通信添加传输层安全性 (TLS),以最低安全要求为基础。这个附加层要求节点验证安全证书,以防止未经授权的节点加入您的 Elasticsearch 集群。

  • Elasticsearch 和 Kibana 之间的外部 HTTP 流量不会被加密,但节点间通信会受到保护。

相关内容

热门资讯

王凤英入职小鹏3年终获股权,此... 5月7日消息,小鹏汽车披露的监管及年报信息显示,公司总裁王凤英已正式进入股东名册,入职小鹏3年后股权...
五块钱红酒卖断货,便宜红酒为何... 最近一段时间,中国的酒类消费市场可以说是显得格外奇怪,一方面,各种高端酒特别是白酒的消费量出现了明显...
财联社C50风向指数调查:4月... 财联社5月8日讯(记者 夏淑媛)新一期财联社“C50风向指数”结果显示,市场机构对4月新增人民币贷款...
央视硬刚国际足联拒掏20亿,背... 作者| 史大郎&猫哥 来源| 是史大郎&大猫财经Pro 央视这次太刚了,离世界杯开幕还有1个月,死活...
新CEO上任直接放大招!Air... 快科技5月8日消息,苹果即将上任的CEO John Ternus对未来一系列新产品充满信心,称这些设...
“特朗普拟邀英伟达、波音等CE... 据路透社当地时间5月7日报道,特朗普政府正邀请英伟达、苹果、埃克森美孚、波音等大公司首席执行官,于下...
世界杯,还能看到直播吗? 2026年美加墨世界杯距离开幕,仅剩一个多月时间。多方信息显示,中央广播电视总台(以下简称“央视”)...
机构警告AI芯片热潮风险,超威... 5月7日,据央视财经,隔夜超威半导体公司(AMD)股价飙升近19%,带动AI芯片热潮持续升温。AMD...
银行员工转走储户1800万最新... 银行员工转走储户1800万最新进展:2名储户已收到银行全部款项
原创 中... 1994年,安徽省的经济格局曾发生过一次戏剧性的转折。在那一年,一座名为安庆的城市,其国内生产总值(...
昆都仑区:政策“蓄力”消费焕新 “一台5000多元的空调,叠加‘国补’和商场的以旧换新活动,能优惠1000元左右,旧机还能免费上门拆...
乐悦置业竞得佛山顺德乐从镇一商... 观点网讯:5月6日,佛山市顺德区乐从镇一商业地块成功出让,由广东省乐悦置业有限公司竞得,乐从南区·邻...
原创 亦... 《爱情没有神话》这部剧,一开始的命运颇为多舛,经历了几次撤档的波折后,终于在观众面前亮相,但其首播的...
美联储34年最大分歧叠加油价飙... 美联储按预期维持利率不变,但内部出现34年来最严重分歧,叠加布油创2022年6月以来新高,美债遭抛售...
支付宝消费券回收后,资金是否支... 摘要: 支付宝消费券回收变现后,资金能否直接转入信用卡?本文解答到账方式的相关规则,帮助用户了解资金...
中医介绍5个化痰穴位!收藏这篇... 很多人忽略了“痰”的危害,觉得咳几下就没事,殊不知,肺里的痰长期堆积,只会一步步加重身体负担。 中医...
黄金平台“杰我睿”涉嫌经济犯罪... 红星资本局5月7日消息,深圳水贝知名金店“杰我睿”兑付困难事件有了新进展。日前,深圳市公安局罗湖分局...
多地出台购房新政促楼市升温 记... 今年的“五一”假期,伴随着多个城市楼市新政密集落地,在叠加市场信心持续修复的作用下,房地产市场热度持...
谁是五一“吸金王”?这5座城市... 来源:市场资讯 (来源:21城市观) 哪座城市成为“五一”假期的大赢家? 图源:摄图网 作者|赵晓...
“低招低裁”格局稳固劳动力市场... 智通财经APP获悉,美国上周初请失业金人数在经历前一周回落至近几十年来最低水平后出现小幅反弹,表明尽...