2017-06-28 14:02:40 -04:00
|
|
|
[role="xpack"]
|
2018-08-23 21:04:02 -04:00
|
|
|
[[security-api-has-privileges]]
|
2018-12-20 13:23:28 -05:00
|
|
|
=== Has privileges API
|
|
|
|
++++
|
|
|
|
<titleabbrev>Has privileges</titleabbrev>
|
|
|
|
++++
|
2017-05-12 02:51:47 -04:00
|
|
|
[[security-api-has-privilege]]
|
|
|
|
|
|
|
|
The `has_privileges` API allows you to determine whether the logged in user has
|
|
|
|
a specified list of privileges.
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-has-privileges-request]]
|
|
|
|
==== {api-request-title}
|
2017-09-22 12:46:09 -04:00
|
|
|
|
2018-12-11 04:13:10 -05:00
|
|
|
`GET /_security/user/_has_privileges`
|
2017-09-22 12:46:09 -04:00
|
|
|
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-has-privileges-prereqs]]
|
|
|
|
==== {api-prereq-title}
|
|
|
|
|
|
|
|
* All users can use this API, but only to determine their own privileges.
|
|
|
|
To check the privileges of other users, you must use the run as feature. For
|
|
|
|
more information, see
|
2019-10-07 18:23:19 -04:00
|
|
|
<<run-as-privilege>>.
|
2019-08-02 13:56:05 -04:00
|
|
|
|
|
|
|
[[security-api-has-privileges-desc]]
|
|
|
|
==== {api-description-title}
|
2017-09-22 12:46:09 -04:00
|
|
|
|
|
|
|
For a list of the privileges that you can specify in this API,
|
2019-10-07 18:23:19 -04:00
|
|
|
see <<security-privileges>>.
|
2017-09-22 12:46:09 -04:00
|
|
|
|
|
|
|
A successful call returns a JSON structure that shows whether each specified
|
|
|
|
privilege is assigned to the user.
|
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-has-privileges-request-body]]
|
|
|
|
==== {api-request-body-title}
|
2017-09-22 12:46:09 -04:00
|
|
|
|
|
|
|
`cluster`:: (list) A list of the cluster privileges that you want to check.
|
|
|
|
|
|
|
|
`index`::
|
|
|
|
`names`::: (list) A list of indices.
|
2019-04-25 05:02:09 -04:00
|
|
|
`allow_restricted_indices`::: (boolean) This needs to be set to `true` (default
|
|
|
|
is `false`) if using wildcards or regexps for patterns that cover restricted
|
|
|
|
indices. Implicitly, restricted indices do not match index patterns because
|
|
|
|
restricted indices usually have limited privileges and including them in
|
|
|
|
pattern tests would render most such tests `false`. If restricted indices are
|
|
|
|
explicitly included in the `names` list, privileges will be checked against
|
|
|
|
them regardless of the value of `allow_restricted_indices`.
|
2017-09-22 12:46:09 -04:00
|
|
|
`privileges`::: (list) A list of the privileges that you want to check for the
|
|
|
|
specified indices.
|
|
|
|
|
2018-08-23 21:04:02 -04:00
|
|
|
`application`::
|
|
|
|
`application`::: (string) The name of the application.
|
|
|
|
`privileges`::: (list) A list of the privileges that you want to check for the
|
|
|
|
specified resources. May be either application privilege names, or the names of
|
|
|
|
actions that are granted by those privileges
|
|
|
|
`resources`::: (list) A list of resource names against which the privileges
|
|
|
|
should be checked
|
|
|
|
|
2017-09-22 12:46:09 -04:00
|
|
|
|
2019-08-02 13:56:05 -04:00
|
|
|
[[security-api-has-privileges-example]]
|
|
|
|
==== {api-examples-title}
|
2017-09-22 12:46:09 -04:00
|
|
|
|
|
|
|
The following example checks whether the current user has a specific set of
|
2018-08-23 21:04:02 -04:00
|
|
|
cluster, index, and application privileges:
|
2017-05-12 02:51:47 -04:00
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console]
|
2017-05-12 02:51:47 -04:00
|
|
|
--------------------------------------------------
|
2018-12-11 04:13:10 -05:00
|
|
|
GET /_security/user/_has_privileges
|
2017-05-12 02:51:47 -04:00
|
|
|
{
|
|
|
|
"cluster": [ "monitor", "manage" ],
|
|
|
|
"index" : [
|
|
|
|
{
|
|
|
|
"names": [ "suppliers", "products" ],
|
|
|
|
"privileges": [ "read" ]
|
2017-06-28 14:02:40 -04:00
|
|
|
},
|
2017-05-12 02:51:47 -04:00
|
|
|
{
|
|
|
|
"names": [ "inventory" ],
|
|
|
|
"privileges" : [ "read", "write" ]
|
|
|
|
}
|
2018-08-23 21:04:02 -04:00
|
|
|
],
|
|
|
|
"application": [
|
|
|
|
{
|
|
|
|
"application": "inventory_manager",
|
|
|
|
"privileges" : [ "read", "data:write/inventory" ],
|
|
|
|
"resources" : [ "product/1852563" ]
|
|
|
|
}
|
2017-05-12 02:51:47 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2017-09-22 12:46:09 -04:00
|
|
|
The following example output indicates which privileges the "rdeniro" user has:
|
2017-05-12 02:51:47 -04:00
|
|
|
|
2019-09-05 14:12:39 -04:00
|
|
|
[source,console-result]
|
2017-05-12 02:51:47 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"username": "rdeniro",
|
|
|
|
"has_all_requested" : false,
|
|
|
|
"cluster" : {
|
|
|
|
"monitor" : true,
|
|
|
|
"manage" : false
|
|
|
|
},
|
|
|
|
"index" : {
|
|
|
|
"suppliers" : {
|
|
|
|
"read" : true
|
|
|
|
},
|
|
|
|
"products" : {
|
|
|
|
"read" : true
|
|
|
|
},
|
|
|
|
"inventory" : {
|
|
|
|
"read" : true,
|
|
|
|
"write" : false
|
|
|
|
}
|
2018-07-24 12:34:46 -04:00
|
|
|
},
|
2018-08-23 21:04:02 -04:00
|
|
|
"application" : {
|
|
|
|
"inventory_manager" : {
|
|
|
|
"product/1852563" : {
|
|
|
|
"read": false,
|
|
|
|
"data:write/inventory": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 02:51:47 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TESTRESPONSE[s/"rdeniro"/"$body.username"/]
|
|
|
|
// TESTRESPONSE[s/: false/: true/]
|