Elasticsearch & Kibana with Shield

Elasticsearch & Kibana with Shield

官方網站:


環境:
kibana-4.5.0
elasticsearch-2.3.2
shield-2.3.2
license-2.3.2


前言:
Shield做爲安全插件能夠嵌入到ELK當中,商業受權,前30天免費
支持多種認證方式 nativefileLDAPActive DirectoryPKI,詳情見 https://www.elastic.co/guide/en/shield/current/how-shield-works.html
這裏以file,native爲例


Elasticsearch with Shield
一.中止全部elasticsearch節點
說明:shield安裝,卸載,升級都須要重啓elasticsearch節點

二.安裝shield插件(全部elasticsearch節點)
說明:shield版本必須和elasticsearch保持一致
在線安裝

/opt/elasticsearch-2.3.2/bin/plugin install licensehtml

/opt/elasticsearch-2.3.2/bin/plugin install shieldnode

或離線安裝linux

/opt/elasticsearch-2.3.2/bin/plugin install file:///root/license-2.3.2.zip 
/opt/elasticsearch-2.3.2/bin/plugin install file:///root/shield-2.3.2.zip

[root@ela-master1 ~]# /opt/elasticsearch-2.3.2/bin/plugin install file:///root/license-2.3.2.zip 安全

-> Installing from file:/root/license-2.3.2.zip...session

Trying file:/root/license-2.3.2.zip ...curl

Downloading .DONEelasticsearch

Verifying file:/root/license-2.3.2.zip checksums if available ...ide

NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)測試

Installed license into /opt/elasticsearch-2.3.2/plugins/license網站

[root@ela-master1 ~]# /opt/elasticsearch-2.3.2/bin/plugin install file:///root/shield-2.3.2.zip

-> Installing from file:/root/shield-2.3.2.zip...

Trying file:/root/shield-2.3.2.zip ...

Downloading .......................DONE

Verifying file:/root/shield-2.3.2.zip checksums if available ...

NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)

Installed shield into /opt/elasticsearch-2.3.2/plugins/shield


注意:一旦shield安裝成功,在elasticsearch重啓後,對elasticsearch的任何操做都須要受權(用戶名和密碼),除非啓用匿名用戶 https://www.elastic.co/guide/en/shield/current/anonymous-access.html

三.配置realm
A.配置file-realm(全部節點)
1.增長file-realm配置
cat >>/opt/elasticsearch-2.3.2/config/elasticsearch.yml <<HERE

shield.authc.realms.file1.type: file

shield.authc.realms.file1.order: 0

HERE

2.啓動(或重啓)elasticsearch

3.建立file based用戶

https://www.elastic.co/guide/en/shield/current/defining-roles.html#valid-role-name

https://www.elastic.co/guide/en/shield/current/enable-basic-auth.html

/opt/elasticsearch-2.3.2/bin/shield/esusers useradd es_admin -p P@ssw0rd -r admin

/opt/elasticsearch-2.3.2/bin/shield/esusers useradd kibana -p P@ssw0rd -r kibana4_server

[root@ela-client ~]# /opt/elasticsearch-2.3.2/bin/shield/esusers list

es_admin       : admin

kibana         : kibana4_server

說明:這裏建立了兩個用戶es_admin(用戶名 es_admin, 密碼P@ssw0rd, 角色admin)和kibana,用戶角色定義能夠參看shield配置文 件/opt/elasticsearch-2.3.2/config/shield/roles.yml
4.file based用戶同步到集羣其它節點
注意:對於用戶和角色的全部操做默認都存放在以下位置,所以集羣中的全部節點都須要上面一樣的操做,固然,也能夠直接copy以下文件到其它節點的對應目錄

/opt/elasticsearch-2.3.2/config/shield/users

/opt/elasticsearch-2.3.2/config/shield/users_roles

5.測試用戶認證

[root@ela-client ~]# curl -u es_admin:P@ssw0rd 'http://localhost:9200/_cat/health?v'

epoch      timestamp cluster               status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 

1462705707 19:08:27  elasticsearch_cluster green           6         2     52  26            0                                           100.0% 

[root@ela-client ~]# curl -u es_admin:P@ssw0rd 'http://localhost:9200/_cat/indices?v'

health status index               pri rep docs.count docs.deleted store.size pri.store.size 

green  open   shakespeare           5   1     111396            0     36.5mb         18.2mb 

green  open   logstash-2015.05.20   5   1       4750            0     72.9mb         35.7mb 

green  open   bank                  5   1       1000              890.5kb        447.9kb 

green  open   .kibana               1                     0     44.5kb         22.2kb 

green  open   logstash-2015.05.18   5   1       4631            0     64.9mb         32.7mb 

green  open   logstash-2015.05.19   5   1       4624            0     66.7mb           32mb 


B.配置native-realm(全部節點)
默認狀況下, native-realm已經被配置到了realm鏈裏, 能夠直接經過 REST API來添加刪除用戶,修改用戶密碼及管理角色, 這也是 官方推薦的認證方式
1.增長native-realm配置
cat >>/opt/elasticsearch-2.3.2/config/elasticsearch.yml <<HERE

shield.authc.realms.native1.type: native

shield.authc.realms.native1.order: 0

HERE

2.啓動(或重啓)elasticsearch

3.建立native用戶

curl -u es_admin:P@ssw0rd -XPOST 'http://localhost:9200/_shield/user/fooadmin' -d '

{

  "password" : "foo.123", 

  "roles" : [ "admin", "other_role1" ], 

  "full_name" : "Jlive Liu", 

  "email" : "iliujun_live@163.com", 

  "metadata" : { 

    "intelligence" : 7

  }

}

'

說明:

1.新增native用戶也須要認證,但啓用了shield以後默認是沒有native用戶的,因此就須要藉助file based用戶來受權

2.native用戶是存放在elasticsearch集羣中,集羣中的全部節點會自動同步

[root@ela-client ~]# curl -u es_admin:P@ssw0rd -XPOST 'http://localhost:9200/_shield/user/fooadmin' -d '

{

  "password" : "foo.123", 

  "roles" : [ "admin", "other_role1" ], 

  "full_name" : "Jlive Liu", 

  "email" : "iliujun_live@163.com", 

  "metadata" : { 

    "intelligence" : 7

  }

}

'


{"user":{"created":true}}

[root@ela-data1 ~]# curl -u es_admin:P@ssw0rd 'http://localhost:9200/_shield/user'

{"fooadmin":{"username":"fooadmin","roles":["admin","other_role1"],"full_name":"Jlive Liu","email":"iliujun_live@163.com","metadata":{"intelligence":7}}}

4.測試用戶認證

[root@ela-master2 ~]# curl -u fooadmin:foo.123 'http://localhost:9200/_cat/health?v'

epoch      timestamp cluster               status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 

1462707192 19:33:12  elasticsearch_cluster green           6         2     54  27            0                                           100.0% 



Kibana with Shield
一.安裝hield插件
說明:shield版本必須和elasticsearch保持一致
在線安裝

/opt/kibana-4.5.0-linux-x64/bin/kibana plugin --install kibana/shield/2.3.2

或離線安裝

wget http://download.elastic.co/kibana/shield/shield-2.3.2.tar.gz

/opt/kibana-4.5.0-linux-x64/bin/kibana plugin --install shield --url file:///mnt/hgfs/linux_soft/ELK/shield-2.3.2.tar.gz


root@jlive:~#/opt/kibana-4.5.0-linux-x64/bin/kibana plugin --install shield --url file:///mnt/hgfs/linux_soft/ELK/shield-2.3.2.tar.gz

Installing shield

Attempting to transfer from file:///mnt/hgfs/linux_soft/ELK/shield-2.3.2.tar.gz

Transferring 7933036 bytes....................

Transfer complete

Extracting plugin archive

Extraction complete

Optimizing and caching browser bundles...

Plugin installation complete


二.啓用認證
A.file realm認證
1.配置具備kibana4-server角色的file based用戶
注意:須要在elasticsearch節點上操做,上面已經建立了一個kibana用戶,這裏就省略建立步驟
2.修改kibana配置文件指定認證用戶
cat >>/opt/kibana-4.5.0-linux-x64/config/kibana.yml <<HERE

kibana_elasticsearch_username: kibana

kibana_elasticsearch_password: P@ssw0rd

shield.encryptionKey: "something_secret"

shield.sessionTimeout: 600000

HERE
3.重啓kibana並訪問

/opt/elasticsearch-2.3.2/config/shield/roles.yml

# The required permissions for the kibana 4 server

kibana4_server:

  cluster:

      - monitor

  indices:

    - names: '.kibana'

      privileges:

        - all

注意:默認的kibana4-server角色用戶指對.kibana索引有全權限,但對其它indices沒有任何權限,若是不指定在登陸kibana後可能會出現以下狀況

Elasticsearch <wbr>& <wbr>Kibana <wbr>with <wbr>Shield

Elasticsearch <wbr>& <wbr>Kibana <wbr>with <wbr>Shield

4.受權用戶訪問指定indices(全部elasticsearch節點)

能夠修改原/opt/elasticsearch-2.3.2/config/shield/roles.yml默認定義的kibana4-server角色,也能夠從新定義一個新角色,這裏定義一個新角色kibana4_indices,能訪問Kibana 官方示例中對應的indices

i.定義角色並受權

cat >>/opt/elasticsearch-2.3.2/config/shield/roles.yml <<HERE

kibana4_indices:

  indices:

    - names: 'shakes*'

      privileges:

        - view_index_metadata

        - read

    - names: 'ba*'

      privileges:

        - view_index_metadata

        - read

    - names: 'logstash*'

      privileges:

        - view_index_metadata

        - read

HERE

ii.用戶受權

[root@ela-master2 ~]# /opt/elasticsearch-2.3.2/bin/shield/esusers roles kibana -a kibana4_indices

[root@ela-master2 ~]# /opt/elasticsearch-2.3.2/bin/shield/esusers list

es_admin       : admin

kibana         : kibana4_indices,kibana4_server

注意:全部的elasticsearch節點都要同步

5.重啓elasticsearch集羣

6.啓動(或重啓)kibana

Elasticsearch <wbr>& <wbr>Kibana <wbr>with <wbr>Shield


B.native realm認證

上文中的native用戶(fooadmin/foo.123)由於是admin用戶,因此能夠直接認證成功。

固然還能夠單獨建個kibana_native用戶來認證

curl -u fooadmin:foo.123 -XPOST 'http://localhost:9200/_shield/user/kibana_native' -d '

{

  "password" : "kibana.123",

  "roles" : [ "kibana4_server","kibana4_indices" ]

}

'

仍是native認證方便,用戶無需全部節點手動同步

相關文章
相關標籤/搜索