Important: We’ve previously suggested in docs and community that you should use the output of the
fly auth token command as your API token for everything; this is no longer true. The auth token, sometimes called the “personal access token” or the “all-powerful auth token”, is a very short-lived token that is automatically created each time you log in with fly auth login. It’s used by flyctl to create, manage, configure, and deploy all the apps in any organization in your account. You should use tokens created with fly tokens deploy or fly tokens org instead. It’s always a good idea to use the token with the narrowest access that will work for your purpose.App-scoped tokens
Use an app-scoped token, sometimes just called a “deploy token”, to limit access to a single app. App-scoped tokens are useful for CI/CD pipelines where you need to share a token with a 3rd party. You can create a standard app-scoped deploy token, a token to SSH into an app’s Machines, or a token to execute commands on an app’s Machines.Org-scoped tokens
Use an org-scoped token for access to manage all the apps within a single organization. An org-scoped token is the middle ground between the auth token and the more restricted app-scoped token, and is useful when you want to automate a single org. You can create a standard org-scoped token or a read-only org-scoped token.Create and manage tokens
Create and manage tokens using flyctl.fly tokens create commands have some useful options for customizing your token:
-
token names: If you’re managing multiple tokens, then give the tokens custom names with the
--nameoption to make them easier to find when you list them with flyctl or view them in your dashboard. -
token expiry: When you create a token, include the duration that the token is valid for with the
--expiryoption. You should specify the shortest possible duration for your use case so that you limit access by time as well as scope. Tokens are valid for 20 years (175200h0m0s) by default.
fly tokens command docs.
Create app-scoped tokens
App-scoped tokens are limited to managing a single app and its resources. Some organization-wide features like managing WireGuard tunnels are integral to deployments and are also accessible to deploy tokens. If you don’t specify a name with the--name option, then the default name is flyctl deploy token.
Create an app-scoped deploy token with a custom name and expiry:
staging one that’s valid for 48 hours:
Create an app-scoped token for SSH only
Create a token to SSH into a single app. The SSH token is scoped to only allow SSH access to a specific app and nothing else. To be able to SSH to an app, this token is also allowed to connect to the org’s WireGuard network. For example:Create an app-scoped token to execute commands on Machines
A machine-exec token can execute a restricted set of commands on an app’s Machines. You can specify commands on the command line or with the--command and --command-prefix options. If no command is provided, all commands are allowed.
Create a machine exec token:
Create org-scoped tokens
Org-scoped tokens are limited to managing a single org and its resources, including apps. If you don’t specify a name with the--name option, then the default name is Org deploy token.
Create an org-scoped deploy token with a custom name and duration:
prod that’s valid for one week:
Create an org-scoped read-only token
You can further limit an org-scoped deploy token by making it read-only, which limits the token access to reading a single org and its resources. If you don’t specify a name with the —name option, then the default name is Read-only org token. Create a read-only org-scoped deploy token with a custom name and expiry:List or view tokens
List all the tokens for current app, or use the--app option to specify an app:
Revoke tokens
-
List the tokens and copy the ID of the token to revoke. Include the
--scope orgto list org-scoped tokens. -
Revoke the token: