Repository navigation
Add guide: create an API-only user #60460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c18066
Add guide: create an API-only user
kitzy a008fa9
Link available API endpoints in API-only user guide
kitzy 43e6b49
Link endpoint list docs instead of YAML in API-only user guide
kitzy 6f519da
Fix verify step for restricted users, GitOps role on Free, and 403 tr…
kitzy 18aa4df
Merge branch 'main' into kitzy/guide-create-api-only-user
kitzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| - 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: | ||
|
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** | ||
|
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."> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.