【新機能】ShieldがKibanaに対応しました

2016.02.03

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

藤本です。

本日(現地時間は昨日)、Elasticで多くのProductの新バージョンがリリースされました。

ElasticsearchのQuery Profile APIやKibanaのShield UI Plugin対応、winlogbeatという新しいBeatsやら内容盛り沢山です!

その中で今回はKibanaのShield UI Plugin対応を早速試してみましたのでご紹介します。

概要

Elastic社のセキュリティ対策PluginとしてShieldというProductがあります。今まではElasticsearchの認証に対応していましたが、今回のShield2.2.0のリリースによりKibanaのUIの認証に対応しました。これにより今までKibanaはノーガードでインターネット向けに公開することは避けられてきましたが、ある程度は解消されるのではないでしょうか?またShieldによりAPIレベルで権限を制御できるため、Kibana上の操作権限も絞ることが可能となりました。

環境

  • Elasticsearch、Kibana導入サーバ
  • OS : CentOS 6.7
  • Elasticsearch : 2.2.0
  • Kibana : 4.4.0
  • Shield : 2.2.0

やってみた

各最新バージョンがリリースされていますので、復習兼ねて、もろもろインストールからしてみます!

Elasticsearchインストール

最新リリースのRPMファイルが公式ページで提供されているので、rpmコマンドでインストールします。

[root@ip-10-0-2-15 ~]# rpm -ivh https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.2.0/elasticsearch-2.2.0.rpm
Retrieving https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.2.0/elasticsearch-2.2.0.rpm
warning: /var/tmp/rpm-tmp.8WCqbX: Header V4 RSA/SHA1 Signature, key ID d88e42b4: NOKEY
Preparing... ########################################### [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
1:elasticsearch ########################################### [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using chkconfig
sudo chkconfig --add elasticsearch
### You can start elasticsearch service by executing
sudo service elasticsearch start

[root@ip-10-0-2-15 ~]# chkconfig --add elasticsearch
[root@ip-10-0-2-15 ~]# service elasticsearch start
Starting elasticsearch: [ OK ]

アクセスしてみます。

[root@ip-10-0-2-15 ~]# curl localhost:9200
{
"name" : "Quasar II",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.2.0",
"build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe",
"build_timestamp" : "2016-01-27T13:32:39Z",
"build_snapshot" : false,
"lucene_version" : "5.4.1"
},
"tagline" : "You Know, for Search"
}

versionは2.2.0になっています。Luceneは5.4.1に上がっていますね。

Kibanaインストール

最新リリースのtar.gzファイルが公式ページで提供されているので、ダウンロード、解凍するだけです。

[root@ip-10-0-2-15 ~]# wget https://download.elastic.co/kibana/kibana/kibana-4.4.0-linux-x64.tar.gz
--2016-02-03 01:55:13-- https://download.elastic.co/kibana/kibana/kibana-4.4.0-linux-x64.tar.gz
Resolving download.elastic.co... 184.72.228.136, 23.21.123.221, 174.129.234.135, ...
Connecting to download.elastic.co|184.72.228.136|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 30878925 (29M) [application/octet-stream]
Saving to: “kibana-4.4.0-linux-x64.tar.gz”

100%[==============================================================================================================================================>] 30,878,925 5.36M/s in 7.4s

2016-02-03 01:55:22 (3.97 MB/s) - “kibana-4.4.0-linux-x64.tar.gz” saved [30878925/30878925]

[root@ip-10-0-2-15 ~]# tar xzf kibana-4.3.1-linux-x64.tar.gz

Shieldインストール

Elasticsearchへのインストール

ShieldはコマーシャルPluginですので、ライセンスをインストールする必要があります。(30日間のみ無料利用可能) 本番環境を導入する場合はElastic社のサブスクリプションを契約する必要があります。Shield以外にも監視・アラートサービスのWatcherも利用可能だったり、何よりサポートがついてくるので是非ご検討を!

[root@ip-10-0-2-15 ~]# /usr/share/elasticsearch/bin/plugin install license
-> Installing license...
Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/license/2.2.0/license-2.2.0.zip ...
Downloading .......DONE
Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/license/2.2.0/license-2.2.0.zip checksums if available ...
Downloading .DONE
Installed license into /usr/share/elasticsearch/plugins/license

[root@ip-10-0-2-15 ~]# /usr/share/elasticsearch/bin/plugin install shield
-> Installing shield...
Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/shield/2.2.0/shield-2.2.0.zip ...
Downloading ....................................................................................................................................DONE
Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/shield/2.2.0/shield-2.2.0.zip checksums if available ...
Downloading .DONE
Installed shield into /usr/share/elasticsearch/plugins/shield

# Path to log files:

Kibanaへのインストール

KibanaのShield Pluginをインストールします。

[root@ip-10-0-2-15 ~]# ./kibana-4.4.0-linux-x64/bin/kibana plugin --install kibana/shield/latest
Installing shield
Attempting to transfer from https://download.elastic.co/kibana/shield/shield-latest.tar.gz
Transferring 5887233 bytes....................
Transfer complete
Extracting plugin archive
Extraction complete
Optimizing and caching browser bundles...
Plugin installation complete

ほんと何から何までインストールが楽なのは嬉しいですね〜。

以降、設定に入ります。

Shieldユーザー/ロール設定

Kibana管理ユーザー

KibanaからElasticsearchへアクセスするようにShieldにユーザーを作成します。このユーザーはShieldとElasticsearch間の認証の役割となり、ログインするユーザーとは異なります。今回はユーザー名をkibana4-server、ロール名もkibana4_serverで設定します。パスワードは対話形式で入力します。

[root@ip-10-0-2-15 ~]# /usr/share/elasticsearch/bin/shield/esusers useradd kibana4-server -r kibana4_server
Enter new password:
Retype new password:

kibana4_serverロールはShieldのデフォルト設定でKibana操作する上での権限が定義されています。

[root@ip-10-0-2-15 ~]# vi /etc/elasticsearch/shield/roles.yml
(略)
# The required permissions for the kibana 4 server
kibana4_server:
cluster:
- cluster:monitor/nodes/info
- cluster:monitor/health
indices:
'.kibana':
privileges: indices:admin/create, 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
(略)

作成したShieldユーザーにKibanaからアクセスするように設定ファイルを編集します。

[root@ip-10-0-2-15 ~]# vi ./kibana-4.4.0-linux-x64/config/kibana.yml
(略)
# If your Elasticsearch is protected with basic auth, these are the user credentials
# used by the Kibana server to perform maintenance on the kibana_index at startup. Your Kibana
# users will still need to authenticate with Elasticsearch (which is proxied through
# the Kibana server)
elasticsearch.username: "kibana4-server"
elasticsearch.password: "password"
(略)

ログインユーザー

まずはログインユーザーに閲覧させたい権限のロールを作成します。今回はlogstash-から始まる全てのインデックスに対して読み取り権限を付与します。

[root@ip-10-0-2-15 ~]# vi /etc/elasticsearch/shield/roles.yml
(以下、追記)
fujimoto_role:
indices:
- names: 'logstash-*'
privileges:
- view_index_metadata
- read
- names: '.kibana*'
privileges:
- manage
- read
- index

次に作成したロールを付与したユーザーを作成します。

[root@ip-10-0-2-15 ~]# /usr/share/elasticsearch/bin/shield/esusers useradd fujimoto -r fujimoto_role
Enter new password:
Retype new password:

[root@ip-10-0-2-15 ~]# /usr/share/elasticsearch/bin/shield/esusers list
fujimoto : fujimoto_role

KibanaのHTTPS接続設定

Shieldを利用する場合、KibanaへのアクセスをHTTPSとする必要があります。 Kibanaの設定ファイルから編集可能です。SSLサーバ証明書、秘密鍵を登録し、任意の暗号化キーを設定します。

[root@ip-10-0-2-15 ~]# vi ./kibana-4.4.0-linux-x64/config/kibana.yml
(略)
# SSL for outgoing requests from the Kibana Server to the browser (PEM formatted)
server.ssl.cert: /etc/elasticsearch/fullchain1.pem
server.ssl.key: /etc/elasticsearch/privkey1.pem
(略)
shield.encryptionKey: "something_secret"
(略)

以上で、設定は完了です。細かい権限管理はしていませんが、軽く検証する上ではインストールも設定も簡単ですね。

動作確認

まずKibanaを起動します。

[root@ip-10-0-2-15 ~]# ./kibana-4.4.0-linux-x64/bin/kibana
log [03:20:31.150] [info][status][plugin:kibana] Status changed from uninitialized to green - Ready
log [03:20:31.179] [info][status][plugin:elasticsearch] Status changed from uninitialized to yellow - Waiting for Elasticsearch
log [03:20:31.439] [info][status][plugin:shield] Status changed from uninitialized to green - Ready
log [03:20:31.443] [info][status][plugin:kbn_vislib_vis_types] Status changed from uninitialized to green - Ready
log [03:20:31.446] [info][status][plugin:markdown_vis] Status changed from uninitialized to green - Ready
log [03:20:31.448] [info][status][plugin:metric_vis] Status changed from uninitialized to green - Ready
log [03:20:31.453] [info][status][plugin:spyModes] Status changed from uninitialized to green - Ready
log [03:20:31.466] [info][status][plugin:statusPage] Status changed from uninitialized to green - Ready
log [03:20:31.475] [info][status][plugin:table_vis] Status changed from uninitialized to green - Ready
log [03:20:31.544] [info][listening] Server running at https://0.0.0.0:5601
log [03:20:31.558] [info][status][plugin:elasticsearch] Status changed from yellow to green - Kibana index ready

ブラウザからKibanaへ接続します。

Kibana

おぉ、今まで設定画面が表示されていたのが、ログイン画面が表示されました。

作成したユーザーでログインします。

Kibana

Settings_-_Kibana

いつもの画面が表示されました。

今までなかったLogoutリンクも追加されています。

まとめ

いかがでしたでしょうか? このように簡単にインストール・設定が可能です。 Elasticsearch/Kibanaは非常にパワフルなデータ分析・可視化のOSSです。Shieldのようにセキュリティ周り、Marvel、Watcherのような運用・監視周りにも力を入れてきており、Enterprise向けとしても対応が進んできています。これから更にどのような発表があるのか楽しみです!