# Access Secure Elastisearch Cluster from Ruby on Rails

**URL:** <https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [December 5, 2022, 10:40am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461 "2022-12-05T10:40:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbm1607](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mbm1607/32/113714_2.png) [@mbm1607](https://discuss.elastic.co/u/mbm1607)\
**Post date:** [December 5, 2022, 10:40am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/1 "2022-12-05T10:40:08Z")

</div>

I have setup a secure Elastisearch cluster with three nodes using the [official installation with Docker Compose guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-compose-file).

It is being accessed from Kibana without issue. However now I need to access it from my custom ROR application. For that, I am using the [official gem](https://github.com/elastic/elasticsearch-rails). But my application is unable to access anything at port 9200, Xpack security is enabled which is causing the issue.

I can get it to work fine by disabling Xpack. How would I go about keeping the Xpack security enabled and still accessing the Elasticsearch REST API endpoint from my application code?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 6, 2022, 5:40am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/2 "2022-12-06T05:40:52Z")

</div>

Welcome to our community! 😃

If Kibana can access things with Security enabled then other things should. You will need to provide a bit more info on what is happening with your app though. Showing the code would be good, as would and errors that Elasticsearch it sending back to the client.

---

<div class="post-metadata">

**Author:** ![mbm1607](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mbm1607/32/113714_2.png) [@mbm1607](https://discuss.elastic.co/u/mbm1607)\
**Post date:** [December 6, 2022, 6:24am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/3 "2022-12-06T06:24:33Z")

</div>

Thanks 🙂

Yes, I know it can be accessed by providing the proper cert & password, sorry for the weird wording.  
The main question I mean to ask is how to configure the Elasticsearch client with an enrollment token in my rails application. Kibana is able to access it because it has been configured with the proper certificate in docker-compose. But my rails application is running on my machine, not a docker instance. Therefore I am at a loss on how to keep security and still connect.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 6, 2022, 7:29am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/4 "2022-12-06T07:29:40Z")

</div>

You don't use an enrolment token, have a look at [Connecting | Elasticsearch Ruby Client [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/current/connecting.html) for an example.

---

<div class="post-metadata">

**Author:** ![mbm1607](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mbm1607/32/113714_2.png) [@mbm1607](https://discuss.elastic.co/u/mbm1607)\
**Post date:** [December 6, 2022, 7:31am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/5 "2022-12-06T07:31:32Z")

</div>

Thank you so much, I knew I was missing something very obvious but couldn't get my head around it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 3, 2023, 7:31am UTC](https://discuss.elastic.co/t/access-secure-elastisearch-cluster-from-ruby-on-rails/320461/6 "2023-01-03T07:31:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
