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