Skip to content

Commit d152639

Browse files
docs(nx-dev): add personal access token blog post (#27719)
1 parent a3c2db8 commit d152639

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Better security with Personal Access Tokens
3+
slug: personal-access-tokens
4+
authors: ['Philip Fulcher']
5+
tags: [nx-cloud]
6+
cover_image: /blog/images/2024-09-05/personal-access-tokens-header.avif
7+
---
8+
9+
Today, Nx Cloud gets a huge upgrade to managing access to your cached artifacts
10+
using [Nx Replay](/ci/features/remote-cache). Previously, workspaces
11+
were limited to defining access tokens with read or read/write permissions for an entire workspace. With the
12+
introduction of _personal access tokens_, you gain much more control over access. This is a feature request we've heard
13+
from many customers, especially our [Enterprise](/enterprise) customers, and we're happy to be able to deliver this
14+
enhancement.
15+
16+
## Access Tokens and the problem of revoking access
17+
18+
Our previous implementation of access tokens required you to commit the access token to your `nx.json` file. Typically,
19+
service providers don't recommend committing any kind of API token like this, and we've fielded a lot of questions about
20+
this practice in the past. It is safe to commit this token, as access to the cached artifacts of Nx Cloud rely on both
21+
the access token and the source code itself. Without access to both, you can't access the cache.
22+
23+
However, this did present the following problem: revoking someone's access to the cache became difficult as long as they
24+
had the source code. Imagine a scenario where someone has left an organization. As long as they have a clone of the
25+
repo, they have everything they need to access the cache, even if their credentials have been
26+
revoked. To fully revoke
27+
their access would require cycling the access token, which could interrupt the work of other developers and CI
28+
pipelines.
29+
30+
## Access Tokens become CI Access Tokens
31+
32+
What we previously called "access tokens" will now be called "[CI access tokens](/ci/recipes/security/access-tokens)."
33+
They are still defined at the workspace
34+
level, but are designed for use in CI. These tokens should be set as environment variables or secrets on your CI
35+
platform so that they're no longer committed to your repo.
36+
37+
## What are personal access tokens?
38+
39+
[Personal access tokens](/ci/recipes/security/personal-access-tokens) are a new type of access token that is scoped to
40+
an individual user. This means that this token lives and dies with that member's access to your Nx Cloud workspace.
41+
Users must log in to Nx Cloud and they are a member of a workspace before a personal access token can be created.
42+
Once created, we validate that token for access each time you use the distributed cache. As soon as a user loses access,
43+
the personal access token no
44+
longer works, and access to the cache is removed.
45+
46+
This gets even more powerful when combined with the GitHub VCS integration. When a user's GitHub access is removed from
47+
a GitHub-connected organization, their access to Nx Cloud is removed, and their personal access token is invalidated.
48+
This means that Nx Cloud can fit into existing user de-provisioning processes you already have.
49+
50+
Open source teams also benefit from personal access tokens. You can configure your access to allow anonymous users to
51+
read from the cache, but limit read/write access to core contributors.
52+
53+
## Controlling default access
54+
55+
![Personal access token settings in Nx Cloud workspace](/blog/images/2024-09-05/workspace-settings.avif)
56+
57+
By default, a workspace that opts in to personal access tokens will allow anonymous users (users without a personal
58+
access token defined) read-only access. This can be changed to disallow access to the cache for anonymous users
59+
in your workspace settings.
60+
61+
Users with personal access tokens will have read-only access to the cache. This can be changed to enable read-write
62+
access in the workspace settings.
63+
64+
## Converting existing workspaces to use personal access tokens
65+
66+
Personal access tokens can be enabled with _Nx versions 13+_. These steps will get you started, but you
67+
can [find more details in our docs](/ci/recipes/security/personal-access-tokens).
68+
69+
1. **Convert to using `nxCloudId` by running `npx nx-cloud convert-to-nx-cloud-id`** - Previously, your `nx.json` had a
70+
CI
71+
access token defined in the `nxCloudAccessToken` property. This command will replace that with `nxCloudId`, a generic
72+
id that references your workspace but no longer provides access to the cache.
73+
2. **Generate a personal access token by running `npx nx-cloud login`** - Follow the directions in your terminal to log
74+
in
75+
to Nx Cloud. Each contributor with access to the workspace will need to complete this step.
76+
3. **Move CI access tokens to environment variables** - Now that the access token is no longer committed to your
77+
`nx.json`,
78+
you'll need to provide that CI access token via the
79+
`NX_CLOUD_ACCESS_TOKEN` [environment variable](/ci/reference/env-vars#nxcloudaccesstoken).
80+
4. **_Optional_ Disable anonymous access** - By default, anyone without a personal access token will have read-only
81+
access
82+
to your cached artifacts. Once everyone has a personal access token defined, you can disable this anonymous access in
83+
your Nx Cloud workspace settings.
84+
85+
[Learn more about using personal access tokens](/ci/recipes/security/personal-access-tokens)
86+
87+
## Learn more
88+
89+
- [Nx Docs](/getting-started/intro)
90+
- [Nx Cloud Cache Security](/ci/concepts/cache-security)
91+
- [Nx Cloud Personal Access Tokens](/ci/recipes/security/personal-access-tokens)
92+
- [Nx Cloud CI Access Tokens](/ci/recipes/security/access-tokens)
93+
- [X/Twitter](https://twitter.com/nxdevtools) -- [LinkedIn](https://www.linkedin.com/company/nrwl/)
94+
- [Nx GitHub](https://github.com/nrwl/nx)
95+
- [Nx Official Discord Server](https://go.nx.dev/community)
96+
- [Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
97+
- [Speed up your CI](https://nx.app/)
Binary file not shown.
Loading
Binary file not shown.

scripts/documentation/internal-link-checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function readApiJson(manifestFileName: string): string[] {
142142
const anchorUrls = ['nx.json', 'ci.json', 'extending-nx.json'].flatMap(
143143
(manifestFileName) => readApiJson(manifestFileName)
144144
);
145-
const ignoreAnchorUrls = ['/nx-api', '/blog', '/pricing'];
145+
const ignoreAnchorUrls = ['/nx-api', '/blog', '/pricing', '/ci/reference'];
146146

147147
const errors: Array<{ file: string; link: string }> = [];
148148
const localLinkErrors: Array<{ file: string; link: string }> = [];

0 commit comments

Comments
 (0)