Skip to content

DirectAdmin API tokens — provisioning automation without admin credentials

Provision DirectAdmin API tokens for automation tooling — scoped login keys at admin/reseller/user level, role policies, rotation, and audit.

Your provisioning service has been authenticating to DirectAdmin with the admin password — the one you also use to log in interactively — for the last two years. The password is in the service’s config file, the file is on disk on the provisioner host, and three engineers have ssh access to that host. You want to fix this before audit week, but you don’t want to interrupt provisioning for half a day. The right primitive is DirectAdmin Login Keys (DA’s API token equivalent), and the gap between “I know they exist” and “they’re properly scoped for the consumer’s actual needs” is bigger than it looks.

What’s happening

DirectAdmin calls API tokens “Login Keys.” They behave like long-lived bearer credentials and can be created at three privilege levels:

  • Admin login keys — full server admin authority. The thing your provisioning service probably shouldn’t have.
  • Reseller login keys — authority over the accounts owned by a specific reseller.
  • User login keys — authority over one specific cPanel-equivalent account.

Each login key has four scoping dimensions: which commands (DA endpoints) it may call, which IPs may use it, an optional expiry, and a label for audit. The default in the UI is “all commands, any IP, no expiry” — i.e. an admin password with a different name. The whole point of moving to login keys is to constrain those four dimensions per consumer.

DirectAdmin endpoints are organized by command name like CMD_API_ACCOUNT_USER, CMD_API_DOMAIN, CMD_API_DATABASE, CMD_API_EMAIL_POP. A provisioner that creates user accounts and adds databases needs CMD_API_ACCOUNT_USER and CMD_API_DATABASE and not much else. A billing exporter just needs the listing endpoints. A monitoring probe doesn’t need any mutating endpoints at all. Locking each consumer to its actual command list is the half of this that always gets skipped because nobody enumerates what the consumer really calls.

How to verify

DirectAdmin stores login keys in /usr/local/directadmin/data/admin/login-keys and per-reseller/user under their directories. List all admin-level keys:

ls -la /usr/local/directadmin/data/admin/login-keys/

Each key has a .conf file describing its scope:

cat /usr/local/directadmin/data/admin/login-keys/provisioner.conf
# active=yes
# expiry=
# ips=
# commands=ALL
# allow_htm=no
# clear_key=yes
# label=provisioner

commands=ALL is the red flag. So is empty ips= and empty expiry=. That key is an admin password with delusions of being a token.

To see usage you need DirectAdmin’s API log:

# Per-day API access logs
ls /var/log/directadmin/api*.log* 2>/dev/null

# Today's calls bucketed by login key (if logging includes the key label)
grep -E '"login_key":' /var/log/directadmin/api.log | \
  jq -r '"\(.login_key) \(.command) \(.remote_ip)"' | \
  sort | uniq -c | sort -rn | head -20

If api.log is empty or doesn’t exist, turn it on:

echo 'log_api=2' >> /usr/local/directadmin/conf/directadmin.conf
/usr/local/directadmin/directadmin reloadconf

Then wait a day and look at what your consumers actually call. That gives you the empirical command list for the scoped replacement key.

The fix

Create scoped admin-level login keys via the API itself. Authenticate as admin once with the admin password, mint scoped keys, then never use the admin password again.

CMD_API_LOGIN_KEYS is the endpoint. The interesting parameters:

  • action=create
  • keyname=<label> — what shows up in the audit log
  • key=<plaintext> or omit to generate (DA returns the generated key)
  • expiry=YYYY-MM-DD — optional, recommended
  • expiry_url= — optional, what to do at expiry
  • allow_htm=no — disable browser-cookie-style access (force header auth)
  • clear_key=yes — DA returns the key as plain text once
  • commands=CMD_API_ACCOUNT_USER:CMD_API_DATABASE:CMD_API_DOMAIN — colon-separated allowlist
  • passwd=<admin password> — required to confirm the action
  • ip_list=10.40.0.21:10.40.0.22 — optional IP allowlist

Mint a provisioning key — full account lifecycle, restricted to one source IP, 6-month expiry:

ADMIN_PASS="$(vault kv get -field=value secret/da-admin/initial)"
DA_HOST="da01.example.com"

curl -sk -u "admin:${ADMIN_PASS}" \
  "https://${DA_HOST}:2222/CMD_API_LOGIN_KEYS" \
  --data-urlencode "action=create" \
  --data-urlencode "keyname=provisioner-2026-05" \
  --data-urlencode "allow_htm=no" \
  --data-urlencode "clear_key=yes" \
  --data-urlencode "commands=CMD_API_ACCOUNT_USER:CMD_API_DOMAIN:CMD_API_DATABASE:CMD_API_EMAIL_POP:CMD_API_SUBDOMAINS:CMD_API_DNS_CONTROL" \
  --data-urlencode "expiry=2026-11-12" \
  --data-urlencode "ip_list=10.40.0.21:10.40.0.22" \
  --data-urlencode "passwd=${ADMIN_PASS}"
# DA returns: error=0&details=KEY_VALUE_HERE

Capture the generated key and store it directly in your secret store:

#!/usr/bin/env bash
# /usr/local/bin/da-mint-token
set -euo pipefail

KEYNAME="${1:?usage: da-mint-token <keyname> <commands> <ip_list> <expiry> <vault-path>}"
COMMANDS="${2:?}"
IPLIST="${3:?}"
EXPIRY="${4:?}"
VAULT_PATH="${5:?}"

DA_HOST="${DA_HOST:-da01.example.com}"
ADMIN_PASS="$(vault kv get -field=value secret/da-admin/initial)"

RESP=$(curl -sk -u "admin:${ADMIN_PASS}" \
  "https://${DA_HOST}:2222/CMD_API_LOGIN_KEYS" \
  --data-urlencode "action=create" \
  --data-urlencode "keyname=${KEYNAME}" \
  --data-urlencode "allow_htm=no" \
  --data-urlencode "clear_key=yes" \
  --data-urlencode "commands=${COMMANDS}" \
  --data-urlencode "expiry=${EXPIRY}" \
  --data-urlencode "ip_list=${IPLIST}" \
  --data-urlencode "passwd=${ADMIN_PASS}")

if [[ "$RESP" != *"error=0"* ]]; then
  echo "Mint failed: $RESP" >&2
  exit 1
fi

KEY=$(echo "$RESP" | sed -n 's/.*details=\([^&]*\).*/\1/p' | python3 -c 'import sys, urllib.parse as u; print(u.unquote(sys.stdin.read().strip()))')
if [[ -z "$KEY" ]]; then
  echo "Could not parse key from response: $RESP" >&2
  exit 1
fi

vault kv put "$VAULT_PATH" \
  value="$KEY" \
  keyname="$KEYNAME" \
  commands="$COMMANDS" \
  ip_list="$IPLIST" \
  expiry="$EXPIRY" \
  minted_at="$(date -u +%FT%TZ)"

echo "Key minted and stored at $VAULT_PATH (label=$KEYNAME, expiry=$EXPIRY)"

Usage:

# Provisioner — write-heavy
da-mint-token \
  provisioner-2026-05 \
  "CMD_API_ACCOUNT_USER:CMD_API_DOMAIN:CMD_API_DATABASE:CMD_API_EMAIL_POP:CMD_API_SUBDOMAINS:CMD_API_DNS_CONTROL" \
  "10.40.0.21:10.40.0.22" \
  "2026-11-12" \
  "secret/da/provisioner/2026-05"

# Billing read-only
da-mint-token \
  billing-readonly-2026-05 \
  "CMD_API_SHOW_USER_USAGE:CMD_API_SHOW_ALL_USERS:CMD_API_RESELLER_STATS" \
  "10.40.0.34" \
  "2026-11-12" \
  "secret/da/billing-readonly/2026-05"

# Monitoring probe — server stats only
da-mint-token \
  monitoring-2026-05 \
  "CMD_API_LICENSE:CMD_API_SHOW_SERVICES" \
  "10.40.0.50" \
  "2026-11-12" \
  "secret/da/monitoring/2026-05"

Reseller-level login keys are minted the same way, authenticated as the reseller. For an automation that should only touch one reseller’s accounts:

RESELLER="acme-reseller"
RESELLER_PASS="$(vault kv get -field=value secret/da-reseller/${RESELLER})"

curl -sk -u "${RESELLER}:${RESELLER_PASS}" \
  "https://${DA_HOST}:2222/CMD_API_LOGIN_KEYS" \
  --data-urlencode "action=create" \
  --data-urlencode "keyname=acme-provisioner-2026-05" \
  --data-urlencode "allow_htm=no" \
  --data-urlencode "clear_key=yes" \
  --data-urlencode "commands=CMD_API_ACCOUNT_USER:CMD_API_DOMAIN:CMD_API_DATABASE" \
  --data-urlencode "expiry=2026-11-12" \
  --data-urlencode "ip_list=10.40.0.21" \
  --data-urlencode "passwd=${RESELLER_PASS}"

A reseller key cannot reach into another reseller’s accounts even if you give it commands=ALL — the privilege ceiling is enforced server-side regardless of the command allowlist.

Consuming a login key from a provisioner — the format is HTTP Basic Auth with the username as the DA admin/reseller/user name and the password as the login key:

TOKEN=$(vault kv get -field=value secret/da/provisioner/2026-05)

curl -sk -u "admin:${TOKEN}" \
  "https://${DA_HOST}:2222/CMD_API_ACCOUNT_USER" \
  --data-urlencode "action=create" \
  --data-urlencode "username=customer42" \
  --data-urlencode "email=ops@example.com" \
  --data-urlencode "passwd=$(openssl rand -base64 24)" \
  --data-urlencode "passwd2=$(openssl rand -base64 24)" \
  --data-urlencode "domain=customer42.example.com" \
  --data-urlencode "package=silver" \
  --data-urlencode "ip=192.0.2.10" \
  --data-urlencode "notify=yes"

Rotation runbook — same shape as for WHM:

  1. Mint a new key with the same scope + IP allowlist + a new month tag (provisioner-2026-11).
  2. Push it to the consumer’s secret store at a new vault path.
  3. Restart the consumer pointing at the new path.
  4. Watch api.log to confirm traffic is on the new key for at least 72 hours.
  5. Revoke the old key:
curl -sk -u "admin:${ADMIN_PASS}" \
  "https://${DA_HOST}:2222/CMD_API_LOGIN_KEYS" \
  --data-urlencode "action=delete" \
  --data-urlencode "keyname=provisioner-2026-05" \
  --data-urlencode "passwd=${ADMIN_PASS}"
  1. Log the rotation event in your change log.

Two design notes worth keeping: never share a login key between consumers that have different IP allowlists, even if they “do the same kind of work” — the moment one of them moves hosts, the other gets blocked, and the audit log can’t tell you which consumer made which call. And the admin password itself becomes a break-glass credential the moment scoped keys are in place; rotate it to something nobody knows, store it in a vault with manual checkout, and treat retrieving it as an incident-grade event.

DirectAdmin fleets where every automation runs on a scoped, IP-locked, expiry-bounded login key with rotation in the calendar are part of how we operate the panel under Managed Cloud Ops with monitoring on api.log for unexpected sources. Open a credentials review if your DA admin password has more knowers than rotations.