Skip to content

VitePress (Private) with Cloudflare Zero Trust

This guide explains how to secure your VitePress site using Cloudflare Zero Trust. This setup ensures that only authorized users can view your documentation, which is ideal for internal team wikis or private projects.

Before starting, ensure you have already deployed your site by following this guide.

Enable Zero Trust

Log in to your Cloudflare dashboard and select Zero Trust from the left sidebar under the "Protect & Connect" section. If this is your first time using it, you will be prompted to choose a team name and a plan. The free plan is more than sufficient for most private documentation needs.

Add an Access Application

Navigate to Access controls and then Applications in the Zero Trust sidebar. Click the Add an application button and select the Self-hosted option.

Provide an application name such as "Private Docs" and set the session duration to your preference. Click the Add public hostname button, and enter the subdomain and domain that matches your VitePress Pages project. Cloudflare will automatically detect if the domain is already managed in your account.

(Optional) Configure Authentication

Cloudflare allows you to choose how users verify their identity. By default, it uses a one-time PIN sent to the user's email. You can manage these settings under Settings and then Authentication in the Zero Trust dashboard. You can also connect other providers like Google or GitHub if you prefer social logins.

Define the Access Policy

The policy determines exactly who is allowed to enter the site. During the application setup, you will reach the Access policies step. Give your policy a name like "Team Access" and ensure the action is set to Allow.

In the Add rules section, select Emails or Email ending in from the selector. Enter the specific email addresses or the company domain allowed to access the documentation. You can add multiple criteria, such as requiring a specific country or a valid certificate, to further harden the security.

Verify the Setup

Once you save the application, open a private or incognito browser window and navigate to your VitePress URL. Instead of your documentation, you should now be greeted by a Cloudflare login page. Enter an authorized email address and verify that you can successfully log in with the PIN sent to your inbox.