### 本節講解內容如下
1.Search Guard的權限設置
2.searchguard索引的管理
3.Kibana、Logstash的設置
#### Search Guard的基本原理
Search Guard的基本組成
- 用戶
- 角色
- 權限(權限組)
- 全局配置
#### 配置文件(權限管理)
這里我饒了很久才明白相互之間的關系,最難的就是角色、用戶和權限的關系
- ##### sg_internal_users.yml(重點)
定義用戶名、密碼、**所屬角色**,如果沒有LDAP等外部外部身份驗證系統,則使用此數據庫
注意,該文件中的role不是定義用戶和權限的關系,是給這個用戶定義一個角色,可以理解為把這個用戶劃分到了某個部門(分組)里
用戶和權限的定義是在sg_roles_mapping.yml中,一個用戶可以有多個角色(讀角色,寫角色)
- ##### sg_roles_mapping.yml(重點)
作用一、為某個用戶指定權限,這類用戶一般就是需要定制權限(比如只能訪問某個索引)
作用二、為某個角色(分組)指定權限,ELKStack權威指南中(第二版)中,定義基層角色
- ##### sg_roles.yml
設置權限名稱及該名稱所設置權限,引用sg_action_groups.yml中設置的權限分組
- ##### sg_action_groups.yml
定義權限組,多個權限組成一個權限分組
- ##### sg_config.yml
全局設置(我沒有配置)
##### 腳本
sgadmin.sh
```shell
創建和更新searchguard索引片的配置
```
hash.sh
```shell
生成加密邏輯用戶(登錄ES和Kibana)的密碼
用法 hash.sh -p 123456
```
install_demo_configuration.sh
```shell
生成Demo數據,不推薦使用
```
#### 默認用戶
默認已經有了用戶和權限配置,都是弱口令,將Example的數據全部刪除,保留測試用戶,出于演示目的,下面這些用戶先統一設置 JnKtaCb1zKdr13I7,生產請自行修改
|Username|Password|Description|
| :------------: | :------------: | ------------|
|admin|admin|Full access to the cluster and all indices, but no access to the Search Guard configuration. Use an admin certificate for that.|
|kibanaserver|kibanaserver|Internal Kibana server user, for configuring elasticsearch.username and elasticsearch.passwordin kibana.yml. Has all permissions on the .kibana index.|
|kibanaro|kibanaro|Regular Kibana user, has READ access to all indices and all permissions on the .kibana index.|
|logstash|logstash|Logstash and Beats user, has CRUD and CREATE_INDEXpermissions on all logstash and beats indices|
|readall|readall|Has read access to all indices|
##### 默認權限
|Role name|Description|
| :------------: | ------------ |
|sg_all_access|All cluster permissions and all index permissions on all indices|
|sg_readall|Read permissions on all indices, but no write permissions|
|sg_readonly_and_monitor|Read and monitor permissions on all indices, but no write permissions|
|sg_kibana_server|Role for the internal Kibana server user, please refer to the Kibana setup chapter for explanation|
|sg_kibana|Role for regular Kibana users, full access to the .kibana index and read permissions on all other indices.|
|sg_logstash|Role for logstash and beats users, grants full access to all logstash and beats indices.|
|sg_manage_snapshots|Grants full permissions on snapshots and repositories.|
|sg_own_index|Grants full permissions on an index named after the authenticated user’s username.|
|sg_monitor|Role for X-Pack Monitoring. Users who wish to use X-Pack Monitoring need this role in addition to the sg_kibana role|
|sg_alerting|Role for X-Pack Alerting. Users who wish to use X-Pack Alerting need this role in addition to the sg_kibana role|
#### 修改默認密碼,并新建用戶
##### 自定義用戶
|Username|Password|Description|
| :------------: | :------------: | ------------|
|dinghe|VpsnrgU5mrvQFLtK|只可以查看logstash-iislog的索引片|
生成強密碼
```shell
#生成默認用戶密碼
sh /usr/share/elasticsearch/plugins/search-guard-5/tools/hash.sh -p JnKtaCb1zKdr13I7
$2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
#生成自定義用戶密碼
sh /usr/share/elasticsearch/plugins/search-guard-5/tools/hash.sh -p VpsnrgU5mrvQFLtK
$2a$12$gWI0A0YZYY56Gccl5Cv1KOcpNrSodyCKgvDtxAN9N09iBE8d7guwG
```
修改sg_internal_users.yml,并設置dinghe的角色為ops
```shell
admin:
hash: $2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
logstash:
hash: $2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
kibanaserver:
hash: $2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
kibanaro:
hash: $2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
roles:
- kibanarole
readall:
hash: $2a$12$HOTSUMRfL1FBa68Z8opIQu.J43GlOoWZ1lu14hACRZkcc.TsRGatu
dinghe:
hash:$2a$12$gWI0A0YZYY56Gccl5Cv1KOcpNrSodyCKgvDtxAN9N09iBE8d7guwG
roles:
- ops
```
關于admin用戶的權限這里多說一下,雖然是admin,對索引有全部控制權限,雖然他可以刪除searchguard索引分片,但是,不可以維護和修改searchguard索引內的數據。
##### 為不同規則名稱配置權限sg_roles.yml
添加需要的權限
```yaml
sg_kibana_iisindex:
cluster:
- CLUSTER_COMPOSITE_OPS_RO
indices:
'logstash-iislog-*':
'*':
- READ
- indices:admin/mappings/fields/get*
'?kibana':
'*':
- INDICES_ALL
```
由于Elasticsearch內部原理復雜,所以我現在還是先設置的比較寬,比如默認給出的readall權限,就可以給查看用戶使用,后期了解Elasticsearch后,再來補充。
##### 修改sg_roles_mapping.yml
刪除Example,增加
```shell
#sg_own_index:
# users:
# - '*'
sg_kibana_iisindex:
backendroles:
- ops
#sg_kibana_iisindex:
# user:
# -dinghe
```
上文兩種授權方式均可,自行理解一下
sg_own_index我認為權限很大,注釋掉
##### (示例)設置分組權限sg_action_groups.yml
這個只是一個示例,僅供參考,由于還不是很理解Elasticsearch的內部原理和操作,就先不設置了。
```shell
KIBANA_SERVER:
- "indices:admin/exists*"
- "indices:admin/mapping/put*"
- "indices:admin/mappings/fields/get*"
- "indices:admin/refresh*"
- "indices:admin/validate/query*"
- "indices:data/read/get*"
- "indices:data/read/mget*"
- "indices:data/read/field_caps"
- "indices:data/read/search*"
- "indices:data/write/delete*"
- "indices:data/write/index*"
- "indices:data/write/update*"
```
sg_roles.yml
```yaml
sg_kibana:
cluster:
- CLUSTER_COMPOSITE_OPS_RO
indices:
'*':
'*':
- READ
'?kibana':
'*':
- KIBANA_SERVER
```
Elasticsearch并不公布所有權限的更新列表了。最后一個已知的發布列表是[shield 2.1](https://www.elastic.co/guide/en/shield/2.1/reference.html#ref-actions-list "shield 2.1")
##### 修改后,更新searchguard索引分片
```shell
sh /usr/share/elasticsearch/plugins/search-guard-5/tools/sgadmin.sh -h 192.168.0.230 -p 9300 -tspass siCPVLDYN2BwuYKo -kspass CNByuENniEtkHRfs -cd /usr/share/elasticsearch/plugins/search-guard-5/sgconfig -ks /etc/elasticsearch/admin-keystore.jks -ts /etc/elasticsearch/truststore.jks -nhnv -cn es-cluster
```
#### 配置Logstash
```yaml
output {
if [type] == "iislog" {
elasticsearch {
hosts => ["192.168.0.231:9200"]
index => "logstash-iislog-%{+YYYY.MM.dd}"
user => "logstash"
password => "JnKtaCb1zKdr13I7"
}
}
}
```
配置后,可以測試寫入了
#### 配置Kibana
```yaml
elasticsearch.url: "http://192.168.0.230:9200"
elasticsearch.username: "kibanaserver"
elasticsearch.password: "JnKtaCb1zKdr13I7"
```
[Kibana用戶相關信息](http://floragunncom.github.io/search-guard-docs/kibana.html "Kibana用戶相關")
這里要多說兩句了,這里配置了kibanaserver用戶,Kibana并沒有用戶登錄驗證功能,這個用戶是Search Guard內置的用戶,是為了你可以正常使用kibana前端的功能。
##### 為Kibana增加用戶登錄功能
[search-guard-kibana-plugin對應版本下載](https://github.com/floragunncom/search-guard-kibana-plugin/releases)
```shell
/usr/share/kibana/bin/kibana-plugin install file:///opt/searchguard-kibana-5.6.4-5.zip
```
安裝完成后,重啟Kibana,就能夠實現用戶登錄功能了,如果ES集群不被Search Guard所保護,Kibana將無法登陸ES集群
### 總結
截至到現在,Search Guard已經初步部署完成,通過2天的研究,主要還是在于原理的理解,配置上比較簡單
#### 后續可研究的東西
1. Kibana和Logstash,使用SSL/TLS加密與ES之間的通訊
2. 備份和恢復
3. Search Guard對性能的影響
4. Kibana多租戶 search-guard-module-kibana-multitenancy
5. 關聯LDAP
- 獻給樂于奉獻的你
- 一、工作感悟
- 1.1 工作感悟
- 1.2 數據庫工作總結
- 二、運維專題(非技術)
- 2.1 公有云運維
- 2.1.1 阿里云采坑記.md
- 三、運維專題(技術類)
- 3.1 Linux(操作系統)
- 3.1.1 常見工作總結
- 3.1.2 常見服務使用和部署
- 3.1.3 操作系統優化
- 3.1.4 常用命令(Centos8)
- 3.2 Docker & K8s(容器技術)
- 3.2.1 Docker
- 1. Docker
- 1-1 容器基礎
- 1-2 部署和加速
- 1-3 常用命令
- 1-4 Dockerfile編寫
- 1-5 容器網絡
- 1-6 數據持久化
- 2. docker-compose
- 2-1 基礎
- 3.2.2 kubernetes
- 1. 導讀-請先看我
- 2. kubeadm部署集群
- 1-1 k8s-1.14-基于calico
- 1-2 k8s-1.17-基于flanne
- 3. 二進制部署集群
- 4. 日常工作及故障處理
- 4-1 常用命令
- 4-2 故障處理
- 3.2.3 依賴服務部署
- 1. Harbor(鏡像倉庫)
- 1-1 harbor-2.1.0(單節點)
- 3.3 CICD(持續集成/部署)
- 3.3.1 GitLab
- 1. 服務部署
- 1-1 Gitlab-CE-13.3.4(單節點)
- 2. Git基礎
- 3.3.2 Ansible
- 1. 服務部署
- 1-2 ansible-2.5(pip部署)
- 3. ansible-playbook
- 3-1 基于Roles的Playbook
- 3-3 循環語法
- 3.3.3 Jnekins
- 1. Jenkins部署
- 1-1 Jenkins-2.65部署
- 1-2 Jenkins-2.249部署
- 2. Jenkins項目初始化
- 3. Jenkins集成
- 3-1 Jenkins-2.65集成Sonar
- 3.4 LB/HA(負載均衡,反向代理)
- 3.4.1 LVS+Keepalive
- 1. LVS為MySQL讀提供負載均衡
- 3.4.2 Pacemaker(HA)
- 1. 常用命令(轉)
- 3.5 Runtime(代碼運行環境)
- 3.5.1 Tomcat(Web中間件)
- 1. Tomcat部署手冊
- 1-1 Tomcat-7.0.76部署
- 2. Tomcat常用腳本
- 3.6 NoSQL(非關系型數據庫)
- 3.6.1 redis(非關系數據庫)
- 1. Redis 基礎
- 2. Redis 4.0變化
- 3. Codis實現Redis的集群
- 4. Redis故障處理
- 5. redis安全第一步
- 6. Redis集群搭建
- 7. CacheCloud部署
- 3.6.1 Redis挑戰
- 3.6.2 MongoDB(文檔數據庫)
- 1. Mongodb基礎
- 1-1 Mongodb4.0新特性
- 1-2 支持多大數據量
- 2. Mongodb安裝
- 2-1 Mac OS安裝Mongodb
- 2-2 Yum安裝Mongodb
- 2-3 二進制安裝Mongodb
- 2-4 docker容器安裝Mongodb
- 2-5 Mongodb 配置文件詳解
- 2-6 Mongodb 生產安全清單
- 2-7 用戶身份認證和授權
- 3. Mongodb副本集
- 3-1 副本集搭建
- 3-2 用戶身份認證與授權
- 4. 日常維護工作
- 4-1 Mongodb磁盤回收
- 4-2 Mongodb備份恢復到任意時間點
- 4-3 Mongodb慢查詢分析
- 4-4 Mongodb版本升級
- 4-5 Mongodb副本集成員狀態
- 4-6 Mongodb備份恢復工具使用
- 4-7 Mongodb服務啟動和停止
- 4-8 修改副本集成員oplog大小
- 4-9 Mongodb 副本集Oplog
- 3.7 MQ(消息隊列)
- 3.7.1 Zookeeper(分布式協調系統)
- 1. ZooKeeper基礎
- 2. ZooKeeper集群搭建
- 2-1 ZK-3.4.10部署
- 3.2 RabbitMQ(消息隊列)
- 1. 服務部署
- 1-1 RabbitMQ-3.8部署
- 2. 常用命令
- 3.8 Monitor(數據收集,監控)
- 3.8.1 Zabbix(運維監控)
- 1. 服務部署
- 1-1 服務端部署
- 1-2 客戶端部署
- 2. 監控服務
- 2-1 監控Apache
- 2-2 監控IIS
- 2-3 監控Ningx
- 2-4 監控Tomcat(6/7/8)
- 2-5 監控WebSphere 7
- 2-6 監控MySQL
- 2-7 監控Oracle
- 2-8 監控SQL Servre
- 2-9 監控Weblogic
- 2-10 監控Windows
- 2-11 自定義監控項
- 3. 告警推送
- 3-1 郵件告警
- 3-2 短信告警
- 3-3 告警推到Syslog
- 4. 日常工作
- 4-1 數據庫優化(TokuDB)
- 4-2 數據庫優化(分區表)
- 4-3 前端定制(Grafana)
- 5. 與Grafana結合
- 3.8.2 ELKBstack(日志收集展示)
- 1. 服務部署
- 1-1 ELK 5.5部署及配置
- 1-1-1 ELKBstack介紹
- 1-1-2 Elasticsearch部署
- 1-1-3 Logstash部署
- 1-1-4 Kibana部署
- 1-1-5 X-pack部署
- 1-1-6 Filebeat部署
- 2. ELK高級配置
- 1. Elasticsearch實戰
- 2. Logstash實戰
- 3. Filebeat實戰
- 5. 引入隊列
- 3.9 Virtualization(虛擬化)
- 3.10 Basic(基礎服務)
- 3.10.1 Piwik-Matomo(用戶行為分析)
- 1. Piwik前期分析
- 2. Piwik介紹和部署
- 2-1 Piwik-3.x版本(早期)
- 3. Piwik 功能配置
- 4. Piwik 模擬數據和壓測
- 5. Piwik運轉原理
- 6. Piwik數據庫模式(一)
- 6-1 第一部分
- 6-2 第二部分
- 3.10.2 Cobbler(系統自動部署)
- 1. Cobbler 可以干什么?
- 2. Cobbler 基礎原理
- 3. Cobbler 安裝
- 3-1 Cobbler-2.8部署
- 4. Cobbler 基礎配置
- 5. Cobbler 配置文件
- 6. 一鍵優化腳本
- 3.10.3 Rsync(數據同步服務)
- 1. Rsync基礎
- 2. 案例:頁面部署(服務端拉取)
- 3.10.4 NFS(共享存儲)
- 1. NFS部署手冊
- 2. 客戶端NFS備份腳本
- 3.10.5 Grafana(可視化)
- 1. 安裝(8.2.x)
- 3.11 Tools(軟件工具)
- 3.11.1 基準測試
- 1. 基準測試方法論
- 2. 壓測工具 - Siege
- 3. 壓測工具 - http_load
- 3.12 DB(關系型數據庫)
- 3.12.1 MySQL(關系數據庫)
- 1. MySQL部署
- 1-1 MySQL-5.7部署
- 1-2 Percona-5.7 + TokuDB 部署
- 2. MySQL復制
- 2-1 MySQL異步復制
- 3. MySQL備份恢復
- 3-1 xtrabackup 備份恢復
- 4. MySQL 高可用
- 4-1 MHA(HA)
- 4-1-1 MHA 架構介紹和原理
- 4-1-2 MHA日常管理
- 4-1-3 MHA 自動Failover
- 4-1-4 MHA常用參數
- 4-1-5 MHA 報錯
- 4-1-6 MHA相關配置文件和腳本
- 4-2 MyCAT
- 4-2-1 MyCAT 介紹和部署
- 4-1-3 MyCAT讀寫分離案例解析
- 5. MySQL 常用腳本
- 5-1 MySQL常用統計語句
- 5-2 MySQL性能分析腳本
- 6. MySQL 日常及故障處理
- 6-1 MySQL死鎖排查
- 6-2 復制故障
- 6-3 MySQL 升級注意事項
- 6-3 MySQL授權
- 3.12.2 Oracle(關系數據庫)
- 1. Oracle部署
- 1-1 Oracle11g單實例部署
- 1-2 Oracle12c單實例部署
- 2. Oracle常用腳本
- 3. Oracle 知識點
- 六、Ansible開源項目
- 6.1 項目初始化手冊
- 6.1.1 Ansible錯誤處理
- 6.1.2 一種預先判斷是否操作的方法
- 6.2 System初始化
- 6.3 Nginx/Tnginx部署
- 6.4 Python部署
- 6.5 PHP部署
- 6.6 MySQL部署
- 6.7 Docker部署
- 6.8 Haproxy部署
- 6.9 Redis部署
- 1. 變量和tags信息
- 3. Redis主從部署
- 4. Redis集群部署
- 5. 清理數據
- 6.10 Software軟件部署
- 6.11 Zabbix部署
- 6.12 Elastic部署
- 6.13 Tomcat
- 6.14 Kafka部署
- 6.15 Zookeeper部署
- 6.16 Etcd集群部署
- 6.17 M3DB部署
- 6.18 Pormetheus部署
- 七、學習資源推薦
- 八、從瞎搞到放棄
- 8.1 CodeQL(語義代碼分析引擎)
- 8.1.1 背景及計劃
- 8.1.2 CodeQL概述
- 8.1.3 簡單部署和使用
- 8.1.4 后續
- 8.2 dbdeployer(輕松部署MySQL)
- 歸檔筆記
- 三、常用服務部署(遷移中)
- 3.4 Nginx & PHP(Web服務)
- 3.4.1 Nginx(Web)
- 1. Nginx基礎和部署
- 2. Nginx 我的一些思考
- 3. Nginx(Web)配置
- 4. Nginx(Proxy)配置
- 5. Nginx日常管理
- 3.4.3 PHP
- 1. PHP 7.1 部署
- 2. PHP5.6 部署
- 4. PHP原理
- 5. PHP 常用模塊
- 二、運維項目實戰(遷移中)
- 2.1 標準化 & 工具化項目
- 2.1.1 系統部署和優化
- 2.1.5 全網日志收集展示平臺項目
- 1. 項目需求
- 2. 整體方案規劃
- 3. 日志收集配置
- 4. 消息緩沖隊列
- 5. 日志處理轉發
- 6. 日志數據展示(待補充)
- 7. ELK安全配置(上)
- 8. ELK安全配置(下)
- 9. 項目總結
- 2.2 高性能Web項目
- 2.2.1 網站需求(完善中)