amazon-web-services - Amazon Elasticsearch 集群的正确访问策略

标签 amazon-web-services elasticsearch amazon-ec2 amazon-iam amazon-elasticsearch

我最近开始使用新的 Amazon Elasticsearch Service,但我似乎无法弄清楚我需要的访问策略,因此我只能从分配了特定 IAM 角色的 EC2 实例访问服务。

这是我目前为 ES 域分配的访问策略示例:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          "arn:aws:iam::[ACCOUNT_ID]:role/my_es_role",
        ]
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:[ACCOUNT_ID]:domain/[ES_DOMAIN]/*"
    }
  ]
}

但正如我所说,这是行不通的。我登录到 EC2 实例(它附加了 my_es_role 角色)并尝试在“https://*.es.amazonaws.com”端点运行一个简单的 curl 调用,我得到以下错误:

{"Message":"User: anonymous is not authorized to perform: es:ESHttpGet on resource: arn:aws:es:us-east-1:[ACCOUNT_ID]:domain/[ES_DOMAIN]/“}

有谁知道我必须更改访问策略才能使其正常工作?

最佳答案

您可以将访问权限锁定为仅限 IAM,但您将如何在浏览器中查看 Kibana?你可以 setup a proxy (see Gist 和/或 NPM module)或启用 IAM 和基于 IP 的访问以查看结果。

我能够通过以下访问策略获得 IAM 访问和 IP 限制访问。请注意顺序很重要:我无法在 IAM 语句之前使用基于 IP 的语句。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::xxxxxxxxxxxx:root"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-west-2:xxxxxxxxxxxx:domain/my-elasticsearch-domain/*"
    },
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-west-2:xxxxxxxxxxxx:domain/my-elasticsearch-domain/*",
      "Condition": {
        "IpAddress": {
          "aws:SourceIp": [
            "192.168.1.0",
            "192.168.1.1"
          ]
        }
      }
    }
  ]
}

我的 EC2 实例有一个实例配置文件 arn:aws:iam::aws:policy/AmazonESFullAccess 政策。 Logstash 应使用 logstash-output-amazon-es output plugin 对请求进行签名.在我的 EC2 实例上运行的 Logstash 包含如下输出部分:

output {
    amazon_es {
        hosts => ["ELASTICSEARCH_HOST"]
        region => "AWS_REGION"
    }
    # If you need to do some testing & debugging, uncomment this line:
    # stdout { codec => rubydebug }
}

我可以从访问策略中的两个 IP(192.168.1.0 和 192.168.1.1)访问 Kibana。

关于amazon-web-services - Amazon Elasticsearch 集群的正确访问策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32978026/

相关文章:

python - 如何在 aws ec2 实例上安装 python3.6

amazon-web-services - 调用 ImportCertificate 操作时出错 (ValidationException) : The private key is not supported

php - Elasticsearch 中类型的意义是什么?

amazon-web-services - Amazon AWS NAT 网关不工作,EC2 未在 ECS 集群中注册

css - 是否可以在 ec2 实例中使用 css

amazon-web-services - 是否需要 AWS SQS

regex - ElasticSearch可视化按字段 “message”中的某些关键字分组

android - 如何在Android中使用Spring RestTemplate在 Elasticsearch 中通过Json搜索

python - 亚马逊 EC2 虚拟环境 : pip says it installed numpy but python can't find it

java - ec2 API 如何决定哪个可用区?