LoginSignup
0
0

More than 3 years have passed since last update.

Elastic Cloud + GCP 事始め④ ~cURLからのロール投入~

Last updated at Posted at 2021-01-09

ゴール

CLI からロールとユーザーを更新する

公式手順

https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role.html
https://www.elastic.co/guide/en/kibana/current/role-management-api-put.html

1. Kinana API key の発行

1.1. GUIからの発行

※こちらはElastic Cloud 内の各環境内を操作するAPIキー

Kibanaのハンバーガーメニュー>「Stack Management」>「API Keys」>「Go to Consle」

image.png

POST /_security/api_key
{
  "name": "test1-api-key",
  "expiration": "7d", 
  "role_descriptors": { 
    "kibana-url-api-role": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

※上記APIキーは7日間のみ有効な全操作権限ありAPIキー。
 目的に応じて適宜ロールや有効期限を変更する事。
 expiration行を削除すれば無期限有効。

image.png

画面右上に「200 - success」と出ていれば成功。
結果を別途保存しておく。(二度と表示されない)

image.png

1.2. base64形式への変換

APIキーにはIDとキー値を:で繋いでbase64形式に変換した文字列を使用する。

echo -n <id>:<api_key> | base64

image.png

出力結果を保存する。

2. ロールの作成/更新

2.1. Kibana endpointのコピー

Elastic Cloud の環境トップページから、Kibana の endpoint をコピーする。

image.png

2.2. cURLコマンドでAPI実行

curl -H 'Authorization: ApiKey <1.2.のbase64ApiKey>' -H 'Content-type: application/json' \
-H 'kbn-xsrf: true' -H '{ WWW-Authenticate={ 0=\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\" & 1=\"Bearer realm=\\\"security\\\"\" & 2=\"ApiKey\" }' \
-X PUT '<KibanaEndpoint>/api/security/role/sample-suzuki@hoge.jp' -d '{
  "metadata" : {
    "version" : 1
  },
  "elasticsearch": {
    "cluster" : [ ],
    "indices": [
      {
        "names": [ "<index名>", "<index名>" ],
        "privileges": ["read"]
      }
    ]
  },
  "kibana": [
    {
      "base": [],
      "feature": {
        "dashboard": ["read"]
      },
      "spaces": [
        "default"
      ]
    }
  ]
}'

上記コマンドで、ロール名 が既存にない場合、登録。ある場合、更新される。
Dashboardから、指定したINDEX内のデータの閲覧権限のみを与える事ができる。

image.png

image.png

image.png

次回予定:未定

0
0
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
0
0