ElasticSearch和Kibana的安全设置以及https设置

2024-08-28 20:20

本文主要是介绍ElasticSearch和Kibana的安全设置以及https设置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

👨‍💻本文专栏:ElasticSearch和Kibana的安全设置以及https设置
👨‍💻本文简述:跟着猿灰灰一起学Java!
👨‍💻上一篇文章:
👨‍💻有任何问题,都可以私聊我,文章最后有vx名片。感谢支持!
🦹知道的越多,不知道的越多!!!不能停下学习的脚步

在这里插入图片描述

ElasticSearch和Kibana的安全设置以及https设置

ElasticSearch8.x之后就默认开始了安全设置,以下记录ES8.x之后的版本的安全设置

首先

基本安全设置

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

在安全集群中,Elasticsearch 节点在与其他节点通信时使用证书来标识自己。 集群必须验证这些证书的真实性。推荐的方法是信任特定的证书颁发机构 (CA)。将节点添加到集群时,它们必须使用由同一 CA 签名的证书。 对于传输层,我们建议使用单独的专用 CA,而不是现有的、可能共享的 CA,以便严格控制节点成员资格。使用elasticsearch-certutil工具为您的集群生成CA。

设置步骤如下:

  • 在启动 Elasticsearch 之前, 使用bin目录下的elasticsearch-certutil 工具为生成 CA

    elasticsearch-certutil ca# 会出现如下提示
    Please enter the desired output file [elastic-stack-ca.p12]:  # 回车就行  默认文件名elastic-stack-ca.p12
    Enter password for elastic-stack-ca.p12 :  # 设置CA的密码
    
  • 用上面生成的CA生成证书和私钥

    elasticsearch-certutil cert --ca elastic-stack-ca.p12# 会出现如下提示
    Enter password for CA (elastic-stack-ca.p12) :  # 输入使用CA的密码  上面设置的
    Please enter the desired output file [elastic-certificates.p12]:  # 回车就行   默认证书的名字
    Enter password for elastic-certificates.p12 :  # 设置证书的密码
    
  • 把生成的证书拷贝到配置文件夹config中

  • 修改es的配置

    # 文件末尾添加如下配置
    xpack.security.enabled: truexpack.security.enrollment.enabled: true# Enable encryption and mutual authentication between cluster nodes
    xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: elastic-certificates.p12truststore.path: elastic-certificates.p12
    
  • 将CA和证书密码存储在Elasticsearch密钥库,使用bin目录下的elasticsearch-keystore工具

    elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
    elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
    

加密 Elasticsearch 的 HTTP 客户端通信(https)

  • 通过运行 Elasticsearch HTTP 证书工具elasticsearch-certutil以生成证书签名请求 (CSR)

    elasticsearch-certutil http# 会出现如下提示
    Generate a CSR? [y/N]n
    Use an existing CA? [y/N]y  # 是否使用已经存在的ca,基本安全设置已经生成过了
    CA Path: elastic-stack-ca.p12  # 输入ca的相对配置文件夹的路径,应该把ca复制到config中
    Password for elastic-stack-ca.p12: # ca的密码
    You may enter the validity period in years (e.g. 3Y), months (e.g. 18M), or days (e.g. 90D)
    For how long should your certificate be valid? [5y] 5y  # 证书有效期 
    Generate a certificate per node? [y/N]n  # 是否为每个节点生成,单节点就n 集群的话就y 根据情况而定
    Enter all the hostnames that you need, one per line.
    When you are done, press <ENTER> once more to move on to the next step  # 输入可以可以颁发(通过)证书的域名  直接回车
    Is this correct [Y/n]yEnter all the IP addresses that you need, one per line.
    When you are done, press <ENTER> once more to move on to the next step.  # 输入可以可以颁发(通过)证书的IP  直接回车
    Is this correct [Y/n]y
    Do you wish to change any of these options? [y/N]n  # 是否修改上述信息
    Provide a password for the "http.p12" file:  [<ENTER> for none] # 设置http证书请求的密码
    What filename should be used for the output zip file? [C:\cvzhanshi\environment\elasticsearch-8.15.0\elasticsearch-ssl-http.zip]  # 生成的文件名  回车默认
    
  • 把生成的文件解压

    /elasticsearch
    |_ README.txt
    |_ http.p12
    |_ sample-elasticsearch.yml
    /kibana
    |_ README.txt
    |_ elasticsearch-ca.pem
    |_ sample-kibana.yml
    
  • 把http.p12复制到es的config中,elasticsearch-ca.pem复制到kibana的config中

  • 修改es的配置文件末尾追加

    # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
    xpack.security.http.ssl:enabled: truekeystore.path: http.p12truststore.path: http.p12
    
  • 将私钥的密码添加到 Elasticsearch 中的安全设置中

    elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
    elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
    

加密 Kibana 和 Elasticsearch 之间的通信

  • 将上面的elasticsearch-ca.pem复制到kibana的config中

  • 修改配置文件

    elasticsearch.hosts: ["https://localhost:9200"]
    elasticsearch.username: "kibana"
    elasticsearch.password: "kibana"
    elasticsearch.ssl.certificateAuthorities: [ "C:/cvzhanshi/environment/kibana-8.15.0/config/elasticsearch-ca.pem" ]
    i18n.locale: "zh-CN"
    

加密浏览器和 Kibana 之间的通信

  • 通过es的工具elasticsearch-certutil为 Kibana 生成服务器证书和私钥。

    elasticsearch-certutil csr -name kibana-server -dns example.com,www.example.com
    

    得到一个文件解压目录如下:

    /kibana-server
    |_ kibana-server.csr
    |_ kibana-server.key
    
  • 解压csr-bundle.zip文件,获取kibana-server.csr未签名安全证书和kibana-server.key未加密私钥

  • 将 kibana-server.csr 证书签名请求发送到您的内部 CA 或受信任的 CA 进行签名,以获得签名证书。

    # 可以使用命令  生成kibana-server.crt证书
    openssl x509 -req -in ./kibana-server.csr -signkey ./kibana-server.key -out ./kibana-server.crt
    
  • 把证书拷贝到config目录下

  • 修改配置文件

    server.ssl.enabled: true
    server.ssl.certificate: C:/cvzhanshi/environment/kibana-8.15.0/config/kibana-server.crt
    server.ssl.key: C:/cvzhanshi/environment/kibana-8.15.0/config/kibana-server.key
    

重启es和kibana测试通过https访问9200和5601端口

附录

完整配置文件

elasticsearch.yml

# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: C:\\cvzhanshi\\environment\\elasticsearch-8.15.0\\data
#
# Path to log files:
#
path.logs: C:\\cvzhanshi\\environment\\elasticsearch-8.15.0\\logsxpack.security.enabled: truexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:enabled: truekeystore.path: http.p12truststore.path: http.p12# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: elastic-certificates.p12truststore.path: elastic-certificates.p12

kibana.yml

# =================== System: Kibana Server (Optional) ===================
# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
server.ssl.enabled: true
server.ssl.certificate: C:/cvzhanshi/environment/kibana-8.15.0/config/kibana-server.crt
server.ssl.key: C:/cvzhanshi/environment/kibana-8.15.0/config/kibana-server.key# =================== System: Elasticsearch ===================
# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["https://localhost:9200"]# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
elasticsearch.username: "kibana"
elasticsearch.password: "kibana"# =================== System: Elasticsearch (Optional) ===================
# These files are used to verify the identity of Kibana to Elasticsearch and are required when
# xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key# Enables you to specify a path to the PEM file for the certificate
# authority for your Elasticsearch instance.
elasticsearch.ssl.certificateAuthorities: [ "C:/cvzhanshi/environment/kibana-8.15.0/config/elasticsearch-ca.pem" ]# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English (default) "en", Chinese "zh-CN", Japanese "ja-JP", French "fr-FR".
i18n.locale: "zh-CN"

参考链接

基本安全设置

传输加密设置https

这篇关于ElasticSearch和Kibana的安全设置以及https设置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1115784

相关文章

mtu设置多少网速最快? 路由器MTU设置最佳网速的技巧

《mtu设置多少网速最快?路由器MTU设置最佳网速的技巧》mtu设置多少网速最快?想要通过设置路由器mtu获得最佳网速,该怎么设置呢?下面我们就来看看路由器MTU设置最佳网速的技巧... 答:1500 MTU值指的是在网络传输中数据包的最大值,合理的设置MTU 值可以让网络更快!mtu设置可以优化不同的网

MySQL 设置AUTO_INCREMENT 无效的问题解决

《MySQL设置AUTO_INCREMENT无效的问题解决》本文主要介绍了MySQL设置AUTO_INCREMENT无效的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录快速设置mysql的auto_increment参数一、修改 AUTO_INCREMENT 的值。

详解Linux中常见环境变量的特点与设置

《详解Linux中常见环境变量的特点与设置》环境变量是操作系统和用户设置的一些动态键值对,为运行的程序提供配置信息,理解环境变量对于系统管理、软件开发都很重要,下面小编就为大家详细介绍一下吧... 目录前言一、环境变量的概念二、常见的环境变量三、环境变量特点及其相关指令3.1 环境变量的全局性3.2、环境变

Java中常见队列举例详解(非线程安全)

《Java中常见队列举例详解(非线程安全)》队列用于模拟队列这种数据结构,队列通常是指先进先出的容器,:本文主要介绍Java中常见队列(非线程安全)的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录一.队列定义 二.常见接口 三.常见实现类3.1 ArrayDeque3.1.1 实现原理3.1.2

安装centos8设置基础软件仓库时出错的解决方案

《安装centos8设置基础软件仓库时出错的解决方案》:本文主要介绍安装centos8设置基础软件仓库时出错的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录安装Centos8设置基础软件仓库时出错版本 8版本 8.2.200android4版本 javas

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

VSCode设置python SDK路径的实现步骤

《VSCode设置pythonSDK路径的实现步骤》本文主要介绍了VSCode设置pythonSDK路径的实现步骤,包括命令面板切换、settings.json配置、环境变量及虚拟环境处理,具有一定... 目录一、通过命令面板快速切换(推荐方法)二、通过 settings.json 配置(项目级/全局)三、

在Spring Boot中实现HTTPS加密通信及常见问题排查

《在SpringBoot中实现HTTPS加密通信及常见问题排查》HTTPS是HTTP的安全版本,通过SSL/TLS协议为通讯提供加密、身份验证和数据完整性保护,下面通过本文给大家介绍在SpringB... 目录一、HTTPS核心原理1.加密流程概述2.加密技术组合二、证书体系详解1、证书类型对比2. 证书获

如何Python使用设置word的页边距

《如何Python使用设置word的页边距》在编写或处理Word文档的过程中,页边距是一个不可忽视的排版要素,本文将介绍如何使用Python设置Word文档中各个节的页边距,需要的可以参考下... 目录操作步骤代码示例页边距单位说明应用场景与高级用China编程途小结在编写或处理Word文档的过程中,页边距是一个

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设