转 Shield Your Kibana Dashboards

简介:

You work with sensitive data in Elasticsearch indices that you do not want everyone to see in their Kibana dashboards. Like a hospital with patient names. You could give each department their own Elasticsearch cluster in order to prevent all departments to see the patient's names, for example.

But wouldn't it be great if there was only one Elasticsearch cluster and every departments could manage their own Kibana dashboards? And still have the security in place to prevent leaking of private data?

With Elasticsearch Shield, you can create a configurable layer of security on top of your Elasticsearch cluster.In this article, we will explore a small example setup with Shield and Kibana.

In this article, we'll use Elasticsearch 1.4.4, Shield 1.0.1 and Kibana 4.0.0. These are at the time of writing the most-recent  versions. Beginner knowledge of Elasticsearch is expected.

Suppose we want to keep our patient’s names private. An index of patients will be available only for one department. An index of cases will be available to all departments.

First, we'll add some test data to the cluster. Create a file hospital.json with the following content:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{  "index"  : {  "_index"  :  "cases" ,  "_type"  :  "case" ,  "_id"  :  "101"  } }
{  "admission"  :  "2015-01-03" ,  "discharge"  :  "2015-01-04" ,  "injury"  :  "broken arm"  }
{  "index"  : {  "_index"  :  "cases" ,  "_type"  :  "case" ,  "_id"  :  "102"  } }
{  "admission"  :  "2015-01-03" ,  "discharge"  :  "2015-01-06" ,  "injury"  :  "broken leg"  }
{  "index"  : {  "_index"  :  "cases" ,  "_type"  :  "case" ,  "_id"  :  "103"  } }
{  "admission"  :  "2015-01-06" ,  "discharge"  :  "2015-01-07" ,  "injury"  :  "broken nose"  }
{  "index"  : {  "_index"  :  "cases" ,  "_type"  :  "case" ,  "_id"  :  "104"  } }
{  "admission"  :  "2015-01-07" ,  "discharge"  :  "2015-01-07" ,  "injury"  :  "bruised arm"  }
{  "index"  : {  "_index"  :  "cases" ,  "_type"  :  "case" ,  "_id"  :  "105"  } }
{  "admission"  :  "2015-01-08" ,  "discharge"  :  "2015-01-10" ,  "injury"  :  "broken arm"  }
{  "index"  : {  "_index"  :  "patients" ,  "_type"  :  "patient" ,  "_id"  :  "101"  } }
{  "name"  :  "Adam" ,  "age"  :  28  }
{  "index"  : {  "_index"  :  "patients" ,  "_type"  :  "patient" ,  "_id"  :  "102"  } }
{  "name"  :  "Bob" ,  "age"  :  45  }
{  "index"  : {  "_index"  :  "patients" ,  "_type"  :  "patient" ,  "_id"  :  "103"  } }
{  "name"  :  "Carol" ,  "age"  :  34  }
{  "index"  : {  "_index"  :  "patients" ,  "_type"  :  "patient" ,  "_id"  :  "104"  } }
{  "name"  :  "David" ,  "age"  :  14  }
{  "index"  : {  "_index"  :  "patients" ,  "_type"  :  "patient" ,  "_id"  :  "105"  } }
{  "name"  :  "Eddie" ,  "age"  :  72  }

Then bulk index these documents in the cluster:

?
1
$ curl -X POST  'http://localhost:9200/_bulk'  --data-binary @. /hospital .json

Without security, every user can access all documents. Let's install Shield to add security.

Directions on how to install Shield can be found at the Elasticsearch website . We will do this step by step.

Shield is a commercial product, so first we need to install the license manager:

?
1
2
3
4
5
$ elasticsearch /bin/plugin  -i elasticsearch /license/latest
-> Installing elasticsearch /license/latest ...
Trying http: //download .elasticsearch.org /elasticsearch/license/license-latest .zip...
Downloading .....................................DONE
Installed elasticsearch /license/latest  into  /home/patrick/blog/elasticsearch/plugins/license

Now install Shield itself in the same manner:

?
1
2
3
4
5
$ elasticsearch /bin/plugin  -i elasticsearch /shield/latest
-> Installing elasticsearch /shield/latest ...
Trying http: //download .elasticsearch.org /elasticsearch/shield/shield-latest .zip...
Downloading .....................................DONE
Installed elasticsearch /shield/latest  into  /home/patrick/blog/elasticsearch/plugins/shield

You will need to restart the nodes of your cluster to activate the plugins.

In the logs of Elasticsearch you'll see some messages from the new plugins:

?
1
2
3
4
5
6
7
8
9
[2015-02-12 08:18:01,347][INFO ][shield.license ] [node0] enabling license  for  [shield]
[2015-02-12 08:18:01,347][INFO ][license.plugin.core ] [node0] license  for  [shield] - valid
[2015-02-12 08:18:01,355][ERROR][shield.license ] [node0]
#
# Shield license will expire on [Saturday, March 14, 2015]. Cluster health, 
# cluster stats and indices stats operations are blocked on Shield license expiration.
# All data operations (read and write) continue to work. If you have a new license,
# please update it. Otherwise, please reach out to your support contact.
#

Notice that you will get a 30-day trial period to experiment with Shield. Now all our data is protected. See what happens when we try to get a document:

?
1
2
3
4
5
6
$ curl localhost:9200 /cases/case/101 ?pretty= true
{
     "error"  : "AuthenticationException[missing authentication token 
               for  REST request [ /cases/case/1 ]]",
     "status"  : 401
}

We need to add some roles and users to configure the role-based access control of Shield. First we define the roles and their privileges. The definition of these are found in the elasticsearch/config/shield/roles.yml file. Some roles, like admin and user are predefined:

?
1
2
3
4
5
6
7
8
9
10
# All cluster rights
# All operations on all indices
admin:
   cluster: all
   indices:
     '*' : all
# Read-only operations on indices
user:
   indices:
     '*' : read

Let's edit this roles.yml file to describe our needs. We do not want for every user to access all indices, so we'll change user.indices . We'll add the two roles needed for our organization: doctor and nurse. A doctor has more privileges than a nurse. Doctors can access all indices. Nurses can only access the cases index:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Read-only operations on indices
#user:
#  indices:
#     '*' : read
 
# Doctors can access all indices
doctor:
   indices:
     '*' : read
 
# Nurses can only access the cases index
nurse:
   indices:
     'cases' : read

Now that the roles are defined, we can create users that have these roles. Shield provides three realms to store the users: an internal realm, LDAP or Active Directory. For now, we use the internal realm. The realm is configured in elasticsearch/config/elasticsearch.yml . If nothing is explicitly configured, the internal realm is used.

To add users the esusers command line tool can be used. Let's create two users (both with abc123 as password), one for each role:

?
1
2
$ elasticsearch /bin/shield/esusers  useradd  alice -r nurse
$ elasticsearch /bin/shield/esusers  useradd  bob -r doctor

Just to check if the security works:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ curl --user alice:abc123 localhost: 9200 /_count?pretty= true
{
   "count"  :  5 ,
   "_shards"  : {
     "total"  :  1 ,
     "successful"  :  1 ,
     "failed"  :  0
   }
}
 
$ curl --user bob:abc123 localhost: 9200 /_count?pretty= true
{
   "count"  :  10 ,
   "_shards"  : {
     "total"  :  2 ,
     "successful"  :  2 ,
     "failed"  :  0
   }
}

Alice can see the 5 cases in our cases index. Bob can see those 5 cases plus the 5 patients in the patients index.

Now it's time to add Kibana in the mix. Instructions to download and install Kibana 4 can be found on the Elasticsearch website.

When we start the Kibana server we notice that Kibana is not allowed access to the Elasticsearch cluster:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ kibana /bin/kibana
{
     "@timestamp" :  "2015-02-26T08:24:48.958Z" ,
     "level" :  "fatal" ,
     "message" :  "AuthenticationException[missing authentication token for REST request [/.kibana/config/_search]]" ,
     "node_env" :  "production" ,
     "error" : {
         "message" :  "AuthenticationException[missing authentication token for REST request [/.kibana/config/_search]]" ,
         "name" :  "Error" ,
         "stack" : "Error: AuthenticationException[missing authentication token  for  REST request [/.kibana /config/_search ]] 
                  at respond ( /home/patrick/kibana/src/node_modules/elasticsearch/src/lib/transport .js:235:15)
                  at checkRespForFailure ( /home/patrick/kibana/src/node_modules/elasticsearch/src/lib/transport .js:203:7)
                  at HttpConnector. ( /home/patrick/kibana/src/node_modules/elasticsearch/src/lib/connectors/http .js:156:7)
                  at IncomingMessage.bound ( /home/patrick/kibana/src/node_modules/elasticsearch/node_modules/lodash-node/modern/internals/baseBind .js:56:17)
                  at IncomingMessage.emit (events.js:117:20)
                  at _stream_readable.js:944:16
                  at process._tickCallback (node.js:442:13)"
     }
}

We need to tell Shield that Kibana is allowed to access our cluster. Extra information of how to let Kibana work with Shield can be found in the Elasticsearch guide .

Shield is shipped with a default configuration for Kibana 4. We find the following role definition in elasticsearch/config/shield/roles.yml.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# The required role for kibana 4 users
kibana4:
   cluster: cluster:monitor /nodes/info
   indices:
     '*' :
       - indices:admin /mappings/fields/get
       - indices:admin /validate/query
       - indices:data /read/search
       - indices:data /read/msearch
       - indices:admin /get
     '.kibana' :
       - 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/search
       - indices:data /write/delete
       - indices:data /write/index
       - indices:data /write/update

When the Kibana Server starts it needs to access the .kibana index. So we need to create a user in Shield for Kibana to connect with:

?
1
$ elasticsearch /bin/shield/esusers  useradd  kibana -r kibana4

This account must be configured in Kibana. Modify kibana/conf/kibana.yml :

?
1
2
3
4
5
6
7
8
9
10
11
12
# If your Elasticsearch is  protected  with basic auth,  this  is the user credentials
# used by the Kibana server to perform maintence on the kibana_index at statup. Your Kibana
# users will still need to authenticate with Elasticsearch (which is proxied thorugh
# the Kibana server)
kibana_elasticsearch_username: kibana
kibana_elasticsearch_password: abc123
 
#----------------------------------------------------------------------------
# In newly version of ElasticSearch  2.1 . 0 , you have to use the following way:
elasticsearch.username: kibana
elasticsearch.password: abc123
#----------------------------------------------------------------------------

The Kibana users must have the kibana4 role to be able to work with Kibana. They must be able to store their visualizations and dashboards in the .kibana index:

?
1
2
$ elasticsearch /bin/shield/esusers  roles alice -a kibana4
$ elasticsearch /bin/shield/esusers  roles bob -a kibana4

Since the default kibana4 role has read access on all indices, alice and bob will be granted all access on all indices. Therefore the role permissions must be modified:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Doctors can access all indices
doctor:
   indices:
     'cases,patients' :
       - indices:admin/mappings/fields/get
       - indices:admin/validate/query
       - indices:data/read/search
       - indices:data/read/msearch
       - indices:admin/get
       
# Nurses can only access the cases index
nurse:
   indices:
     'cases' :
       - indices:admin/mappings/fields/get
       - indices:admin/validate/query
       - indices:data/read/search
       - indices:data/read/msearch
       - indices:admin/get
       
# The required role  for  kibana  4  users
kibana4:
   cluster:
       - cluster:monitor/nodes/info
       - cluster:monitor/health
   indices:
     '.kibana' :
       - 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/search
       - indices:data/write/delete
       - indices:data/write/index
       - indices:data/write/update
       - indices:admin/create

With this configuration any user with the kibana4 role is able to use Kibana but only sees data that he or she has the proper clearance for.

We can now start the Kibana Server and see that it runs as it should:

?
1
2
3
4
5
6
7
$ kibana /bin/kibana
{
     "@timestamp" :  "2015-02-26T08:53:18.961Z" ,
     "level" :  "info" ,
     "message" :  "Listening on 0.0.0.0:5601" ,
     "node_env" :  "production"
}

We can open a browser and head to localhost:5601 to open the Kibana web interface. Log in as Alice:

After logging in, Kibana will ask for the index pattern. We'll keep it simple:

Then in the discover tab you can add fields to your view. Notice that Alice only sees cases:

When we log in as Bob our discover tab shows both cases and patients:

To summarize: we added security to Elasticsearch with Shield and configured some users and roles. There's nothing more to it!



原文地址:http://blog.trifork.com/2015/03/05/shield-your-kibana-dashboards/

相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
目录
相关文章
|
编解码 Shell 文件存储
Rockchip saveBaseParameter程序来设置显示器参数
Rockchip saveBaseParameter程序来设置显示器参数
1696 50
|
JavaScript 前端开发
js 文字超出长度用省略号代替,鼠标悬停并以悬浮框显示
js 文字超出长度用省略号代替,鼠标悬停并以悬浮框显示
|
人工智能 搜索推荐 API
蚂蚁百宝箱联手深铁打造全国首个地铁 AI 智能体「深铁宝」:你的全能城市向导来啦~
蚂蚁百宝箱联合深铁集团、深圳通推出全国首个“公共出行+城市服务”AI智能体「深铁宝」,上线于深圳地铁、深圳通及支付宝APP,实现一句话直达、秒级响应的智慧出行体验,涵盖出行规划、乘车码快捷调取、周边生活服务推荐等一站式功能,助力城市交通与服务数字化升级。
1072 0
蚂蚁百宝箱联手深铁打造全国首个地铁 AI 智能体「深铁宝」:你的全能城市向导来啦~
|
6月前
|
JSON 运维 监控
Skills 是什么?Claude 官方教你做一个好用的 Skill
Skills 可以理解成 Claude Code 给 Agent 准备的任务经验包。它把一类任务里反复出现的说明、脚本、模板、配置、坑点和历史记录放在一起,让 Claude 下次遇到类似任务时,可以直接复用已有经验。
577 0
Skills 是什么?Claude 官方教你做一个好用的 Skill
|
5月前
|
弹性计算 负载均衡 网络协议
阿里云负载均衡SLB对接使用完全指南:从入门到生产级实战
本文系统讲解阿里云负载均衡SLB的完整对接使用流程。从ALB、NLB、CLB三大产品家族的选型策略切入,深入剖析四层与七层负载均衡的核心原理与差异。文章详细覆盖实例创建、服务器组配置、监听规则设置、健康检查参数调优、会话保持机制、安全组与访问控制配置、HTTPS证书部署、监控报警设置等全链路操作步骤,并提供阿里云CLI命令行工具及Python SDK的代码示例。同时结合高并发场景下的最佳实践,分享权重梯度调整、连接复用优化、跨可用区容灾部署等进阶技巧,帮助读者构建高可用、高性能的流量分发架构。
|
6月前
|
人工智能 缓存 自然语言处理
阿里云百炼Token Plan标准/高级/尊享坐席怎么选?Token Plan额度、计费与成本效益全面分析
阿里云百炼Token Plan是面向团队的AI大模型订阅服务,以Credits作为统一计量积分,覆盖文本生成、图像生成、代码开发等全场景模型调用,兼容主流AI编程与智能体工具,提供团队管理、预算管控、数据安全等企业级能力。该方案采用包月订阅制,提供标准、高级、尊享三档坐席,用户按月付费获取固定Credits额度,所有模型调用、工具使用、上下文缓存均按统一规则折算Credits扣除,告别传统按量付费的账单波动,实现AI使用成本的精准可控。本文将从资费额度、Token消耗规则、核心权益、性价比四个维度,全面对比三大坐席差异,为不同使用强度的团队提供清晰的选型参考。
763 0
|
7月前
|
人工智能 API 网络安全
阿里云 OpenClaw(Clawdbot)汉化中文版全场景部署指南:一键脚本+Docker+npm三模式适配
OpenClaw(曾用名Clawdbot/Moltbot)作为GitHub星标120k+的开源个人AI助手平台,凭借“本地运行+多渠道交互+任务执行”的核心优势,成为AI工具领域的热门选择。其支持通过WhatsApp、Telegram、Discord等聊天软件触发邮件管理、日历规划、网页操作等实际任务,真正实现“聊天即操作”。但原版全英文界面给中文用户带来了使用门槛,开源社区推出的第三方汉化中文版完美解决这一问题——CLI命令行与Dashboard网页控制台深度汉化,每小时自动同步官方最新代码,提供稳定版与开发版双选择,开箱即用无需手动打补丁。本文将详细拆解Ubuntu环境配置、一键脚本/NP
586 0
|
12月前
|
机器学习/深度学习 人工智能 监控
云原生AI应用开发
本指南系统阐述云原生AI应用开发实践路径,涵盖MLOps体系构建、PAI-DSW开发平台、特征工程管理、AutoML模型训练、A/B测试部署、全链路监控及AI-CICD流水线,结合阿里云PAI工具链与行业案例,助力企业实现高效、稳定、可迭代的AI应用落地。(238字)
641 0
|
人工智能 文字识别 并行计算
牛逼,DeepSeek-OCR 最新免费,引爆文档处理效率的黑科技模型
小华同学推荐:DeepSeek-OCR,由DeepSeek-AI开源的高效OCR工具,支持视觉压缩编码、结构化输出(如Markdown),可批量处理海量文档,适配PDF/图片,兼容vLLM,助力企业级文档自动化。
1246 3
|
安全 Java API
JUC系列《深入剖析ConcurrentHashMap:高并发环境的Map最优解 》
本文深入解析Java并发容器ConcurrentHashMap,从JDK 1.7分段锁到JDK 1.8的CAS+synchronized优化,剖析其高性能设计原理,并结合核心API与实战代码,详解线程安全、原子操作及LongAdder性能优化技巧,助你掌握高并发编程利器。