Repository navigation
Security
This page is a hands-on guide to NodePilot's security features: two-factor sign-in, login lockout, the panel's own SSH key, sealing the master key into a TPM, the audit log and its forwarding, the security checklist, HTTPS and cookies, and how API tokens are stored. It complements the project's SECURITY.md, which describes the threat model and how to report vulnerabilities.
Most settings are on the Security page in the sidebar. The page shows, from top to bottom: the Security checklist, Two-factor authentication, Panel SSH key, Master key and Audit log forwarding. The log itself is on the Audit log page.
With 2FA on, signing in needs the password and a 6-digit code from an authenticator app (Google Authenticator, Aegis, 1Password, Bitwarden and others). 2FA is per user.
- Open Security → Two-factor authentication and click Enable 2FA.
- Scan the QR code, or type the Key for manual entry into the app. Type: time-based (TOTP), 6 digits, 30 seconds.
- Enter the current code and click Enable.
- Save the 10 recovery codes that appear (Copy all or Download .txt). They are shown only once. Tick I have saved the recovery codes.
Details:
- Codes are standard RFC 6238 TOTP (HMAC-SHA1, 6 digits, 30-second step). The panel accepts one step of clock skew either way. If codes are rejected, check that the phone sets its time automatically.
- An accepted code cannot be used again for the same user.
- The TOTP secret is stored encrypted with the master key. Until you confirm it with a code, the new secret is only pending and 2FA stays off.
- Setting up, disabling and regenerating codes only work from a browser session. With an API token these calls return 403. Tokens can read the status (
GET /api/auth/2fa).
The sign-in form asks for the code after the password. Choose Use a recovery code if you don't have the phone.
Over the API, POST /api/auth/login with only username and password returns:
HTTP/1.1 401 Unauthorized
{"error": "two-factor code required", "two_factor_required": true}Send the request again with code set to the app code or a recovery code:
{ "username": "admin", "password": "…", "code": "123456" }A wrong code counts as a failed attempt for the lockout.
- 10 single-use codes like
3f9a1-0c2b7. Case does not matter. - They are stored only as SHA-256 hashes. A used code is removed.
- The 2FA card shows how many are left. The checklist warns when 3 or fewer are left.
- New recovery codes creates a new set of 10 and invalidates all old ones. Confirm with a code from the app (a recovery code also works).
Click Disable and enter your password and a code from the app or a recovery code.
If a user lost both the phone and the recovery codes, an administrator with shell access to the panel host can reset 2FA from the CLI:
sudo -u nodepilot nodepilot user reset-2fa alice --data-dir /var/lib/nodepilotThis turns 2FA off for that user, deletes their recovery codes, ends all of their browser sessions and writes an auth:2fa-reset-cli event to the audit log. The user then signs in with the password and sets up 2FA again. See CLI-Reference.
[!NOTE]
If the master key is sealed in the TPM, CLI commands also need the key. See Running the CLI with a sealed key.
The panel counts failed sign-ins separately for each username and each client IP address:
| Rule | Value |
|---|---|
| Failures that trigger a lockout | 5 within 15 minutes, per username and per IP |
| First lockout | 5 minutes |
| Next lockouts | 10, 20, 40, then 60 minutes (the maximum) |
| What counts as a failure | Wrong password, unknown username, wrong 2FA code |
| What resets the counter | A successful sign-in for that username/IP |
| While locked |
POST /api/auth/login returns 429 with a Retry-After header (seconds), without checking the password |
- The counters are kept in memory and reset when the panel restarts.
- Missing the 2FA code (the
two_factor_requiredresponse) is not a failure. - Failed sign-ins are written to the audit log as
auth:loginwith outcomedenied(severitywarning). Attempts rejected because of a lockout are logged with outcomelocked(severitycritical). - Password hashes are Argon2id. For an unknown username the panel still runs a hash so the response time does not reveal which usernames exist.
The client IP is the TCP peer address unless the request comes from a trusted reverse proxy: loopback, or an address listed in NODEPILOT_TRUSTED_PROXIES. Then the panel reads X-Forwarded-For from the right and takes the first address that is not a trusted proxy, so clients cannot spoof it. If your proxy runs on another host, add it to NODEPILOT_TRUSTED_PROXIES; otherwise every sign-in appears to come from the proxy and one attacker could lock out everyone by IP.
By default the panel connects with the passwords and keys you add for each server. The panel SSH key is a better option: one ed25519 key owned by the panel, which servers accept only from the panel's addresses, and which you can rotate or revoke on all servers at once.
The key line the panel adds to ~/.ssh/authorized_keys looks like this:
from="203.0.113.10,10.0.0.0/8",no-port-forwarding,no-agent-forwarding,no-X11-forwarding ssh-ed25519 AAAA… nodepilot-panel-key:5c1e0a9b3f2d
-
from=makes sshd reject the key from any other address, so a stolen key is useless elsewhere. - Port, agent and X11 forwarding are disabled.
- The comment
nodepilot-panel-key:<marker>identifies the panel's lines for rotation and revocation, with or without the panel.
The private key is stored in the keychain (encrypted with the master key) as an identity named NodePilot panel key <marker>.
- Open Security → Panel SSH key and click Create panel key.
- Under Panel addresses (as servers see them), enter the IP addresses or CIDR networks the servers will see the panel connect from, for example
203.0.113.10or10.0.0.0/8. IPv6 works too. Press Enter or comma to add each one, then Save addresses.
If the list is empty, the key is accepted from anywhere. The UI warns about this, and the checklist marks it.
The address a server sees can differ from what you expect (NAT, VPN, several interfaces). Use Detect from a server…: pick a server and click Detect address. The panel runs printf '%s' "$SSH_CLIENT" on that server over its current connection and shows "The server sees the panel as …". Add that address to the list.
API: POST /api/security/panel-key/detect-ip with {"server_id": "…"} returns {"ip": "…"}.
Click Install on servers…, choose servers (search, Only those not on the key) or a whole Project, and run. For each server the panel:
- Adds the key line to
~/.ssh/authorized_keysof the server's SSH user. An older line with the same marker is replaced, other keys are kept, and a backup is saved asauthorized_keys.nodepilot.bak. - Checks that it can log in with the panel key.
- If Switch servers to the panel key after a successful check is on (the default), switches the server in the panel to the panel key and forgets its previous password or key.
Servers where any step fails keep their current credentials. Up to 8 servers are processed at a time. The results list each server as OK or with its error.
Switching does not remove the old password or key from the server itself. Remove it yourself when you're sure, and consider PasswordAuthentication no in sshd_config.
If you change the addresses later, servers keep the old from= list until you run Install on servers again.
You can also install the key by hand. The card shows the Line for authorized_keys and an Install manually command to run on a server as the panel's SSH user.
API: POST /api/security/panel-key/deploy with {"server_ids": […]} and/or {"project_id": "…"}, and "switch_auth": false to install without switching.
Rotate key creates a new key with the same addresses and, on every server that uses the key or got it installed:
- installs the new line,
- checks login with the new key,
- switches the server to the new key (if it was using the old one),
- removes every other panel key line, including lines left by earlier failed rotations.
The rotation results list each server as OK or with its error. A server where something fails stays on the old key, and the old key's line stays in its authorized_keys. The old identity is deleted, or renamed with (retired) if some server still uses it, so you can see its marker on the Keys page.
The panel remembers servers left on an earlier key. Fix the connection and rotate again: those servers are switched to the new key and their old lines are removed. Emergency revoke also covers them and removes all panel key lines, old and new.
API: POST /api/security/panel-key/rotate.
Use Emergency revoke if the panel or its database may be compromised. Type REVOKE to confirm. The panel removes every nodepilot-panel-key: line from authorized_keys on all servers that used or received the key, and destroys the key. The panel loses access to servers that relied on it until you add a password or key again.
API: POST /api/security/panel-key/revoke.
If the panel is down or you don't trust it, remove the keys yourself. Run this on each server as the SSH user the panel logs in with:
if [ -f "$HOME/.ssh/authorized_keys" ]; then sed -i.nodepilot.bak '/nodepilot-panel-key:/d' "$HOME/.ssh/authorized_keys"; fiOn a whole fleet with Ansible (the card shows the same command under Revoke without the panel):
ansible all -m shell -a 'if [ -f "$HOME/.ssh/authorized_keys" ]; then sed -i.nodepilot.bak '\''/nodepilot-panel-key:/d'\'' "$HOME/.ssh/authorized_keys"; fi'Add -u <user> (or -b with become_user) so it runs as the panel's SSH user. Afterwards, change the passwords that were stored in the panel, the S3 keys, and API tokens used by other systems.
The master key (32 random bytes, base64) encrypts everything secret in the panel database with XChaCha20-Poly1305: server passwords and SSH keys, the panel key, S3 secrets, database passwords and passphrases of backup jobs, TOTP secrets and the webhook secret.
The panel looks for the key in this order:
| Source (UI) | master_key.kind |
Where |
|---|---|---|
| sealed | systemd-credential |
$CREDENTIALS_DIRECTORY/master.key, provided by systemd (LoadCredentialEncrypted=, for example sealed in the TPM) |
| separate file | file |
The file named by NODEPILOT_MASTER_KEY_FILE
|
| plaintext on disk | data-dir |
master.key in the data directory, next to the database |
On first start with an empty database the panel creates master.key in the data directory (mode 0600). It never creates a new key over existing data: if no key is found but the database already has users, servers or identities, it refuses to start. It also refuses to start with a wrong key.
Keep an offline copy of the key. Without it, stored credentials cannot be decrypted.
packaging/seal-master-key.sh (in the release asset nodepilot-linux-packaging.tar.gz) seals the key with systemd-creds so it is no longer on disk in plaintext. A stolen disk, VM snapshot or backup of /var/lib/nodepilot cannot be decrypted without that machine's TPM.
Requirements: run as root; systemd 250 or newer (Ubuntu 24.04+, Debian 12+); systemd-creds; a usable TPM 2.0 (systemd-creds has-tpm2). In a VM, enable a virtual TPM (vTPM / swtpm). The script uses the standard install paths.
sudo ./packaging/seal-master-key.sh --backup-to /root/nodepilot-master.key.backupWhat it does:
- Copies the key to the backup file (fails if the file already exists; mode 0400). Move that copy off the server and delete it there.
- Encrypts
/var/lib/nodepilot/master.keyinto/etc/nodepilot/master.key.credwithsystemd-creds encrypt --with-key=tpm2 --name=master.key. - Checks that the credential decrypts back to the same key.
- Writes the drop-in
/etc/systemd/system/nodepilot.service.d/master-key.confwithLoadCredentialEncrypted=master.key:/etc/nodepilot/master.key.cred, reloads systemd and restarts the panel. - Waits 3 seconds and checks that the service is active. If not, it stops and keeps the plaintext key.
- Deletes the plaintext key (
shred -u, orrmifshredis missing).
Options:
| Option | Meaning |
|---|---|
--backup-to <file> |
Write a copy of the key to <file> before sealing. |
--i-have-a-backup |
Seal without making a copy, confirming you already have one. Without this or --backup-to, the script refuses to run. |
--with-key tpm2 |
Bind the credential to the TPM only. This is the default. |
--with-key host+tpm2 |
Bind it to the TPM and to the host key /var/lib/systemd/credential.secret. |
--unseal |
Reverse the process: decrypt the credential back to /var/lib/nodepilot/master.key (owned by nodepilot), remove the drop-in and restart the panel. /etc/nodepilot/master.key.cred is kept; delete it if you no longer need it. Use this before moving the panel to another machine. |
-h, --help
|
Show usage. |
After sealing, reload the Security page: the Master key card should show the source as sealed ("systemd credential"). The card also shows whether a TPM and systemd-creds were found, and warns if a plaintext copy is still in the data directory.
Note
The default systemd unit sets PrivateDevices=true, which hides /dev/tpm* from the panel. The card therefore also checks /sys/class/tpm, and a key that already comes from a systemd credential counts as TPM-backed. The script checks the TPM itself with systemd-creds has-tpm2.
If the TPM or the motherboard fails, the sealed credential cannot be decrypted. Restore the key from your offline backup to /var/lib/nodepilot/master.key, remove the drop-in and restart.
CLI commands such as nodepilot user reset-2fa, nodepilot token create and nodepilot mcp open the same database and need the master key too. Outside the service there is no $CREDENTIALS_DIRECTORY, so when the key is sealed (/etc/nodepilot/master.key.cred exists and there is no master.key in the data directory) the CLI runs itself again through systemd-run: systemd decrypts the credential, and the command runs as the owner of the data directory, so database files keep the service's ownership. Just use sudo:
sudo nodepilot --data-dir /var/lib/nodepilot user reset-2fa aliceWithout sudo the command stops with "the master key is sealed in the TPM; run this command with sudo". If you keep the credential elsewhere, point NODEPILOT_MASTER_KEY_CRED at it.
In a container, keep the key outside the data volume: pass it as a Docker secret and set NODEPILOT_MASTER_KEY_FILE=/run/secrets/nodepilot_master_key. The source then shows as "separate file". See Installation and Configuration.
The panel records who did what. Open Audit log in the sidebar (or Audit log on the Security page).
What is recorded:
- every API request that changes something (anything except
GET), with its outcome (okorerror: HTTP <code>); - every request denied for lack of token permissions (outcome
denied); - sign-ins (
auth:login:ok,denied,locked) and the initialauth:setup; - commands:
execwith the command text and exit code,exec:bulk,terminal:open,terminal:input(first 500 characters of the input); - 2FA changes, panel key deploy/rotate/revoke, backup key generation;
- every MCP tool call (
mcp:<tool>) with its arguments.
Each entry has the time, severity, user, API token name (if any), client IP, action, target, details and outcome. In the details, values of fields whose names contain password, passphrase, secret or private_key, and of fields named token, are replaced with *** before storage.
Text typed into terminal sessions through the API or the MCP terminal_send tool is logged as-is (up to 500 characters). Don't type secrets at prompts there if you don't want them in the log.
Severity:
| Severity | Examples |
|---|---|
critical |
Bulk exec; token, security, 2FA, identity and audit settings changes; host key reset; power actions; update install; locked logins; denied or destructive MCP calls |
warning |
Single exec, terminal activity, deletes, file and service changes, denied requests, wrong passwords, MCP calls that write |
info |
Everything else |
| Filter (UI) | Query parameter | Behaviour |
|---|---|---|
| Action or target… | q |
Substring of the action, target or details |
| User | actor |
Exact username |
| Severity | severity |
Minimum: Any severity, Warnings and critical, Critical only |
| Load older | before_id |
Entries older than this id (paging) |
limit |
Default 200, maximum 1000 |
curl -H "Authorization: Bearer $NP_TOKEN" \
"https://panel.example.com/api/audit?severity=critical&q=exec&limit=50"Reading the log and its settings needs admin:read; changing settings needs admin:write.
Keep in the panel, days (retention_days): from 7 to 3650, default 180. Older entries are purged once a day.
Someone who takes over the panel host can wipe the local log. Forward events off the server so the copy survives. Configure it under Security → Audit log forwarding:
| Field (UI) | API field | Notes |
|---|---|---|
| Syslog | syslog |
udp://host:port or tcp://host:port. Empty turns it off. |
| Webhook URL | webhook_url |
http:// or https://. Each event is POSTed as JSON. Empty turns it off. |
| Webhook secret | webhook_secret |
HMAC signing secret, stored encrypted. Empty string removes it. Never returned; the API shows webhook_secret_set. |
| Forward events from | min_severity |
info, warning or critical. The panel's own log keeps everything. |
| Keep in the panel, days | retention_days |
7–3650 |
Send test event (or Save and test) sends a test event to the configured destinations and reports delivery errors.
Syslog messages are RFC 5424 with facility authpriv, app name nodepilot and message ID audit. Severity maps to syslog levels: critical → 2, warning → 4, info → 6. TCP uses octet counting (RFC 6587). The message body is the same JSON as the webhook payload.
Webhook payload:
{
"ts": "2025-01-01T03:00:00.123Z",
"severity": "critical",
"actor": "admin",
"token": "claude-code",
"ip": "203.0.113.5",
"action": "mcp:bulk_exec",
"target": null,
"details": { "command": "apt-get -y upgrade", "project_id": "…" },
"outcome": "ok",
"source": "nodepilot"
}The request has Content-Type: application/json and User-Agent: nodepilot-audit, and times out after 10 seconds. Delivery is best-effort: a failed delivery is logged by the panel and not retried.
When a webhook secret is set, each request carries:
X-NodePilot-Signature: sha256=<hex HMAC-SHA256 of the raw request body, keyed with the secret>
Compute the HMAC over the raw body bytes exactly as received, before parsing the JSON, and compare in constant time.
Python (Flask):
import hashlib, hmac, os
from flask import Flask, request, abort
SECRET = os.environ["NODEPILOT_WEBHOOK_SECRET"].encode()
app = Flask(__name__)
@app.post("/nodepilot-audit")
def audit():
body = request.get_data() # raw bytes
expected = "sha256=" + hmac.new(SECRET, body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, request.headers.get("X-NodePilot-Signature", "")):
abort(401)
event = request.get_json()
print(event["severity"], event["actor"], event["action"], event["outcome"])
return "", 204Node.js (Express):
const crypto = require("crypto");
const express = require("express");
const app = express();
app.post("/nodepilot-audit", express.raw({ type: "application/json" }), (req, res) => {
const expected = "sha256=" + crypto.createHmac("sha256", process.env.NODEPILOT_WEBHOOK_SECRET)
.update(req.body).digest("hex");
const got = req.get("X-NodePilot-Signature") || "";
if (got.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected))) {
return res.sendStatus(401);
}
const event = JSON.parse(req.body);
console.log(event.severity, event.actor, event.action, event.outcome);
res.sendStatus(204);
});Your endpoint must answer with a 2xx status. Anything else counts as a failed delivery.
The top of the Security page scores the panel's setup ("N of M checks passed") and links each item to the place where you fix it. It is built from GET /api/security/status (needs admin:read).
| Check | Passes when | Otherwise |
|---|---|---|
| Master key | Loaded from a systemd credential or from NODEPILOT_MASTER_KEY_FILE
|
Warning: plaintext file next to the database |
| Plaintext copy of the master key | (shown only when it applies) | Warning: the key is loaded from elsewhere but master.key is still in the data directory |
| Two-factor authentication | 2FA is on for you and more than 3 recovery codes are left | Warning: 2FA is off, or few codes are left |
| Panel SSH key | Restricted by address and used by all servers | Warning if accepted from any address; info if not set up or not on every server |
| Backup encryption | All jobs encrypted to public keys | Warning if any job is unencrypted; info if any job uses a passphrase, or there are no jobs |
| API tokens | No token has full access and every token has an expiry | Warning listing full-access tokens and tokens without expiry |
| Audit log forwarding | Syslog or a webhook is set | Info |
| HTTPS | Secure cookies are on | Warning |
The 2FA check is for the signed-in user. The token check counts the API tokens of all users.
The panel listens on 127.0.0.1:7780 by default and serves plain HTTP. Put it behind a reverse proxy with TLS (nginx, Caddy, Traefik), ideally reachable only over a VPN, and start it with secure cookies:
# /etc/nodepilot/nodepilot.env
NODEPILOT_SECURE_COOKIES=trueor nodepilot serve --secure-cookies. See Configuration.
The browser session cookie is np_session with HttpOnly, SameSite=Strict, Path=/ and a 30-day lifetime. With secure cookies on it also has Secure, so browsers send it only over HTTPS. Without it, the checklist shows the HTTPS warning.
Sign-out deletes the session on the server. Changing a password with nodepilot user passwd and resetting 2FA with nodepilot user reset-2fa end all of that user's sessions.
- A token is
np_followed by 64 hex characters (32 random bytes). API tokens and browser sessions use the same format. - The database stores only the SHA-256 hash of the token, never the token itself. An API token is shown once, when it is created. If you lose it, revoke it and issue a new one.
- Sessions expire after 30 days. API tokens expire after
expires_in_days(1–3650) or never (0). -
last_used_atis updated at most once a minute. - Each token carries its own permissions. A token can never create or edit a token with more access than it has itself.
- User passwords are hashed with Argon2id and must be at least 8 characters.
Recommendations:
- Give each client its own token, with only the areas it needs and an expiry date.
- Don't give AI agents
admin, and avoidexecwhere you can. See MCP-and-AI-Agents. - Revoke tokens you no longer use (API → Tokens).
NodePilot · Releases · Report a vulnerability · Apache-2.0
Set up
Use
Secure
Integrate
Reference