Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions articles/create-an-api-only-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Create an API-only user

Scripts, CI pipelines, and integrations that call the Fleet API should use an API-only user, not a person's account. An API-only user can't sign in to the Fleet UI, and its API token doesn't expire. Automation keeps working when people change roles or leave. This guide covers creating an API-only user in the Fleet UI and with the Fleet REST API.

## Prerequisites

- The global admin role in Fleet. Only global admins can open **Settings > Users**.
- Fleet Premium, to assign the user to specific fleets, give it the GitOps role, or limit it to specific API endpoints.
Comment thread
kitzy marked this conversation as resolved.
Resolved
- To use the REST API, an API token for your own account. Select your avatar in the top right, select **My account**, then select **Get API token**.

## Choose the user's access

Give the user only the access its integration needs:

- Role: API-only users can have the same roles as regular users, plus GitOps. Use Observer for read-only reporting and GitOps for `fleetctl gitops` pipelines. See [role-based access](https://fleetdm.com/guides/role-based-access) for what each role can do.
- Fleets: With Fleet Premium, assign the user to specific fleets instead of giving it a global role.
- API endpoints: With Fleet Premium, limit the user to the endpoints its integration calls. If the token leaks, it only works on those endpoints. To see which endpoints you can choose, use [List API endpoints for API-only user permissions](https://fleetdm.com/docs/rest-api/rest-api#list-api-endpoints-for-api-only-user-permissions).

> **Note:** Limiting API endpoints narrows access, but it never grants more than the user's role allows. For example, a fleet admin limited to [Update configuration](https://fleetdm.com/docs/rest-api/rest-api#update-configuration) still gets a `403` response. Only global admins and global GitOps users can use that endpoint.

## Create the user in the Fleet UI

1. Go to **Settings > Users**.
2. Select **Add user**, then select **API-only user**.
3. In **Name**, enter a name that says what uses the token, for example "GitHub Actions GitOps".
4. Set the user's access:
- With Fleet Premium, under **Permissions**, select **Global user** and choose a **Role**. Or select **Assign to fleet(s)**, then choose each fleet and the user's role on it.
- With Fleet Free, choose a **Role**.
5. Optional (Fleet Premium): Under **API access**, select **Specific API endpoints**, then select the endpoints the user can call.
6. Select **Add**.
7. Copy the **API key** and store it in your secrets manager, then select **Done**.

> **Warning:** Fleet only shows the API key once. If you lose it, create a new API-only user and delete the old one. See [Rotate an API-only user's token](https://fleetdm.com/guides/rotate-api-only-user-token).

## Create the user with the REST API

Replace `fleet.example.com` with your Fleet server's address, and `<admin_token>` with your own API token.

### Find API endpoints (optional)

To limit the user to specific endpoints (Fleet Premium), find each endpoint's `method` and `path` with [List API endpoints for API-only user permissions](https://fleetdm.com/docs/rest-api/rest-api#list-api-endpoints-for-api-only-user-permissions). This example searches for host endpoints:

```sh
curl "https://fleet.example.com/api/v1/fleet/rest_api?query=hosts" \
-H "Authorization: Bearer <admin_token>"
```

Use each `method` and `path` exactly as the response shows it, including path parameters like `:id`.

### Create the user

Send the user's name and access to [Create API-only user](https://fleetdm.com/docs/rest-api/rest-api#create-api-only-user). This example creates a global observer:

```sh
curl -X POST "https://fleet.example.com/api/v1/fleet/users/api_only" \
-H "Authorization: Bearer <admin_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "Inventory export",
"global_role": "observer"
}'
```

With Fleet Premium, replace `global_role` with `fleets` to assign fleet roles, and add `api_endpoints` to limit the user's endpoints. This example creates an observer on fleet `2` that can only list hosts and get a host by ID:

```sh
curl -X POST "https://fleet.example.com/api/v1/fleet/users/api_only" \
-H "Authorization: Bearer <admin_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "Inventory export",
"fleets": [{ "id": 2, "role": "observer" }],
"api_endpoints": [
{ "method": "GET", "path": "/api/v1/fleet/hosts" },
{ "method": "GET", "path": "/api/v1/fleet/hosts/:id" }
]
}'
```

> **Note:** Send either `global_role` or `fleets`, not both.

The response includes the new user's details and its `token`. Copy the token and store it in your secrets manager. Fleet doesn't return it again.

## Verify

Confirm the new token works:
Comment thread
kitzy marked this conversation as resolved.
Resolved

```sh
curl "https://fleet.example.com/api/v1/fleet/me" \
-H "Authorization: Bearer <new_token>"
```

Fleet returns the new user's details, including its `name` and `"api_only": true`. If Fleet returns an error message instead, check that you copied the whole token.

## Troubleshoot

**The user gets a `403` response from an endpoint**

The user's role doesn't allow that action, or the endpoint isn't in the user's API endpoint list. Edit the user in **Settings > Users** and update its role, fleets, or API endpoints.

**Creating the user fails with an `api_endpoints` error**

The `method` and `path` must match an endpoint from [List API endpoints for API-only user permissions](https://fleetdm.com/docs/rest-api/rest-api#list-api-endpoints-for-api-only-user-permissions). An empty `api_endpoints` array isn't allowed. To give the user access to every endpoint, leave `api_endpoints` out.

**The Specific API endpoints option or the GitOps role is missing**
Comment thread
kitzy marked this conversation as resolved.
Resolved

Both require Fleet Premium.

## Further reading

- [Rotate an API-only user's token](https://fleetdm.com/guides/rotate-api-only-user-token)
- [Using fleetctl with an API-only user](https://fleetdm.com/guides/fleetctl#using-fleetctl-with-an-api-only-user)
- [Role-based access](https://fleetdm.com/guides/role-based-access)
- [Users REST API reference](https://fleetdm.com/docs/rest-api/rest-api#users)

<meta name="articleTitle" value="Create an API-only user">
<meta name="authorFullName" value="Kitzy">
<meta name="authorGitHubUsername" value="kitzy">
<meta name="category" value="guides">
<meta name="publishedOn" value="2026-12-02">
<meta name="description" value="Create an API-only user for scripts and integrations in the Fleet UI or with the REST API, with only the access it needs.">
2 changes: 1 addition & 1 deletion articles/rotate-api-only-user-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Note the old user's `id` from the response. You'll need it to delete the user la

## Step 2: Create the new API-only user

Follow instructions to [create an new API-only user](https://fleetdm.com/guides/fleetctl#create-api-only-user) and give the new user a name that tells the two users apart, for example `test-api-user (2026-10)`.
[Create a new API-only user](https://fleetdm.com/guides/create-an-api-only-user) and give the new user a name that tells the two users apart, for example `test-api-user (2026-10)`.

## Step 3: Update your integrations

Expand Down
Loading