Skip to content

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 ​

MethodUsed byHow it is sentNotes
API keyBilling, scripts, monitoring, CLIX-API-Key headerNo CSRF. Rate limited. Can have scopes, an IP allowlist, and mTLS.
Staff sessionAdmin GUI in a browsermoorcp_session cookiePassword + 2FA login. Changing requests require the X-CSRF-Token header.
Client API tokenA hosting client's own scripts and CIAuthorization: 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.

bash
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.

RolePermissions
adminAll operations, including staff, API keys, and secrets
technicianAll 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
billingProvisioning 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 ​

  1. Open Settings › API credentials.
  2. Click New API key.
  3. Enter a name, pick a role, and if needed an expiry date, owner (for the billing role), scopes, and source IPs.
  4. Copy the key that appears. It cannot be shown again.

Only staff with the admin role can manage API keys.

From the API ​

bash
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).

FieldRequiredContent
nameyesFree-form name, max 80 characters
rolenoadmin, technician, support (default), or billing
ownerfor billingShort slug of the billing system, pattern ^[a-z0-9][a-z0-9-]{0,39}$, for example mybilling
expiresAtnoThe key stops working after this time
scopesnoAllowed feature groups. Empty = all.
allowedNetsnoList of source IPs or CIDRs
serverIdsnoServers 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. A billingOwner field 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.

CaseResult
Header missing400 cp.billing_client_required
Header does not match404

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.

ScopeCovers
provisioningCreate, suspend, unsuspend, change package, terminate accounts, login links
websitesWebsites, domains, SSL, redirects, changing the account's primary domain, PHP, apps (including WordPress Manager login links and settings), Redis and Memcached, website visitor statistics
filesFile manager
databasesDatabases, database users, and remote database access hosts
emailMailboxes, forwarders, filters, spam, delivery history (Track delivery)
dnsThe account's DNS zones and records
backupAccount backup and restore, restore from a portable archive, external backup storage and rules
devtoolsCron, FTP, SSH keys, SSH/SFTP password and IP allowlist, Git
usageResource usage and monthly visits
securityMalware reports and the account's WAF IP allowlist
webhooksOutgoing webhooks

Example: a key for a usage dashboard that only reads:

json
{"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.

bash
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.

  1. On the billing server, create a private key and CSR:

    bash
    openssl req -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
      -keyout billing.key -out billing.csr -subj "/CN=billing"
  2. An admin signs the CSR. In the GUI: Settings › API credentials, pick the key, then Sign CSR. Through the API:

    bash
    jq -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.crt
  3. Billing calls the API with that certificate:

    bash
    curl -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 ​

ActionEndpointEffect
RotatePOST /v1/api-keys/{id}/rotateNew key with the same name, role, owner, scopes, allowlist, and mTLS pin
Change restrictionsPATCH /v1/api-keys/{id}Change scopes, allowedNets, serverIds, or clearCert
RevokeDELETE /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.

bash
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:

  1. Rotate the key with enough graceHours for a deploy.
  2. Put the new key in billing and deploy.
  3. Check that the Last used column of the new key moves.
  4. 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 byAdmin staff, in Settings › API credentialsThe account owner, in the client panel under Settings › API tokens
PortAdmin port (8443)Client panel port (2083) only
ReachDepends on the role: the whole panel, or a billing owner's accountsOne account only. Other accounts and websites answer 404
Allowed routesPer role and scopesThe 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
Scopesprovisioning, websites, files, databases, email, dns, backup, devtools, usage, security, webhooksAt least one of websites, files, databases, email, dns, backup, devtools, usage, security; :read for read only
Audit actorapikey:<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:

EndpointPurpose
GET /v1/accounts/{id}/api-tokensList the tokens (without secrets) and the available scopes
POST /v1/accounts/{id}/api-tokensCreate 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
json
{"name": "GitHub deploy", "scopes": ["websites", "dns:read"],
 "allowedNets": ["203.0.113.0/24"], "expiresAt": "2027-02-15T00:00:00Z"}
  • allowedNets limits 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 ​

bash
curl -sS https://panel.example.com:2083/v1/websites \
  -H "Authorization: Bearer CLIENT_TOKEN"
  • X-API-Key: CLIENT_TOKEN works 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_session cookie 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-Token from GET /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 own allowedNets.
  • 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.

  • One API key per system and per environment (production, staging).
  • The billing role with an owner for billing; never an admin key.
  • Fill allowedNets with the billing server's IPs.
  • Use mTLS if the panel serves TLS itself.
  • Set expiresAt and schedule rotation.
  • Keep keys in a secret manager, not in a code repository.

See also ​

MoorCP Shared, a shared hosting panel for server fleets.