create-users.asciidoc 4.1 KB

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