# Connect Elasticsearch Kerberos realm using java Rest Client

**URL:** <https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [May 23, 2019, 12:36pm UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438 "2019-05-23T12:36:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhrchatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhrchatt/32/46374_2.png) [@dhrchatt](https://discuss.elastic.co/u/dhrchatt)\
**Post date:** [May 23, 2019, 12:36pm UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/1 "2019-05-23T12:36:29Z")

</div>

Can you give code sample/snippets of how java Rest Client can connect to an Elasticsearch cluster having configured Kerberos Realm authentication.

---

<div class="post-metadata">

**Author:** ![Yogesh\_Gaikwad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_gaikwad/32/27025_2.png) [@Yogesh\_Gaikwad](https://discuss.elastic.co/u/Yogesh_Gaikwad)\
**Post date:** [May 29, 2019, 8:11am UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/2 "2019-05-29T08:11:57Z")

</div>

Hi @dhrchatt,

If you follow the java rest client guide you can see the way to use `HttpClientConfigCallback` for customisation:  
[https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/\_basic\_authentication.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html)

An example implementation which might help you:

> <https://github.com/bizybot/kerb-demo/blob/master/src/main/java/org/elasticsearch/xpack/client/demo/kerberos/support/CustomHttpClientConfigCallbackHandler.java>

Hope this helps.

Thanks and Regards,  
Yogesh Gaikwad

---

<div class="post-metadata">

**Author:** ![Yogesh\_Gaikwad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_gaikwad/32/27025_2.png) [@Yogesh\_Gaikwad](https://discuss.elastic.co/u/Yogesh_Gaikwad)\
**Post date:** [June 3, 2019, 11:14pm UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/4 "2019-06-03T23:14:30Z")

</div>

Hi @dhrchatt,

The value for the config name `CRED_CONF_NAME = "ESClientLoginConf"` can be anything.  
Instead of jaas conf we are using in memory configuration.  
Hope this helps.

Regards,  
Yogesh Gaikwad

---

<div class="post-metadata">

**Author:** ![dhrchatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhrchatt/32/46374_2.png) [@dhrchatt](https://discuss.elastic.co/u/dhrchatt)\
**Post date:** [June 10, 2019, 12:14pm UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/5 "2019-06-10T12:14:29Z")

</div>

Hi Yogesh,  
In my case, the KDC and target server are in different machines (different IP/HOST and port). Where are we specifying KDC server details ? Also, the krb5.conf file used in testing, should it refer to the path of the file in machine where KDC is configured ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Yogesh\_Gaikwad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_gaikwad/32/27025_2.png) [@Yogesh\_Gaikwad](https://discuss.elastic.co/u/Yogesh_Gaikwad)\
**Post date:** [June 11, 2019, 12:00am UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/6 "2019-06-11T00:00:52Z")

</div>

Hi @dhrchatt,

I am assuming you are asking this on the client side.  
The machine you are running the java rest client, you will also have a `krb5.conf` which has the Kerberos configuration information. If you do not have one on the client machine then you will need to get one. This file has the KDC locations and admin server locations and used by the client to get the Kerberos tickets. `kdc` is the tag underwhich you will have kdc locations. Refer: [https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf\_files/krb5\_conf.html](https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html)

This sections from Java docs should help you how Java determines the location of krb5.conf and if it finds one then uses it by default  
[https://docs.oracle.com/en/java/javase/12/security/kerberos-requirements.html#GUID-0C6413BA-417B-493D-BC89-F9FB90D5E641](https://docs.oracle.com/en/java/javase/12/security/kerberos-requirements.html#GUID-0C6413BA-417B-493D-BC89-F9FB90D5E641)

Hope this helps.

Thanks and Regards,  
Yogesh Gaikwad

---

<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:** [July 9, 2019, 12:00am UTC](https://discuss.elastic.co/t/connect-elasticsearch-kerberos-realm-using-java-rest-client/182438/7 "2019-07-09T00:00:54Z")

</div>

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