dak ブログ

python、rubyなどのプログラミング、MySQL、サーバーの設定などの備忘録。レゴの写真も。

Elasticsearch で role、user を作成する方法

2021-11-03 23:56:29 | elasticsearch
Elasticsearch で role、user を作成する方法のメモ。

role、user を有効にするには、config/elasticsearch.yml に以下を設定してから
elasticsearch を起動します。
xpack.security.enabled: true

全インデックスに対する read 権限を持つ read-role を作成。
curl "http://localhost:9200/_security/role/read-role" \
     -u elastic:espasswd \
     -X PUT \
     -H 'Content-Type: application/json' \
     -d "
{
  \"indices\": [
  {
    \"names\": [\"*\"],
    \"privileges\": [\"read\"]
  }
  ]
}"

上記の names でインデックス名を指定すると、そのインデックスに対してのみ読み込みを許可することができます。

read-role を持つ read-user を作成。
url 'http://localhost:9200/_security/user/read-user' \
     -u elastic:espasswd \
     -X PUT \
     -H 'Content-Type: application/json' \
     --data '
{
        "enabled": true,
        "password": "es-read-user-passwd",
        "roles": ["read-role"]
}'