# Basic Authentication with https and native realm

**URL:** https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [February 23, 2021, 3:53am UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148 "2021-02-23T03:53:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![shivkumar.chelwa](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shivkumar.chelwa](https://discuss.elastic.co/u/shivkumar.chelwa)
#### Post date: [February 23, 2021, 3:53am UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/1 "2021-02-23T03:53:06Z")

</div>

I am trying to use Basic Authentication when HTTPS is enabled. I am using default "native" realm. Is Basic Authentication not supported when HTTPS is enabled and realm is "native"?

I successfully used API Key and but could NOT use Token because I think the free version does not support generating token. Another interesting thing is, I think Kibana uses https and basic authentication but it fails for me when I use a high level REST API Java client.

I just added following xpack properties to my elasticsearch.yml.

```auto
xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: elasticsearch/http.p12
xpack.security.http.ssl.truststore.path: elasticsearch/http.p12

```

Please note, this is my dev environment and I am trying to keep the configuration changes to a minimum to begin with. I am using all defaults including the user for basic authentication i.e. "elastic". Also, my application works fine with basic authentication but HTTPS disabled.

Any clues? Thank you in advance.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [February 23, 2021, 5:00am UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/2 "2021-02-23T05:00:27Z")

</div>

Hi @shivkumar.chelwa

Yes API Keys are available as part of basic if you want to see what is included in basic see [here](https://github.com/bvader/howtos/tree/master/basic-security-elasticsearch).

With respect to basic auth and TLS I wrote a little how to [here](https://github.com/bvader/howtos/tree/master/basic-security-elasticsearch) if you are interested. Take a look it has helped a few folks.

And of course the official documentation Getting Started with Security can be found [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-getting-started.html)

---

<div class="post-metadata">

### Author: ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)
#### Post date: [February 23, 2021, 5:17am UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/3 "2021-02-23T05:17:28Z")

</div>

> [@shivkumar.chelwa](#):
>
> it fails for me when I use a high level REST API Java client.

It's hard to diagnose "it fails". The more details you can provide, the more likely it is that we can help you solve it.

---

<div class="post-metadata">

### Author: ![shivkumar.chelwa](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shivkumar.chelwa](https://discuss.elastic.co/u/shivkumar.chelwa)
#### Post date: [February 23, 2021, 2:39pm UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/4 "2021-02-23T14:39:59Z")

</div>

@TimV , My java client code along with elasticsearch.yml is available at [GitHub - shivchelwa/elastic-ssl-client: Elastic SSL Client](https://github.com/shivchelwa/elastic-ssl-client). I am getting a "401 Unauthorized" as below:

```auto
ElasticsearchStatusException[method [HEAD], host [https://localhost:9200], URI [/test_index_1?ignore_throttled=false&ignore_unavailable=false&expand_wildcards=open%2Cclosed&allow_no_indices=false], status line [HTTP/1.1 401 Unauthorized]]; nested: ResponseException[method [HEAD], host [https://localhost:9200], URI [/test_index_1?ignore_throttled=false&ignore_unavailable=false&expand_wildcards=open%2Cclosed&allow_no_indices=false], status line [HTTP/1.1 401 Unauthorized]];
	at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1885)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1645)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1617)
	at org.elasticsearch.client.IndicesClient.exists(IndicesClient.java:974)
	at org.me.elastic.ElasticSSLClient.createIndexes(ElasticSSLClient.java:88)
	at org.me.elastic.ElasticSSLClient.main(ElasticSSLClient.java:37)
Caused by: org.elasticsearch.client.ResponseException: method [HEAD], host [https://localhost:9200], URI [/test_index_1?ignore_throttled=false&ignore_unavailable=false&expand_wildcards=open%2Cclosed&allow_no_indices=false], status line [HTTP/1.1 401 Unauthorized]
	at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:326)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:296)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:270)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1632)
	... 4 more

```

---

<div class="post-metadata">

### Author: ![shivkumar.chelwa](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shivkumar.chelwa](https://discuss.elastic.co/u/shivkumar.chelwa)
#### Post date: [February 23, 2021, 2:57pm UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/5 "2021-02-23T14:57:06Z")

</div>

@stephenb, elastic and kibana setup with TLS and basic authentication works fine for me. The problem is when I use high-level REST client. Thank you.

---

<div class="post-metadata">

### Author: ![shivkumar.chelwa](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shivkumar.chelwa](https://discuss.elastic.co/u/shivkumar.chelwa)
#### Post date: [February 23, 2021, 5:26pm UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/6 "2021-02-23T17:26:07Z")

</div>

I found the issue with my Java REST client. I was not setting credential provider along with sslcontext. Closing this thread.

---

<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: [March 23, 2021, 5:26pm UTC](https://discuss.elastic.co/t/basic-authentication-with-https-and-native-realm/265148/7 "2021-03-23T17:26:21Z")

</div>

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