-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support cloudflare access (#348)
Co-authored-by: Sébastien Chopin <seb@nuxt.com>
- Loading branch information
1 parent
6556a74
commit 713bcb9
Showing
15 changed files
with
233 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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,116 @@ | ||
--- | ||
title: Cloudflare Access Integration | ||
navigation.title: Cloudflare Access | ||
description: Learn how to use Cloudflare Access to protect your Nuxt application deployed on Cloudflare Pages. | ||
--- | ||
|
||
[Cloudflare Access](https://www.cloudflare.com/zero-trust/products/access/) allows you to secure your web applications by restricting who can reach your application by applying configured identity-aware Access policies. Cloudflare Access is part of [Cloudflare's Zero Trust](https://www.cloudflare.com/plans/zero-trust-services/) offerings. | ||
|
||
NuxtHub fully supports Cloudflare Access across the NuxtHub admin, module and CLI. | ||
|
||
## Setup Cloudflare Access | ||
|
||
These steps covers setting up Cloudflare Access for a deployed NuxtHub project. | ||
|
||
::important{to="#nuxtdev-subdomain-with-cloudflare-access"} | ||
When using Cloudflare Access with NuxtHub, the nuxt.dev subdomain is unavailable due to a Cloudflare limitation. [Learn more](#nuxtdev-subdomain-with-cloudflare-access). | ||
:: | ||
|
||
1. Create a Cloudflare Access [service token](https://developers.cloudflare.com/cloudflare-one/identity/service-tokens/) in the [Cloudflare Zero Trust dashboard](https://one.dash.cloudflare.com/) | ||
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to Access → Service Auth → Service Tokens | ||
2. Select Create Service Token | ||
3. Name the service token. For example, the NuxtHub project's name | ||
- The name allows you to easily identify events related to the token in the logs | ||
4. Choose a Service Token Duration. This sets the expiration date for the token | ||
5. Select Generate token. You will see the generated Client ID and Client Secret for the service token | ||
::warning | ||
This is the only time Cloudflare Access will display the Client Secret. If you lose the Client Secret, you will need to rotate the service token | ||
:: | ||
2. Configure the Cloudflare Access integration within [NuxtHub admin](https://admin.hub.nuxt.com/) | ||
1. In the [NuxtHub admin](https://admin.hub.nuxt.com/), go to Projects → Settings → General → Cloudflare Access | ||
2. Provide the Client ID and Client Secret generated in the previous step | ||
3. Enable Cloudflare Access on the Pages project | ||
1. On the [Cloudflare dashboard](https://dash.cloudflare.com/login?to=/:account/workers-and-pages) → Workers & Pages → Your Pages project | ||
2. Go to Settings → General → Access Policy | ||
3. Select Enable to create a Cloudflare Access application. | ||
::note | ||
The default policy covers the preview environments on the `pages.dev` subdomain, adds an allow policy with all members of the account, and uses the email one-time-pin IdP. | ||
:: | ||
4. Add an Access policy to permit the service token | ||
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to Access → Applications and select the application | ||
2. Create a new policy with the name "NuxtHub" and the action Service Auth | ||
3. Enable the 401 Response boolean | ||
4. Within Configure rules, set Selector to Service Token and the value to the service token created earlier | ||
5. Save the policy | ||
5. Optionally edit your Allow Access policy | ||
::callout{to="https://developers.cloudflare.com/cloudflare-one/policies/access/#allow"} | ||
Learn more about Cloudflare Access policies on Cloudflare's documentation. | ||
:: | ||
6. Optionally add additional domains to your Access application | ||
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to Access → Applications and select the application | ||
2. From the header, select Overview | ||
3. Add additional application domains, such as the production domain, or any custom domains assigned to the project | ||
|
||
### Importing Pages projects | ||
|
||
We plan to directly support importing existing Pages projects that are protected with Cloudflare Access enabled in the future. | ||
|
||
Currently, you will need to temporarily create an Access application which sets a Bypass policy for Everyone on the project's default pages.dev domain and the path `/api/_hub/manifest`. | ||
|
||
## Service token expiry and rotation | ||
|
||
### Service token expiry | ||
|
||
When a service token is expired, it can be rotated from the Cloudflare dashboard. | ||
|
||
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to Access → Service Auth → Service Tokens | ||
2. Click `...` on the expired token | ||
3. Select Rotate | ||
|
||
::tip | ||
The duration of active service tokens can be extended by refreshing it from the Zero Trust dashboard | ||
:: | ||
|
||
### Service token rotation | ||
|
||
If a service token is rotated, the new Client Secret needs to be provided on [NuxtHub admin](https://admin.hub.nuxt.com/). | ||
1. In the [NuxtHub admin](https://admin.hub.nuxt.com/), go to Projects → Settings → General → Cloudflare Access | ||
2. Click Disable integration | ||
3. Provide the Client ID and Client Secret generated in the previous step | ||
4. Click Enable integration | ||
|
||
## Remote storage | ||
|
||
These steps will cover using [remote storage](/docs/getting-started/remote-storage) with an environment protected by Cloudflare Access. | ||
|
||
1. Open `.env` | ||
2. Set the following variables with your service token's Client ID and Client Secret | ||
- `NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_ID` | ||
- `NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET` | ||
|
||
::note | ||
A separate service token can optionally be created only for local development | ||
:: | ||
|
||
|
||
::tip | ||
No configuration is required if using [Cloudflare WARP](https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/) with Cloudflare Zero Trust, as WARP handles authenticating with Cloudflare Access | ||
:: | ||
|
||
## CLI | ||
|
||
The following environment variables can be passed to the CLI | ||
- `NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_ID` | ||
- `NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET` | ||
|
||
```bash [Terminal] | ||
export NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_ID="" | ||
export NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET="" | ||
npx nuxthub database migrations list --preview | ||
``` | ||
|
||
## `nuxt.dev` subdomain with Cloudflare Access | ||
|
||
Due to a technical Cloudflare limitation, when using Cloudflare Access with NuxtHub, the nuxt.dev subdomain is unavailable. | ||
|
||
If the nuxt.dev subdomain is the primary domain, enabling the Cloudflare Access integration will set the primary domain to the pages.dev subdomain. |
This file contains 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,32 @@ | ||
--- | ||
title: Cloudflare Access integration | ||
description: "We now support Cloudflare Access within NuxtHub admin, module and CLI" | ||
date: 2024-10-29 | ||
image: '/images/changelog/cloudflare-access.png' | ||
authors: | ||
- name: Rihan Arfan | ||
avatar: | ||
src: https://avatars.githubusercontent.com/u/20425781?v=4 | ||
to: https://x.com/RihanArfan | ||
username: RihanArfan | ||
--- | ||
|
||
::tip | ||
This feature is available on all [NuxtHub plans](/pricing) and comes with the [v0.8.4](https://github.com/nuxt-hub/core/releases/tag/v0.8.4) release of `@nuxthub/core`. | ||
:: | ||
|
||
We now fully support Cloudflare Access across admin, module and CLI. | ||
|
||
## What is Cloudflare Access | ||
|
||
:nuxt-img{src="/images/changelog/cloudflare-access.png" alt="Cloudflare Access" width="915" height="515"} | ||
|
||
[Cloudflare Access](https://www.cloudflare.com/zero-trust/products/access/) allows you to secure your web applications by restricting who can reach your application by applying configured identity-aware Access policies. Cloudflare Access is part of [Cloudflare's Zero Trust](https://www.cloudflare.com/plans/zero-trust-services/) offerings. | ||
|
||
## What does this mean for NuxtHub | ||
|
||
This enables you to create secure internal web applications on NuxtHub, without compromising on features like NuxtHub admin for management and remote storage during development. | ||
|
||
::callout{to="/docs/recipes/cloudflare-access" icon="i-ph-book-open-duotone"} | ||
Learn more about enabling Cloudflare Access with NuxtHub. | ||
:: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.