Elasticsearch - Configuring security in Elasticsearch 开启用户名和密码访问

news2024/9/28 13:19:53

文章目录

  • 概述
  • 实操
    • Step 1 验证当前版本是否支持安全功能
    • Step 2 打开安全设置
    • Step 3 配置节点间通讯传输的安全性
      • 创建证书颁发机构
      • 为Elasticsearch集群中的节点生成证书
    • Step 4 修改 elasticsearch.yml配置
    • 设置 用户名和密码

在这里插入图片描述

概述

ES版本: 7.6

官方指导手册: https://www.elastic.co/guide/en/elasticsearch/reference/7.6/configuring-security.html

翻译一下:

  • 验证当前版本是否支持安全功能

  • 是否打开安全设置

  • 基于FIPS的一些验证

  • 配置节点间通讯传输的安全性

  • 配置内置用户的密码

  • 选择用户验证用户身份的领域类型

  • 设置角色和用户以控制对Elasticsearch的访问

  • 启用审核以跟踪与Elasticsearch集群的尝试和成功的交互

如果只是启用账号密码, 只需要如下几个步骤

  • 验证当前版本是否支持安全功能
  • 是否打开安全设置
  • 配置节点间通讯传输的安全性
  • 配置内置用户的密码

在这里插入图片描述


实操

Step 1 验证当前版本是否支持安全功能

在这里插入图片描述

ES的安全策略需要X-Pack插件的支持, 7.X以上版本X-Pack已经内置 ,我这里是7.6 ,所以忽略即可


Step 2 打开安全设置

在这里插入图片描述

xpack.security.enabled控制安全配置的开启, 默认情况下为false, 要想开启安全策略需要在所有集群中把改参数设置为true

在这里插入图片描述


Step 3 配置节点间通讯传输的安全性

ERROR: [1] bootstrap checks failed
[1]: 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]

仅仅开启安全设置再启动服务的时候会抛出错误, 因为传输网络层用于集群中节点之间的内部通信。启用安全功能后,必须使用TLS来确保节点之间的通信已加密。

为节点间通讯配置安全策略需要两个步骤:

  • 生成节点间安全策略使用的证书

  • 修改各个节点的安全配置

在这里插入图片描述


创建证书颁发机构

推荐方法是信任签署证书的证书颁发机构(CA)。

这样将节点添加到群集后,各个节点只需要使用由同一CA签名的证书,即可自动允许该节点加入群集。

证书中可以包含与节点的IP地址和DNS名称相对应的主题备用名称以便可以执行主机名验证。

为Elasticsearch集群创建发证机构,使用下面的步骤为集群创建一个CA授权证书 ./elasticsearch-certutil ca

[artisan@localhost bin]$ ./elasticsearch-certutil ca
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_11/jre] does not meet this requirement
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 :[artisan@localhost bin]$

①:此位置设置文档输出地址和名称。默认名称为elastic-stack-ca.p12。这个文件是PKCS#12密钥存储库,它包含您的CA的公共证书和用于为每个节点签署证书的私有密钥。 这里我敲得回车,使用默认

②:此位置设置证书的密码。计划将来向集群添加更多的节点,记住其密码。 这里我敲得回车 ,无密码。

如下

在这里插入图片描述

-rw-------. 1 artisan artisan 2524 Feb 17 14:19 elastic-stack-ca.p12

为Elasticsearch集群中的节点生成证书

使用下面的名称生成集群使用的生成节点证书。elastic-stack-ca.p12为上一步生成CA证书。

-rw-------. 1 artisan artisan 2524 Feb 17 14:19 elastic-stack-ca.p12

过程如下,执行如下命令

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12


[artisan@localhost elasticsearch-7.6.2]$ ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_11/jre] does not meet this requirement
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).
    * 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)
    * -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 files

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

Certificates written to /home/artisan/elasticsearch-7.6.2/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.



在输入命令后控制台会输出此命令的信息描述,然后你需要先执行{A}的操作然后执行{B}的操作,最后执行{C}的操作。

A : 输入elastic-stack-ca.p12 CA授权证书的密码 . 我这里敲得回车 ,因为上一步我没有设置密码

B : 此位置为需要输出证书位置。 我这里敲得回车,使用默认,使用当前路径

C : 此位置为证书的密码。使用空密码可以直接回车结束。

默认情况下,elasticsearch-certutil生成的证书中没有主机名信息。即集群中的任意节点使用此证书,但需要关闭主机名验证。


Step 4 修改 elasticsearch.yml配置

修改每个节点的

[artisan@localhost elasticsearch-7.6.2]$ ll
total 560
drwxr-xr-x.  2 artisan artisan   4096 Feb 14 15:46 bin
drwxr-xr-x.  2 artisan artisan    178 Feb 17 14:55 config
drwxrwxr-x.  3 artisan artisan     19 Feb 14 15:50 data
-rw-------.  1 artisan artisan   3440 Feb 17 14:50 elastic-certificates.p12
-rw-------.  1 artisan artisan   2524 Feb 17 14:19 elastic-stack-ca.p12
drwxr-xr-x.  9 artisan artisan    107 Feb 14 15:46 jdk
drwxr-xr-x.  3 artisan artisan   4096 Feb 14 15:46 lib
-rw-r--r--.  1 artisan artisan  13675 Feb 14 15:46 LICENSE.txt
drwxr-xr-x.  2 artisan artisan   4096 Feb 17 08:49 logs
drwxr-xr-x. 38 artisan artisan   4096 Feb 14 15:46 modules
-rw-r--r--.  1 artisan artisan 523209 Feb 14 15:46 NOTICE.txt
drwxr-xr-x.  2 artisan artisan      6 Feb 14 15:46 plugins
-rw-r--r--.  1 artisan artisan   8164 Feb 14 15:46 README.asciidoc
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$ mkdir cert
[artisan@localhost elasticsearch-7.6.2]$ mv elastic-certificates.p12 ./cert/
[artisan@localhost elasticsearch-7.6.2]$ mv elastic-stack-ca.p12  ./cert/
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$ ll
total 552
drwxr-xr-x.  2 artisan artisan   4096 Feb 14 15:46 bin
drwxrwxr-x.  2 artisan artisan     66 Feb 17 14:56 cert
drwxr-xr-x.  2 artisan artisan    178 Feb 17 14:55 config
drwxrwxr-x.  3 artisan artisan     19 Feb 14 15:50 data
drwxr-xr-x.  9 artisan artisan    107 Feb 14 15:46 jdk
drwxr-xr-x.  3 artisan artisan   4096 Feb 14 15:46 lib
-rw-r--r--.  1 artisan artisan  13675 Feb 14 15:46 LICENSE.txt
drwxr-xr-x.  2 artisan artisan   4096 Feb 17 08:49 logs
drwxr-xr-x. 38 artisan artisan   4096 Feb 14 15:46 modules
-rw-r--r--.  1 artisan artisan 523209 Feb 14 15:46 NOTICE.txt
drwxr-xr-x.  2 artisan artisan      6 Feb 14 15:46 plugins
-rw-r--r--.  1 artisan artisan   8164 Feb 14 15:46 README.asciidoc
[artisan@localhost elasticsearch-7.6.2]$


[artisan@localhost elasticsearch-7.6.2]$ mv cert  ./config/
[artisan@localhost elasticsearch-7.6.2]$ tree ./config/cert/
./config/cert/
├── elastic-certificates.p12
└── elastic-stack-ca.p12

0 directories, 2 files
[artisan@localhost elasticsearch-7.6.2]$ tree ./config/
./config/
├── cert
│   ├── elastic-certificates.p12
│   └── elastic-stack-ca.p12
├── elasticsearch.keystore
├── elasticsearch.yml
├── jvm.options
├── log4j2.properties
├── role_mapping.yml
├── roles.yml
├── users
└── users_roles

1 directory, 10 files

elastic-stack-ca.p12文件(只需要此文件)复制到每个节点上的Elasticsearch配置目录中的一个目录中。比如我是放到了每个节点的config/cert目录下。

然后修改每个节点的elasticsearch.yml配置。

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

xpack.security.transport.ssl.verification_mode 如果在elasticsearch-certutil cert命令中使用—dns或—ip选项,并且希望启用严格的主机名检查,此参数需要设置为full。这里我们没有使用严格的主机检查。


设置 用户名和密码

保证ES是启动状态。

如果elastic用户没有密码,则使用默认的引导密码。 使用bin/elasticsearch-setup-passwords interactive命令

[artisan@localhost elasticsearch-7.6.2]$ ./bin/elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_11/jre] does not meet this requirement
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]:
Passwords do not match.
Try again.
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]
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$
[artisan@localhost elasticsearch-7.6.2]$

需要设置多个默认用户的信息,每个内置用户负责不同的内容。

elastic  -----> 超级用户
kibana	----->负责Kibana连接Elasticsearch
logstash_system	----->Logstash将监控信息存储在Elasticsearch中时使用
beats_system	----->Beats在Elasticsearch中存储监视信息时使用
apm_system	----->APM服务器在Elasticsearch中存储监视信息时使用
remote_monitoring_user----->	Metricbeat用户在Elasticsearch中收集和存储监视信息时使用

无需重启,直接访问 http://ip:9200/ 弹出校验框, 输入 elastic 和 设置的密码 即可进入。

over over

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/353748.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Spring MVC之WebApplicationContext 容器的初始化

简介因为 spring-mvc项目,是 spring-framework的子项目,所以需要拉取 spring-framework整个工程,包含 Spring 所有的子项目前期准备工作源码拉取从 Spring 的 Git 仓库 Fork 项目到自己的 Git 仓库,方便我们在阅读源码的过程中&am…

3年软件测试工作经验裸辞,有点后悔了...

2019年毕业,现在有3年的软件测试工作经验,刚毕业前半年在一家知名上市公司,后面则进入一家传统行业公司待到现在2年半。 由于看不到技术成长以及其他原因,上上周辞职了,目前交接中,下个月中旬就得离开了&a…

基于国产龙芯 CPU 的气井工业网关研究与设计(一)

当前,我国气田的自动化控制程度还未完全普及,并且与世界已普及的气井站的自 动化程度也存在一定的差距。而在天然气资源相对丰富的国家,开采过程中设备研发资 金投入较大,研发周期较长,更新了一代又一代的自动化开采系…

看过来,u盘删除的文件还能找回吗?两种方法,

u盘删除的文件还能找回吗?u盘,全称USB闪存驱动器,它不需物理驱动器,即插即用,且其存储容量远超过软盘,方便携带使用。u盘作为我们常用的存储设备,也是有自己不同功能和划分。以下例举了几种&…

ArcGIS API for JavaScript 4.15系列(8)——Dojo中类的定义

1、前言 JavaScript本质上是基于原型继承的一种编程语言,在ES6标准出现以前,JavaScript定义类的方式往往让人很难理解。而Dojo则很好地解决了这个问题。开发者可以通过dojo/_base/declare模块定义类,也可以通过define引用各个类模块。本文就…

Swift基础语法 - 可选项

可选项(Optional) 可选项,一般也叫可选类型,它允许将值设置为 nil 在类型名称后面加个问号 ? 来定义一个可选项 var name: String? "CSDN" name nilvar age: Int? //默认就是nil age 30 age nilvar array [2,…

提升电脑运行速度,看这里就够了!

电脑是我们经常使用的工具之一,但是它却很容易出现问题,比如运行速度过慢,那么要如何提升电脑运行速度呢?方法1. 通过系统配置设置启动项1. 按下组合键“WinR”打开“运行”,在运行中输入“msconfig”然后按“回车”。…

LVGL-基于Windows系统Visual Studio模拟器搭建

LVGL-基于Windows系统Visual Studio模拟器搭建简述下载安装Visual Studio下载LVGL源码运行效果简述 LVGL是一个轻量级多功能图形库 丰富且强大的模块化图形组件:按钮 (buttons)、图表 (charts)、列表 (lists)、滑动条 (sliders)、图片 (images) 等高级的图形引擎&…

UUID简介以及java代码获取UUID示例

什么是UUIDUUID 是指(UniversallyUnique Identifier)通用唯一识别码,128位。RFC 4122描述了具体的规范实现。现实问题我们开发的时候,数据库表总会有一个主键,以前我们可能会使用自增的数字作为主键。这样做去确实查询…

PyTorch使用Visdom绘制训练过程曲线

最近在训练网络,网络的损失和准确率都是在终端输出的,很不直观,也看不出变化,就想着有没有一种工具可以实现实时的绘制模型的训练过程,然后就搜到了Visdom,发现这是个好东西啊,完全满足了我的需…

【Kafka】二.Kafka消息发布/消费流程

Kafka 通过对消费方进行分组管理来支持消息一写多读。 我画的图:工具(processon在线画图) 这个 Topic 分为 4 个 Partition,就是图中的 P1到 P4,上部的生产方根据规则选择一个 Partition 进行写入,默认规则…

算法练习-链表(一)

算法练习-链表(一) 文章目录算法练习-链表(一)解题技巧1. 实现链表1.1 节点的定义1.2 链表的遍历1.3 节点的查找1.4节点的插入1.4.1 链头插入1.4.2 链尾插入1.4.3 在给定节点之后插入1.5 删除节点1.5.1 删除给定节点之后的节点、1…

如何快速完成园区数据的可视化分析?

对于园区运营方来说,如果没有专业针对性的管理方案以及管理系统辅助的话,实现园区可视化管理的难度非常大,而且操作成本会很高。但如果园区运营方选择引进快鲸智慧楼宇推出的园区数据孪生可视化管理系统的话就会简单很多。 快鲸智慧楼宇数据孪…

python项目使用pipenv管理环境,如何使用pycharm调试模式

写在开始 了解pipenv的朋友们应该知道,使用pipenv管理项目环境后,仅pipenv虚拟环境中安装有项目的依赖包,测试机本身并没有安装这个依赖包,这就是pipenv使用的意义。但是,如果想要进入调试模式呢?我们要如…

Coqui TTS docker 使用记录

前言 之前介绍过 Coqui TTS 的安装,不过那个环境被我玩挂掉了…… 这次记录一下 docker 版本的使用。 参考网址:Docker images - TTS 0.11.1 documentation 正文 首先按照官网指示先把镜像 pull 下来。(后记:确保 GPU driver…

重生之我是赏金猎人-番外篇-记一次层层突破的攻防演练

0x00 前言 本文简单记述了一下本人在某攻防演练过程中一次层层突破的有趣经历 技术性一般,但是层层突破属实艰难,并用到了比较多的思路,还望各位大佬多多指教 0x01 SSO账号获取 由于目标是某大学,对外开放的服务基本上都是一些…

CSS 预处理工具 Less 的介绍及使用 步骤

文章目录Less是什么Less的使用方法Less 中的注释Less 中的变量Less 中的嵌套Less 中的混合(Mixin)Less 中的运算Less 中的转译Less 中的作用域Less 中的导入Less实用实例文字超出省略文字垂直居中定位上下左右居中Less是什么 Less 是一门 CSS 预处理语言…

spring的事务控制

1.调用这个方法的对象是否是spring的代理对象($CGLIB结尾的) 2.这个方法是否是加了Transactional注释 都符合才可以被事物控制 如果调用方法的对象没有被事物控制,那么被调用的方法即便是加了Transactional也是没用的 事务失效情况&#xf…

基于MATLAB计算MIMO信道容量(附完整代码与分析)

目录 一.介绍 二. 代码 三. 运行结果及分析 3.1 MIMO信道容量:固定发射天线数为4 3.2 MIMO信道容量:固定接收天线数为4 3.3 AWGN信道与瑞利信道容量 四. 总结 一.介绍 本文章将在MATLAB环境中分析MIMO信道容量,AWGN信道容量&#xf…

秒懂SpringBoot之全网最易懂的Spring Security教程

[版权申明] 非商业目的注明出处可自由转载 出自:shusheng007 文章目录概述简介原理默认实现使用Token认证方案JWT认证流程自定义Authentication Provider自定义Provider修改配置认证失败与授权失败处理认证失败处理授权失败处理支持方法级别的授权总结源码概述 现如…