---
url: /en/docs/additions/setup.md
description: >-
  Deploy Sveltia CMS Additions to Cloudflare Workers for free, connect your CMS,
  run the setup wizard and secure your GitHub repository with our checklist.
---

# Setting Up Sveltia CMS Additions

Setting up [Sveltia CMS Additions](/en/docs/additions) takes four steps:

1. [Deploy the Worker](#deploying-the-worker) to Cloudflare and [turn on its URL](#turning-on-the-worker-s-url).
2. [Point the CMS at it](#configuring-the-cms) in your CMS configuration.
3. [Run the setup wizard](#running-the-setup-wizard) to create the first admin and connect GitHub.
4. [Go through the security checklist](#security-checklist).

With the Deploy button, you won’t need the command line.

## Deploying the Worker

Click the button below:

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/sveltia/sveltia-cms-additions/tree/main/templates/cloudflare)

It copies a small repository into your GitHub account, creates the Durable Object that stores the data, and deploys the Worker with [Workers Builds](https://developers.cloudflare.com/workers/ci-cd/builds/). The repository only holds configuration: the code comes from the `@sveltia/cms-additions` npm package.

The button asks for one value, `ADMIN_SECRET`. Generate a random one with:

```sh
openssl rand -base64 32
```

Keep the admin secret in a password manager. It unlocks the setup wizard, and the data the service stores is encrypted with a key that it protects. It must be at least 32 characters long.

::: details Deploying from your computer

Copy the [`templates/cloudflare`](https://github.com/sveltia/sveltia-cms-additions/tree/main/templates/cloudflare) folder of the Sveltia CMS Additions repository, then run:

```sh
pnpm install
pnpm exec wrangler secret put ADMIN_SECRET
pnpm run deploy
```

:::

### Turning On the Worker’s URL

The Deploy button deploys the Worker, but Cloudflare may leave its `workers.dev` URL turned off, so nothing can reach it yet. In the [Cloudflare dashboard](https://dash.cloudflare.com/), open **Workers & Pages**, select the Worker, go to **Domains**, and turn on the **Production** URL. The **Preview** URL isn’t needed and can stay off.

Note the Worker’s URL, e.g. `https://sveltia-cms-additions.example.workers.dev`. You can also add a [custom domain](https://developers.cloudflare.com/workers/configuration/routing/custom-domains/) on the same page and use that instead.

## Configuring the CMS

In your CMS configuration, use the [GitHub backend](/en/docs/backends/github) with `auth_type: additions`, and set `base_url` to the Worker’s URL:

::: code-group

```yaml [YAML]{5-6}
backend:
  name: github
  repo: owner/repo
  branch: main
  auth_type: additions
  base_url: https://sveltia-cms-additions.example.workers.dev
```

```toml [TOML]{5-6}
[backend]
name = "github"
repo = "owner/repo"
branch = "main"
auth_type = "additions"
base_url = "https://sveltia-cms-additions.example.workers.dev"
```

```json [JSON]{6-7}
{
  "backend": {
    "name": "github",
    "repo": "owner/repo",
    "branch": "main",
    "auth_type": "additions",
    "base_url": "https://sveltia-cms-additions.example.workers.dev"
  }
}
```

```js [JavaScript]{6-7}
{
  backend: {
    name: "github",
    repo: "owner/repo",
    branch: "main",
    auth_type: "additions",
    base_url: "https://sveltia-cms-additions.example.workers.dev",
  },
}
```

:::

`base_url` is required with `auth_type: additions`.

The CMS loads the code for Sveltia CMS Additions only when `auth_type` is `additions`, so sites that don’t use it don’t download it.

::: tip Content Security Policy

If the CMS page has a [Content Security Policy](/en/docs/security#setting-up-content-security-policy), allow the Worker’s origin in `connect-src` twice: with `https:` for requests, and with `wss:` for the connection that keeps locks and comments up to date. For example:

```http
Content-Security-Policy: connect-src 'self' https://sveltia-cms-additions.example.workers.dev wss://sveltia-cms-additions.example.workers.dev …
```

Keep the other origins the policy already allows, such as `https://api.github.com`. Without the Worker’s origins, the browser blocks the CMS from reaching the service, and signing in fails. The [CSP builder](/en/docs/security#setting-up-content-security-policy) adds them for you: select **GitHub with Sveltia CMS Additions** and enter your Worker URL.

:::

## Running the Setup Wizard

Open the CMS and select **Use Admin Secret** on the sign-in page, then enter the admin secret. The wizard has two steps:

1. It creates the first admin account, and adds the site’s domain to the [allowed domains](/en/docs/additions/administration#domains).
2. It creates a GitHub App for the site, and asks you to install it. Install it on **Only select repositories**, with just the site’s repository.

It shows one step at a time. Once both are done, opening it again with the admin secret shows a summary instead, where **Reset Admin Password** sets a new password for an admin who can’t sign in.

GitHub then sends you back to the CMS. Sign in with the admin account you’ve just created, and open **Administration** in the toolbar to [add people](/en/docs/additions/users#adding-users).

::: tip

To try the CMS on your computer as well, add `localhost` to the [allowed domains](/en/docs/additions/administration#domains). Without it, the service refuses requests from a local development server.

:::

### Getting Back In

The same wizard gets you back in when no admin can sign in:

* **Forgotten admin password:** open the wizard with the admin secret, and reset the password of an admin or create a new admin.
* **Lost admin secret:** set a new one in the Cloudflare dashboard, open the wizard with it, and select **Start Over**. Passwords are kept, but everyone is signed out, and you need to [upload the GitHub App’s private key](/en/docs/additions/administration#github) again, as the stored secrets can’t be read without the old admin secret.
* **Changed admin secret:** if you replace the admin secret but still know the old one, the wizard asks for it and keeps everything as it is. Nobody is signed out.

Wrong admin secrets are rate limited, for each visitor and for everyone together, so repeated guesses can lock the wizard for up to 10 minutes, even for the right secret. Try again later.

## Security Checklist

Sveltia CMS Additions hands out tokens that can write to your repository, so take a few minutes to secure the accounts and the repository around it:

1. Turn on two-factor authentication for your Cloudflare and GitHub accounts. Give Cloudflare members the smallest role that works, and scope API tokens.
2. Keep `ADMIN_SECRET` in a password manager, and nowhere else.
3. Make sure the GitHub App is installed on the site’s repository only.
4. Add a [ruleset](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets) to the repository that blocks force pushes and restricts deletions on the default branch and on tags, without the app on its bypass list. The [GitHub section](/en/docs/additions/administration#github) of the Administration page warns you until there is one.
5. Move deployment secrets to environment secrets limited to protected branches, so a change pushed through the CMS can’t reach them.
6. Check the [allowed domains](/en/docs/additions/administration#domains). List only sites you control, prefer exact host names to wildcards, and never use a wildcard on a domain where anyone can get a subdomain.
7. Pin the version of Sveltia CMS your site loads, and add a [Content Security Policy](/en/docs/security#setting-up-content-security-policy) to the CMS page.
8. Watch the [Sveltia CMS Additions releases](https://github.com/sveltia/sveltia-cms-additions/releases), and [update](#updating) when the Administration page says a new version is out.

## Updating

Dependabot opens a pull request in your copy of the repository when a new version is released. Merge it, and Workers Builds deploys the update. You can also change the version of `@sveltia/cms-additions` in its `package.json` yourself.

Don’t change `wrangler.jsonc` unless the release notes ask you to. The service applies its own database changes after an update, so there’s nothing else to run.

When a new version is out, admins see a notice with a link to the release notes on the [Administration page](/en/docs/additions/administration).

## Renaming or Moving the Repository

Renaming the repository doesn’t break anything: the service knows it by its ID and picks up the new name, which the [GitHub section](/en/docs/additions/administration#github) of the Administration page then shows. Change `repo` in the CMS configuration to the new name as well, because GitHub redirects the old name only until another repository takes it.

Moving the repository to another owner takes it out of the GitHub App’s installation. Install the app for the new owner, with the repository selected, then run the setup wizard again to record the installation.

## Several Sites on One Worker

A single Worker can serve several sites, e.g. an agency’s clients. Each site is a *tenant* with its own users, sessions, settings, GitHub App and data, kept in storage no other tenant can reach. The site you set up above is the *default* tenant, served at the root of the Worker. Other tenants are served under `/t/<ID>`.

### Adding a Site

Manage the tenants in the setup wizard of the default tenant’s CMS: select **Use Admin Secret** on its sign-in page, enter the admin secret, and select **Manage Other Sites**. It lists the other tenants, and lets you add one with an ID and an optional name. The ID has 1 to 32 lowercase letters, digits and hyphens, and becomes part of the tenant’s URL, so it can’t be changed later.

It shows each tenant’s URL, with a button to copy it. The URL becomes the `base_url` in that site’s CMS configuration:

::: code-group

```yaml [YAML]{5}
backend:
  name: github
  repo: acme/website
  auth_type: additions
  base_url: https://sveltia-cms-additions.example.workers.dev/t/acme
```

```toml [TOML]{5}
[backend]
name = "github"
repo = "acme/website"
auth_type = "additions"
base_url = "https://sveltia-cms-additions.example.workers.dev/t/acme"
```

```json [JSON]{6}
{
  "backend": {
    "name": "github",
    "repo": "acme/website",
    "auth_type": "additions",
    "base_url": "https://sveltia-cms-additions.example.workers.dev/t/acme"
  }
}
```

```js [JavaScript]{6}
{
  backend: {
    name: "github",
    repo: "acme/website",
    auth_type: "additions",
    base_url: "https://sveltia-cms-additions.example.workers.dev/t/acme",
  },
}
```

:::

Then run the [setup wizard](#running-the-setup-wizard) in that site’s CMS. It creates the site’s first admin and its own GitHub App.

### Managing Users of Each Site

Each tenant’s admins manage its users on the [Administration page](/en/docs/additions/administration) of that site’s CMS, as on a single site. An admin of one tenant can’t see or manage the others, so to manage several sites yourself, add yourself as an admin to each. If nobody can sign in to a tenant any more, its setup wizard gets you back in with the admin secret, as described in [Getting Back In](#getting-back-in).

### Deleting a Site

To delete a tenant, select the delete button next to it under **Manage Other Sites**, and type its ID to confirm. Its users, settings and comments are deleted, which can’t be undone. Its GitHub App stays on GitHub, where you can delete it in the app’s settings.

### Limits and Alternatives

The tenants share the admin secret and the Free plan’s allowances. If you change `ADMIN_SECRET`, open the setup wizard of every tenant with the new secret, so each one keeps its data.

To keep clients apart at the Cloudflare account level as well, deploy a separate Worker for each instead, giving each its own Worker name. The Deploy button asks for it; from your computer, change `name` in `wrangler.jsonc` before the first deploy.
