Security
About 1901 words
unifi-cli holds a credential that can reconfigure your network. This page says where that credential lives, what the tool sends and to whom, and what you can do to limit the damage a leaked key or a careless command could cause.
Where the API key lives
An API key is in exactly one of three places, and never in the configuration file.
| Store | When | Protection |
|---|---|---|
| OS keychain | The default. macOS Keychain, the Secret Service on Linux, Windows Credential Manager. A keychain that doesn't answer within three seconds is skipped in favor of the file. | Whatever your OS gives its keychain; one entry per account under the service name unifi-cli, or unifi-cli:<path> for a configuration file at a non-default location. |
| Credentials file | On machines without a keychain, or when UNIFI_CREDENTIAL_STORE=file is set. ~/.config/unifi-cli/credentials.yaml. | File mode 0600. unifi-cli refuses to read it when group or others have access. The key is in plain text. |
UNIFI_API_KEY | When you set it. | None beyond your process environment. It overrides both stores above. |
Because the configuration file holds no secrets, you can commit it to a dotfiles repository.
When you sign in, prefer --api-key-stdin or the interactive prompt over --api-key. Command-line arguments are visible in the process list and end up in shell history.
When a key is saved to one store, a stale copy of it in the other is removed, so there is one place to look.
unifi logout and unifi ctx delete remove the stored key. A key you created yourself stays valid at Ubiquiti until you delete it where you created it.
What the e-mail sign-in stores
The experimental --sso sign-in asks for your UI account password and one-time code, uses them once to create a Site Manager API key, and never stores the password. The key is named unifi-cli (<hostname>) and expires after a year unless --key-expiration says otherwise.
It does store one more thing next to the key: the session cookie of the sign-in. Its only use is revoking that key later with unifi logout --revoke-key; no other command sends it anywhere. If you'd rather not have it on disk, sign in with --no-store-session, and logout asks for your password when you want the key revoked.
What goes where
unifi-cli makes network connections to these places and no others:
| Destination | When | What is sent |
|---|---|---|
Your controller, at the context's address | local contexts | API requests with the key in the X-API-KEY header |
api.ui.com | cloud contexts | The same requests, forwarded to your console by the cloud connector, plus console listing and ISP metrics |
The UI account services (sso.ui.com, developer.svc.ui.com) | unifi login --sso, and unifi logout --revoke-key for a key it created | e-mail, password, one-time code; then the session to create or revoke the key |
| Your OTLP endpoint | only when telemetry.otlpEndpoint is set | traces of API calls |
There's no update check, no usage analytics and no crash reporting. With tracing off, which is the default, a local context talks to your console and to nothing else.
The API key goes to the origin it was issued for and nowhere else. unifi-cli doesn't follow a redirect to another origin: if a controller, or something pretending to be one, answers with a redirect elsewhere, the request fails instead of carrying the key there.
With a cloud context, your requests and the controller's answers pass through Ubiquiti's cloud. That's the same path the UniFi mobile app and unifi.ui.com use; if you'd rather keep management traffic on your own network, use a local context.
TLS
Connections to api.ui.com are verified against your system's certificate authorities, with no way to turn that off.
Consoles ship with a self-signed certificate, so local contexts need a decision:
- Pinning trusts exactly the certificate the console presented when you signed in.
unifi loginshows its SHA-256 fingerprint for you to compare with the console's, saves the certificate undercerts/in the configuration directory, and sets it as the controller'scaFile. A different certificate later is an error that prints the pinned and the presented fingerprint side by side and stops every command for that controller until you pin again. This is trust on first use: it protects every connection after the first, and the fingerprint comparison is what protects the first. caFilewith a file you exported yourself does the same with a certificate or an authority of your choosing.insecureSkipTlsVerify: truetrusts anything. The connection is still encrypted, but to whoever answers, and that party receives your API key in the first request.
On a home network you control end to end, skipping verification is a common shortcut, and pinning costs one more keypress. On a network you share, or across a VPN you don't run, pin. unifi ctx describe prints which of these a context uses.
A certificate can only be pinned for an address it is valid for; a factory certificate issued to unifi.local can't be pinned for an IP address. Signing out, or deleting the last context of a controller, removes its pinned certificate from certs/.
Secrets in output
Objects on the controller contain secrets: WiFi passphrases, RADIUS shared secrets, VPN private and pre-shared keys, the device SSH password.
unifi-cli redacts them wherever it prints an object. describe, get --output yaml|json, export, diff, set --dry-run and everything unifi shell prints show <redacted>; tables don't show secret fields at all. A changed secret appears in a diff as <redacted> → <redacted> (changed). The shell's history file keeps a line that sets a secret with the value redacted.
One classifier decides what a secret is, for output, for the log and for the cache alike. A field counts as secret when its name starts with x_ (the controller's own convention), contains a word such as passphrase, password, secret, token, cookie, psk or community, or ends in key. Names that describe a secret instead of holding one, such as x_ssh_auth_password_enabled, keyExpiresAt or publicKey, are exempt. The rule is by name, so it's a net with a known mesh: a secret that a future Network version stores under an innocent field name would get through. Look at an export before you publish it.
--show-secrets on get, describe and export prints the real values in YAML and JSON. The values then exist in your terminal's scrollback, in any file you redirect to, and in the context of any AI agent that ran the command.
Secrets don't travel on command lines either. A WiFi passphrase is read from a prompt or from standard input (--passphrase-stdin), --set refuses a path that names a secret and points at --set-stdin <path> instead, and unifi login warns when a key is passed with --api-key, because arguments show in the process list and in shell history.
unifi export writes its files with mode 0600. A redacted export is safe to commit; an export made with --show-secrets is as sensitive as the keys in it.
The cache
The cache under the state directory holds site lists, completion candidates, the last dashboard snapshot and the like, for minutes to a day. It never holds an API key or another secret: the store refuses a value with a field named like one. It does hold names and addresses from your network, as the log does. Delete the directory whenever you like.
The log
The log file (~/.local/state/unifi-cli/unifi.log) records request paths, status codes, durations and errors. It's created with mode 0600.
Every record passes a filter that blanks attributes whose name looks like a key, password, secret, token, cookie or authorization header. Request bodies aren't logged; a failed request logs the controller's short error message.
What the log does contain is the shape of your network: controller addresses, site names, device and client names in error messages. Treat it as internal, and read an excerpt before attaching it to a public issue.
Tracing
Tracing is off unless you set telemetry.otlpEndpoint, and it sends data only to that endpoint. Spans carry the operation, the site, and the device or client an operation targets, by name, ID and MAC address. They carry no API keys and no request bodies.
Point it at a collector you run. A hosted tracing service would receive the names and MAC addresses of your devices.
Limiting what a key can do
The controller, not unifi-cli, decides what a key may do. Use that.
Local keys inherit the role of the administrator who created them. A key created by a view-only administrator can read everything and change nothing. That's the right key for dashboards, monitoring, drift detection in CI, and AI agents that should diagnose but not act.
Give automation its own administrator. The audit log attributes changes to the key's owner, so a dedicated administrator for your CI job or your agent turns unifi events get --audit into an answer to "who did that".
Site Manager keys reach every console of the account. A cloud key is broader than a local one by nature. For automation that manages one site, a local key on that console is the smaller grant.
Rotate after exposure. If a key was in a shell history, a CI log or a world-readable file, delete it on the console or at unifi.ui.com and sign in with a new one: unifi login --name <context> replaces the stored key.
Guard rails against yourself
Not every incident is an attacker.
- Commands that take something live offline or destroy something ask for confirmation, and refuse to run unattended without
--yes. - Objects the controller defines itself can't be changed or deleted, and neither can the default network.
- A field name that no object on the site has is refused as a typo, in
--setand in manifests, unless you pass--force. - In
unifi shell, staged changes are applied bycommitand by nothing else; leaving a mode discards them. - Disabling a device's own uplink port needs
--forceon top of that. applynever deletes unless you pass--prune, and prune is limited to the kinds your manifests contain.- Every configuration change has a preview:
--dry-runorunifi diff. --contextand--siteon the command line make the target explicit, and the prompt segment keeps the current one in view.
These reduce accidents. They aren't access control; a key that may change the network can change it.
The demo controller
unifi-mock ships with fixed, public credentials by design, and it's built to stay on your machine. It listens on 127.0.0.1 unless told otherwise, the compose file publishes its port on loopback only, and its fake UI account refuses sign-in when the mock listens beyond loopback with the public demo password and code. Don't expose it to a network you don't trust, and never point real devices at it.
Report a vulnerability
Please don't open a public issue for a security problem. The repository's security policy explains how to report one privately, and how to verify a release's cosign signature.
