LoginSignup
1
1

More than 3 years have passed since last update.

Amazon Elasticsearch Service で kibana からのアクセスを制限したい

Last updated at Posted at 2019-06-05

最近AWS入門しました。

Elasticsearch Service 付属の Kibana を使うとPUTやらDELETEを制限できない?

AmazonさんのElasticsearchデフォルトでは色々と融通が効かないらしく、調べてもEC2に設定済み Kibana を乗っけるようなやつしか見つからなかった。

セキュリティポリシーで制限できるのでは?

と、先輩にアドバイスをいただいた。
そして次のURLを投げてくださった。

基本的にこれを参考にした。

試行1: "es:ESHttpGet" のみ許可

ダメでござった。Discoverを見ようとした段階で読み込めない。
読み込める状態( "es:ESHttp*" )にしてChromeでネットワークを見てみると、POSTしてる先がいくつか。

/_plugin/kibana/elasticsearch/_msearch?rest_total_hits_as_int=true&ignore_throttled=true`
/_plugin/kibana/api/saved_objects/_bulk_get

つまりkibanaへのPOSTを通す必要がある思われるので、試行2へ。

試行2: /_plugin/kibana/* 以下だけ全メソッド許可したい

効きません
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<id>:role/Cognito_myappmovieAuth_Role"
      },
      "Action": "es:ESHttp*",
      "Resource": "arn:aws:es:us-west-2:<id>:domain/movies/_plugin/*"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<id>:role/Cognito_myappmovieAuth_Role"
      },
      "Action": "es:ESHttpGet",
      "Resource": "arn:aws:es:us-west-2:<id>:domain/movies/*"
    }
  ]
}

無理でござった。Discoverを読み込めない同じ症状。
https://docs.aws.amazon.com/ja_jp/elasticsearch-service/latest/developerguide/es-ac.html#es-ac-types-resource

↑これだとindexをリソースに指定することはできるようだけど、 _plugin とかいうただのパスはダメなのでしょうか。

いろいろムラムラしつつここで "Effect": "Deny" にたどり着く。
上のリンク先の少しスクロールしたところにめっちゃ普通に書いてあるやん。

試行3: 守りたい index

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<id>:role/Cognito_myappmovieAuth_Role"
      },
      "Action": "es:ESHttp*",
      "Resource": "arn:aws:es:us-west-2:<id>:domain/movies/*"
    },
    {
      "Effect": "Deny",
      "Principal": {
        "AWS": "arn:aws:iam::<id>:role/Cognito_myappmovieAuth_Role"
      },
      "Action": [
        "es:ESHttpPost",
        "es:ESHttpPut",
        "es:ESHttpDelete"
      ],
      "Resource": "arn:aws:es:us-west-2:<id>:domain/movies/kibana_sample_data_ecommerce*"
    }
  ]
}

Discoverは見たところ普通に使えるのだった。
この状態で Dev Tools を開き、

DELETE kibana_sample_data_ecommerce
{
  "Message": "User: arn:aws:sts::<id>:assumed-role/Cognito_myappmovieAuth_Role/CognitoIdentityCredentials is not authorized to perform: es:ESHttpDelete with an explicit deny"
}

良い感じ。
一方、

PUT test
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "test"
}
DELETE test
{
  "acknowledged" : true
}

ほーん。
最初から PUT を Allow しなければ良いだけでは?(試してない)

願望

kibanaに対してだけメソッド開放したい。

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