Elasticsearch安全加固指南:啟用登錄認證與SSL加密

在之前文章中我們介紹了Elasticsearch安全與權限控制,本篇文章我們將詳細介紹 啟用登錄認證與SSL加密實踐配置操作

1 為什么需要安全加固?

Elasticsearch默認不啟用安全功能,會導致以下風險:
  • 未授權訪問:任何人都能讀取/修改數據
  • 數據泄露:網絡傳輸未加密,可能被竊聽
  • 合規性風險:不符合企業安全審計要求

2 環境準備

  • ES版本:Elasticsearch 7.10.1
  • 操作系統:CentOS 7.9

3 配置步驟

3.1 生成SSL證書

# 進入ES安裝目錄
cd /export/home/elasticsearch-7.10.1/# 生成CA證書
/export/home/elasticsearch-7.10.1/bin/elasticsearch-certutil ca --pass ""# 生成節點證書
/export/home/elasticsearch-7.10.1/bin/elasticsearch-certutil cert \
--ca /export/home/elasticsearch-7.10.1/elastic-stack-ca.p12 \
--ip 192.168.10.33,192.168.10.34,192.168.10.35,127.0.0.1 \
--dns node3,node4,node5,localhost# 創建證書目錄
mkdir config/certs# 部署證書,同時在其余節點上創建相同目錄并拷貝證書過去
mv elastic-certificates.p12 config/certs/

3.2 修改elasticsearch.yml

#編輯elasticsearch.yml文件增加如下內容cat >>/export/home/elasticsearch-7.10.1/config/elasticsearch.yml<<EOF
# 安全核心配置
# HTTP層SSL
xpack.security.http.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/elastic-certificates.p12truststore.path: certs/elastic-certificates.p12# 傳輸層SSL
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/elastic-certificates.p12truststore.path: certs/elastic-certificates.p12
EOF# 重啟elasticsearch服務
ps -ef |grep elasticsearch-7.10.1|grep -v grep |awk '{print $2}'|xargs kill -9
/export/home/elasticsearch-7.10.1/bin/elasticsearch -d

3.3 設置內置用戶密碼

# 交互式設置密碼
/export/home/elasticsearch-7.10.1/bin/elasticsearch-setup-passwords interactive# 自動生成密碼(輸出需保存)
/export/home/elasticsearch-7.10.1/bin/elasticsearch-setup-passwords auto
涉及的主要用戶
  • elastic:超級管理員
  • kibana_system:Kibana服務賬號
  • logstash_system:Logstash連接賬號

4 驗證配置

4.1 檢查HTTPS訪問

curl -k -u elastic:Lahmy1c@ https://192.168.10.33:9200
正常應返回包含"tagline" : "You Know, for Search"的JSON
[lianggj@node4 config]$ curl -k -u elastic:Lahmy1c@ https://192.168.10.33:9200
{"name" : "node4","cluster_name" : "my_es_cluster","cluster_uuid" : "6JC1NLZXTWymb5WiLPvjaA","version" : {"number" : "7.10.1","build_flavor" : "default","build_type" : "tar","build_hash" : "1c34507e66d7db1211f66f3513706fdf548736aa","build_date" : "2020-12-05T01:00:33.671820Z","build_snapshot" : false,"lucene_version" : "8.7.0","minimum_wire_compatibility_version" : "6.8.0","minimum_index_compatibility_version" : "6.0.0-beta1"},"tagline" : "You Know, for Search"
}
[lianggj@node4 config]$ 

4.2 測試用戶權限

# 嘗試未授權訪問
curl https://192.168.10.33:9200/_cat/indices# 使用正確憑證訪問
curl -k -u elastic:Lahmy1c@ https://192.168.10.33:9200/_security/user
[lianggj@node4 config]$ curl https://192.168.10.33:9200/_cat/indices
curl: (60) Peer's certificate issuer has been marked as not trusted by the user.
More details here: http://curl.haxx.se/docs/sslcerts.htmlcurl performs SSL certificate verification by default, using a "bundle"of Certificate Authority (CA) public keys (CA certs). If the defaultbundle file isn't adequate, you can specify an alternate fileusing the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented inthe bundle, the certificate verification probably failed due to aproblem with the certificate (it might be expired, or the name mightnot match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, usethe -k (or --insecure) option.
[lianggj@node4 config]$ curl -k -u elastic:Lahmy1c@ https://192.168.10.33:9200/_security/user
{"elastic":{"username":"elastic","roles":["superuser"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"kibana":{"username":"kibana","roles":["kibana_system"],"full_name":null,"email":null,"metadata":{"_deprecated":true,"_deprecated_reason":"Please use the [kibana_system] user instead.","_reserved":true},"enabled":true},"kibana_system":{"username":"kibana_system","roles":["kibana_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"logstash_system":{"username":"logstash_system","roles":["logstash_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"beats_system":{"username":"beats_system","roles":["beats_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"apm_system":{"username":"apm_system","roles":["apm_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"remote_monitoring_user":{"username":"remote_monitoring_user","roles":["remote_monitoring_collector","remote_monitoring_agent"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true}}[lianggj@node4 config]$ 

5 Kibana集成配置

# PKCS12文件中提取CA證書:
cd /export/home/elasticsearch-7.10.1/config/certs
openssl pkcs12 -in elastic-certificates.p12 -out ca.pem -nodes# 編輯修改kibana.yml,添加如下內容
cat >>/export/home/kibana-7.10.1-linux-x86_64/config/kibana.yml<<EOF
elasticsearch.hosts: ["https://192.168.10.33:9200","https://192.168.10.34:9200","https://192.168.10.35:9200"]
elasticsearch.username: "kibana_system"
elasticsearch.password: "Lahmy1c@"
elasticsearch.ssl.verificationMode: "certificate"
elasticsearch.ssl.certificateAuthorities: ["/export/home/elasticsearch-7.10.1/config/certs/ca.pem"]
EOF# 重啟
ps -ef |grep esmagent|grep -v grep |awk '{print $2}'|xargs kill -9
nohup ./bin/kibana &> kibana.log &

6 常見問題解決

6.1 證書錯誤

PKIX path validation failed: java.security.cert.CertPathValidatorException
解決方案
  • 確認所有節點使用相同CA簽發證書
  • 在客戶端添加--cacert參數
curl --cacert /path/to/ca.crt https://es-node:9200

6.2 密碼重置

bin/elasticsearch-reset-password -u elastic

6.3 臨時關閉安全(僅開發)

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

7 附:常用安全命令

# 查看用戶列表
GET /_security/user# 創建自定義角色
POST /_security/role/my_admin
{"cluster": ["myindx"],"indices": [{"names": ["myindex-*"],"privileges": ["read", "write"]}]
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/900177.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/900177.shtml
英文地址,請注明出處:http://en.pswp.cn/news/900177.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

前端知識點---本地存儲(javascript)

localStorage 是瀏覽器提供的一個 本地存儲 API&#xff0c;可以在用戶的瀏覽器中存儲數據&#xff0c;數據不會隨頁面刷新而丟失。 1. 基本用法 (1) 存儲數據&#xff08;setItem&#xff09; localStorage.setItem("username", "zhangsan");存儲 “use…

神經網絡能不能完全擬合y=x2 ???

先說結論&#xff1a;關鍵看激活函數的選擇 ReLU神經網絡對非線性函數的擬合分析 ReLU神經網絡對非線性函數&#xff08;如 y x 2 y x^2 yx2&#xff09;的擬合只能是逼近&#xff0c;而無法實現數學意義上的完全重合。這一結論源于ReLU的分段線性本質與目標函數的非線性結…

14.流程自動化工具:n8n和家庭自動化工具:node-red

n8n 安裝 docker方式 https://docs.n8n.io/hosting/installation/docker/ #https://hub.docker.com/r/n8nio/n8n docker pull n8nio/n8n:latest docker rm -f n8n; docker run -it \ --network macvlan --hostname n8n \ -e TZ"Asia/Shanghai" \ -e GENERIC_TIME…

哈密爾頓路徑(Hamiltonian Path)及相關算法題目

哈密爾頓路徑要求訪問圖中每個頂點恰好一次&#xff0c;通常用于解決旅行商問題&#xff08;TSP&#xff09;或狀態壓縮DP問題。 哈密爾頓路徑&#xff08;Hamiltonian Path&#xff09;是指在一個圖中經過每個頂點恰好一次的路徑。如果這條路徑的起點和終點相同&#xff08;即…

面試算法高頻02-樹

樹類型對比 數據結構定義節點特點遍歷方式常見操作時間復雜度&#xff08;平均&#xff09;時間復雜度&#xff08;最壞&#xff09;空間復雜度&#xff08;最壞&#xff09;與其他結構關系應用場景樹有根節點&#xff0c;分層級&#xff0c;包含父子、兄弟節點及子樹關系的非…

數論4 組合數

目錄 前言 求法一 代碼 求法二 代碼 求法三 代碼 求法四 代碼 前言 今天要將最后一部分&#xff0c;主要涉及組合數的四種求法。 前置知識 組合數的通項公式&#xff1a; 組合數的遞推公式&#xff1a; 盧卡斯定理&#xff1a; 我們今天需要求的四種求法主要基…

構建自己的私有 Git 服務器:基于 Gitea 的輕量化部署實戰指南

對于個人開發者、小型團隊乃至企業來說&#xff0c;將項目代碼托管在 GitHub、Gitee 等公共平臺雖然方便&#xff0c;但也存在一定的隱私與可控性問題。 搭建一套私有 Git 代碼倉庫系統&#xff0c;可以實現對源碼的完全控制&#xff0c;同時不依賴任何第三方平臺&#xff0c;…

Linux操作系統 4.Linux實用操作

一、各類小技巧&#xff08;快捷鍵&#xff09; 1.CTRL C 強制停止 1.Linux某些程序的運行&#xff0c;如果想要強行停止它&#xff0c;可以使用ctrlc 2.命令輸入錯誤&#xff0c;也可以通過快捷鍵ctrl c,退出當前輸入&#xff0c;重新輸入&#xff0c;或者ctrlc跳過當前這…

react redux的學習,單個reducer

redux系列文章目錄 一 什么redux&#xff1f; redux是一個專門用于做狀態管理的JS庫(不是react插件庫)。它可以用在react, angular, vue等項目中, 但基本與react配合使用。集中式管理react應用中多個組件共享的狀 簡單來說&#xff0c;就是存儲頁面的狀態值的一個庫&#xf…

PCI與PCIe接口的通信架構是主從模式嗎?

PCI&#xff08;Peripheral Component Interconnect&#xff09;總線在通信架構上本質是主從模式&#xff0c;但其具體實現和角色分配在不同版本&#xff08;如傳統PCI與PCI Express&#xff09;中存在差異。以下是詳細分析&#xff1a; 傳統PCI總線的主從模式 (1) 基本架構 主…

java項目掛機自動重啟操作指南

前段時間有個伙伴問我&#xff0c;java項目掛機怎么自動重啟。。。。。。今天就寫一個 .sh腳本來實現應用掛機的自動重啟功能 #!/bin/bash # 查詢mita的進程個數 countps -ef | grep mita.jar | grep -v "grep" | wc -l # echo $count nowtimedate "%Y-%m-%d %H…

開放最短路徑優先 - OSPF【LSA詳細】

目錄 LSA的頭部結構 LSA類型 LSA數據包 LSA的主要作用是傳遞路由信息。 LSA的頭部結構 共占20個字節&#xff0c;不同類型的LSA頭部字段部分都是相同的。 鏈路狀態老化時間(Link-State Age) 2個字節。指示該條LSA的老化時間&#xff0c;即它存在了多長時間&#xff0c;單位…

SpringBoot+Spring+MyBatis相關知識點

目錄 一、相關概念 1.spring框架 2.springcloud 3.SpringBoot項目 4.注解 5.SpringBoot的文件結構 6.啟動類原理 二、相關操作 1.Jar方式打包 2.自定義返回的業務狀態碼 3.Jackson 4.加載配置文件 5.異常處理 三、優化配置 1.簡化sql語句 2.查詢操作 復雜查詢 一…

《雙影奇境》手機版上線?ToDesk用跨平臺技術實現「全設備云電腦3A游戲」

《雙影奇境》是由Hazelight Studios研發發行的一款雙人合作冒險類游戲&#xff0c;玩家們在游戲中將扮演米歐和佐伊兩位風格迥異的女作家&#xff0c;劇情講述的是她們被騙進入一臺意在竊取創意的機器后便陷入了自己創作的故事之中&#xff0c;并且必須相互依靠&#xff0c;努力…

【教程】Windows下 Xshell 連接跳板機和開發機

需求 使用遠程連接工具 Xshell 連接跳板機&#xff0c;再從跳板機連接開發機&#xff0c;用戶登陸方式為使用密鑰。 方法 首先&#xff0c;建立一個會話&#xff0c;用于配置跳板機信息和開發機轉跳信息&#xff1a; 在【連接】頁面&#xff0c;給跳板機取個名字&#xff0c…

如何快速入門物聯網單片機開發?

背景 物聯網單片機硬件開發涉及多個階段&#xff0c;元器件是否“自己設計”取決于具體需求。以下是詳細解答和學習方案&#xff1a; 一、元器件是否自己設計&#xff1f; 通用元器件&#xff1a; 大多數情況下&#xff0c;開發者直接使用現成的標準化元器件&#xff08;如電阻…

每日一題(小白)模擬娛樂篇11

由題可知就是要求計算一個數字&#xff0c;可以整除10進制的每一位&#xff0c;亦可以整除8進制和16進制的每一位。要求找出第2023個能夠在三個進制下同時被10進制整除的數字。 Java中已經封裝了進制轉換的方法&#xff0c;以下是一些常用的轉換方法&#xff1a;&#x1f447;…

阿里巴巴langengine二次開發大模型平臺

阿里巴巴LangEngine開源了&#xff01;支撐億級網關規模的高可用Java原生AI應用開發框架 - Leepy - 博客園 阿里國際AI應用搭建平臺建設之路(上) - 框架篇 基于java二次開發 目前Spring ai、spring ai alibaba 都是java版本的二次基礎能力 重要的是前端工作流 如何與 服務端的…

MINIQMT學習課程Day8

獲取qmt賬號的資金賬號后&#xff0c;我們進入下一步&#xff0c;如何獲得當前賬號的持倉情況 還是之前的步驟&#xff0c;打開qmt&#xff0c;選擇獨立交易&#xff0c; 之后使用pycharm&#xff0c;編寫py文件。 from xtquant import xtdata from xtquant.xttrader import…

在QGIS中將矢量數據導出為JSON

在QGIS中將矢量數據導出為JSON的完整操作指南如下&#xff0c;支持GeoJSON標準格式及自定義配置&#xff1a; 一、標準GeoJSON導出&#xff08;推薦&#xff09; 適用場景&#xff1a;生成符合OGC標準的地理JSON文件&#xff0c;適用于Web地圖開發 準備圖層 確保目標圖層在QG…