AWS Elasticsearch服务不断提供“用户匿名”错误

时间:2015-11-27 16:08:13

标签: ruby amazon-web-services elasticsearch

我正在尝试从EC2实例连接到我的ES群集,并已配置我的IAM策略以接受来自我的密钥/密钥对的请求。我正在使用ruby来尝试查询服务并继续获得403'用户:匿名无权执行:es:ESHttpGet on resource:arn ...'

我的代码如下:

require 'faraday_middleware/aws_signers_v4'

client = Elasticsearch::Client.new url: 'https://myEScluster.es.amazonaws.com' do |f|
  f.request :aws_signers_v4,
        credentials: Aws::Credentials.new('mykey', 'mysecret'),
        service_name: 'es',
        region: 'us-east-1'
end  

当我尝试做client.search时,我收到错误。我已经查看了ES gem的所有github问题和文档,它们说要做我正在尝试的事情: “您可以在配置块中使用任何标准的法拉第中间件和插件,例如签署AWS Elasticsearch服务的请求:”

require 'patron'
require 'faraday_middleware/aws_signers_v4'

client = Elasticsearch::Client.new url: 'https://search-my-cluster-abc123....es.amazonaws.com' do |f|
  f.request :aws_signers_v4,
            credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_ACCESS_KEY']),
            service_name: 'es',
            region: 'us-east-1'
end

正如你所看到的,它几乎是一样的。我也试过这些:

https://github.com/elastic/elasticsearch-ruby/issues/232

https://github.com/elastic/elasticsearch-ruby/pull/235

另一件事,这是我的ES服务安全策略:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "myarn"
      },
      "Action": "es:*",
      "Resource": "myresourcearn/*"
    }
  ]
}

不幸的是,亚马逊的文档缺乏,他们的服务api只提供基本的维护功能。任何人都可以帮助我吗?

提前致谢!

1 个答案:

答案 0 :(得分:1)

检查你的elasticsearch gem版本,我使用1.0.14并得到相同的错误。 Bumping to 1.0.15 fixed允许块配置传输以使用签名请求。请参阅https://github.com/elastic/elasticsearch-ruby/blob/master/CHANGELOG.md#1015