---
type: api
title: Get service accounts
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-security-get-service-accounts
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-security-get-service-accounts
products:
  - Elasticsearch
---

# Get service accounts


Availability: Generally available since 7.13

## Paths

- `GET` `/_security/service/{namespace}/{service}`
- `GET` `/_security/service/{namespace}`
- `GET` `/_security/service`

#### Path parameters

- `namespace` (string) — optional, leave it out to use `/_security/service`
  The name of the namespace.
Omit this parameter to retrieve information about all service accounts.
If you omit this parameter, you must also omit the `service` parameter.
- `service` (string) — optional, leave it out to use `/_security/service`
  The service name.
Omit this parameter to retrieve information about all service accounts that belong to the specified `namespace`.

## Description

Get a list of service accounts that match the provided path parameters.

NOTE: Currently, only the `elastic/fleet-server` service account is available.

[More about service accounts](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/service-accounts)

## Required authorization

- Cluster privileges: `manage_service_account`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Response

`application/json`

- `<string>` (object)
  - `role_descriptor` (object)
    - `cluster` (union anyOf[])
      A list of cluster privileges. These privileges define the cluster level actions that API keys are able to execute.
      Values: `all`, `cancel_task`, `clone_api_key`, `create_snapshot`, `cross_cluster_replication`, `cross_cluster_search`, `delegate_pki`, `grant_api_key`, `manage`, `manage_api_key`, `manage_autoscaling`, `manage_behavioral_analytics`, `manage_ccr`, `manage_data_frame_transforms`, `manage_data_stream_global_retention`, `manage_enrich`, `manage_esql`, `manage_ilm`, `manage_index_templates`, `manage_inference`, `manage_ingest_pipelines`, `manage_logstash_pipelines`, `manage_ml`, `manage_oidc`, `manage_own_api_key`, `manage_pipeline`, `manage_reindex`, `manage_rollup`, `manage_saml`, `manage_search_application`, `manage_search_query_rules`, `manage_search_synonyms`, `manage_security`, `manage_service_account`, `manage_slm`, `manage_token`, `manage_transform`, `manage_user_profile`, `manage_watcher`, `monitor`, `monitor_data_frame_transforms`, `monitor_data_stream_global_retention`, `monitor_enrich`, `monitor_esql`, `monitor_inference`, `monitor_ml`, `monitor_reindex`, `monitor_rollup`, `monitor_snapshot`, `monitor_stats`, `monitor_text_structure`, `monitor_transform`, `monitor_watcher`, `none`, `post_behavioral_analytics_event`, `read_ccr`, `read_fleet_secrets`, `read_ilm`, `read_pipeline`, `read_security`, `read_slm`, `transport_client`, `write_connector_secrets`, `write_fleet_secrets`
    - `indices` (object[])
      A list of indices permissions entries.
      - `field_security` (object)
        The document fields that the owners of the role have read access to.
        - `except` (string)
        - `grant` (string)
      - `names` (union string | string[])
        A list of indices (or index name patterns) to which the permissions in this entry apply.
      - `privileges` (union anyOf[])
        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)
        A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
      - `allow_restricted_indices` (boolean · default: false)
        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` (object[])
      A list of indices permissions for remote clusters.
      - `clusters` (string)
        A list of cluster aliases to which the permissions in this entry apply.
      - `field_security` (object)
        The document fields that the owners of the role have read access to.
        - `except` (string)
        - `grant` (string)
      - `names` (union string | string[])
        A list of indices (or index name patterns) to which the permissions in this entry apply.
      - `privileges` (union anyOf[])
        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)
        A search query that defines the documents the owners of the role have access to. A document within the specified indices must match this query for it to be accessible by the owners of the role.
      - `allow_restricted_indices` (boolean · default: false)
        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_cluster` (object[])
      A list of cluster permissions for remote clusters.
NOTE: This is limited a subset of the cluster permissions.
      - `clusters` (string)
        A list of cluster aliases to which the permissions in this entry apply.
      - `privileges` (enum[])
        The cluster level privileges that owners of the role have on the remote cluster.
        Values: `monitor_enrich`, `monitor_stats`
    - `global` (object)
      An object defining global privileges. A global privilege is a form of cluster privilege that is request-aware.
      - `application` (object)
        - `manage` (object)
          - `applications` (string[])
      - `data_source` (object[])
        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 anyOf[])
          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`
    - `applications` (object[])
      A list of application privilege entries
      - `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.
    - `metadata` (object)
      Optional meta-data. Within the metadata object, keys that begin with `_` are reserved for system usage.
    - `run_as` (string[])
      A list of users that the API keys can impersonate.
NOTE: In Elastic Cloud Serverless, the run-as feature is disabled.
For API compatibility, you can still specify an empty `run_as` field, but a non-empty list will be rejected.
    - `description` (string)
      Optional description of the role descriptor
    - `restriction` (object)
      Restriction for when the role descriptor is allowed to be effective.
      - `workflows` (union anyOf[])
        A list of workflows to which the API key is restricted.
NOTE: In order to use a role restriction, an API key must be created with a single role descriptor.
        Values: `search_application_query`
    - `transient_metadata` (map string to object)
## Code examples

#### Console

```console
GET /_security/service/elastic/fleet-server
```

#### JavaScript

```javascript
const response = await client.security.getServiceAccounts({
  namespace: "elastic",
  service: "fleet-server",
});
```

#### Python

```python
resp = client.security.get_service_accounts(
    namespace="elastic",
    service="fleet-server",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_security/service/elastic/fleet-server" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.security().getServiceAccounts(g -> g
    .namespace("elastic")
    .service("fleet-server")
);
```

#### C#

```c#
var response = await client.Security
    .GetServiceAccountsAsync(d1 => d1
        .Namespace("elastic")
        .Service("fleet-server")
    );
```

#### PHP

```php
$resp = $client->security()->getServiceAccounts([
    "namespace" => "elastic",
    "service" => "fleet-server",
]);
```

#### Ruby

```ruby
response = client.security.get_service_accounts(
  namespace: "elastic",
  service: "fleet-server"
)
```

## Response examples

#### Get service accounts response example1

A successful response from `GET /_security/service/elastic/fleet-server`. The response contains information about the `elastic/fleet-server` service account.

```json
{
  "elastic/fleet-server": {
    "role_descriptor": {
      "cluster": [
        "monitor",
        "manage_own_api_key",
        "read_fleet_secrets"
      ],
      "indices": [
        {
          "names": [
            "logs-*",
            "metrics-*",
            "traces-*",
            ".logs-endpoint.diagnostic.collection-*",
            ".logs-endpoint.action.responses-*",
            ".logs-endpoint.heartbeat-*"
          ],
          "privileges": [
            "write",
            "create_index",
            "auto_configure"
          ],
          "allow_restricted_indices": false
        },
        {
          "names": [
            "profiling-*"
          ],
          "privileges": [
            "read",
            "write"
          ],
          "allow_restricted_indices": false
        },
        {
          "names": [
            "traces-apm.sampled-*"
          ],
          "privileges": [
            "read",
            "monitor",
            "maintenance"
          ],
          "allow_restricted_indices": false
        },
        {
          "names": [
            ".fleet-secrets*"
          ],
          "privileges": [
            "read"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-actions*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-agents*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-artifacts*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-enrollment-api-keys*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-policies*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-policies-leader*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-servers*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            ".fleet-fileds*"
          ],
          "privileges": [
            "read",
            "write",
            "monitor",
            "create_index",
            "auto_configure",
            "maintenance"
          ],
          "allow_restricted_indices": true
        },
        {
          "names": [
            "synthetics-*"
          ],
          "privileges": [
            "read",
            "write",
            "create_index",
            "auto_configure"
          ],
          "allow_restricted_indices": false
        }
      ],
      "applications": [
        {
          "application": "kibana-*",
          "privileges": [
            "reserved_fleet-setup"
          ],
          "resources": [
            "*"
          ]
        }
      ],
      "run_as": [],
      "metadata": {},
      "transient_metadata": {
        "enabled": true
      }
    }
  }
}
```

