Skip to content

Commit 3b3c309

Browse files
authored
Access on Workers docs (#25603)
* Access on Workers docs * Add detail about environment variables and hero image
1 parent 6e9cd78 commit 3b3c309

File tree

4 files changed

+114
-22
lines changed

4 files changed

+114
-22
lines changed
452 KB
Loading
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: One-click Cloudflare Access for Workers
3+
description: You can now enable Cloudflare Access for your workers.dev and preview URLs in a single click.
4+
products:
5+
- workers
6+
date: 2025-10-03
7+
---
8+
9+
import { DashButton } from "~/components";
10+
11+
You can now enable [Cloudflare Access](/cloudflare-one/policies/access/) for your [`workers.dev`](/workers/configuration/routing/workers-dev/) and [Preview URLs](/workers/configuration/previews/) in a single click.
12+
13+
![Screenshot of the Enable/Disable Cloudflare Access button on the workers.dev route settings page](~/assets/images/workers/changelog/workers-access.png)
14+
15+
Access allows you to limit access to your Workers to specific users or groups. You can limit access to yourself, your teammates, your organization, or anyone else you specify in your [Access policy](/cloudflare-one/policies/access).
16+
17+
To enable Cloudflare Access:
18+
19+
1. In the Cloudflare dashboard, go to the **Workers & Pages** page.
20+
21+
<DashButton url="/?to=/:account/workers-and-pages" />
22+
23+
2. In **Overview**, select your Worker.
24+
3. Go to **Settings** > **Domains & Routes**.
25+
4. For `workers.dev` or Preview URLs, click **Enable Cloudflare Access**.
26+
5. Optionally, to configure the Access application, click **Manage Cloudflare Access**. There, you can change the email addresses you want to authorize. View [Access policies](/cloudflare-one/policies/access/#selectors) to learn about configuring alternate rules.
27+
28+
To fully secure your application, it is important that you validate the JWT that Cloudflare Access adds to the `Cf-Access-Jwt-Assertion` header on the incoming request.
29+
30+
The following code will validate the JWT using the [jose NPM package](https://www.npmjs.com/package/jose):
31+
32+
```javascript
33+
import { jwtVerify, createRemoteJWKSet } from "jose";
34+
35+
export default {
36+
async fetch(request, env, ctx) {
37+
// Get the JWT from the request headers
38+
const token = request.headers.get("cf-access-jwt-assertion");
39+
40+
// Check if token exists
41+
if (!token) {
42+
return new Response("Missing required CF Access JWT", {
43+
status: 403,
44+
headers: { "Content-Type": "text/plain" },
45+
});
46+
}
47+
48+
try {
49+
// Create JWKS from your team domain
50+
const JWKS = createRemoteJWKSet(
51+
new URL(`${env.TEAM_DOMAIN}/cdn-cgi/access/certs`),
52+
);
53+
54+
// Verify the JWT
55+
const { payload } = await jwtVerify(token, JWKS, {
56+
issuer: env.TEAM_DOMAIN,
57+
audience: env.POLICY_AUD,
58+
});
59+
60+
// Token is valid, proceed with your application logic
61+
return new Response(`Hello ${payload.email || "authenticated user"}!`, {
62+
headers: { "Content-Type": "text/plain" },
63+
});
64+
} catch (error) {
65+
// Token verification failed
66+
return new Response(`Invalid token: ${error.message}`, {
67+
status: 403,
68+
headers: { "Content-Type": "text/plain" },
69+
});
70+
}
71+
},
72+
};
73+
```
74+
75+
#### Required environment variables
76+
77+
Add these [environment variables](/workers/configuration/environment-variables/) to your Worker:
78+
79+
- `POLICY_AUD`: Your application's AUD tag
80+
- `TEAM_DOMAIN`: `https://<your-team-name>.cloudflareaccess.com`
81+
82+
Both of these appear in the modal that appears when you enable Cloudflare Access.
83+
84+
You can set these variables by adding them to your Worker's [Wrangler configuration file](/workers/wrangler/configuration/), or via the Cloudflare dashboard under **Workers & Pages** > **your-worker** > **Settings** > **Environment Variables**.

src/content/docs/workers/configuration/previews.mdx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The [`wrangler versions upload`](/workers/wrangler/commands/#upload) command upl
6262
<DashButton url="/?to=/:account/workers-and-pages" />
6363

6464
2. Select your Worker.
65-
2. Go to the **Deployments** tab, and find the version you would like to view.
65+
3. Go to the **Deployments** tab, and find the version you would like to view.
6666

6767
### Aliased preview URLs
6868

@@ -97,29 +97,16 @@ The resulting alias would be associated with this version, and immediately avail
9797
When enabled, all preview URLs are available publicly. You can use [Cloudflare Access](/cloudflare-one/policies/access/) to require visitors to authenticate before accessing preview URLs. You can limit access to yourself, your teammates, your organization, or anyone else you specify in your [access policy](/cloudflare-one/policies/access).
9898

9999
To limit your preview URLs to authorized emails only:
100+
100101
1. In the Cloudflare dashboard, go to the **Workers & Pages** page.
101102

102103
<DashButton url="/?to=/:account/workers-and-pages" />
103104

104-
2. Select **Create application**.
105-
3. Select **Self Hosted**.
106-
4. Name your application (for example, "my-worker") and add your `workers.dev` subdomain as the **Application domain**.
107-
108-
For example, if you want to secure preview URLs for a Worker running on `my-worker.my-subdomain.workers.dev`.
109-
110-
- Subdomain: `*-my-worker`
111-
- Domain: `my-subdomain.workers.dev`
112-
113-
:::note
114-
You must press enter after you input your Application domain for it to save. You will see a "Zone is not associated with the current account" warning that you may ignore.
115-
:::
116-
117-
6. Go to the next page.
118-
7. Add a name for your access policy (for example, "Allow employees access to preview URLs for my-worker").
119-
8. In the **Configure rules** section create a new rule with the **Emails** selector, or any other attributes which you wish to gate access to previews with.
120-
9. Enter the emails you want to authorize. View [access policies](/cloudflare-one/policies/access/#selectors) to learn about configuring alternate rules.
121-
10. Go to the next page.
122-
11. Add application.
105+
2. In **Overview**, select your Worker.
106+
3. Go to **Settings** > **Domains & Routes**.
107+
4. For Preview URLs, click **Enable Cloudflare Access**.
108+
5. Optionally, to configure the Access application, click **Manage Cloudflare Access**. There, you can change the email addresses you want to authorize. View [Access policies](/cloudflare-one/policies/access/#selectors) to learn about configuring alternate rules.
109+
6. [Validate the Access JWT](https://developers.cloudflare.com/cloudflare-one/identity/authorization-cookie/validating-json/#cloudflare-workers-example) in your Worker script using the audience (`aud`) tag and JWKs URL provided.
123110

124111
## Toggle Preview URLs (Enable or Disable)
125112

@@ -131,6 +118,7 @@ Note:
131118
### From the Dashboard
132119

133120
To toggle Preview URLs for a Worker:
121+
134122
1. In the Cloudflare dashboard, go to the **Workers & Pages** page.
135123

136124
<DashButton url="/?to=/:account/workers-and-pages" />
@@ -153,15 +141,19 @@ Older Wrangler versions will default to Preview URLs being enabled.
153141
To toggle Preview URLs for a Worker, include any of the following in your Worker's Wrangler file:
154142

155143
<WranglerConfig>
144+
156145
```toml
157146
preview_urls = true
158147
```
148+
159149
</WranglerConfig>
160150

161151
<WranglerConfig>
152+
162153
```toml
163154
preview_urls = false
164155
```
156+
165157
</WranglerConfig>
166158

167159
If not given, `preview_urls = false` is the default.
@@ -175,4 +167,4 @@ If you enable or disable Preview URLs in the Cloudflare dashboard, but do not up
175167
- Preview URLs are not generated for Workers that implement a [Durable Object](/durable-objects/).
176168
- Preview URLs are not currently generated for [Workers for Platforms](/cloudflare-for-platforms/workers-for-platforms/) [user Workers](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#user-workers). This is a temporary limitation, we are working to remove it.
177169
- You cannot currently configure Preview URLs to run on a subdomain other than [`workers.dev`](/workers/configuration/routing/workers-dev/).
178-
- You cannot view logs for Preview URLs today, this includes Workers Logs, Wrangler tail and Logpush.
170+
- You cannot view logs for Preview URLs today, this includes Workers Logs, Wrangler tail and Logpush.

src/content/docs/workers/configuration/routing/workers-dev.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ It's recommended to run production Workers on a [Workers route or custom domain]
2121

2222
All Workers are assigned a `workers.dev` route when they are created or renamed following the syntax `<YOUR_WORKER_NAME>.<YOUR_SUBDOMAIN>.workers.dev`. The [`name`](/workers/wrangler/configuration/#inheritable-keys) field in your Worker configuration is used as the subdomain for the deployed Worker.
2323

24+
## Manage access to `workers.dev`
25+
26+
When enabled, your `workers.dev` URL is available publicly. You can use [Cloudflare Access](/cloudflare-one/policies/access/) to require visitors to authenticate before accessing preview URLs. You can limit access to yourself, your teammates, your organization, or anyone else you specify in your [access policy](/cloudflare-one/policies/access).
27+
28+
To limit your `workers.dev` URL to authorized emails only:
29+
30+
1. In the Cloudflare dashboard, go to the **Workers & Pages** page.
31+
32+
<DashButton url="/?to=/:account/workers-and-pages" />
33+
34+
2. In **Overview**, select your Worker.
35+
3. Go to **Settings** > **Domains & Routes**.
36+
4. For `workers.dev`, click **Enable Cloudflare Access**.
37+
5. Optionally, to configure the Access application, click **Manage Cloudflare Access**. There, you can change the email addresses you want to authorize. View [Access policies](/cloudflare-one/policies/access/#selectors) to learn about configuring alternate rules.
38+
6. [Validate the Access JWT](https://developers.cloudflare.com/cloudflare-one/identity/authorization-cookie/validating-json/#cloudflare-workers-example) in your Worker script using the audience (`aud`) tag and JWKs URL provided.
39+
2440
## Disabling `workers.dev`
2541

2642
### Disabling `workers.dev` in the dashboard
@@ -38,7 +54,7 @@ To disable the `workers.dev` route for a Worker:
3854

3955
### Disabling `workers.dev` in the Wrangler configuration file
4056

41-
To disable the `workers.dev` route for a Worker, include the following in your Worker's [Wrangler configuration file](/workers/wrangler/configuration/):
57+
To disable the `workers.dev` route for a Worker, include the following in your Worker's [Wrangler configuration file](/workers/wrangler/configuration/):
4258

4359
<WranglerConfig>
4460

0 commit comments

Comments
 (0)