Skip to content

Commit 1a46ea0

Browse files
committed
fix(fly-node): do not rely on access-token for authentication
1 parent d94f897 commit 1a46ea0

8 files changed

Lines changed: 403 additions & 618 deletions

File tree

packages/fly-node/README.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ It's built with a configuration-first approach, meaning that you provide a `fly.
3535

3636
- [Installation](#installation)
3737
- [Usage](#usage)
38+
- [Authentication](#authentication)
3839
- [Create a Fly instance](#create-a-fly-instance)
3940
- [Verify that the Fly client is ready](#verify-that-the-fly-client-is-ready)
4041
- [Deploying apps \& machines](#deploying-apps--machines)
@@ -85,21 +86,40 @@ The library behaves just like the Fly CLI tool regarding all default values.
8586

8687
For any command you run, your local `flyctl` installation will be verified. If it's not present, the command will abort with exception.
8788

88-
### Create a Fly instance
89+
> [!TIP]
90+
> Instead of `flyctl` you can also use `fly` if preferred.
91+
92+
### Authentication
93+
94+
Supported authentication methods to Fly.io in order:
95+
96+
1. authenticate locally via `flyctl auth login`
97+
2. provide a token when creating the Fly instance
98+
3. set access token environment variable `FLY_ACCESS_TOKEN`
99+
4. set API token environment variable `FLY_API_TOKEN`
100+
101+
> [!NOTE]
102+
> See [Fly Docs about security tokens](https://fly.io/docs/security/tokens/) for more details.
103+
104+
**Flaky `--access-token` flag**
105+
106+
From version **0.3.210** the access token flag has a regression, reported in <https://github.com/superfly/flyctl/issues/4648>.
89107

90-
Fly will try to connect to Fly.io in the following order:
108+
> [!IMPORTANT]
109+
> To avoid pinning a previous version, this library no longer relies on the `--access-token` flag.
110+
> When a token is provided to the Fly instance, the library will set `FLY_ACCESS_TOKEN` internally.
111+
>
112+
> This legitimate workaround might change depending on how the Fly team responds to the issue. The intention is to handle this internally without affecting the library api.
91113
92-
1. A user has already authenticated locally using `flyctl auth login`
93-
2. The library authenticates using the provided Fly API `token`
94-
3. The library authenticates using environment variable `FLY_API_TOKEN`
114+
### Create a Fly instance
95115

96116
```ts
97117
import { Fly } from '@cdwr/fly-node';
98118

99119
const fly = new Fly();
100120

101-
// Provide a Fly API token
102-
const fly = new Fly({ token: 'fly-api-token' });
121+
// Provide a Fly token
122+
const fly = new Fly({ token: 'my-fly-token' });
103123
```
104124

105125
> [!TIP]
@@ -131,14 +151,13 @@ const fly = new Fly({ token: 'fly-api-token' });
131151
132152
**Options**
133153
134-
| Name | Description |
135-
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
136-
| `token` | Fly API access token. |
137-
| `authStrategy` | Authentication strategy: `'user-first'` (default) checks local authenticated user first and `'token-first'` checks provided token first. |
138-
| `app` or `config` | Name of the application or the path to the fly configuration file to run all commands on. |
139-
| `org` | Target organisation for your created apps. Defaults to your personal organisation. |
140-
| `region` | Target region for your deployed apps. Defaults to auto-detect the fastest location. |
141-
| `logger` | Custom logger for the library. Defaults to using `console.log()` and `console.error()`. CLI tracing can be enabled when needed. |
154+
| Name | Description |
155+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------- |
156+
| `token` | Fly access token, when none of `FLY_ACCESS_TOKEN` or `FLY_API_TOKEN` is provided. |
157+
| `app` or `config` | Name of the application or the path to the fly configuration file to run all commands on. |
158+
| `org` | Target organisation for your created apps. Defaults to your personal organisation. |
159+
| `region` | Target region for your deployed apps. Defaults to auto-detect the fastest location. |
160+
| `logger` | Custom logger for the library. Defaults to using `console.log()` and `console.error()`. CLI tracing can be enabled when needed. |
142161
143162
#### Verify that the Fly client is ready
144163
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`Fly CLI Compatibility & Schema Validation > Core Commands > cli.version returns valid response 1`] = `"0.4.0"`;
3+
exports[`Fly CLI Compatibility & Schema Validation > Initialization > cli namespace > cli.version returns valid response 1`] = `"0.4.0"`;

0 commit comments

Comments
 (0)