http.asciidoc 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Alternatively, you can use
  13. <<token-authentication-services,token-based authentication services>>.
  14. [discrete]
  15. [[http-clients-examples]]
  16. ==== Client examples
  17. This example uses `curl` without basic auth to create an index:
  18. [source,shell]
  19. -------------------------------------------------------------------------------
  20. curl -XPUT 'localhost:9200/idx'
  21. -------------------------------------------------------------------------------
  22. [source,js]
  23. -------------------------------------------------------------------------------
  24. {
  25. "error": "AuthenticationException[Missing authentication token]",
  26. "status": 401
  27. }
  28. -------------------------------------------------------------------------------
  29. Since no user is associated with the request above, an authentication error is
  30. returned. Now we'll use `curl` with basic auth to create an index as the
  31. `rdeniro` user:
  32. [source,shell]
  33. ---------------------------------------------------------
  34. curl --user rdeniro:taxidriver -XPUT 'localhost:9200/idx'
  35. ---------------------------------------------------------
  36. [source,js]
  37. ---------------------------------------------------------
  38. {
  39. "acknowledged": true
  40. }
  41. ---------------------------------------------------------
  42. [discrete]
  43. [[http-clients-secondary-authorization]]
  44. ==== Secondary authorization
  45. Some APIs support secondary authorization headers for situations where you want
  46. tasks to run with a different set of credentials. For example, you can send the
  47. following header in addition to the basic authentication header:
  48. [source,shell]
  49. --------------------------------------------------
  50. es-secondary-authorization: Basic <TOKEN> <1>
  51. --------------------------------------------------
  52. <1> The `<TOKEN>` is computed as `base64(USERNAME:PASSWORD)`
  53. The `es-secondary-authorization` header has the same syntax as the
  54. `Authorization` header. It therefore also supports the use of
  55. <<token-authentication-services,token-based authentication services>>. For
  56. example:
  57. [source,shell]
  58. --------------------------------------------------
  59. es-secondary-authorization: ApiKey <TOKEN> <1>
  60. --------------------------------------------------
  61. <1> The `<TOKEN>` is computed as `base64(API key ID:API key)`
  62. [discrete]
  63. [[http-clients-libraries]]
  64. ==== Client libraries over HTTP
  65. For more information about using {security-features} with the language
  66. specific clients, refer to:
  67. * {java-rest}/_basic_authentication.html[Java]
  68. * {jsclient-current}/auth-reference.html[JavaScript]
  69. * https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/configuration-options.html[.NET]
  70. * https://metacpan.org/pod/Search::Elasticsearch::Cxn::HTTPTiny#CONFIGURATION[Perl]
  71. * https://www.elastic.co/guide/en/elasticsearch/client/php-api/master/security.html[PHP]
  72. * https://elasticsearch-py.readthedocs.io/en/master/#ssl-and-authentication[Python]
  73. * https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport#authentication[Ruby]