-
Notifications
You must be signed in to change notification settings - Fork 614
Description
We are using the elasticsearch gem from an AWS lambda that talks to an AWS elasticsearch cluster. The security of our AWS elasticsearch cluster requires all requests to be signed with AWS sig4 using the AWS credentials provided by lambda execution role (which has been granted access the the elasticsearch cluster in its IAM policy).
In our AWS lambda, we create our client like so:
require 'elasticsearch'
require 'faraday_middleware/aws_sigv4'
elastic_client = Elasticsearch::Client.new(url: ENV.fetch("ELASTICSEARCH_URL"), logger: nil) do |f|
f.request :aws_sigv4,
service: 'es',
region: ENV.fetch('AWS_REGION'), # assumes the lambda and ES domain live in the same region.
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
session_token: ENV['AWS_SESSION_TOKEN'] # optional
end
When we were using version 7.8.1 of the elasticsearch gem, this worked just fine. After upgrading the elasticsearch gem to 7.9.0, we immediately started to get errors on every request:
Elasticsearch::Transport::Transport::Errors::Forbidden
User: arn:aws:sts::<redacted_aws_account_id>:assumed-role/<redacted_lambda_name>_<redacted_aws_region>_execution_role/<redacted_lambda_name> is not authorized to perform: es:ESHttpPost
Here's the bits of the stack trace from the elasticsearch gems:
elasticsearch-transport-7.9.0/lib/elasticsearch/transport/transport/base.rb:218:in `__raise_transport_error'
elasticsearch-transport-7.9.0/lib/elasticsearch/transport/transport/base.rb:347:in `perform_request'
elasticsearch-transport-7.9.0/lib/elasticsearch/transport/transport/http/faraday.rb:37:in `perform_request'
elasticsearch-transport-7.9.0/lib/elasticsearch/transport/client.rb:176:in `perform_request'
elasticsearch-api-7.9.0/lib/elasticsearch/api/actions/msearch.rb:89:in `msearch'
When we reverted back to 7.8.1 the problem went away and our requests to our AWS Elasticsearch cluster started to succeed again. So, it appears there is some regression in 7.9.0 that somehow breaks the AWS Sig4 signing in such a way that our requests are rejected when they should not be.
I dug through the Changelog and didn't see anything that appeared to be related to this but I may have missed it.