http.asciidoc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. [[http-clients]]
  2. === HTTP/REST clients and security
  3. The {es} {security-features} work with standard HTTP
  4. https://en.wikipedia.org/wiki/Basic_access_authentication[basic authentication]
  5. headers to authenticate users. Since Elasticsearch is stateless, this header must
  6. be sent with every request:
  7. [source,shell]
  8. --------------------------------------------------
  9. Authorization: Basic <TOKEN> <1>
  10. --------------------------------------------------
  11. <1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`
  12. [float]
  13. ==== Client examples
  14. This example uses `curl` without basic auth to create an index:
  15. [source,shell]
  16. -------------------------------------------------------------------------------
  17. curl -XPUT 'localhost:9200/idx'
  18. -------------------------------------------------------------------------------
  19. [source,js]
  20. -------------------------------------------------------------------------------
  21. {
  22. "error": "AuthenticationException[Missing authentication token]",
  23. "status": 401
  24. }
  25. -------------------------------------------------------------------------------
  26. Since no user is associated with the request above, an authentication error is
  27. returned. Now we'll use `curl` with basic auth to create an index as the
  28. `rdeniro` user:
  29. [source,shell]
  30. ---------------------------------------------------------
  31. curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'
  32. ---------------------------------------------------------
  33. [source,js]
  34. ---------------------------------------------------------
  35. {
  36. "acknowledged": true
  37. }
  38. ---------------------------------------------------------
  39. [float]
  40. ==== Client libraries over HTTP
  41. For more information about using {security-features} with the language
  42. specific clients, refer to:
  43. * {java-rest}/_basic_authentication.html[Java]
  44. * {jsclient-current}/auth-reference.html[JavaScript]
  45. * https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/configuration-options.html[.NET]
  46. * https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION[Perl]
  47. * https://www.elastic.co/guide/en/elasticsearch/client/php-api/master/security.html[PHP]
  48. * https://elasticsearch-py.readthedocs.io/en/master/#ssl-and-authentication[Python]
  49. * https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication[Ruby]