---
type: api
title: Get user privileges
description: Get the security privileges for the logged in user.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-get-user-privileges
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/operation/operation-security-get-user-privileges
products:
  - Elasticsearch
---

# Get user privileges

Availability: 6.5+

## Paths

- `GET` `/_security/user/_privileges`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/authentication#bearerauth)

## Description

Get the security privileges for the logged in user.
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.
To check whether a user has a specific list of privileges, use the has privileges API.

## Response

`application/json`

- `applications` ([] ApplicationPrivileges)
  - `application` (string)
    The name of the application to which this entry applies.
  - `privileges` ([] string)
    A list of strings, where each element is the name of an application privilege or action.
  - `resources` ([] string)
    A list resources to which the privileges are applied.
- `cluster` ([] string)
- `remote_cluster` ([] RemoteClusterPrivileges)
  - `clusters` (string Names)
    A list of cluster aliases to which the permissions in this entry apply.
  - `privileges` ([] enum RemoteClusterPrivilege)
    The cluster level privileges that owners of the role have on the remote cluster.
    Values: `monitor_enrich`, `monitor_stats`
- `global` ([] GlobalPrivilege)
  - `application` ({} ApplicationGlobalUserPrivileges)
    - `manage` ({} ManageUserPrivileges)
      - `applications` ([] string)
  - `profile` ({} WriteProfileGlobalUserPrivileges)
    A privilege that grants the ability to write the `data` and `access` sections of user profiles for the specified applications.
    - `write` ({} ManageUserPrivileges)
      The applications for which user profile data can be written.
Absent when the `profile` section is present but grants no privileges.
      - `applications` ([] string)
  - `role` ({} ManageRolesGlobalUserPrivileges)
    A privilege that grants the ability to manage roles that are scoped to the specified indices.
    - `manage` ({} ManageRolesPrivileges)
      The index-scoped role management privileges.
Absent when the `role` section is present but grants no privileges.
      - `indices` ([] ManageRolesIndexPermissions)
        - `names` ([] string)
          A list of indices (or index name patterns) that the owners of the role can manage roles for.
        - `privileges` ([] string)
          The index privileges that the managed roles are allowed to grant on the specified indices.
  - `data_source` ([] DataSourcePrivileges)
    A list of data source privilege entries, used to grant access to ES|QL data sources.
    - `names` ([] string)
      A list of data source names or wildcard patterns to which the permissions in this entry apply.
    - `privileges` ([] union DataSourcePrivilege)
      The data source privileges that owners of the role have for the specified data sources.

Supported values include:
  - `create`: Grants privilege to create a data source with a matching name.
  - `delete`: Grants privilege to delete a data source with a matching name.
  - `read_metadata`: Grants privilege to read a data source's metadata.
  - `read`: Grants privilege to attach a dataset to a data source with a matching name.
  - `manage`: Grants all data source privileges, including `create`, `delete`, `read`, and `read_metadata`.
      Values: `create`, `delete`, `read_metadata`, `read`, `manage`
- `indices` ([] UserIndicesPrivileges)
  - `field_security` ([] FieldSecurity)
    The document fields that the owners of the role have read access to.
    - `except` (string Fields)
    - `grant` (string Fields)
  - `names` (union IndexName | [] IndexName)
    A list of indices (or index name patterns) to which the permissions in this entry apply.
  - `privileges` ([] union IndexPrivilege)
    The index level privileges that owners of the role have on the specified indices.
    Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `create_view`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `delete_view`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `manage_view`, `monitor`, `none`, `read`, `read_cross_cluster`, `read_view_metadata`, `view_index_metadata`, `write`
  - `query` ([] union IndicesPrivilegesQuery)
    Search queries that define the documents the user has access to. A document within the specified indices must match these queries for it to be accessible by the owners of the role.
    - **string**
    - **[QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
      An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
    - **RoleTemplateQuery**
      - `template` ({} RoleTemplateScript)
        When you create a role, you can specify a query that defines the document level security permissions. You can optionally
use Mustache templates in the role query to insert the username of the current authenticated user into the role.
Like other places in Elasticsearch that support templating or scripting, you can specify inline, stored, or file-based
templates and define custom parameters. You access the details for the current authenticated user through the _user parameter.
        - `source` (RoleTemplateInlineQuery)
        - `id` (string Id)
          The `id` for a stored script.
        - `params` (map string to object)
          Specifies any named parameters that are passed into the script as variables.
Use parameters instead of hard-coded values to decrease compile time.
        - `lang` (ScriptLanguage · default: painless)
          Specifies the language the script is written in.

Supported values include:
  - `painless`: Painless scripting language, purpose-built for Elasticsearch.
  - `expression`: Lucene’s expressions language, compiles a JavaScript expression to bytecode.
  - `mustache`: Mustache templated, used for templates.
  - `java`: Expert Java API
          Values: `painless`, `expression`, `mustache`, `java`
        - `options` (map string to string)
  - `allow_restricted_indices` (boolean)
    Set to `true` if using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in the `names` list, Elasticsearch checks privileges against these indices regardless of the value set for `allow_restricted_indices`.
- `remote_indices` ([] RemoteUserIndicesPrivileges)
  - `clusters` ([] string)
  - `field_security` ([] FieldSecurity)
    The document fields that the owners of the role have read access to.
    - `except` (string Fields)
    - `grant` (string Fields)
  - `names` (union IndexName | [] IndexName)
    A list of indices (or index name patterns) to which the permissions in this entry apply.
  - `privileges` ([] union IndexPrivilege)
    The index level privileges that owners of the role have on the specified indices.
    Values: `all`, `auto_configure`, `create`, `create_doc`, `create_index`, `create_view`, `cross_cluster_replication`, `cross_cluster_replication_internal`, `delete`, `delete_index`, `delete_view`, `index`, `maintenance`, `manage`, `manage_data_stream_lifecycle`, `manage_follow_index`, `manage_ilm`, `manage_leader_index`, `manage_view`, `monitor`, `none`, `read`, `read_cross_cluster`, `read_view_metadata`, `view_index_metadata`, `write`
  - `query` ([] union IndicesPrivilegesQuery)
    Search queries that define the documents the user has access to. A document within the specified indices must match these queries for it to be accessible by the owners of the role.
    - **string**
    - **[QueryContainer](https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)**
      An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
    - **RoleTemplateQuery**
      - `template` ({} RoleTemplateScript)
        When you create a role, you can specify a query that defines the document level security permissions. You can optionally
use Mustache templates in the role query to insert the username of the current authenticated user into the role.
Like other places in Elasticsearch that support templating or scripting, you can specify inline, stored, or file-based
templates and define custom parameters. You access the details for the current authenticated user through the _user parameter.
        - `source` (RoleTemplateInlineQuery)
        - `id` (string Id)
          The `id` for a stored script.
        - `params` (map string to object)
          Specifies any named parameters that are passed into the script as variables.
Use parameters instead of hard-coded values to decrease compile time.
        - `lang` (ScriptLanguage · default: painless)
          Specifies the language the script is written in.

Supported values include:
  - `painless`: Painless scripting language, purpose-built for Elasticsearch.
  - `expression`: Lucene’s expressions language, compiles a JavaScript expression to bytecode.
  - `mustache`: Mustache templated, used for templates.
  - `java`: Expert Java API
          Values: `painless`, `expression`, `mustache`, `java`
        - `options` (map string to string)
  - `allow_restricted_indices` (boolean)
    Set to `true` if using wildcard or regular expressions for patterns that cover restricted indices. Implicitly, restricted indices have limited privileges that can cause pattern tests to fail. If restricted indices are explicitly included in the `names` list, Elasticsearch checks privileges against these indices regardless of the value set for `allow_restricted_indices`.
- `run_as` ([] string)
## Code Examples

#### Console

```console
GET /_security/user/_privileges
```

#### JavaScript

```javascript
const response = await client.security.getUserPrivileges();
```

#### Python

```python
resp = client.security.get_user_privileges()
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_security/user/_privileges" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().getUserPrivileges();
```

#### C#

```c#
var response = await client.Security.GetUserPrivilegesAsync();
```

#### PHP

```php
$resp = $client->security()->getUserPrivileges();
```

#### Ruby

```ruby
response = client.security.get_user_privileges
```

## Response Examples

#### Security get user privileges response example1

A successful response from `GET /_security/user/_privileges`.

```json
{
  "cluster" : [
    "all"
  ],
  "global" : [ ],
  "indices" : [
    {
      "names" : [
        "*"
      ],
      "privileges" : [
        "all"
      ],
      "allow_restricted_indices" : true
    }
  ],
  "applications" : [
    {
      "application" : "*",
      "privileges" : [
        "*"
      ],
      "resources" : [
        "*"
      ]
    }
  ],
  "run_as" : [
    "*"
  ]
}
```

