# Got response code '401' contacting Elasticsearch at URL

**URL:** <https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [June 1, 2021, 9:39am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608 "2021-06-01T09:39:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)\
**Post date:** [June 1, 2021, 9:39am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/1 "2021-06-01T09:39:13Z")

</div>

Dear team,

I have enabled TLS on cluster and wanted to switch communication between logstash and Elasticsearch to secure protocol. After I set up all I received following error while starting logstash (btw. password is correct I tried it):

```auto
[2021-06-01T11:35:43,223][WARN][logstash.outputs.elasticsearch][main] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"https://logstash_write:xxxxxx@10.194.144.63:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError, :error=>"Got response code '401' contacting Elasticsearch at URL 'https://10.194.144.63:9200/'"}

```

My output pipe:

```auto
elasticsearch {
        hosts => ["https://10.194.144.64", "https://10.194.144.62", "https://10.194.144.63"]
        cacert => "/app/products/logstash/conf/certs/elasticsearch-ca.pem"
        index => "log-beancounter"
        user => "logstash_write"
        password => " *******"
        template => "/app/products/logstash/conf/templates/log-beancounter.json"
        template_name => "log-beancounter"
        template_overwrite => "true"
        manage_template => true
        document_id => "%{[@metadata][fingerprint]}"
      }

```

User has following role assigned (I believe it is sufficient to do any operations):

```auto
{
  "logstash_write" : {
    "cluster" : [
      "manage_ilm",
      "manage_index_templates",
      "manage_ingest_pipelines",
      "manage_rollup",
      "read_ilm",
      "monitor",
      "manage",
      "all"
    ],
    "indices" : [
      {
        "names" : [
          "*"
        ],
        "privileges" : [
          "all"
        ],
        "allow_restricted_indices" : false
      }
    ],
    "applications" : [],
    "run_as" : [],
    "metadata" : { },
    "transient_metadata" : {
      "enabled" : true
    }
  }
}

```

---

<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:** [June 2, 2021, 2:29am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/2 "2021-06-02T02:29:19Z")

</div>

401 means the auth details are wrong, can you try it with a curl?

---

<div class="post-metadata">

**Author:** ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)\
**Post date:** [June 2, 2021, 8:35am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/3 "2021-06-02T08:35:59Z")

</div>

Hi, I tried, curl returns the same. I tried even to change the PWD, no luck either with new password. What else might be wrong? Maybe we need api keys? WIth superuser I have no issues, or applications definitions?

---

<div class="post-metadata">

**Author:** ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)\
**Post date:** [June 2, 2021, 10:02am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/4 "2021-06-02T10:02:17Z")

</div>

Ok, I think I found an Issue, somewhere in documentation is mentioned this:

If your node has `xpack.security.http.ssl.enabled` set to `true` , then you must specify `https` when creating your API key.

I think the same applies for the user, now question, how to specify this? I could not find more information sadly..

---

<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:** [June 3, 2021, 3:37am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/5 "2021-06-03T03:37:56Z")

</div>

> [@vaclav1](#):
>
> curl returns the same.

Does that mean curl works or fails?

Can you provide the exact test that you ran?

> [@vaclav1](#):
>
> I think the same applies for the user,

There is no SSL requirement for users, and even if there was, your original logstash configuration uses `https`.

---

<div class="post-metadata">

**Author:** ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)\
**Post date:** [June 4, 2021, 6:08am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/6 "2021-06-04T06:08:19Z")

</div>

I found and solve the issue 🙂 enabled debug mode helped me. I forgot to explicitly define in output Elasticsearch logstash plugin ssl =\> true

---

<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 2, 2021, 6:08am UTC](https://discuss.elastic.co/t/got-response-code-401-contacting-elasticsearch-at-url/274608/7 "2021-07-02T06:08:51Z")

</div>

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