2017-04-06 21:29:29 -04:00
|
|
|
[[http-clients]]
|
2018-12-19 17:53:37 -05:00
|
|
|
=== HTTP/REST clients and security
|
2017-04-06 21:29:29 -04:00
|
|
|
|
2020-02-03 09:50:11 -05:00
|
|
|
The {es} {security-features} work with standard HTTP
|
2019-11-05 17:07:39 -05:00
|
|
|
https://en.wikipedia.org/wiki/Basic_access_authentication[basic authentication]
|
2017-04-06 21:29:29 -04:00
|
|
|
headers to authenticate users. Since Elasticsearch is stateless, this header must
|
|
|
|
be sent with every request:
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
--------------------------------------------------
|
|
|
|
Authorization: Basic <TOKEN> <1>
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`
|
|
|
|
|
2020-04-29 19:29:38 -04:00
|
|
|
Alternatively, you can use
|
|
|
|
<<token-authentication-services,token-based authentication services>>.
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[http-clients-examples]]
|
2017-04-06 21:29:29 -04:00
|
|
|
==== Client examples
|
|
|
|
|
|
|
|
This example uses `curl` without basic auth to create an index:
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
curl -XPUT 'localhost:9200/idx'
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
"error": "AuthenticationException[Missing authentication token]",
|
|
|
|
"status": 401
|
|
|
|
}
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Since no user is associated with the request above, an authentication error is
|
|
|
|
returned. Now we'll use `curl` with basic auth to create an index as the
|
|
|
|
`rdeniro` user:
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
---------------------------------------------------------
|
|
|
|
curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
---------------------------------------------------------
|
|
|
|
{
|
|
|
|
"acknowledged": true
|
|
|
|
}
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
2020-04-29 19:29:38 -04:00
|
|
|
[discrete]
|
|
|
|
[[http-clients-secondary-authorization]]
|
|
|
|
==== Secondary authorization
|
|
|
|
|
|
|
|
Some APIs support secondary authorization headers for situations where you want
|
|
|
|
tasks to run with a different set of credentials. For example, you can send the
|
|
|
|
following header in addition to the basic authentication header:
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
--------------------------------------------------
|
|
|
|
es-secondary-authorization: Basic <TOKEN> <1>
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`
|
|
|
|
|
|
|
|
The `es-secondary-authorization` header has the same syntax as the
|
|
|
|
`Authorization` header. It therefore also supports the use of
|
|
|
|
<<token-authentication-services,token-based authentication services>>. For
|
|
|
|
example:
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
--------------------------------------------------
|
|
|
|
es-secondary-authorization: ApiKey <TOKEN> <1>
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> The `<TOKEN>` is computed as `base64(API key ID:API key)`
|
|
|
|
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
[[http-clients-libraries]]
|
2019-11-05 17:07:39 -05:00
|
|
|
==== Client libraries over HTTP
|
2017-04-06 21:29:29 -04:00
|
|
|
|
2020-02-03 09:50:11 -05:00
|
|
|
For more information about using {security-features} with the language
|
2019-11-05 17:07:39 -05:00
|
|
|
specific clients, refer to:
|
|
|
|
|
|
|
|
* {java-rest}/_basic_authentication.html[Java]
|
|
|
|
* {jsclient-current}/auth-reference.html[JavaScript]
|
|
|
|
* https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/configuration-options.html[.NET]
|
|
|
|
* https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION[Perl]
|
2020-02-03 09:50:11 -05:00
|
|
|
* https://www.elastic.co/guide/en/elasticsearch/client/php-api/master/security.html[PHP]
|
2019-11-05 17:07:39 -05:00
|
|
|
* https://elasticsearch-py.readthedocs.io/en/master/#ssl-and-authentication[Python]
|
2020-02-03 09:50:11 -05:00
|
|
|
* https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication[Ruby]
|