Skip to content

Commit a3c2db8

Browse files
catfirepartylourw
andauthored
docs(nx-cloud): add new documentation for PATs and emphasise Access Tokens are for CI (#27227)
- adds a new Personal Access Tokens page - updates the existing Access Tokens page to emphasise they're more for CI - adds `nx-cloud login` reference - adds `nx-cloud configure` reference --------- Co-authored-by: lourw <[email protected]>
1 parent 3d8c3ed commit a3c2db8

File tree

16 files changed

+301
-76
lines changed

16 files changed

+301
-76
lines changed

docs/generated/cli/login.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: 'login - CLI command'
3-
description: 'Login to Nx Cloud.'
3+
description: 'Login to Nx Cloud. This command is an alias for [`nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login).'
44
---
55

66
# login
77

8-
Login to Nx Cloud.
8+
Login to Nx Cloud. This command is an alias for [`nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login).
99

1010
## Usage
1111

docs/generated/cli/logout.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: 'logout - CLI command'
3-
description: 'Logout from Nx Cloud.'
3+
description: 'Logout from Nx Cloud. This command is an alias for [`nx-cloud logout`](/ci/reference/nx-cloud-cli#npx-nxcloud-logout).'
44
---
55

66
# logout
77

8-
Logout from Nx Cloud.
8+
Logout from Nx Cloud. This command is an alias for [`nx-cloud logout`](/ci/reference/nx-cloud-cli#npx-nxcloud-logout).
99

1010
## Usage
1111

docs/generated/manifests/ci.json

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@
560560
},
561561
{
562562
"id": "access-tokens",
563-
"name": "Access Tokens",
563+
"name": "CI Access Tokens",
564564
"description": "",
565565
"mediaImage": "",
566566
"file": "nx-cloud/recipes/access-tokens",
@@ -569,6 +569,17 @@
569569
"path": "/ci/recipes/security/access-tokens",
570570
"tags": []
571571
},
572+
{
573+
"id": "personal-access-tokens",
574+
"name": "Personal Access Tokens",
575+
"description": "",
576+
"mediaImage": "",
577+
"file": "nx-cloud/recipes/personal-access-tokens",
578+
"itemList": [],
579+
"isExternal": false,
580+
"path": "/ci/recipes/security/personal-access-tokens",
581+
"tags": []
582+
},
572583
{
573584
"id": "encryption",
574585
"name": "Enable End to End Encryption",
@@ -1056,7 +1067,7 @@
10561067
},
10571068
{
10581069
"id": "access-tokens",
1059-
"name": "Access Tokens",
1070+
"name": "CI Access Tokens",
10601071
"description": "",
10611072
"mediaImage": "",
10621073
"file": "nx-cloud/recipes/access-tokens",
@@ -1065,6 +1076,17 @@
10651076
"path": "/ci/recipes/security/access-tokens",
10661077
"tags": []
10671078
},
1079+
{
1080+
"id": "personal-access-tokens",
1081+
"name": "Personal Access Tokens",
1082+
"description": "",
1083+
"mediaImage": "",
1084+
"file": "nx-cloud/recipes/personal-access-tokens",
1085+
"itemList": [],
1086+
"isExternal": false,
1087+
"path": "/ci/recipes/security/personal-access-tokens",
1088+
"tags": []
1089+
},
10681090
{
10691091
"id": "encryption",
10701092
"name": "Enable End to End Encryption",
@@ -1094,7 +1116,7 @@
10941116
},
10951117
"/ci/recipes/security/access-tokens": {
10961118
"id": "access-tokens",
1097-
"name": "Access Tokens",
1119+
"name": "CI Access Tokens",
10981120
"description": "",
10991121
"mediaImage": "",
11001122
"file": "nx-cloud/recipes/access-tokens",
@@ -1103,6 +1125,17 @@
11031125
"path": "/ci/recipes/security/access-tokens",
11041126
"tags": []
11051127
},
1128+
"/ci/recipes/security/personal-access-tokens": {
1129+
"id": "personal-access-tokens",
1130+
"name": "Personal Access Tokens",
1131+
"description": "",
1132+
"mediaImage": "",
1133+
"file": "nx-cloud/recipes/personal-access-tokens",
1134+
"itemList": [],
1135+
"isExternal": false,
1136+
"path": "/ci/recipes/security/personal-access-tokens",
1137+
"tags": []
1138+
},
11061139
"/ci/recipes/security/encryption": {
11071140
"id": "encryption",
11081141
"name": "Enable End to End Encryption",

docs/generated/manifests/menus.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5694,13 +5694,21 @@
56945694
"disableCollapsible": false
56955695
},
56965696
{
5697-
"name": "Access Tokens",
5697+
"name": "CI Access Tokens",
56985698
"path": "/ci/recipes/security/access-tokens",
56995699
"id": "access-tokens",
57005700
"isExternal": false,
57015701
"children": [],
57025702
"disableCollapsible": false
57035703
},
5704+
{
5705+
"name": "Personal Access Tokens",
5706+
"path": "/ci/recipes/security/personal-access-tokens",
5707+
"id": "personal-access-tokens",
5708+
"isExternal": false,
5709+
"children": [],
5710+
"disableCollapsible": false
5711+
},
57045712
{
57055713
"name": "Enable End to End Encryption",
57065714
"path": "/ci/recipes/security/encryption",
@@ -6056,13 +6064,21 @@
60566064
"disableCollapsible": false
60576065
},
60586066
{
6059-
"name": "Access Tokens",
6067+
"name": "CI Access Tokens",
60606068
"path": "/ci/recipes/security/access-tokens",
60616069
"id": "access-tokens",
60626070
"isExternal": false,
60636071
"children": [],
60646072
"disableCollapsible": false
60656073
},
6074+
{
6075+
"name": "Personal Access Tokens",
6076+
"path": "/ci/recipes/security/personal-access-tokens",
6077+
"id": "personal-access-tokens",
6078+
"isExternal": false,
6079+
"children": [],
6080+
"disableCollapsible": false
6081+
},
60666082
{
60676083
"name": "Enable End to End Encryption",
60686084
"path": "/ci/recipes/security/encryption",
@@ -6083,13 +6099,21 @@
60836099
"disableCollapsible": false
60846100
},
60856101
{
6086-
"name": "Access Tokens",
6102+
"name": "CI Access Tokens",
60876103
"path": "/ci/recipes/security/access-tokens",
60886104
"id": "access-tokens",
60896105
"isExternal": false,
60906106
"children": [],
60916107
"disableCollapsible": false
60926108
},
6109+
{
6110+
"name": "Personal Access Tokens",
6111+
"path": "/ci/recipes/security/personal-access-tokens",
6112+
"id": "personal-access-tokens",
6113+
"isExternal": false,
6114+
"children": [],
6115+
"disableCollapsible": false
6116+
},
60936117
{
60946118
"name": "Enable End to End Encryption",
60956119
"path": "/ci/recipes/security/encryption",

docs/generated/packages/nx/documents/login.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: 'login - CLI command'
3-
description: 'Login to Nx Cloud.'
3+
description: 'Login to Nx Cloud. This command is an alias for [`nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login).'
44
---
55

66
# login
77

8-
Login to Nx Cloud.
8+
Login to Nx Cloud. This command is an alias for [`nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login).
99

1010
## Usage
1111

docs/generated/packages/nx/documents/logout.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: 'logout - CLI command'
3-
description: 'Logout from Nx Cloud.'
3+
description: 'Logout from Nx Cloud. This command is an alias for [`nx-cloud logout`](/ci/reference/nx-cloud-cli#npx-nxcloud-logout).'
44
---
55

66
# logout
77

8-
Logout from Nx Cloud.
8+
Logout from Nx Cloud. This command is an alias for [`nx-cloud logout`](/ci/reference/nx-cloud-cli#npx-nxcloud-logout).
99

1010
## Usage
1111

docs/map.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,10 +1766,15 @@
17661766
"file": "nx-cloud/recipes/google-auth"
17671767
},
17681768
{
1769-
"name": "Access Tokens",
1769+
"name": "CI Access Tokens",
17701770
"id": "access-tokens",
17711771
"file": "nx-cloud/recipes/access-tokens"
17721772
},
1773+
{
1774+
"name": "Personal Access Tokens",
1775+
"id": "personal-access-tokens",
1776+
"file": "nx-cloud/recipes/personal-access-tokens"
1777+
},
17731778
{
17741779
"name": "Enable End to End Encryption",
17751780
"id": "encryption",

docs/nx-cloud/concepts/cache-security.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ If a malicious actor were able to modify the cache and those output files were t
2222

2323
In order to keep your cache secure, there are a few steps we recommend you take:
2424

25-
### Specify a Read-Only Token in `nx.json`
25+
### Use Personal Access Tokens to Provide Fine-Grained Access Control for Local Development
2626

27-
The [token you specify](/ci/recipes/security/access-tokens) for the `nxCloudAccessToken` property in `nx.json` is visible to anyone who can view your codebase. If this token was a read-write token someone who doesn't even have permission to create a PR could still add entries to the remote cache, which would then be used on other developer's machines and in CI.
27+
When you use a [personal access token](/ci/recipes/security/personal-access-tokens) to connect to Nx Cloud, you can control the level of access that your developers have to the cache after they authenticate by logging in. By default, all personal access tokens have read-only access to the cache. If you need to give a developer write access to the cache, you can do so in the workspace settings of the Nx Cloud UI.
28+
29+
You can strengthen your workspace security further by revoking all access to the cache for unauthenticated users. This is done by changing the ID Access Level in your workspace settings. By default this is set to `read-only`, but you can change it to `none` to prevent all access.
30+
31+
### Avoid using CI Access Tokens in `nx.json`
32+
33+
While you can [specify a token](/ci/recipes/security/access-tokens) with the `nxCloudAccessToken` property in `nx.json`, this is visible to anyone who can view your codebase. A read-write token would give someone who may not even have permission to create a PR the access to add entries to the remote cache, which would then be used on other developer's machines and in CI. We recommend you restrict CI Access Tokens to CI use only and rely on [personal access tokens](/ci/recipes/security/personal-access-tokens) for local development instead.
2834

2935
### Use a Read-Write Token in CI
3036

docs/nx-cloud/recipes/access-tokens.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
# Nx CLI and Access Tokens
1+
# Nx CLI and CI Access Tokens
22

3-
The permissions and membership define what developers can access on [Nx Cloud](https://nx.app). They don't affect what happens when you run Nx commands locally or on CI. To manage that, you need to provision access tokens. To do that, go to Workspace Options / Manage Access Tokens.
3+
The permissions and membership define what developers can access on nx.app but they don't affect what happens when you run Nx commands in CI. To manage that, you need to provision CI access tokens in Workspace settings / Manage CI access tokens.
44

5-
## Types of Access Tokens
5+
## Access Types
66

77
{% callout type="warning" title="Use Caution With Read-Write Tokens" %}
8-
Read-write tokens allow full write access to your remote cache. They should only be used in trusted environments. For instance, open source projects should only use read-write tokens as secrets configured for protected branches (e.g, main). Read-only tokens should be used in all other cases.
8+
Read-write tokens allow full write access to your remote cache. They should only be used in trusted environments.
99
{% /callout %}
1010

11-
There are currently two (2) types of Access Tokens for Nx Cloud's runner that you can use on your workspace. Both tokens support distributed task execution and allow Nx Cloud to store metadata about runs.
11+
There are currently two (2) types of CI Access Token for Nx Cloud's runner that you can use with your workspace. Both support distributed task execution and allow Nx Cloud to store metadata about runs.
1212

1313
- `read-only`
1414
- `read-write`
1515

16-
### Access Tokens: Read Only
16+
### Read Only Access
1717

18-
The `read-only` access tokens will only read from the remote cache. Task results will not be stored in the remote cache for other developers to use.
18+
The `read-only` access tokens will only read from the remote cache. Task results will not be stored in the remote cache for other machines or CI pipelines to use.
1919

20-
### Access Tokens: Read & Write
20+
### Read & Write Access
2121

22-
The `read-write` access tokens allows task results to be stored in the remote cache for other developers to download and replay on their machines.
22+
The `read-write` access tokens allows task results to be stored in the remote cache for other other machines or CI pipelines to download and replay.
2323

24-
## Setting Access Tokens
24+
## Setting CI Access Tokens
2525

26-
Let's see how access tokens work.
26+
You can configure an access token in CI by setting the `NX_CLOUD_ACCESS_TOKEN` environment variable. `NX_CLOUD_ACCESS_TOKEN` takes precedence over any value in your `nx.json`.
2727

28-
If you open your `nx.json`, you will see something like this:
28+
We do not recommend that you commit an access token to your repository but older versions of Nx do support this and if you open your `nx.json`, you may see something like this:
2929

3030
{% tabs %}
3131
{% tab label="Nx >= 17" %}
@@ -40,24 +40,24 @@ If you open your `nx.json`, you will see something like this:
4040
{% tab label="Nx < 17" %}
4141

4242
```json
43-
"tasksRunnerOptions": {
43+
{
44+
"tasksRunnerOptions": {
4445
"default": {
4546
"runner": "nx-cloud",
4647
"options": {
4748
"accessToken": "SOMETOKEN"
4849
}
4950
}
5051
}
52+
}
5153
```
5254

5355
{% /tab %}
5456
{% /tabs %}
5557

56-
If you remove the `nxCloudAccessToken` or `accessToken` property from the configuration, the runner will run all commands as if you were not connected to Nx Cloud. This essentially turns off Nx Cloud.
57-
58-
## Setting a Different Access Token in CI
59-
60-
You can also configure the access token by setting the `NX_CLOUD_ACCESS_TOKEN` environment variable. `NX_CLOUD_ACCESS_TOKEN` takes precedence over the `accessToken` property. It's common to have a read-only token stored in `nx.json` and a read-write token set via `NX_CLOUD_ACCESS_TOKEN` in CI.
58+
{% callout type="warning" title="Nx Cloud authentication is changing" %}
59+
From Nx 19.7 new workspaces are connected to Nx Cloud with a property called `nxCloudId` instead, and we recommend developers use [`nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login) to provision their own local [personal access tokens](/ci/recipes/security/personal-access-tokens).
60+
{% /callout %}
6161

6262
## Using `nx-cloud.env`
6363

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Nx Cloud and Personal Access Tokens
2+
3+
From Nx 19.7 repositories are connected to Nx Cloud via a property in `nx.json` called `nxCloudId`. By default this value allows anyone who clones the repository `read-only` access to Nx Cloud features for that workspace. These permissions can be updated in the workspace settings. To disallow access to anonymous users or allow `read-write` access to known users it is required that all users provision their own personal access token. To do that they need to use [`npx nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login).
4+
5+
{% callout type="warning" title="Personal Access Tokens require the `nxCloudId` field in `nx.json`" %}
6+
Ensure that you have the `nxCloudId` property in your `nx.json` file to connect to Nx Cloud with a Personal Access Token. If you have been using `nxCloudAccessToken`, you can convert it to `nxCloudId` by running [`npx nx-cloud convert-to-nx-cloud-id`](/ci/reference/nx-cloud-cli#npx-nxcloud-converttonxcloudid).
7+
{% /callout %}
8+
9+
{% tabs %}
10+
{% tab label="Nx >= 19.7" %}
11+
12+
```json {% fileName="nx.json" %}
13+
{
14+
"nxCloudId": "SOMEID"
15+
}
16+
```
17+
18+
{% /tab %}
19+
{% tab label="Nx <= 19.6" %}
20+
21+
```json {% fileName="nx.json" %}"
22+
"tasksRunnerOptions": {
23+
"default": {
24+
"runner": "nx-cloud",
25+
"options": {
26+
"nxCloudId": "SOMEID"
27+
}
28+
}
29+
}
30+
```
31+
32+
To utilize personal access tokens and Nx Cloud ID with Nx <= 19.6, the nx-cloud npm package is also required to be installed in your workspaces `package.json`.
33+
34+
```json {% fileName="package.json" %}"
35+
{
36+
"devDependencies": {
37+
"nx-cloud": "latest"
38+
}
39+
}
40+
```
41+
42+
{% /tab %}
43+
{% /tabs %}
44+
45+
## Personal Access Tokens (PATs)
46+
47+
When you run [`npx nx-cloud login`](/ci/reference/nx-cloud-cli#npx-nxcloud-login) you will be directed to the Nx Cloud app where you will be required to create an account and login. A new personal access token will be provisioned and saved in a local configuration file in your home folder (the location of this will be displayed when login is complete and varies depending on OS).
48+
49+
## Permissions
50+
51+
By default all personal access tokens have `read-only` local access to Nx Cloud features for the workspace in which that user is a member. This can be updated to `read-write` in the workspace settings if required, although it is typical for local access to be restricted to `read-only`.
52+
53+
## Better Security
54+
55+
Without an access token committed to your `nx.json` file you gain more fine-grained control over who has access to your cache artifacts and who can utilise Nx Cloud features that you pay for. When you remove a member from your organization they will immediately lose access to all Nx Cloud features saving you the trouble of needing to cycle any tokens you were previously committing to the repository.

0 commit comments

Comments
 (0)