Installing cpKamra

A simplified guide to setting up the full system, and single-server mode for one or two servers. The less common cases (installing without Docker, troubleshooting) are in the project wiki.

Which setup should you choose?

Full system: for several cPanel servers and for hosting providers. The cPanel servers can only append to their backups, there is a central dashboard, key escrow and alerting, and accounts can be transferred from one server to another. It has three parts: the controller, the storage server with a maintenance node, and the agent on every cPanel server. Install them in this order, because every later step needs a token or an address from an earlier one.

Single-server mode: for one or two servers that back up to a storage-only target (SFTP storage such as a NAS, or an S3-compatible bucket). There is no controller and no maintenance node; the agent does the maintenance itself. For this the agent needs delete permission, so the backups have to be protected on the storage side. If you choose this, skip to single-server mode. You can move to the full system later without moving any data.

The examples use these names; replace them with your own:

Example Meaning
backup-ctl.example.net the controller, as the cPanel servers and the storage server reach it
backup-dash.example.net the dashboard behind the TLS reverse proxy
backup1.example.net the storage server
storage1 the name of the backup destination
storage1-maint the name of the maintenance node
cp01 the ID of a cPanel server (server_id)

What you will need

  • Controller: a Linux machine with Docker Engine and the Compose plugin, a DNS name the other machines can reach it by, and a TLS reverse proxy (Caddy, nginx, Traefik) in front of the dashboard. The Docker images are built for amd64; on an aarch64 machine, use the packages.
  • Storage server: a Linux machine with Docker, with enough disk for the backups in one directory (/srv/backup in the examples).
  • cPanel servers: cPanel & WHM with the Jupiter theme, on AlmaLinux, CloudLinux or RHEL 8/9, on an x86_64 or aarch64 processor, with root access.

The network connections needed:

From To Port For
cPanel servers controller 8443/tcp agent API (mTLS)
storage server controller 8443/tcp maintenance API (mTLS)
cPanel servers storage server 8000/tcp backups (rest-server)
admins reverse proxy 443/tcp dashboard

Every part of cpKamra is published signed at https://repo.csb-it.hu: a dnf package repository for EL8–EL10, an apt package repository for Debian 13, and under /releases/v<version>/ every file of a release, including the Docker installation bundle. The current version is shown on the home page of the project wiki.

Compare the keys you download with these fingerprints before you trust them:

Key Fingerprint
GPG release key (packages, package repository) 350C 4B79 8571 10B7 A4DB 9D3C A655 EE16 CCDD F715
minisign key (release files) RWRAv27jiL/8UXFrS1XJfkmfVuMPLxIbHoNkYyXmGw9B207TRBera7Fw

1. Controller

Downloading and checking the bundle

On the controller machine, download the release’s Docker installation bundle, the checksums and their signature (V is the current version):

V=<version>; R=https://repo.csb-it.hu/releases/v$V
curl -fL -O $R/cpkamra-docker-$V.tar.gz -O $R/SHA256SUMS -O $R/SHA256SUMS.minisig

Check the signature and the checksum (minisign is in EPEL and in Debian), then unpack it:

minisign -Vm SHA256SUMS -P RWRAv27jiL/8UXFrS1XJfkmfVuMPLxIbHoNkYyXmGw9B207TRBera7Fw
sha256sum -c --ignore-missing SHA256SUMS
mkdir -p /opt/cpkamra && tar xzf cpkamra-docker-$V.tar.gz -C /opt/cpkamra --strip-components=1
cd /opt/cpkamra

The directory holds the controller’s docker-compose.yml and .env.example files, and maint/ holds the maintenance node’s.

Settings and start

cp .env.example .env && chmod 600 .env

These are required in the .env file:

Variable Value
CPK_HOSTS every name and IP the cPanel servers and the storage server reach the controller by, comma-separated
CPK_DB_PASSWORD the password of the cpkamra database user
MARIADB_ROOT_PASSWORD the MariaDB root password
CPK_BOOTSTRAP_ADMIN_PASSWORD the password of the first dashboard user (admin), at least 12 characters

We also recommend TZ (for example TZ=Europe/Budapest), and for alerts CPK_ALERT_WEBHOOK (Slack- or Mattermost-compatible) or the CPK_SMTP_* variables. Start and check:

docker compose up -d
docker compose ps
docker compose exec controller cpkamra-admin status

On its first start the controller creates its own certificate authority, the server certificate and the key escrow key, and adds the first admin. The controller service should be healthy.

Back up the keys, right now

The controller volume holds the certificate authority’s key (ca.key) and the key escrow key (escrow.key). Without escrow.key the escrowed repository passwords are lost, and without ca.key every server has to register again. Copy the volume and a database dump to an offline location, not to the storage the system protects:

docker run --rm -v cpkamra_controller:/v:ro -v "$PWD":/out alpine tar czf /out/controller-etc.tgz -C /v .
docker compose exec db sh -c 'mariadb-dump -uroot -p"$MARIADB_ROOT_PASSWORD" --single-transaction cpkamra' | gzip > cpkamra-db.sql.gz

Keep backing up the database regularly after this. Then delete the CPK_BOOTSTRAP_ADMIN_PASSWORD line from .env.

The dashboard behind TLS

The dashboard listens on plain HTTP at 127.0.0.1:8080; put a TLS reverse proxy in front of it on the same machine. With Caddy, for example:

backup-dash.example.net {
    reverse_proxy 127.0.0.1:8080
}

Put only the dashboard behind the proxy, not port 8443: the cPanel servers and the maintenance node connect to the controller directly, with a client certificate, and a proxy that terminates TLS breaks that. For the audit log and the login rate limit to see the real client address, the CPK_DASHBOARD_TRUST_PROXY and CPK_DASHBOARD_TRUSTED_PROXIES variables also need to be set in .env; the details are in the wiki’s installation guide.

Sign in as admin. You can add more users on the Users page.

Adding the backup destination

On the dashboard: Storage → Add destination, or from the command line (4 concurrent jobs, 1 of them kept for restores):

docker compose exec controller cpkamra-admin destination storage1 4 1

The name (storage1) has to match everywhere: here, in the maintenance node’s token and in the agents’ settings.

2. Storage server

rest-server, append-only

The agents write to a restic rest-server, which must run with the --append-only --private-repos flags: this way a compromised cPanel server can’t delete its backups, and each server reaches only its own repositories. Keep the repositories in a directory on the host (not in a named volume), because the maintenance node mounts the same directory. For example, /opt/rest-server/compose.yml:

services:
  rest-server:
    image: restic/rest-server:0.14.0
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      OPTIONS: "--append-only --private-repos --tls --tls-cert /certs/fullchain.pem --tls-key /certs/privkey.pem"
    volumes:
      - /srv/backup:/data
      - /etc/rest-server/certs:/certs:ro

The agents use an https:// address, so the rest-server needs a certificate (for example from Let’s Encrypt), or a TLS proxy in front of it. Start it, and create a user for every cPanel server, named exactly as its server_id, with a long random password:

docker compose -f /opt/rest-server/compose.yml up -d
docker compose -f /opt/rest-server/compose.yml exec rest-server create_user cp01

Keep the password; you need it for the agent’s settings.

Maintenance node

On the controller, create a one-time token valid for 24 hours (or on the dashboard: Storage → Maintenance token):

docker compose exec controller cpkamra-admin token storage1-maint -role maint -destination storage1

On the storage server, download, check and unpack the same Docker installation bundle as on the controller, then:

cd /opt/cpkamra/maint
cp .env.example .env && chmod 600 .env

In the .env file:

Variable Value
CPK_NAME storage1-maint, the same name as in the token
CPK_CONTROLLER https://backup-ctl.example.net:8443; always include the :8443 port
CPK_ENROLL_TOKEN the token
CPK_TYPE local (for an S3 destination, s3 and the CPK_S3_* variables)
CPK_DATA_DIR /srv/backup, the rest-server’s data directory
CPK_EXPORTS_DIR where customer exports go, for example /srv/backup-exports
CPK_HOSTNAME the name shown on the dashboard, for example backup1
CPK_WINDOW when maintenance may run, in local time, 08:00-20:00 by default; keep it away from the nightly backups
TZ the time zone

Try it first: this registers the node and shows what it would do, but deletes nothing. Then start the service:

docker compose run --rm maint once -dry-run
docker compose up -d

After the first start, delete the CPK_ENROLL_TOKEN line from .env and back up the etc volume; without it the node would have to register again with a new token:

docker run --rm -v cpkamra-maint_etc:/v:ro -v "$PWD":/out alpine tar czf /out/maint-etc.tgz -C /v .

The node appears on the dashboard’s Storage page. You can set the retention (7 daily and 4 weekly snapshots by default) on the dashboard’s Policies page.

3. cPanel servers

Do these steps on every cPanel server, as root.

Installation

Add the cpKamra package repository and install the agent:

curl -fsS -o /etc/yum.repos.d/cpkamra.repo https://repo.csb-it.hu/el$(rpm -E %rhel)/cpkamra.repo
dnf --enablerepo=cpkamra install cpkamra-agent

On the first installation dnf asks whether to import the cpKamra GPG key: compare its fingerprint with the one above first. The package repository is disabled by default, so cPanel’s nightly update and dnf-automatic never upgrade cpKamra on their own; name it with --enablerepo=cpkamra when you install or upgrade.

The package brings restic too, installs the agent under /usr/local/cpkamra, and sets up the cPanel and WHM plugins; on CloudLinux it also does the CageFS setup. On a new installation the service doesn’t start yet.

Settings

Edit /usr/local/cpkamra/etc/cpkamra.yaml:

server_id: cp01                  # unique; also the rest-server user name
destination:
  name: storage1                 # the destination added on the controller
  type: rest
  url: https://backup1.example.net:8000
  username: cp01                 # = server_id
  password: <the rest-server password>
  key_policy: shared             # or per-repo
schedule:
  daily: "02:00"                 # start of the nightly backup, in server time
parallel: 2
excludes:
  - "public_html/wp-content/cache"
  - ".cache"
  - "tmp"

The exclusions and the schedule can later be changed in WHM too (where Load recommended settings is also available); the destination and its password only in this file. Check the settings:

/usr/local/cpkamra/bin/cpkamrad check

Registration and start

On the controller, create a token for the server (or on the dashboard: Servers → Enroll a server):

docker compose exec controller cpkamra-admin token cp01

Register with it on the cPanel server. The command asks for the token; don’t give it on the command line, because every user of the machine can see that:

/usr/local/cpkamra/bin/cpkamrad enroll -controller https://backup-ctl.example.net:8443

The token contains the fingerprint of the controller’s certificate authority, so no certificate has to be copied by hand. Then start the service:

systemctl enable --now cpkamrad

Starting it begins the first, full backup at once, without waiting for the nightly time. So finish the settings first, especially the exclusions, and start it when a full backup of the server fits the load.

After the first backups, the repository keys go into escrow on the controller by themselves. Even so, keep a copy of the /usr/local/cpkamra/etc/ directory in a safe place.

Enabling the cPanel plugin

The cPanel plugin appears for the accounts whose feature list includes it: WHM → Packages → Feature Manager → edit the feature list → Backup & Restore (cpkamra). Or from the command line:

whmapi1 update_featurelist featurelist=default cpkamra=1

The Back up now and Export buttons have their own features (cpkamra-backupnow, cpkamra-export); they are on until a feature list turns them off.

Checking

cpkamractl status
cpkamractl jobs
cpkamractl accounts

status shows the controller connection, the queue and the next nightly run, and accounts shows the result for each account; in the end every account should be ok. On the dashboard the server appears under Servers, and its accounts under Accounts.

Single-server mode

For one or two cPanel servers whose backups go to a storage-only target. There is no controller, no maintenance node and no dashboard; the agent itself does the retention, the prune, the checks and the deletion of removed accounts’ backups. The cPanel and WHM plugins work the same way, except for customer exports. Alerts go to the address set in WHM’s Contact Manager.

Protecting the storage

Here the agent’s storage access can also delete, so a compromised server could delete its own backups. That is why the backups have to be protected on the storage side:

  • SFTP storage (for example a NAS): turn on automatic snapshots on the storage, for example daily, kept for at least 14 days, in a way that the SFTP user can’t delete them.
  • S3-compatible bucket: turn on versioning, add a lifecycle rule that deletes non-current versions after at least 14 days, and give the agent a key that can’t change object versions, versioning or lifecycle rules.

Installation and settings

Install the agent as described under cPanel servers, then in /usr/local/cpkamra/etc/cpkamra.yaml:

server_id: cp01
destination:
  name: nas
  type: sftp
  host: nas.example.net
  port: 22
  user: cpkamra
  key_file: /usr/local/cpkamra/etc/keys/nas_ed25519
  path: cpkamra                  # relative: below the user's home directory
  # For S3:
  # type: s3
  # endpoint: https://s3.example.net
  # bucket: cpkamra
  # prefix: hosting
  # access_key: …
  # secret_key: …
maintenance:
  mode: self
  window: "08:00-20:00"          # server time, away from the nightly backup
  retention: {daily: 7, weekly: 4, monthly: 0}
  orphan_days: 30

For SFTP, create the SSH key, install its public half on the storage, and accept the storage’s host key:

ssh-keygen -t ed25519 -N "" -f /usr/local/cpkamra/etc/keys/nas_ed25519
ssh-copy-id -s -i /usr/local/cpkamra/etc/keys/nas_ed25519.pub cpkamra@nas.example.net
ssh-keyscan nas.example.net >> /root/.ssh/known_hosts
/usr/local/cpkamra/bin/cpkamrad check

Start and key export

systemctl enable --now cpkamrad
cpkamractl backup --all

When the first backup is done, export the repository keys and keep them offline (in a password manager or printed). There is no key escrow here: without the keys the backups can’t be opened if the server is lost.

cpkamractl key export > /root/cpkamra-keys.txt

Take the file off the server, then delete it there. Finally, look at what the maintenance would do, and at the state of the repositories:

cpkamractl maint run --dry-run
cpkamractl maint

The cPanel plugin has to be enabled in the feature lists the same way as in the full system.

Upgrading in brief

Upgrade the controller first, then the maintenance nodes, and the cPanel servers last; try the new version on one cPanel server first. The steps specific to a release are in the wiki’s upgrade guide; read that first.

  • Controller and maintenance node (Docker): download and check the new release’s Docker installation bundle, unpack it over the old one (your .env files stay), then on the controller run docker compose pull && docker compose up -d, and on the node docker compose pull && docker compose run --rm maint check && docker compose up -d.
  • cPanel servers: dnf --enablerepo=cpkamra upgrade cpkamra-agent cpkamra-restic, outside the nightly backup window. The daemon waits for the running jobs and restarts with the new version only afterwards; it doesn’t touch the settings, the keys or the registration.

Checklist

  • The controller is healthy, and the dashboard is reachable only over TLS.
  • The controller volume and a database dump are in an offline location.
  • CPK_BOOTSTRAP_ADMIN_PASSWORD and CPK_ENROLL_TOKEN are deleted from the .env files.
  • The rest-server runs with the --append-only --private-repos flags.
  • The maintenance node is registered, its etc volume is backed up, and the maintenance window is away from the nightly backups.
  • Every cPanel server is registered, the first backup is ok, and /usr/local/cpkamra/etc/ is copied.
  • The cpkamra feature is on in the feature lists.
  • The alerts have been tested.

Installing without Docker, troubleshooting and every setting are in the wiki’s installation guide.