打开微信扫一扫,关注微信公众号【数据与算法联盟】
转载请注明出处: http://blog.csdn.net/gamer_gyt
博主微博: http://weibo.com/234654758
Github: https://github.com/thinkgamer
写在前边的话
elk是日志分析的利器,但是就elk本身而言室友一个弊端的那就是任何人都可以访问和操作,权限的管理方面似乎是一个空白,但是幸好elastic公司对其有辅助的产品Shield,Shield是一个收费的项目,但幸好有一个月的试用期,那么接下来我们就来玩玩这个shield
Shield简介
Shield是Elastic公司官方发布的权限管理产品。其主要特性包括:
- 提供集群节点身份验证和集群数据访问身份验证
- 提供基于身份角色的细粒度资源和行为访问控制,细到索引级别的读写控制
- 提供节点间数据传输通道加密保护输出传输安全
- 提供审计功能
- 以插件的形式发布
基本部署
1:Elasticsearch安装shield 2.4.0插件,最基本的用户验证
先决条件:
Java version >= java 7
Elasticsearch 2.4
Elasticsearch liscense 2.4.0 plugin
在线安装:
终端进入elasticsearch的根目录,此时要注意
以elasticsearch所属用户进行安装,同时注意elastic所属的用户组,若是属于root用户组,在安装时会报错提示没有权限
bin/plugin install license
bin/plugin install shield
这里默认安装的是最新版本
离线安装:
下载需要的licese和shield包
https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/license/2.4.0/license-2.4.0.zip(sha1) https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/shield/2.4.0/shield-2.4.0.zip(sha1)
放在一个path下(eg:/opt/shield/),不要把zip包放在elasticsearch的plugins目录
然后执行安装命令(网友的说法是:这里的目录是绝对路径,不能写成相对路径):
bin/plugin install /opt/shield/license-2.4.0.zip
bin/plugin install /opt/shield/shield-2.4.0.zip
版本升级:
版本升级相对比较简单,只需要把原先的版本给remove掉,然后install就ok,因为卸载时shield会保留其配置
bin/plugin remove shield
bin/plugin install shield
卸载:
bin/plugin remove shield
之后重启elasticsearch即可
2:shield在elasticsearch上的验证
当安装完shield后,启动elasticsearch
执行
curl -X GET http://localhost:9200
会爆出以下error
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"shield\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"shie
因为shield已经起作用了,当然你也可以通过web访问http://localhost:920
我的是win10 的Edge跳出弹出框:
创建用户:
我们可以在shell终端中创建一个es_admin的用户(在es的根目录下执行)
bin/shield/esusers useradd es_admin -r admin
es_admin 为用户名,-r 表示指定的角色为admin
PS:我们可以使用以下命令查看帮助
bin/shield/esusers -h
登录验证:
我们可以在web弹出的输入框输入账号和密码进行登录查看数据,也可以使用下面的这条命令进行验证
es_admin 是用户名,elasticsearch是我es_admin对应的密码
master@ubuntu:/opt/elk/elasticsearch-2.4.0$ curl -u es_admin:elasticsearch -X GET http://localhost:9200
{
"name" : "Mauvais",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.4.0",
"build_hash" : "ce9f0c7394dee074091dd1bc4e9469251181fc55",
"build_timestamp" : "2016-08-29T09:14:17Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
至此shield在elasticsearch上的简单部署已经完成
3:shield在Logstash中的应用
首先我们创建一个logstash用户,用于logstash访问elasticsearch
同样在elasticsearch的根目录下执行创建命令:
master@ubuntu:/opt/elk/elasticsearch-2.4.0$ bin/shield/esusers useradd logstash -r logstash
Enter new password:
Retype new password:
然后当我们编写**.conf文件时,在output中加入
output{
...
elasticsearch{
....
user => "logstash"
password => "logstash"
}
}
4:shield在kibana中的应用
kibana的配置相对比较麻烦,我会在下一篇博客中集合具体的实例讲解:
http://blog.csdn.net/gamer_gyt/article/details/52896522
Shield的工作原理
Shield作为插件安装到elasticsearch中,一旦安装,插件会拦截入栈API调用,以强制执行身份验证和授权,插件还可以使用Secure Sockets Layer/Transport Layer Security (SSL/TLS)为来自网络和elasticsearch的网络流量提供加密,该插件还是用API拦截层,该层使身份验证和授权能够提供审计日志记录功能。
1:用户验证
Shield已经定义了一组用户,以便对发出请求的用户进行身份验证,这组用户集合通过一个称为realm来定义,realm是配置为使用shield插件的用户数据库,native, file, LDAP, Active Directory, PKI支持 realm
- 在native realm中,用户将与Elasticsearch集群一起存储和分发。对于native realm,管理员使用API管理用户进行用户管理,所有用户操作都发生在Elasticsearch集群中。用户使用用户名和密码对进行身份验证。
- 在 file realm中,用户保存与存储在Elasticsearch集群的每个节点上的文件中。使用file realm,管理员使用Elasticsearch提供的工具管理用户,所有用户操作都发生在Elasticsearch集群中。用户使用用户名和密码对进行身份验证。
- 在LDAP realm中,管理员使用LDAP供应商提供的工具管理用户。Elasticsearch通过访问配置的LDAP服务器来验证用户。用户使用用户名和密码对进行身份验证。Shield还支持将LDAP组映射到Shield中的角色。
- 在Active realm中,管理员在Active Directory中管理用户。Elasticsearch使用LDAP协议向Active Directory验证用户。用户使用用户名和密码对进行身份验证。Shield还支持将Active Directory安全组映射到Shield中的角色。
- 在PKI realm,管理员使用X.509证书管理工具管理用户。 Elasticsearch通过验证用户的X.509证书已由可信的授权方签名来验证用户。用户通过在TLS通信期间显示其PKI证书进行身份验证,Shield会将主题映射到适当的角色
您的应用程序可以是Shield领域中的用户。 Elasticsearch客户端通过为每个请求提供用户名和密码对(a.k.a身份验证令牌)来对集群进行身份验证。
shield定义的用户规则的路径为
ES_HOME/config/shield/roles.yml
# All cluster rights
# All operations on all indices
admin:
cluster:
- all
indices:
- names: '*'
privileges:
- all
# monitoring cluster privileges
# All operations on all indices
power_user:
cluster:
- monitor
indices:
- names: '*'
privileges:
- all
# Read-only operations on indices
user:
indices:
- names: '*'
privileges:
- read
# Defines the required permissions for transport clients
transport_client:
cluster:
- transport_client
# The required permissions for the kibana 4 server
kibana4_server:
cluster:
- monitor
indices:
- names: '.kibana*'
privileges:
- all
- names: '.reporting-*'
privileges:
- all
# The required role for logstash users
logstash:
cluster:
- manage_index_templates
indices:
- names: 'logstash-*'
privileges:
- write
- read
- create_index
# Marvel user role. Assign to marvel users.
marvel_user:
indices:
- names: '.marvel-es-*'
privileges: [ "read" ]
- names: '.kibana'
privileges:
- view_index_metadata
- read
# Marvel remote agent role. Assign to the agent user on the remote marvel cluster
# to which the marvel agent will export all its data
remote_marvel_agent:
cluster: [ "manage_index_templates" ]
indices:
- names: '.marvel-es-*'
privileges: [ "all" ]
2:授权规则
Shield的行动授权数据包含以下元素:
- Secured Resource :定义资源的安全特权,包括集群索引/别名,或一组指标/集群中的别名
- Privilege:用户可以针对安全资源执行的一个或多个动作。 这包括命名的动作组(例如读取)或设置特定动作(例如,索引:/ data / read / percolate)
- Permissions:针对安全资源的一个或者多个特权(eg:在索引“products”上的read)
- Role:命名的特权集
- Users:可以分配零个或多个角色的实体,授权他们对其角色并集中描述的安全资源执行操作
安全的Elasticsearch集群通过角色管理用户的权限。 角色具有唯一的名称,并标识一组权限,这些权限转换为资源上的权限。 用户可以具有任意数量的角色。 有两种类型的权限:集群和索引。 用户具有的总权限集由所有角色中的权限的并集来定义。根据使用的领域,Shield提供了向用户分配角色的适当方法。