Setting Up Sveltia CMS Additions
Setting up Sveltia CMS Additions takes four steps:
- Deploy the Worker to Cloudflare and turn on its URL.
- Point the CMS at it in your CMS configuration.
- Run the setup wizard to create the first admin and connect GitHub.
- Go through the security checklist.
With the Deploy button, you won’t need the command line.
Deploying the Worker
Click the button below:
It copies a small repository into your GitHub account, creates the Durable Object that stores the data, and deploys the Worker with Workers 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:
openssl rand -base64 32Keep 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.
Deploying from your computer
Copy the templates/cloudflare folder of the Sveltia CMS Additions repository, then run:
pnpm install
pnpm exec wrangler secret put ADMIN_SECRET
pnpm run deployTurning 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, 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 on the same page and use that instead.
Configuring the CMS
In your CMS configuration, use the GitHub backend with auth_type: additions, and set base_url to the Worker’s URL:
backend:
name: github
repo: owner/repo
branch: main
auth_type: additions
base_url: https://sveltia-cms-additions.example.workers.dev[backend]
name = "github"
repo = "owner/repo"
branch = "main"
auth_type = "additions"
base_url = "https://sveltia-cms-additions.example.workers.dev"{
"backend": {
"name": "github",
"repo": "owner/repo",
"branch": "main",
"auth_type": "additions",
"base_url": "https://sveltia-cms-additions.example.workers.dev"
}
}{
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.
Content Security Policy
If the CMS page has a 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:
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 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:
- It creates the first admin account, and adds the site’s domain to the allowed domains.
- 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.
TIP
To try the CMS on your computer as well, add localhost to the allowed 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 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:
- Turn on two-factor authentication for your Cloudflare and GitHub accounts. Give Cloudflare members the smallest role that works, and scope API tokens.
- Keep
ADMIN_SECRETin a password manager, and nowhere else. - Make sure the GitHub App is installed on the site’s repository only.
- Add a ruleset 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 of the Administration page warns you until there is one.
- Move deployment secrets to environment secrets limited to protected branches, so a change pushed through the CMS can’t reach them.
- Check the allowed 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.
- Pin the version of Sveltia CMS your site loads, and add a Content Security Policy to the CMS page.
- Watch the Sveltia CMS Additions releases, and update 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.
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 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:
backend:
name: github
repo: acme/website
auth_type: additions
base_url: https://sveltia-cms-additions.example.workers.dev/t/acme[backend]
name = "github"
repo = "acme/website"
auth_type = "additions"
base_url = "https://sveltia-cms-additions.example.workers.dev/t/acme"{
"backend": {
"name": "github",
"repo": "acme/website",
"auth_type": "additions",
"base_url": "https://sveltia-cms-additions.example.workers.dev/t/acme"
}
}{
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 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 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.
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.