-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Access on Workers docs #25603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Access on Workers docs #25603
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions
84
src/content/changelog/workers/2025-10-03-one-click-access-for-workers.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| title: One-click Cloudflare Access for Workers | ||
| description: You can now enable Cloudflare Access for your workers.dev and preview URLs in a single click. | ||
| products: | ||
| - workers | ||
| date: 2025-10-03 | ||
| --- | ||
|
|
||
| import { DashButton } from "~/components"; | ||
|
|
||
| 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. | ||
|
|
||
|  | ||
|
|
||
| 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). | ||
|
|
||
| To enable Cloudflare Access: | ||
|
|
||
| 1. In the Cloudflare dashboard, go to the **Workers & Pages** page. | ||
|
|
||
| <DashButton url="/?to=/:account/workers-and-pages" /> | ||
|
|
||
| 2. In **Overview**, select your Worker. | ||
| 3. Go to **Settings** > **Domains & Routes**. | ||
| 4. For `workers.dev` or Preview URLs, click **Enable Cloudflare Access**. | ||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| The following code will validate the JWT using the [jose NPM package](https://www.npmjs.com/package/jose): | ||
|
|
||
| ```javascript | ||
| import { jwtVerify, createRemoteJWKSet } from "jose"; | ||
|
|
||
| export default { | ||
| async fetch(request, env, ctx) { | ||
| // Get the JWT from the request headers | ||
| const token = request.headers.get("cf-access-jwt-assertion"); | ||
|
|
||
| // Check if token exists | ||
| if (!token) { | ||
| return new Response("Missing required CF Access JWT", { | ||
| status: 403, | ||
| headers: { "Content-Type": "text/plain" }, | ||
| }); | ||
| } | ||
|
|
||
| try { | ||
| // Create JWKS from your team domain | ||
| const JWKS = createRemoteJWKSet( | ||
| new URL(`${env.TEAM_DOMAIN}/cdn-cgi/access/certs`), | ||
| ); | ||
|
|
||
| // Verify the JWT | ||
| const { payload } = await jwtVerify(token, JWKS, { | ||
| issuer: env.TEAM_DOMAIN, | ||
| audience: env.POLICY_AUD, | ||
| }); | ||
|
|
||
| // Token is valid, proceed with your application logic | ||
| return new Response(`Hello ${payload.email || "authenticated user"}!`, { | ||
| headers: { "Content-Type": "text/plain" }, | ||
| }); | ||
| } catch (error) { | ||
| // Token verification failed | ||
| return new Response(`Invalid token: ${error.message}`, { | ||
| status: 403, | ||
| headers: { "Content-Type": "text/plain" }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| #### Required environment variables | ||
|
|
||
| Add these [environment variables](/workers/configuration/environment-variables/) to your Worker: | ||
|
|
||
| - `POLICY_AUD`: Your application's AUD tag | ||
| - `TEAM_DOMAIN`: `https://<your-team-name>.cloudflareaccess.com` | ||
|
|
||
| Both of these appear in the modal that appears when you enable Cloudflare Access. | ||
|
|
||
| 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**. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,22 @@ It's recommended to run production Workers on a [Workers route or custom domain] | |
|
|
||
| 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. | ||
|
|
||
| ## Manage access to `workers.dev` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one adding this here |
||
|
|
||
| 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). | ||
|
|
||
| To limit your `workers.dev` URL to authorized emails only: | ||
|
|
||
| 1. In the Cloudflare dashboard, go to the **Workers & Pages** page. | ||
|
|
||
| <DashButton url="/?to=/:account/workers-and-pages" /> | ||
|
|
||
| 2. In **Overview**, select your Worker. | ||
| 3. Go to **Settings** > **Domains & Routes**. | ||
| 4. For `workers.dev`, click **Enable Cloudflare Access**. | ||
| 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. | ||
| 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. | ||
|
|
||
| ## Disabling `workers.dev` | ||
|
|
||
| ### Disabling `workers.dev` in the dashboard | ||
|
|
@@ -38,7 +54,7 @@ To disable the `workers.dev` route for a Worker: | |
|
|
||
| ### Disabling `workers.dev` in the Wrangler configuration file | ||
|
|
||
| To disable the `workers.dev` route for a Worker, include the following in your Worker's [Wrangler configuration file](/workers/wrangler/configuration/): | ||
| To disable the `workers.dev` route for a Worker, include the following in your Worker's [Wrangler configuration file](/workers/wrangler/configuration/): | ||
|
|
||
| <WranglerConfig> | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like including the code snippet in the changelog, and the guidance
If we are going to do that we might need to guide people though on (1) where these env vars come from and (2) how to set them
https://developers.cloudflare.com/cloudflare-one/identity/authorization-cookie/validating-json/#required-environment-variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or alternatively — just link there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, sorry, missed those from my copy-paste of your code snippet. Adding now! (I think good to copy rather than just link so it's all in one place and pads the changelog out a bit).