转 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/

时间: 2024-10-21 23:37:27

转 Shield Your Kibana Dashboards的相关文章

kibana4 分析和搜索仪表板 安装和配置

Kibana4 是 Elasticsearch 分析和搜索仪表板 Elasticsearch 必须要先安装 风来了.fox 1.下载和安装 下载地址 https://www.elastic.co/downloads/kibana 目前最新版本 4.6.1 这里选择 LINUX 64-BIT 即方式一 方式一:源码 wget https://download.elastic.co/kibana/kibana/kibana-4.6.1-linux-x86_64.tar.gz tar -zxvf ki

ELK菜鸟手记 (三) - X-Pack权限控制之给Kibana加上登录控制以及index_not_found_exception问题解决

  0. 背景 我们在使用ELK进行日志记录的时候,通过网址在Kibana中查看我们的应用程序(eg: Java Web)记录的日志, 但是默认是任何客户端都可以访问Kibana的, 这样就会造成很不安全,我们应该设置相应的用户名和密码, 只有通过登录用户名和密码才能通过Kibana查看我们的日志.   1. 在elasticsearch 2.x的版本是怎么做的 笔者网上查了一些博文,大部分推荐的是通过给elasticsearch安装Shield插件,参考链接如下: http://blog.cs

为程序中按钮添加Shield图标

之前讲的Windows 7兼容性Webcast中我做了一个Shield Icon的Demo,这个图标就是表示点击该按钮后执行的是一个要求提升权限的操作,借此写一下它的主要实现过程以及把Webcast中的Demo放出来. 其实主要实现是调用了user32.dll中的方法给现有按钮控件贴上一个小图标,可以使用下面方法来实现: [DllImport("user32.dll")] private static extern IntPtr SendMessage(HandleRef hWnd,

教你在Safari里完美屏蔽Hotspot shield广告条的最终方法

  Hotspot shield:Hotspot Shield是一款国外免费自动搜索VPN代理软件,能够有效保护你的个人隐私以及访问你想访问的网站. 对于苦于无法访问某些国外著名网站,以及受困于公司内部被Websense所限制的网站,甚至实现绕国国外某些网站对中国IP地址的限制的朋友,这一VPN代理软件,不仅速度快,而且稳定性强,更重要的是这是一款免费软件. 下载.安装并运行. 会打开 http://www.hotspotshield.com/launch/ 页面, 点击"Run Hotspot

ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台

ELK平台介绍 在搜索ELK资料的时候,发现这篇文章比较好,于是摘抄一小段: 以下内容来自:http://baidu.blog.51cto.com/71938/1676798 日志主要包括系统日志.应用程序日志和安全日志.系统运维和开发人员可以通过日志了解服务器软硬件信息.检查配置过程中的错误及错误发生的原因.经常分析日志可以了解服务器的负荷,性能安全性,从而及时采取措施纠正错误. 通常,日志被分散的储存不同的设备上.如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志.这样

Docker日志自动化: ElasticSearch、Logstash、Kibana以及Logspout

本文讲的是Docker日志自动化: ElasticSearch.Logstash.Kibana以及Logspout,[编者的话]本文主要介绍了如何使用ElasticSearch.Logstash.Kibana和Logspout技术栈来部署自动化的日志系统. You, too, could Logstash. 快速念五遍这个题目!不过说实话,我其实并不确定该给这篇文章起个什么样的名字才能确保人们可以找到它. 这篇文章是基于Evan Hazlett's article on running the

kibana有中文版的,急需答案,拜托各位大神

问题描述 kibana有中文版的,急需答案,拜托各位大神 现在我用的kibana4是英文的,请问各位kibana 有中文版的吗

Kibana——数据图形化制作

Kibana把数据图形化,可以帮助我们更好的去分析数据,找到数据里面的结构 注意看一下,上面缩看的界面,是一个聚合的结果,他是由CPU Usage图表.System Load图表.CPU usage over time图表. System Load over time图表一起构造而成的.我把这种聚合称作一组相关性的数据看板,你可以随意的组合你的看板,如果你觉得这样做是合适的.那么,CPU Usage图表.System Load图表.CPU usage over time图表. System Lo

Logstash+Redis+Elasticsearch+Kibana+Nginx搭建日志分析系统

前言: 随着实时分析技术的发展及成本的降低,用户已经不仅仅满足于离线分析.目前我们服务的用户包括微博.微盘.云存储.弹性计算平台等十多个部门的多个产品的日志搜索分析业务,每天处理约32亿条(2TB)日志.哈哈 以上都是新浪的信息~不是我们小公司的分析业务规模. 当然为了使得运行在客户端的软件有良好的体验,并且得到有用的数据,我们需要对这些系统产生的数据,进行统计和分析,这个过程通常包括数据采集,清洗,建模,分析,报表等.接下来在本篇文章中,将会构建一个基于logstash,redis,elast