LoginSignup
10
8

More than 3 years have passed since last update.

Elasticsearch の無償版でレルム認証を試す

Last updated at Posted at 2019-05-22

はじめに

Elasticsearch の無償版でセキュリティ機能をアップデートするというリリースがありました
https://www.elastic.co/jp/blog/security-for-elasticsearch-is-now-free?blade=tw&hulk=social
今まで、ずっと無償版を使ってきて、公式の認証機能とか使ったことがないので、使ってみたいと思います

環境準備

1. DockerImageをPull する

まずはElastic社公式から最新のDockerImageを落とします
7.1.0以降対応とのことなので、それ以降ですね
https://www.docker.elastic.co/#
スクリーンショット 2019-05-22 10.50.56.png

なんでロゴが表示されないんだろう。。。

2. docker-compose を作る

まずは基本的な状態の復習から

docker-compose.yml
version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
    container_name: es01
    environment:
      - node.name=es01
      - discovery.type=single-node
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
      - 9300:9300

https://www.elastic.co/jp/blog/getting-started-with-security
こちらの参考にセキュリティ機能を ON します

docker-compose.yml
version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0
    container_name: es01
    environment:
      - node.name=es01
      - discovery.type=single-node
      - xpack.security.enabled=true
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
      - 9300:9300

この状態でElasticsearchを開くと認証画面が出てくる!

スクリーンショット 2019-05-22 10.54.28.png

さて、問題はユーザー名とパスワード

これは一旦コマンドで追加しようと思います
追加は elasticsearch-users ってコマンドで
ヘルプはこちら -> https://www.elastic.co/guide/en/elasticsearch/reference/current/users-command.html
roles の一覧が知りたければこちら -> https://www.elastic.co/guide/en/elastic-stack-overview/current/built-in-roles.html

とりあえず今回は superuser で追加


$ docker exec -i -t es01 bash
[root@85348ffa1c22 elasticsearch]# ls
LICENSE.txt  NOTICE.txt  README.textile  bin  config  data  jdk  lib  logs  modules  plugins
[root@85348ffa1c22 elasticsearch]# ./bin/elasticsearch-users list
No users found
[root@85348ffa1c22 elasticsearch]# ./bin/elasticsearch-users useradd gessy0129 -p elasticsearchpassword -r superuser
[root@85348ffa1c22 elasticsearch]# ./bin/elasticsearch-users list
gessy0129         : superuser

無事に認証突破できました!

スクリーンショット 2019-05-22 11.17.19.png

kibana も立ち上げようと思いますが、その前に kibana用のパスワードを設定

# bin/elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y


Changed password for user apm_system
PASSWORD apm_system = 6OwQOziAuOwP0wJWzh0r

Changed password for user kibana
PASSWORD kibana = 9t1W2rbdw37MDAdslnF3

Changed password for user logstash_system
PASSWORD logstash_system = qthwfaKCqOIBKk9ChBfX

Changed password for user beats_system
PASSWORD beats_system = LaObvuySUIg8Pqhg0gsh

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = fizpyUp3ESkgWuReVmvj

Changed password for user elastic
PASSWORD elastic = AJg2zp3UF4VRZiAmBpes

とりあえず一旦ここまで!

続編

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8