2020-12-24 22:12:44 +00:00
# fleetctl CLI
2021-06-07 01:10:58 +00:00
2024-02-23 19:14:47 +00:00
fleetctl (pronounced "Fleet control") is a CLI tool for managing Fleet from the command line. fleetctl enables a GitOps workflow with Fleet.
2022-02-07 22:56:02 +00:00
2024-02-23 19:14:47 +00:00
fleetctl also provides a quick way to work with all the data exposed by Fleet without having to use the Fleet UI or work directly with the Fleet API.
2022-03-31 15:34:58 +00:00
2022-08-31 18:09:20 +00:00
< div purpose = "embedded-content" >
< iframe src = "https://www.youtube.com/embed/ERbknt6w8eg" allowfullscreen > < / iframe >
< / div >
2024-02-23 19:14:47 +00:00
## Installing fleetctl
Install fleetctl with npm or download the binary from [GitHub ](https://github.com/fleetdm/fleet/releases ).
```sh
npm install -g fleetctl
```
### Upgrading fleetctl
The easiest way to update fleetctl is by running the installation command again.
```sh
npm install -g fleetctl@latest
```
## Usage
2022-03-31 15:34:58 +00:00
### Available commands
2024-02-23 19:14:47 +00:00
2023-05-01 15:27:02 +00:00
Much of the functionality available in the Fleet UI is also available in `fleetctl` . You can run queries, add and remove users, generate agent (fleetd) installers to add new hosts, get information about existing hosts, and more!
2024-02-23 19:14:47 +00:00
To see the available commands you can run:
```sh
> fleetctl --help
```
2022-03-31 15:34:58 +00:00
### Get more info about a command
2024-02-23 19:14:47 +00:00
Each command has a help menu with additional information. To pull up the help menu, run `fleetctl <command> --help` , replacing `<command>` with the command you're looking up:
2022-03-31 15:34:58 +00:00
2023-09-22 21:57:40 +00:00
```sh
2022-03-31 15:34:58 +00:00
> fleetctl setup --help
```
2024-02-23 19:14:47 +00:00
You will see more info about the command, including the usage and information about any additional commands and options (or 'flags'):
2022-03-31 15:34:58 +00:00
2023-09-22 21:57:40 +00:00
```sh
2022-03-31 15:34:58 +00:00
NAME:
fleetctl setup - Set up a Fleet instance
USAGE:
fleetctl setup [options]
OPTIONS:
--email value Email of the admin user to create (required) [$EMAIL]
--name value Name or nickname of the admin user to create (required) [$NAME]
--password value Password for the admin user (recommended to use interactive entry) [$PASSWORD]
--org-name value Name of the organization (required) [$ORG_NAME]
--config value Path to the fleetctl config file (default: "/Users/ksatter/.fleet/config") [$CONFIG]
--context value Name of fleetctl config context to use (default: "default") [$CONTEXT]
--debug Enable debug http request logging (default: false) [$DEBUG]
--help, -h show help (default: false)
2020-12-24 22:12:44 +00:00
```
2024-02-23 19:14:47 +00:00
## Authentication
2020-12-24 22:12:44 +00:00
2024-02-23 19:14:47 +00:00
This section walks you through authentication, assuming you already have a running Fleet instance. To learn how to set up new Fleet instance, check out the [Deploy ](https://fleetdm.com/docs/deploy/introduction ) section or [Building Fleet locally ](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Building-Fleet.md ) docs.
2020-12-24 22:12:44 +00:00
2024-02-23 19:14:47 +00:00
### Login
2020-12-24 22:12:44 +00:00
2024-02-23 19:14:47 +00:00
To log in to your Fleet instance, run following commands:
2020-12-24 22:12:44 +00:00
2024-02-23 19:14:47 +00:00
1. Set the Fleet instance address
2020-12-24 22:12:44 +00:00
2023-09-22 21:57:40 +00:00
```sh
2024-02-23 19:14:47 +00:00
> fleetctl config set --address https://fleet.example.com
[+] Set the address config key to "https://fleet.example.com" in the "default" context
2020-12-24 22:12:44 +00:00
```
2024-02-23 19:14:47 +00:00
2. Log in with your credentials
2020-12-24 22:12:44 +00:00
2023-09-22 21:57:40 +00:00
```sh
2024-02-23 19:14:47 +00:00
> fleetctl login
2020-12-24 22:12:44 +00:00
Log in using the standard Fleet credentials.
Email: mike@arpaia.co
Password:
[+] Fleet login successful and context configured!
```
2024-02-23 19:14:47 +00:00
Once your local context is configured, you can use `fleetctl` normally.
2020-12-24 22:12:44 +00:00
2024-02-23 19:14:47 +00:00
### Log in with SAML (SSO) authentication
2020-12-24 22:12:44 +00:00
Users that authenticate to Fleet via SSO should retrieve their API token from the UI and set it manually in their `fleetctl` configuration (instead of logging in via `fleetctl login` ).
2024-02-23 19:14:47 +00:00
**Fleet UI:**
1. Go to the **My account** page (https://fleet.example.com/profile)
2. Select the **Get API token** button to bring up a modal with the API token.
3. Set the API token in the `~/.fleet/config` file.
2020-12-24 22:12:44 +00:00
2023-09-22 21:57:40 +00:00
```yaml
2020-12-24 22:12:44 +00:00
contexts:
default:
address: https://fleet.corp.example.com
email: example@example.com
token: your_token_here
```
2024-02-23 19:14:47 +00:00
The token can also be set with `fleetctl config set --token` , but this may leak the token into a user's shell history.
2020-12-24 22:12:44 +00:00
2022-03-30 16:38:38 +00:00
## Using fleetctl with an API-only user
2024-02-23 19:14:47 +00:00
When running automated workflows using the Fleet API, we recommend an API-only user's API key rather than the API key of a regular user. A regular user's API key expires frequently for security purposes, requiring routine updates. Meanwhile, an API-only user's key does not expire.
2022-07-19 20:46:52 +00:00
An API-only user does not have access to the Fleet UI. Instead, it's only purpose is to interact with the API programmatically or from fleetctl.
2022-03-30 16:38:38 +00:00
2024-02-23 19:14:47 +00:00
### Create API-only user
2022-03-30 16:38:38 +00:00
2024-04-01 13:53:00 +00:00
Before creating the API-only user, log in to `fleetctl` as an admin. See [authentication ](https://#authentication ) above for details.
2024-02-23 19:14:47 +00:00
To create your new API-only user, use `fleetctl user create` :
2022-03-30 16:38:38 +00:00
2023-09-22 21:57:40 +00:00
```sh
2023-09-28 18:21:25 +00:00
fleetctl user create --name "API User" --email api@example.com --password temp@pass123 --api-only
2022-03-30 16:38:38 +00:00
```
2024-02-23 19:14:47 +00:00
#### Permissions
An API-only user can be given the same permissions as a regular user. The default access level is **Observer** . You can specify what level of access the new user should have using the `--global-role` flag:
2022-03-30 16:38:38 +00:00
2023-09-22 21:57:40 +00:00
```sh
2024-02-23 19:14:47 +00:00
fleetctl user create --name "API User" --email api@example.com --password temp@pass123 --api-only --global-role admin
2022-03-30 16:38:38 +00:00
```
2024-02-23 19:14:47 +00:00
On Fleet Premium, use the `--team <team_id>:<role>` to create an API-only user on a team:
2023-04-07 15:36:47 +00:00
2023-09-22 21:57:40 +00:00
```sh
2024-02-23 19:14:47 +00:00
fleetctl user create --name "API User" --email api@example.com --password temp@pass123 --api-only --team 4: gitops
2023-04-07 15:36:47 +00:00
```
2024-02-23 19:14:47 +00:00
#### Changing permissions
2023-04-07 15:36:47 +00:00
To change roles of a current user, log into the Fleet UI as an admin and navigate to **Settings > Users** .
> Suggestion: To disable/enable a user's access to the UI (converting a regular user to an API-only user or vice versa), create a new user.
2024-02-23 19:14:47 +00:00
### Get API token for API-only user
2022-06-29 19:07:07 +00:00
2024-02-23 19:14:47 +00:00
To get the API key of an API-only user, you need to call the [login API ](https://fleetdm.com/docs/rest-api/rest-api#log-in ) with the credentials supplied during user creation.
2022-06-29 19:07:07 +00:00
```sh
2024-02-23 19:14:47 +00:00
curl --location --request POST 'https://fleet.example.com/api/v1/fleet/login' \
2022-06-29 19:07:07 +00:00
--header 'Content-Type: application/json' \
--data-raw '{
2022-12-14 22:13:12 +00:00
"email": "api@example.com",
2022-06-29 19:07:07 +00:00
"password": "foobar12345"
}'
```
2022-07-05 13:20:15 +00:00
The [Log in API ](https://fleetdm.com/docs/using-fleet/rest-api#log-in ) will return a response similar to the one below with the API token included that will not expire.
2022-06-29 19:07:07 +00:00
```json
{
"user": {
"id": 82,
"name": "API User",
2022-12-14 22:13:12 +00:00
"email": "api@example.com",
2022-06-29 19:07:07 +00:00
"global_role": "observer",
"api_only": true
},
"available_teams": [],
"token": "foo_token"
}
```
2022-05-02 18:33:12 +00:00
2022-03-30 16:38:38 +00:00
### Switching users
2022-07-19 21:46:20 +00:00
To use `fleetctl` with your regular user account but occasionally use your API-only user for specific cases, you can set up your `fleetctl` config with a new `context` to hold the credentials of your API-only user:
2022-03-30 16:38:38 +00:00
2023-09-22 21:57:40 +00:00
```sh
2022-07-19 20:46:52 +00:00
fleetctl config set --address https://dogfood.fleetdm.com --context api
[+] Context "api" not found, creating it with default values
[+] Set the address config key to "https://dogfood.fleetdm.com" in the "api" context
2022-03-30 16:38:38 +00:00
```
2022-07-19 20:46:52 +00:00
From there on, you can use the `--context api` flag whenever you need to use the API-only user's identity, rather than logging in and out to switch accounts:
2022-03-30 16:38:38 +00:00
2023-09-22 21:57:40 +00:00
```sh
2022-03-30 16:38:38 +00:00
fleetctl login --context admin
Log in using the admin Fleet credentials.
Email: admin@example.com
Password:
[+] Fleet login successful and context configured!
```
2022-07-19 20:46:52 +00:00
Running a command with no context will use the default profile.
2022-03-30 16:38:38 +00:00
2022-05-17 13:00:47 +00:00
## Debugging Fleet
`fleetctl` provides debugging capabilities about the running Fleet server via the `debug` command. To see a complete list of all the options run:
2023-09-22 21:57:40 +00:00
```sh
2022-05-17 13:00:47 +00:00
fleetctl debug --help
```
To generate a full debugging archive, run:
2023-09-22 21:57:40 +00:00
```sh
2022-05-17 13:00:47 +00:00
fleetctl debug archive
```
This will generate a `tar.gz` file with:
- `prof` archives that can be inspected via `go tools pprof <archive_name_here>` .
2022-10-26 23:26:49 +00:00
- A file containing a set of all the errors that happened in the server during the interval of time defined by the [logging_error_retention_period ](https://fleetdm.com/docs/deploying/configuration#logging-error-retention-period ) configuration.
2022-05-20 18:01:54 +00:00
- Files containing database-specific information.
2022-05-17 13:00:47 +00:00
2022-02-23 18:17:55 +00:00
< meta name = "pageOrderInSection" value = "300" >
2023-07-13 16:57:17 +00:00
< meta name = "description" value = "Read about fleetctl, a CLI tool for managing Fleet and osquery configurations, running queries, generating installers, and more." >
2024-02-23 19:14:47 +00:00
< meta name = "navSection" value = "The basics" >