企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 本节讲解内容如下 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