create-users.asciidoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. [role="xpack"]
  2. [[security-api-put-user]]
  3. === Create or update users API
  4. ++++
  5. <titleabbrev>Create or update users</titleabbrev>
  6. ++++
  7. .New API reference
  8. [sidebar]
  9. --
  10. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  11. --
  12. Adds and updates users in the native realm. These users are commonly referred
  13. to as _native users_.
  14. [[security-api-put-user-request]]
  15. ==== {api-request-title}
  16. `POST /_security/user/<username>` +
  17. `PUT /_security/user/<username>`
  18. [[security-api-put-user-prereqs]]
  19. ==== {api-prereq-title}
  20. * To use this API, you must have at least the `manage_security` cluster privilege.
  21. [[security-api-put-user-desc]]
  22. ==== {api-description-title}
  23. A `password` is required for adding a new user but is optional when updating an
  24. existing user. To change a user's password without updating any other fields,
  25. use the <<security-api-change-password, change password API>>.
  26. For more information about the native realm, see
  27. <<realms>> and <<native-realm>>.
  28. [[security-api-put-user-path-params]]
  29. ==== {api-path-parms-title}
  30. `username`::
  31. (Required, string) An identifier for the user.
  32. +
  33. --
  34. [[username-validation]]
  35. NOTE: Usernames must be at least 1 and no more than 507 characters. They can
  36. contain alphanumeric characters (`a-z`, `A-Z`, `0-9`), spaces, punctuation, and
  37. printable symbols in the {wikipedia}/Basic_Latin_(Unicode_block)[Basic Latin (ASCII) block]. Leading or trailing whitespace is not allowed.
  38. --
  39. [[security-api-put-user-query-params]]
  40. ==== {api-query-parms-title}
  41. `refresh`::
  42. (string) One of `true`, `false`, or `wait_for`.
  43. These values have the same meaning as in the <<docs-refresh, Index API>>,
  44. but the default value for this API (Put User) is `true`.
  45. [[security-api-put-user-request-body]]
  46. ==== {api-request-body-title}
  47. The following parameters can be specified in the body of a POST or PUT request:
  48. `enabled`::
  49. (Boolean) Specifies whether the user is enabled. The default value is `true`.
  50. `email`::
  51. (string) The email of the user.
  52. `full_name`::
  53. (string) The full name of the user.
  54. `metadata`::
  55. (object) Arbitrary metadata that you want to associate with the user.
  56. `password`::
  57. (Required<<not-always-required,*>>, string) The user's password. Passwords must be at least 6 characters long.
  58. +
  59. When adding a user, one of `password` or `password_hash` is required.
  60. When updating an existing user, the password is optional, so that other
  61. fields on the user (such as their roles) may be updated without modifying
  62. the user's password.
  63. `password_hash`::
  64. (string) A _hash_ of the user's password. This must be produced using the
  65. same hashing algorithm as has been configured for password storage. For more
  66. details, see the explanation of the
  67. `xpack.security.authc.password_hashing.algorithm` setting in
  68. <<hashing-settings>>.
  69. +
  70. Using this parameter allows the client to pre-hash the password for
  71. performance and/or confidentiality reasons.
  72. +
  73. The `password` parameter and the `password_hash` parameter cannot be
  74. used in the same request.
  75. `roles`::
  76. (Required, list) A set of roles the user has. The roles determine the user's
  77. access permissions. To create a user without any roles, specify an empty list:
  78. `[]`.
  79. --
  80. [[not-always-required]]
  81. *Indicates that the setting is required in some, but not all situations.
  82. --
  83. [[security-api-put-user-example]]
  84. ==== {api-examples-title}
  85. The following example creates a user `jacknich`:
  86. [source,console]
  87. --------------------------------------------------
  88. POST /_security/user/jacknich
  89. {
  90. "password" : "l0ng-r4nd0m-p@ssw0rd",
  91. "roles" : [ "admin", "other_role1" ],
  92. "full_name" : "Jack Nicholson",
  93. "email" : "jacknich@example.com",
  94. "metadata" : {
  95. "intelligence" : 7
  96. }
  97. }
  98. --------------------------------------------------
  99. A successful call returns a JSON structure that shows whether the user has been
  100. created or updated.
  101. [source,console-result]
  102. --------------------------------------------------
  103. {
  104. "created": true <1>
  105. }
  106. --------------------------------------------------
  107. <1> When an existing user is updated, `created` is set to false.
  108. After you add a user, requests from that user can be authenticated. For example:
  109. [source,shell]
  110. --------------------------------------------------
  111. curl -u jacknich:l0ng-r4nd0m-p@ssw0rd http://localhost:9200/_cluster/health
  112. --------------------------------------------------
  113. // NOTCONSOLE