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
|
|
|
|
2018-12-19 17:53:37 -05:00
|
|
|
The {es} {security-features} work with standard HTTP
|
|
|
|
{wikipedia}/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)`
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== 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
|
|
|
|
}
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Client Libraries over HTTP
|
|
|
|
|
2018-12-19 17:53:37 -05:00
|
|
|
For more information about using {security-features} with the language
|
|
|
|
specific clients, refer to
|
2017-04-06 21:29:29 -04:00
|
|
|
https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication[Ruby],
|
|
|
|
http://elasticsearch-py.readthedocs.org/en/master/#ssl-and-authentication[Python],
|
|
|
|
https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION[Perl],
|
2019-04-23 12:41:22 -04:00
|
|
|
http://www.elastic.co/guide/en/elasticsearch/client/php-api/current/security.html[PHP],
|
2017-04-06 21:29:29 -04:00
|
|
|
http://nest.azurewebsites.net/elasticsearch-net/security.html[.NET],
|
2019-01-07 08:44:12 -05:00
|
|
|
http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html[JavaScript]
|
2017-04-06 21:29:29 -04:00
|
|
|
|
|
|
|
////
|
|
|
|
Groovy - TODO link
|
|
|
|
////
|