Authentication and API keys
This page explains how other systems sign in to API v1: API keys, billing keys limited to their own accounts, IP allowlists, mTLS, client API tokens, and how all of this differs from staff sessions in the GUI.
Ways in
| Method | Used by | How it is sent | Notes |
|---|---|---|---|
| API key | Billing, scripts, monitoring, CLI | X-API-Key header | No CSRF. Rate limited. Can have scopes, an IP allowlist, and mTLS. |
| Staff session | Admin GUI in a browser | moorcp_session cookie | Password + 2FA login. Changing requests require the X-CSRF-Token header. |
| Client API token | A hosting client's own scripts and CI | Authorization: Bearer or X-API-Key header, on the client panel port (2083) | Created by the client. Limited to that one account and to client features. See Client API tokens. |
Integrations always use an API key. Staff sessions are only for the GUI and are not meant to be used from scripts.
curl -sS https://panel.example.com:8443/v1/billing/capabilities \
-H "X-API-Key: API_KEY"WARNING
API keys only work on the admin port (8443). On the client panel port (2083), an API key is not accepted. The only tokens that work there are client API tokens (mcct_...), and those do not work on the admin port.
API key format
API keys look like mcpk_<prefix>_<secret>.
- The raw key is shown only once, when it is created or rotated. The panel stores only its prefix and hash.
- The prefix appears in the API key list and in the audit log (
apikey:<prefix>), so you can tell which key was used without seeing the secret. - The last-used time (
lastUsed) is recorded at most once per minute.
Bootstrap key
The installer creates one random key in /etc/moorcp-shared/env (MOORCP_ADMIN_API_KEY) with the admin role. This key is for initial setup and emergency access. Do not give it to other systems. Create a stored API key for each integration.
Roles
Every API key carries one role. Permissions are checked per route, the same way as for staff.
| Role | Permissions |
|---|---|
admin | All operations, including staff, API keys, and secrets |
technician | All operations except /v1/staff, /v1/api-keys, /v1/secrets, changing notification channels, and other admin-only operations (for example webhooks, DNS nameserver nodes, opening/closing firewall ports, server reboot) |
support (default) | Read only, plus account suspend/unsuspend, server ping, post-migration checks, and alert ack |
billing | Provisioning and client operations only on accounts owned by the key's owner. Server and infrastructure routes are refused. |
For billing systems, always use the billing role. Staff roles (admin, technician) see the whole panel.
Creating an API key
From the GUI
- Open Settings › API credentials.
- Click New API key.
- Enter a name, pick a role, and if needed an expiry date, owner (for the
billingrole), scopes, and source IPs. - Copy the key that appears. It cannot be shown again.
Only staff with the admin role can manage API keys.
From the API
curl -sS -X POST https://panel.example.com:8443/v1/api-keys \
-H "X-API-Key: ADMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Production billing",
"role": "billing",
"owner": "mybilling",
"allowedNets": ["203.0.113.10"],
"expiresAt": "2027-12-31T23:59:59Z"
}'The 201 response contains key (the raw key, shown once) and apiKey (metadata).
| Field | Required | Content |
|---|---|---|
name | yes | Free-form name, max 80 characters |
role | no | admin, technician, support (default), or billing |
owner | for billing | Short slug of the billing system, pattern ^[a-z0-9][a-z0-9-]{0,39}$, for example mybilling |
expiresAt | no | The key stops working after this time |
scopes | no | Allowed feature groups. Empty = all. |
allowedNets | no | List of source IPs or CIDRs |
serverIds | no | Servers where the key may create accounts. Empty = all. |
Billing keys and owners
A billing role key must have an owner. The owner decides which accounts the key may touch:
- Accounts created by the key automatically get
billingOwner= the key's owner. AbillingOwnerfield in the body is ignored. - Accounts of another owner, or accounts with no owner, are answered with 404
cp.account_not_found. The panel answers 404 on purpose, not 403, so it does not reveal that the account exists. - Older or migrated accounts are bound to an owner by an admin with
PUT /v1/accounts/{id}/billing. - Packages and webhooks created by a billing key also belong to that owner and are invisible to other owners.
Two different billing systems just use different owners. Each one sees only its own accounts, packages, and webhooks.
The X-Billing-Client-ID header
Client operations (anything beyond provisioning), such as creating a website, database, or mailbox, must send the X-Billing-Client-ID header with the ID of the client signed in to billing. Its value must match the account's billingClientId.
| Case | Result |
|---|---|
| Header missing | 400 cp.billing_client_required |
| Header does not match | 404 |
This header stops a billing bug (a wrong account ID) from opening another client's account. Provisioning (create, view, suspend, unsuspend, package change, terminate, SSO link) needs only the billing key.
Scopes
Scopes limit a key to certain feature groups. The :read suffix means read only.
| Scope | Covers |
|---|---|
provisioning | Create, suspend, unsuspend, change package, terminate accounts, login links |
websites | Websites, domains, SSL, redirects, changing the account's primary domain, PHP, apps (including WordPress Manager login links and settings), Redis and Memcached, website visitor statistics |
files | File manager |
databases | Databases, database users, and remote database access hosts |
email | Mailboxes, forwarders, filters, spam, delivery history (Track delivery) |
dns | The account's DNS zones and records |
backup | Account backup and restore, restore from a portable archive, external backup storage and rules |
devtools | Cron, FTP, SSH keys, SSH/SFTP password and IP allowlist, Git |
usage | Resource usage and monthly visits |
security | Malware reports and the account's WAF IP allowlist |
webhooks | Outgoing webhooks |
Example: a key for a usage dashboard that only reads:
{"name": "Usage dashboard", "role": "billing", "owner": "mybilling", "scopes": ["usage:read", "provisioning:read"]}- Requests outside the scopes are refused with 403
cp.scope_denied. - Job status (
GET /v1/jobs/{id}) can always be read. - Staff keys with scopes cannot touch infrastructure routes (servers, configuration, migration), and cannot retry jobs.
IP allowlist
allowedNets limits the source address of the connection. It takes single IPs or CIDRs.
curl -sS -X PATCH https://panel.example.com:8443/v1/api-keys/KEY_ID \
-H "X-API-Key: ADMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"allowedNets": ["203.0.113.10", "198.51.100.0/24"]}'Requests from other IPs are refused with 403 cp.ip_not_allowed.
WARNING
The allowlist uses the IP of the direct connection to the control plane. If the panel sits behind a reverse proxy, every request appears to come from the proxy. In that case, enforce IP restrictions at the proxy or a VPN.
mTLS (client certificates)
For extra security, a key can be required to use a client certificate. The certificate is signed by the panel's internal CA. Its private key is created on the billing server and is never sent to the panel.
On the billing server, create a private key and CSR:
bashopenssl req -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ -keyout billing.key -out billing.csr -subj "/CN=billing"An admin signs the CSR. In the GUI: Settings › API credentials, pick the key, then Sign CSR. Through the API:
bashjq -n --rawfile csr billing.csr '{csr: $csr, days: 365}' | \ curl -sS -X POST https://panel.example.com:8443/v1/api-keys/KEY_ID/client-cert \ -H "X-API-Key: ADMIN_API_KEY" \ -H "Content-Type: application/json" -d @- \ | jq -r .certificate > billing.crtBilling calls the API with that certificate:
bashcurl -sS --cert billing.crt --key billing.key \ https://panel.example.com:8443/v1/accounts \ -H "X-API-Key: API_KEY"
Notes:
- Validity is 1–825 days (default 365). The response also includes
caCertificate, the panel's internal CA. - The CN in the CSR is ignored. The certificate always has CN
apikey:<prefix>and is for client auth only, so it cannot be used to impersonate an agent. - Once signed, the key is only accepted together with that certificate. Without it: 401
cp.client_cert_required. - Signing a new CSR replaces the old certificate.
PATCH /v1/api-keys/{id}with{"clearCert": true}removes the mTLS requirement.
WARNING
mTLS only works when the control plane serves TLS itself. Behind a reverse proxy that terminates TLS, the client certificate never reaches the panel.
Rotation and revocation
| Action | Endpoint | Effect |
|---|---|---|
| Rotate | POST /v1/api-keys/{id}/rotate | New key with the same name, role, owner, scopes, allowlist, and mTLS pin |
| Change restrictions | PATCH /v1/api-keys/{id} | Change scopes, allowedNets, serverIds, or clearCert |
| Revoke | DELETE /v1/api-keys/{id} | The key stops working immediately |
Rotation accepts graceHours (default 24, max 720). During that transition the old key keeps working, then expires. graceHours: 0 revokes the old key at once.
curl -sS -X POST https://panel.example.com:8443/v1/api-keys/KEY_ID/rotate \
-H "X-API-Key: ADMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"graceHours": 48}'Zero-downtime rotation:
- Rotate the key with enough
graceHoursfor a deploy. - Put the new key in billing and deploy.
- Check that the Last used column of the new key moves.
- Let the old key expire, or revoke it sooner.
In the GUI, the Rotate and Revoke buttons are on the key's row.
Client API tokens
Hosting clients can create their own API tokens for scripts and automation (deploys, CI, monitoring) without sharing their panel password. A client API token is not an API key:
API key (mcpk_...) | Client API token (mcct_...) | |
|---|---|---|
| Created by | Admin staff, in Settings › API credentials | The account owner, in the client panel under Settings › API tokens |
| Port | Admin port (8443) | Client panel port (2083) only |
| Reach | Depends on the role: the whole panel, or a billing owner's accounts | One account only. Other accounts and websites answer 404 |
| Allowed routes | Per role and scopes | The same endpoints as the client panel, within the token's scopes. Never provisioning (suspend, package), contact details, the panel password or 2FA, client login links, /v1/client/*, panel users, or managing tokens |
| Scopes | provisioning, websites, files, databases, email, dns, backup, devtools, usage, security, webhooks | At least one of websites, files, databases, email, dns, backup, devtools, usage, security; :read for read only |
| Audit actor | apikey:<prefix> | client with ID token:<prefix>, on behalf of the account |
Creating and revoking client tokens
The client panel (or staff, or an API key without scope limits) manages the tokens through these endpoints:
| Endpoint | Purpose |
|---|---|
GET /v1/accounts/{id}/api-tokens | List the tokens (without secrets) and the available scopes |
POST /v1/accounts/{id}/api-tokens | Create a token. The raw token mcct_<prefix>_<secret> is returned only once |
DELETE /v1/accounts/{id}/api-tokens/{tokenId} | Revoke a token. It stops working immediately |
{"name": "GitHub deploy", "scopes": ["websites", "dns:read"],
"allowedNets": ["203.0.113.0/24"], "expiresAt": "2027-02-15T00:00:00Z"}allowedNetslimits the source IPs; empty means any.- An account can have up to 20 active tokens. The panel stores only the prefix and a hash.
Using a client token
curl -sS https://panel.example.com:2083/v1/websites \
-H "Authorization: Bearer CLIENT_TOKEN"X-API-Key: CLIENT_TOKENworks too. No cookie and no CSRF token are needed.- Changes are refused while the account is suspended.
- Requests count toward the same per-account rate limit as the client panel. Wrong tokens count toward the API guessing lockout.
- The last-used time is updated at most once per minute.
TIP
Panel users (sub-accounts) use the same scopes as client tokens, but sign in to the client panel with <login>@<account username> and a password. See Settings (client).
Staff sessions
Staff sessions are used by the admin GUI:
- Login with email and password (
POST /v1/auth/login), then a 2FA code if enabled. - The
moorcp_sessioncookie is HttpOnly, Secure, SameSite=Strict. - Absolute session lifetime is 12 hours (
MOORCP_SESSION_HOURS), with a 2-hour idle timeout. - Changing requests require
X-CSRF-TokenfromGET /v1/auth/me. - Admins can require 2FA for all staff (
MOORCP_ADMIN_REQUIRE_2FA=true) and limit GUI IPs (MOORCP_ADMIN_ALLOWED_CIDRS). The GUI IP allowlist does not apply to API keys; API keys have their ownallowedNets. - Changing a staff member's role, password, or status, or resetting their 2FA, revokes all their sessions.
Guessing lockout
The panel counts wrong API keys per IP, the same way as failed logins. After too many guesses, that IP gets 429 cp.auth_locked with Retry-After. Valid API keys are never held back. The settings are under Security › Login protection.
Recommended practices
- One API key per system and per environment (production, staging).
- The
billingrole with an owner for billing; never an admin key. - Fill
allowedNetswith the billing server's IPs. - Use mTLS if the panel serves TLS itself.
- Set
expiresAtand schedule rotation. - Keep keys in a secret manager, not in a code repository.
