集中式日志分析平臺 - ELK Stack?- 安全解決方案 X-Pack

簡介

X-Pack 已經作為 Elastic 公司單獨的產品線,前身是 Shield, Watcher, Marvel, Graph, 和 reporting,先來說說這幾個爸爸是做什么的吧:

  • Shield: 提供對數據的 Password-Protect,以及加密通信、基于角色的權限控制,IP 過濾,審計,可以有效地:
    • 防止未授權的訪問:基于 Password-Protect,基于角色的權限控制,IP過濾;
    • 保證數據的完整性:基于消息認證和 TLS/SSL 加密;
    • 審計跟蹤:可以知道誰在什么時候對數據做了什么;
  • Watcher: 提供對數據操作的變更的監控和報警。
  • Marvel: 基于 Kibana 的插件,主要用于監控 ES 集群。可以看到集群的健康狀況、實時的性能指標,分析歷史集群、索引、節點的指標等。
  • Graph: 用于分析數據間的關系。
  • Reporting: 用于快速生成 Kibana Visualization 和 Dashboard 的報表,可以對生成的時間定制計劃,并且可以由某些特定條件觸發。

再來看看我們的兒子 X-Pack 是做啥的,哦,他就是他們的兒子,一個大合集,便于安裝、不用為版本兼容性犯愁,可以靈活 disable / enable 其中的各個組件。他還多干了一件事兒,可以監控 Logstash。

關于免費和收費版本,版本功能比較可以查看:https://www.elastic.co/subscriptions

免費版本注冊地址:https://register.elastic.co/xpack_register

付費版本(分為黃金、白金級別)購買地址:https://www.elastic.co/subscriptions/xpack

默認的免費版本有一個月的 trial 試用期。免費版本試用期只包含 ES 集群監控、圖分析和可視化,基于角色的 ES 權限控制和搜索用戶信息的功能。不包含:

  • 安全組件 Shield:
    • TLS/SSL加密;
    • LDAP的整合;
    • 日志審計;
    • 第三方的認證域整合;
  • 報警組件 Watcher;
  • 報表組件 Reporting;

總的來說免費版本對于安全組件這塊什么都不支持。

呵呵呵呵

安裝

安裝 X-Pack 前必須安裝 ES 和 Kibana ,我們使用的是 5.2.1 版本 集中式日志分析平臺 - ELK Stack - 部署篇。X-Pack 我們也使用 5.2.1,我們來講講如何離線安裝吧。

Step1. 下載 X-Pack Zip 文件:https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-5.2.1.zip (sha1),尼瑪有119MB那么大。

Step2. 上傳 zip 文件至服務器 /tmp 目錄;

Step3. 在 ES 安裝目錄運行 bin/elasticsearch-plugin install 命令 :

bin/elasticsearch-plugin install file:/tmp/x-pack-5.2.1.zip

以下輸出表示安裝成功:

-> Downloading file:/home/admin/x-pack-5.2.1.zip
[=================================================] 100% 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission accessClassInPackage.com.sun.activation.registries
* java.lang.RuntimePermission getClassLoader
* java.lang.RuntimePermission setContextClassLoader
* java.lang.RuntimePermission setFactory
* java.security.SecurityPermission createPolicy.JavaPolicy
* java.security.SecurityPermission getPolicy
* java.security.SecurityPermission putProviderProperty.BC
* java.security.SecurityPermission setPolicy
* java.util.PropertyPermission * read,write
* java.util.PropertyPermission sun.nio.ch.bugLevel write
* javax.net.ssl.SSLPermission setHostnameVerifier
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed x-pack

Step4. 在 Kibana 安裝目錄運行 bin/kibana-plugin install 命令安裝:

bin/kibana-plugin install file:/tmp/x-pack-5.2.1.zip

以下輸出表示安裝成功:

Attempting to transfer from file:/home/admin/x-pack-5.2.1.zip
Transferring 124956667 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete

Step5. 在 Logstash 安裝目錄運行 bin/logstash-plugin install 命令安裝:

bin/logstash-plugin install file:/tmp/x-pack-5.2.1.zip

以下輸出表示安裝成功:

Installing file: /home/admin/x-pack-5.2.1.zip
Install successful

功能開關

我們可以通過以下配置進行功能開關:

Setting Description
xpack.security.enabled 設置為 false 可以關閉 X-Pack security 功能。需要在 elasticsearch.ymlkibana.yml 同時配置。
xpack.monitoring.enabled 設置為 false 可以關閉 X-Pack monitoring 功能。 需要在elasticsearch.ymlkibana.yml 同時配置。
xpack.graph.enabled 設置為 false 可以關閉 X-Pack graph 功能。 需要在elasticsearch.ymlkibana.yml 同時配置。
xpack.watcher.enabled 設置為 false 可以關閉 Watcher 功能。 只需要在 elasticsearch.yml 配置。
xpack.reporting.enabled 設置為 false 可以關閉 reporting 功能。 只需要在 kibana.yml 配置。

重啟服務

我們需要重啟三個服務:

./bin/logstash -f config/logstash.conf 2>&1 &
/home/admin/soft/elasticsearch-5.2.1/bin/elasticsearch &
./bin/kibana --verbose > kibana.log 2>&1 &

重啟后發現日志數據無法上傳到 ES,filebeat 報錯:

2017-02-22T14:01:27+08:00 ERR Failed to publish events caused by: read tcp 172.16.134.3:56109->172.16.134.2:5044: i/o timeout

logstash 的 5044 端口可以訪問,查看 logstash 日志:

[2017-02-22T14:02:21,705][WARN ][logstash.outputs.elasticsearch] UNEXPECTED POOL ERROR {:e=>#<LogStash::Outputs::ElasticSearch::HttpClient::Pool::NoConnectionAvailableError: No Available connections>}
[2017-02-22T14:02:21,705][ERROR][logstash.outputs.elasticsearch] Attempted to send a bulk request to elasticsearch, but no there are no living connections in the connection pool. Perhaps Elasticsearch is unreachable or down? {:error_message=>"No Available connections", :class=>"LogStash::Outputs::ElasticSearch::HttpClient::Pool::NoConnectionAvailableError", :will_retry_in_seconds=>64}

調用 ES 服務 curl http://172.16.134.2:9200

{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}

發現是出現了認證失敗,筆者推算和 logstash 訪問 ES 未以授權方式進行導致,修改 logstash.confoutput 段里添加:

user => 'elastic'
password => 'changeme'

修改 logstash.yml,添加:

xpack.monitoring.elasticsearch.url: "http://172.16.134.2:9200" 
xpack.monitoring.elasticsearch.username: "logstash_system" 
xpack.monitoring.elasticsearch.password: "changeme"

重啟服務后OK。

功能使用

打開 Kibana 頁面,筆者很尷尬,根本不知道用戶名和密碼是啥,OK 萬能的谷歌告訴我們了:

username: elastic
password: changeme

Kibana 的界面多了如下幾個功能跳轉:Graph Monitoring elastic Logout

Graph

Graph 可以根據實時查詢,對給定的 field 得到圖視角的關聯關系,筆者以一個快速發現集群中哪臺 host 有明顯 ERROR 為例講解下如何使用。Index Pattern 我們選擇 filebeat-*,我們添加 兩個 filed:host log_level,然后在我們的搜索框添加 hour:14 AND minute: [20 TO 37] ,得到以下繪圖:

Graph

可以直觀的看到我們的兩臺被采集機器和日志級別的關系,v134003.yn1 INFO 日志較多,v134008.yn1 ERROR 日志較多。點擊灰色的邊,我們可以看到這個 Link 的概況:

Link Summary

有一個直觀的包含交集圖,還有3個數字,分別表示:

  • 1022 個文本中包含了 v134003.yn1 這個 term;
  • 986 個文本中同時包含了 v134003.yn1 和 INFO 這2個 term;
  • 2013 個文本中包含了 INFO 這個 term;

Monitoring(免費版本只支持單 ES 集群)

查看 ES 集群的 health:

ES Cluster Health
  • 集群級別:
    • Uptime : 集群運行時間;
  • 節點級別:
    • Disk Available:可用磁盤;
    • JVM Heap: JVM 使用情況;
  • 索引級別:
    • Indices:索引數量,相當于數據庫數;
    • Documents:文檔數量,相當于記錄數;
    • Disk Usage:磁盤使用情況;
    • Primary Shards:分片數;
    • Replica Shards:冗余分片數;
Overview

相較于集群健康視圖,這里的指標更多:

  • Serach Rate (/s):近1小時的查詢速率,QPS;
  • Search Latency (ms):近1小時的查詢延遲;
  • Index Rate (/s):近1小時的索引速率,IPS;
  • Index Latency (ms):近1小時的索引延遲;
  • Shard Activity:對于 Shard 的操作歷史;
Indices

索引視角的監控視圖,包含以下指標:

  • Document Count:文檔數;
  • Data:數據量;
  • Index Rate:索引速率;
  • Search Rate:查詢速率;
  • Unassigned Shards:未分配的分片數;

點擊 Index Name 可以進入查看對于索引的詳細基礎監控:

  • Index Memory (KB):索引內存使用,分為 Lucene、Term、Points;
  • Index Size (MB):索引大小;
  • Search Rate (/s):查詢速率;
  • Indexing Rate (/s):索引速率;
  • Segment Count:段數;
  • Document Count:文檔數;
  • Shard Legend:分片狀態圖譜,分為 Primary, Replica,Relocating,Initializing,Unassigned Primary,Unassigned Replica 多個狀態。

點擊 Advanced 可以看到高級監控頁面,請讀者自己去感受下。

Nodes

節點監控,首先看到的是概述指標:

  • CPU Usage: CPU 使用率;
  • Load Average:CPU 平均負載;
  • JVM Memory:JVM 使用情況;
  • Disk Free Space:磁盤空閑空間;
  • Shards:分片數;

點擊某個節點我們可以看到詳細基礎監控:

  • JVM Heap (GB):JVM 使用情況;
  • Index Memory (KB):索引占用內存;
  • CPU Utilization (%):CPU 使用率;
  • System Load:系統負載;
  • Latency (ms):延遲,分為索引和查詢;
  • Segment Count:段數量;
  • Shard Legend:分片狀態圖譜, Primary, Replica,Relocating,Initializing多個狀態。

基于角色的權限控制

該功能的入口在 Management -> Users/RolesUsers 可以方便的管理用戶并且對其賦予角色,角色和權限掛鉤。Roles 可以方便的管理角色,對其進行賦權。RolePermission 的集合,PermissionPrivilege 的集合,下面來說說權限:

  • 集群權限(Cluster Privilege);
  • Run As Privileges:可以使得新建角色擁有所選用戶集的權限;
  • 索引權限(Index Privilege):
    • Indices:指定在哪些索引上賦權;
    • Privileges:指定賦予哪些權限;
    • Granted Documents Query(可選):指定在哪些 Query 上賦權;
    • Granted Fields(可選):指定在哪些 fields 上賦權;

其中,集群權限和索引權限的詳細細分權限如下:

Cluster Privileges

權限類型 權限描述
all 所有群集管理操作,如快照,節點關閉/重新啟動,設置更新,重新路由或管理用戶和角色。
monitor 所有集群只讀操作,如集群健康狀態,熱線程,節點信息,節點和集群統計信息,快照/恢復狀態,掛起集群任務。
manage 構建在監視器上,并添加可更改集群中值的集群操作。這包括快照,已檢查的設置和重新路由。此權限不包括管理安全性的能力。
manage_security 所有與安全性相關的操作,如對用戶和角色的CRUD操作以及緩存清除。
manage_index_templates 對索引模板的所有操作。
manage_pipeline 對管道的所有操作。
transport_client 傳輸客戶端連接所需的所有權限。

Indices Privileges

權限類型 權限描述
all 所有索引操作權限。
monitor 監控(恢復,細分信息,索引統計信息和狀態)所需的所有操作。
manage 所有監視器權限和索引管理( aliases, analyze, cache clear, close, delete, exists, flush, mapping, open, force merge, refresh, settings, search shards, templates, validate
view_index_metadata 只讀訪問索引元數據(aliases, aliases exists, get index, exists, field mappings, mappings, search shards, type exists, validate, warmers, settings)。此權限主要供Kibana用戶使用。
read 只讀訪問操作(count, explain, get, mget, get indexed scripts, more like this, multi percolate/search/termvector, percolate, scroll, clear_scroll, search, suggest, tv)。還授予對更新映射操作的訪問權限。
index 索引和更新文檔的權限。還授予對更新映射操作的訪問權限。
create 索引文檔的權限。還授予對更新映射操作的訪問權限。
delete 刪除文檔的權限。
write 對文檔執行所有寫操作的權限,包括對文檔進行索引,更新和刪除以及執行批量操作的權限。還授予對更新映射操作的訪問權限。
delete_index 刪除索引的權限。
create_index 創建索引的權限。創建索引請求可能包含在創建后添加到索引的別名。在這種情況下,請求還要求在索引和別名名稱上具有manage特權。

具體的 Privilege 可以參看:https://www.elastic.co/guide/en/x-pack/current/security-privileges.html

小結

本文主要介紹了安全解決方案 X-Pack 的概況、免費和收費版本的區別、部署步驟以及基本免費功能的使用。基于此,我們的結論是,對于企業級安全解決方案來說,免費版本的 X-Pack 的確力不從心,需要購買或者結合第三方免費插件進行安全方案升級。

Q&A

Q: 打開 Kibana 遇到 Login is disabled because your license has expired. Please extend your license or disable Security in Elasticsearch.
A: 說明體驗的 x-pack 功能證書過期,需要 disable 之后才可以恢復使用,在 elasticsearch.yml 中添加:

xpack.security.enabled: false
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容