create-users.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. [role="xpack"]
  2. [[security-api-put-user]]
  3. === Create or update users API
  4. Adds and updates users in the native realm. These users are commonly referred
  5. to as _native users_.
  6. ==== Request
  7. `POST /_xpack/security/user/<username>` +
  8. `PUT /_xpack/security/user/<username>`
  9. ==== Description
  10. When updating a user, you can update everything but its `username` and `password`.
  11. To change a user's password, use the
  12. <<security-api-change-password, change password API>>.
  13. For more information about the native realm, see
  14. {stack-ov}/realms.html[Realms] and <<configuring-native-realm>>.
  15. ==== Path Parameters
  16. `username` (required)::
  17. (string) An identifier for the user.
  18. +
  19. --
  20. [[username-validation]]
  21. NOTE: Usernames must be at least 1 and no more than 1024 characters. They can
  22. contain alphanumeric characters (`a-z`, `A-Z`, `0-9`), spaces, punctuation, and
  23. printable symbols in the https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)[Basic Latin (ASCII) block]. Leading or trailing whitespace is not allowed.
  24. --
  25. ==== Request Body
  26. The following parameters can be specified in the body of a POST or PUT request:
  27. `enabled`::
  28. (boolean) Specifies whether the user is enabled. The default value is `true`.
  29. `email`::
  30. (string) The email of the user.
  31. `full_name`::
  32. (string) The full name of the user.
  33. `metadata`::
  34. (object) Arbitrary metadata that you want to associate with the user.
  35. `password` (required)::
  36. (string) The user's password. Passwords must be at least 6 characters long.
  37. `roles` (required)::
  38. (list) A set of roles the user has. The roles determine the user's access
  39. permissions. To create a user without any roles, specify an empty list: `[]`.
  40. ==== Authorization
  41. To use this API, you must have at least the `manage_security` cluster privilege.
  42. ==== Examples
  43. The following example creates a user `jacknich`:
  44. [source,js]
  45. --------------------------------------------------
  46. POST /_xpack/security/user/jacknich
  47. {
  48. "password" : "j@rV1s",
  49. "roles" : [ "admin", "other_role1" ],
  50. "full_name" : "Jack Nicholson",
  51. "email" : "jacknich@example.com",
  52. "metadata" : {
  53. "intelligence" : 7
  54. }
  55. }
  56. --------------------------------------------------
  57. // CONSOLE
  58. A successful call returns a JSON structure that shows whether the user has been
  59. created or updated.
  60. [source,js]
  61. --------------------------------------------------
  62. {
  63. "user": {
  64. "created" : true <1>
  65. }
  66. }
  67. --------------------------------------------------
  68. // TESTRESPONSE
  69. <1> When an existing user is updated, `created` is set to false.
  70. After you add a user, requests from that user can be authenticated. For example:
  71. [source,shell]
  72. --------------------------------------------------
  73. curl -u jacknich:j@rV1s http://localhost:9200/_cluster/health
  74. --------------------------------------------------
  75. // NOTCONSOLE