简体   繁体   English

AWS Elasticsearch Service IAM 基于角色的访问策略

[英]AWS Elasticsearch Service IAM Role based Access Policy

I have been struggling to figure out how to communicate with the Amazon ES service from my EC2 instances.我一直在努力弄清楚如何从我的 EC2 实例与 Amazon ES 服务进行通信。

The documentation clearly states that the Amazon ES service supports IAM User & Role based access policies.该文档明确指出 Amazon ES 服务支持基于 IAM 用户和角色的访问策略。 http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html#es-createdomain-configure-access-policies http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html#es-createdomain-configure-access-policies

However, when I have this access policy for my ES domain:但是,当我的 ES 域具有此访问策略时:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789:role/my-ec2-role"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-west-2:123456789:domain/myDomain/*"
    }
  ]
}

I can't log into an ec2 instance and run a curl to hit my elasticsearch cluster.我无法登录 ec2 实例并运行 curl 来访问我的 elasticsearch 集群。

Trying to do a simple curl of the _search API:尝试对 _search API 做一个简单的 curl:

curl "http://search-myDomain.es.amazonaws.com/_search"

Produces an authentication error response:产生一个认证错误响应:

{"Message":"User: anonymous is not authorized to perform: es:ESHttpGet on resource: arn:aws:es:us-west-2:123456789:domain/myDomain/_search"}

Just to be extra safe I put the AmazonESFullAccess Policy on my IAM Role, still doesn't work.为了更加安全,我将AmazonESFullAccess策略放在我的 IAM 角色上,但仍然不起作用。

I must be missing something, because being able to programmatically interact with Elasticsearch from ec2 instances that use an IAM Role is essential to getting anything accomplished with the Amazon ES Service.我一定遗漏了一些东西,因为能够从使用 IAM 角色的 ec2 实例以编程方式与 Elasticsearch 交互对于使用 Amazon ES 服务完成任何事情至关重要。

I also see this contradictory statement in the docs.我也在文档中看到了这个矛盾的陈述。

IAM-based Policy Example You create IAM-based access policies by using the AWS IAM console rather than the Amazon ES console.基于 IAM 的策略示例 您可以使用 AWS IAM 控制台而不是 Amazon ES 控制台创建基于 IAM 的访问策略。 For information about creating IAM-based access policies, see the IAM documentation.有关创建基于 IAM 的访问策略的信息,请参阅 IAM 文档。

That link to IAM documentation, is to the home page of IAM and contains exactly zero information about how to do it.指向 IAM 文档的链接是指向 IAM 的主页,其中包含有关如何执行此操作的完全零信息。 Anyone got a solution for me?有没有人为我提供解决方案?

When using IAM service with AWS, you must sign your requests.在 AWS 中使用 IAM 服务时,您必须签署您的请求。 curl doesn't support signed requests (which consists of hashing the request and adding a parameter to the header of the request). curl 不支持签名请求(包括对请求进行哈希处理并向请求的标头添加参数)。 You can use one of their SDK's that has the signing algorithm built in, and then submit that request.您可以使用其内置签名算法的 SDK 之一,然后提交该请求。

See: http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/what-is-amazon-elasticsearch-service.html#signing-requests请参阅: http : //docs.aws.amazon.com/elasticsearch-service/latest/developerguide/what-is-amazon-elasticsearch-service.html#signing-requests

You can find the SDKs for popular languages here: http://aws.amazon.com/tools/您可以在此处找到流行语言的 SDK: http : //aws.amazon.com/tools/

First, you said you can't login to an EC2 instance to curl the ES instance?首先,你说你不能登录EC2实例来curl ES实例? You can't login?你不能登录? Or you can't curl it from EC2?或者你不能从 EC2 卷曲它?

I have my Elasticsearch (Service) instance open to the world (with nothing on it) and am able to curl it just fine, without signing.我的 Elasticsearch(服务)实例向全世界开放(上面没有任何内容),并且无需签名就可以很好地卷曲它。 I changed the access policy to test, but unfortunately it takes forever to come back up after changing it...我更改了访问策略以进行测试,但不幸的是,更改后需要很长时间才能恢复...

My policy looks like this:我的政策是这样的:

{   "Version": "2012-10-17",   "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:843348267853:domain/myDomain/*"
    },
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:843348267853:domain/myDomain"
    }   
   ] 
}

I realize this isn't exactly what you want, but start off with this (open to the world), curl from outside AWS and test it.我意识到这不完全是您想要的,但从这个开始(向世界开放),从 AWS 外部卷曲并测试它。 Then restrict it, that way you're able to isolate the issues.然后限制它,这样你就可以隔离问题。

Also, I think you have an issue with the "Principal" in your access policy.另外,我认为您的访问策略中的“主体”存在问题。 You have your EC2 Role.您拥有 EC2 角色。 I understand why you're doing that, but I think the Principal requires a USER, not a role.我理解你为什么这样做,但我认为 Principal 需要一个 USER,而不是一个角色。

See below:见下文:

http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html#es-createdomain-configure-access-policies http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-createupdatedomains.html#es-createdomain-configure-access-policies

Principal主要的

Specifies the AWS account or IAM user that is allowed or denied access to a resource.指定允许或拒绝访问资源的 AWS 账户或 IAM 用户。 Specifying a wildcard (*) enables anonymous access to the domain, which is not recommended.指定通配符 (*) 启用对域的匿名访问,这是不推荐的。 If you do enable anonymous access, we strongly recommend that you add an IP-based condition to restrict which IP addresses can submit requests to the Amazon ES domain.如果您启用匿名访问,我们强烈建议您添加基于 IP 的条件来限制哪些 IP 地址可以向 Amazon ES 域提交请求。

EDIT 1编辑 1

To be clear, you added the AmazonESFullAccess policy to the my-ec2-role?需要明确的是,您将 AmazonESFullAccess 策略添加到 my-ec2-role? If you're going to use IAM access policies, I don't think you can have a resource based policy attached to it (which is what you're doing).如果您打算使用 IAM 访问策略,我认为您不能将基于资源的策略附加到它(这就是您正在做的事情)。

http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_compare-resource-policies.html http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_compare-resource-policies.html

For some AWS services, you can grant cross-account access to your resources.对于某些 AWS 服务,您可以授予对资源的跨账户访问权限。 To do this, you attach a policy directly to the resource that you want to share, instead of using a role as a proxy.为此,您可以将策略直接附加到要共享的资源,而不是使用角色作为代理。 The resource that you want to share must support resource-based policies.您要共享的资源必须支持基于资源的策略。 Unlike a user-based policy, a resource-based policy specifies who (in the form of a list of AWS account ID numbers) can access that resource.与基于用户的策略不同,基于资源的策略指定谁(以 AWS 账户 ID 号列表的形式)可以访问该资源。

Possibly try removing the access policy altogether?可能尝试完全删除访问策略?

Why you don't create a proxy with elastic ip and allow your proxy to access your ES?为什么不创建带有弹性ip的代理并允许您的代理访问您的ES? Basically exists three forms that you can limit access in your ES:基本上存在三种形式,您可以限制 ES 中的访问:

  • Allow everyone允许所有人
  • White IP list白名单
  • Signing the access key and secret key provided by AWS.签署 AWS 提供的访问密钥和秘密密钥。

I'm using two forms, in my php apps I prefer to use proxy behind the connection to ES and in my nodejs app I prefer to sign my requests using the http-aws-es node module.我使用了两种形式,在我的 php 应用程序中,我更喜欢在连接到 ES 之后使用代理,而在我的 nodejs 应用程序中,我更喜欢使用 http-aws-es 节点模块签署我的请求。 It's useful to create a proxy environment because my users needs to access the kibana interface to see some reports and it's possible because they have configured the proxy in their browsers =)创建代理环境很有用,因为我的用户需要访问 kibana 界面才能看到一些报告,而且可能是因为他们在浏览器中配置了代理 =)

I must recommend to you close the access to your ES indexes, because it's pretty easy to delete them, curl -XDELETE https://your_es_address/index anyone can do it but you can say: "how the others users will get my ES address?"我必须建议你关闭对 ES 索引的访问,因为删除它们很容易, curl -XDELETE https://your_es_address/index任何人都可以这样做,但你可以说:“其他用户将如何获得我的 ES 地址?” and I will answer you: "Security based in dimness isn't a real security"我会回答你:“基于昏暗的安全不是真正的安全”

My security access policy is basically something like it:我的安全访问策略基本上是这样的:

http://pastebin.com/EUKT1ekX http://pastebin.com/EUKT1ekX

I encountered this issue recently and the root problem is that none of the Amazon SDKs yet support calling Elasticsearch operations like search, put, etc.我最近遇到了这个问题,根本问题是没有一个 Amazon SDK 支持调用 Elasticsearch 操作,如搜索、放置等。

The only workaround at the moment is to execute requests directly against the endpoint using signed requests: http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html目前唯一的解决方法是使用签名请求直接对端点执行请求: http : //docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html

The example here is for calling EC2, but it can be modified to instead call against Elasticsearch.此处的示例用于调用 EC2,但可以将其修改为调用 Elasticsearch。 Just modify the "service" value to "es".只需将“服务”值修改为“es”。 From there, you have to fill in values for从那里,你必须填写值

  • the endpoint (which is the full URL of your cluster including operation without request parameters)端点(这是集群的完整 URL,包括没有请求参数的操作)
  • the host (the part between https:// and your canonical URI like /_status主机(https:// 和您的规范 URI 之间的部分,如 /_status
  • the canonical uri which is the URI after the first / inclusive (like /_status) but without the query string规范 uri,它是第一个 / 包含(如 /_status)之后的 URI,但没有查询字符串
  • the request parameters (everything after ? inclusive)请求参数(包括 ? 之后的所有内容)

Note that I've only managed to get this working so far using AWS credentials as the assumption is that you pass in an access key and secret key to the various signing calls (access_key and secret_key in the example).请注意,到目前为止,我仅使用 AWS 凭证设法使其工作,因为假设您将访问密钥和秘密密钥传递给各种签名调用(示例中的 access_key 和 secret_key)。 It should be doable using IAM roles but you'll have to call into the security token service first to get temporary credentials that can be used to sign the request.使用 IAM 角色应该是可行的,但您必须首先调用安全令牌服务以获取可用于签署请求的临时凭证。 Until you do that, be sure to edit your access policy on the Elasticsearch cluster to allow user creds (user/在您这样做之前,请确保在 Elasticsearch 集群上编辑您的访问策略以允许用户凭据(用户/

you need to sign your request and unfortunately, it is no longer supported by the official elasticsearch library.您需要签署您的请求,不幸的是,官方elasticsearch 库不再支持它。 Check this Github issue ( https://github.com/elastic/elasticsearch-js/issues/1182#issuecomment-630641702 )检查这个 Github 问题( https://github.com/elastic/elasticsearch-js/issues/1182#issuecomment-630641702

They want to enforce their own cloud solution他们希望实施自己的云解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Elasticsearch 快照 - 由于服务相关角色导致的 IAM 问题 - AWS Elasticsearch Snapshots - IAM issue because of service-linked role 策略路径“arn:aws:iam::aws:policy/aws-service-role”和“”arn:aws:iam::aws:policy/service-role 之间的区别 - Difference between policy path “arn:aws:iam::aws:policy/aws-service-role” and “”arn:aws:iam::aws:policy/service-role S3 存储桶策略拒绝除特定 AWS 服务角色和 IAM 角色之外的所有内容 - S3 bucket policy to deny all except a particular AWS service role and IAM role 基于标签的 AWS IAM 策略限制不给我任何访问权限 - AWS IAM policy restriction based on Tags not giving me any access AWS IAM 策略基于父 Cloudformation 限制对资源的访问 - AWS IAM Policy restrict access to resources based on parent Cloudformation 仅基于存储桶策略将 AWS IAM 实例角色策略设置为 GetObject - Setup AWS IAM instace role policy to GetObject based only on bucket policy Terraform:将 aws_iam_role 与 aws_iam_policy 相关联 - Terraform: associate an aws_iam_role with an aws_iam_policy 具有策略分配的 terraform aws iam 角色 - terraform aws iam role with policy assignment AWS IAM 用户角色或策略自包含 - AWS IAM user role or policy self contained AWS IAM角色策略资源限制 - AWS IAM Role Policy Resource Restriction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM