Skip to content

Commit 9adf5a2

Browse files
docs(cloudflare): document populateCache setup behind Cloudflare Access (#218)
1 parent 7c8a550 commit 9adf5a2

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

pages/cloudflare/cli.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,43 @@ The `populateCache` command supports R2 batching to speed up the upload of large
3636

3737
</Callout>
3838

39+
#### Populating remote bindings when Workers are protected by Cloudflare Access
40+
41+
`populateCache remote` (also called implicitly by `deploy` and `upload`) temporarily deploys a helper Worker named `open-next-cache-populate` at `open-next-cache-populate.<account>.workers.dev` and uses it to write to your remote R2 bucket.
42+
43+
If your account's `workers.dev` subdomain — or a parent route on a custom domain — is protected by [Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/applications/), the helper Worker is protected by the same policy and the upload fails with either:
44+
45+
```text
46+
Failed to send request to R2 worker: The operation was aborted due to timeout.
47+
```
48+
49+
or a `403 Forbidden` returned by the Access edge.
50+
51+
To let the adapter authenticate:
52+
53+
1. Open the **existing** Cloudflare Access application that already covers `open-next-cache-populate.<account>.workers.dev` — typically the wildcard application for `*.<account>.workers.dev` — and attach the policy described below to that application.
54+
55+
<Callout type="warning">
56+
Creating a separate Access application scoped specifically to the `open-next-cache-populate` hostname has
57+
been observed to block the upload, even when kept alongside the existing wildcard application (see
58+
[#1171](https://github.com/opennextjs/opennextjs-cloudflare/issues/1171)). Prefer attaching the policy to
59+
the existing application that already protects the hostname.
60+
</Callout>
61+
62+
2. Add a **Service Auth** policy to that application:
63+
64+
- Set the policy **Action** to "Service Auth".
65+
- Add an **Include** rule for "Any Access Service Token", or for a specific service token.
66+
67+
3. Create the service token under Zero Trust → Access → Service Auth → Service Tokens, then expose its credentials to the environment that runs `opennextjs-cloudflare`:
68+
69+
```sh
70+
export CLOUDFLARE_ACCESS_CLIENT_ID=<id>
71+
export CLOUDFLARE_ACCESS_CLIENT_SECRET=<secret>
72+
```
73+
74+
Then run `opennextjs-cloudflare populateCache remote` (or `deploy` / `upload`). In CI, set the two values as secrets and expose them to the deploy step.
75+
3976
### `preview` command
4077

4178
It starts by populating the local cache and then launches a local development server (via `wrangler dev`) so that you can preview the application locally.

pages/cloudflare/troubleshooting.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,9 @@ To fix this issue, update your `compatibility_date` in `wrangler.toml` or `wrang
135135
```
136136

137137
Refer to the [Cloudflare Workers compatibility flags documentation](https://developers.cloudflare.com/workers/configuration/compatibility-flags/#enable-finalizationregistry-and-weakref) for more details.
138+
139+
### `Failed to send request to R2 worker` or `Could not determine Cloudflare auth credentials after login`
140+
141+
These errors come from `populateCache remote` (called implicitly by `deploy` and `upload`) when the temporary `open-next-cache-populate.<account>.workers.dev` helper Worker is fronted by a Cloudflare Access application.
142+
143+
See [Populating remote bindings when Workers are protected by Cloudflare Access](/cloudflare/cli#populating-remote-bindings-when-workers-are-protected-by-cloudflare-access) for setup steps.

0 commit comments

Comments
 (0)