Skip to main content
Glama
NetDefense for OPNsense

NetDefense for OPNsense

Official
README.md
# ndcli

**Manage a fleet of OPNsense firewalls from your terminal — or let any MCP-compatible AI agent do it.**

`ndcli` is the command-line interface and MCP server for [NetDefense for OPNsense](https://netdefense.io): list devices, push config, run health checks, roll out firmware, manage backups, and orchestrate an entire organizational unit or fleet from one command — scriptable end to end, no web app required.

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)

## Give an AI agent your firewall fleet

The second binary in this repo, `netdefense-mcp`, exposes **182 [MCP](https://modelcontextprotocol.io) tools** covering every domain `ndcli` does — devices, organizations, OUs, sync, tasks, run commands, schedules, snippets, software policies, templates, networks, variables, backups, firmware tracks, support tickets, the responder console, and persistent remote consoles. Point Claude, or any other MCP-compatible client, at it and it can inspect and operate your entire fleet the same way a human operator would from the CLI — not a single device, the whole organization.

**Start with the sharp edge, because it's the one that matters.** `ndcli.device.console_exec` runs arbitrary shell commands on a device, with administrative privilege, and takes no confirmation flag. It is gated on the caller's role — a read-only token is refused before a stream ever opens — but an agent holding a write-scoped token has a shell. Scope the token you hand an agent accordingly, and if you want a hard limit that no token can cross, set the device-side remote-access policy on the firewall itself (Services → NetDefense → Settings), which caps what any session may be regardless of who asks.

The rest of the AI-facing surface has real, but narrower, guardrails:

- **Destructive and fleet-wide tools require an explicit confirmation.** Every tool whose name says delete, remove, rename, revoke or disable (`ndcli.device.remove`, `ndcli.org.delete`, `ndcli.schedule.disable` and the rest), detaching backup from its schedule (`ndcli.backup.config_set_schedule`), and fleet-wide actions such as `ndcli.device.approve_all`, `ndcli.sync.apply` and the `ndcli.run.*` commands, return a dry-run preview unless the caller passes `confirm=true` — an agent can't wipe a fleet on its first hallucinated call. Many other changes act at once: most tools that create or add things, every enable, attaching backup to a schedule, replying on a ticket, and `console_exec` (see above).
- **High-impact tools ask you, not the agent.** Approving devices (`ndcli.device.approve`, `ndcli.device.approve_all`), removing, powering off or restarting devices, attaching snippets, software policies, templates or devices (`ndcli.template.add_snippet`, `ndcli.template.add_software`, `ndcli.ou.template_add`, `ndcli.ou.add_device`), changing a role or sending an invite, opening a console session, and every tool that reads or writes a local file (the attachment tools and `attach_paths`) run only after you approve the exact call in a prompt your MCP client shows you (MCP elicitation). The prompt shows what the server looked up, such as a pending device's uuid and registration time. If that changes while the prompt is open, say a device registers, the call is refused (`APPROVAL_STALE`) and nothing runs. `confirm=true` alone does not run them: the agent can set it, but it can't answer the prompt. A client that cannot show the prompt gets `APPROVAL_UNAVAILABLE` and the `ndcli` command to run yourself. Setting `"NDCLI_MCP_APPROVAL": "off"` in the server's `env` runs these tools without asking, as a plain `confirm=true` call: it reopens the gap the prompt closes, since an agent steered by text in a device name, a ticket or a variable can then approve devices, attach configuration or upload files on its own. The prompt comes once per `console_open`, not per `console_exec`, so command output read during a session can still steer the commands that follow.
- **It structurally cannot mint non-expiring credentials.** `ndcli.auth.token_create` only accepts bounded lifetimes (30–365 days) over MCP; a `never`-expiring personal access token can only be created interactively on the CLI — the MCP tool schema doesn't offer the option, and the handler rejects it if forced.
- **Secrets never enter the AI-facing toolset.** Backup encryption keys and storage credentials have no MCP tool and no MCP-exposed field. They're reachable only via `ndcli backup encryption-key` and `ndcli backup config set` on the CLI. The organization's agent token, which registers devices, is returned only by `ndcli.org.create`, once; `ndcli.org.describe` leaves it out, and `ndcli org describe` shows it.
- **Ticket attachment tools touch the local filesystem.** `ndcli.support.attachment_upload`, `ndcli.respond.attachment_upload` and the `attach_paths` of the create, reply and note tools read a local path on the machine running the server (a regular file, at most 25 MiB), and only inside the directories listed under `mcp.attachment_dirs` in ndcli's `config.yaml` (none until you add one; `~/` is your home directory, and each directory covers its subtree). ndcli's own configuration and credential files are never uploaded; `ndcli.support.attachment_download` and `ndcli.respond.attachment_download` write one, always as a new file named `netdefense-<code>-<random>` in the directory set under `mcp.download_dir` in `config.yaml` (the server's working directory when unset; some MCP clients start servers in `/`, where nothing can be written): the filename an attachment carries is chosen by whoever uploaded it and is never used on disk, and the tools take no destination path and never overwrite. They are the only tools in the set that read or write local files.
- **Interactive login and account deletion stay CLI-only.** Browser-based login and `ndcli auth delete` aren't exposed to MCP — they need a human in the loop by design. Note this is about those *commands*: `ndcli device connect` is CLI-only too, but the underlying device-session capability is reachable over MCP through the `console_*` tools, so treat "CLI-only command" and "not reachable by an agent" as different things.

Point any MCP-compatible agent at the `netdefense-mcp` binary (config shape varies by client; this is the common form):

```json
{
  "mcpServers": {
    "netdefense": {
      "command": "netdefense-mcp",
      "env": { "NDCLI_TOKEN": "ndpat_..." }
    }
  }
}
```

The server uses ndcli's default config. To point it at another one, add `"args": ["--conf", "/path/to/config.yaml"]` with an absolute path; the file must exist. `netdefense-mcp --help` lists its flags and exits.

Every tool carries MCP annotations: `readOnlyHint` on the tools that change nothing, and `destructiveHint` on those that overwrite, remove or act on a device. To offer an agent only the read-only tools, start the server with `--read-only` (or set `"NDCLI_MCP_READ_ONLY": "true"` in its `env`). Names, device facts, variable values and ticket text in tool results are written by organization members, devices and support, not by you, so an agent can meet text that tries to instruct it; the server tells the agent to treat them as data, and read-only mode is the hard limit when you only need answers.

Each tool result has two text blocks. The first is the server's own header: `success`, `error_code` and `pagination` when they apply, and `result`, a note naming the tag of the second block. The second is the response JSON (`success`, `data`, `message`, `error`, `pagination`) between `<ndcli-data-TAG>` and `</ndcli-data-TAG>` lines, with a new random tag for each result. Text in the data can't close the block early, because the encoder writes `<` and `>` as `\u003c` and `\u003e`. Programs read the response by dropping the first and last line of the second block; results carry no `structuredContent`. The `ndcli://org/{name}` and `ndcli://org/{name}/devices` resources use the same block, as `text/plain`.

Full tool list and setup: https://netdefense.io/docs/mcp/

## Install

### Homebrew (macOS / Linux)

```bash
brew install netdefense-io/tap/ndcli
```

### Scoop (Windows)

```powershell
scoop bucket add netdefense https://github.com/netdefense-io/scoop-bucket
scoop install ndcli
```

### Binary downloads

Pre-built archives for macOS (amd64/arm64), Linux (amd64/arm64), and Windows (amd64) are on the [ndcli-releases](https://github.com/netdefense-io/ndcli-releases/releases) page. Each archive contains `ndcli`, `netdefense-mcp`, the `netdefense` terminal UI and `netdefense-connect`.

`netdefense-connect` is a companion the other three start for a remote session when the organization uses the direct-peer + encrypted relay transport. It is looked up beside the program that starts it, so keep the four in one directory. `THIRD_PARTY_NOTICES`, in the same archive, holds the licences of the software they are built from.

### From source

Requires Go 1.27.4+.

```bash
git clone https://github.com/netdefense-io/NDCLI.git
cd NDCLI
make build build-mcp
make build-connect   # the companion for direct-peer + encrypted relay sessions
```

## Usage

```bash
ndcli auth login                              # interactive login, opens a browser
ndcli config set org acme-corp

ndcli device list                             # see the fleet
ndcli device approve edge-fw-03               # bring a newly-registered device under management
ndcli run ping --device edge-fw-03 --host 1.1.1.1
ndcli sync apply --ou branch-offices
ndcli device health edge-fw-03 -f detailed
```

Every command supports `-f table|simple|detailed|json`. Run `ndcli --help` for the full surface.

Exit status: 0 on success, 1 when a command fails, and 3 when a bulk command (`device approve-all`, `sync apply`) succeeded for some devices and failed for others.

## Security model

NDAgent — the daemon that runs on the firewall — understands exactly **eleven named operations**: ping, config sync, config pull, restart, reboot, shutdown, backup, remote session, plugin install, firmware upgrade, firmware track step. It rejects anything else.

Every command dispatched to a device is **Ed25519-signed**, covering the operation, the target device, an expiry, and a strictly-increasing per-device sequence number — so a command can't be replayed, reordered, or forged by a compromised relay in the middle. The agent **opens no listening ports**; it only dials out over TLS, so there's nothing on the device for an attacker to scan or connect to.

**What that does and doesn't buy you.** All of the above is integrity on the *command channel*: it stops tampering, replay, misdelivery, and a compromised relay minting instructions. It is not containment. One of those eleven operations is a remote session, and a session reaches a shell — so a compromised control plane, or a stolen credential with write access, is not stopped by any of it. The honest claim is cryptographic integrity on the channel, not "an attacker with your credentials can't do anything".

The limit that *is* enforced against a caller who already holds write access is set on the device, not here: NDAgent's remote-access policy caps every session at `full`, `readonly` (web UI only — no shell, no SSH, no exec stream) or `disabled`, and the control plane cannot raise it.

Full writeup and threat model: **https://netdefense.io/security**

## What's open source

NDAgent and NDCLI (this repo) — the daemon that runs on your firewall, and the CLI/MCP server you run from your workstation — are open source under **Apache-2.0**. The source is public, so your team can also review the code that runs on your firewall and your workstation: build it from source, and read how the agent verifies signed commands, the agent's operation set and the MCP tool definitions directly.

The control plane that coordinates a fleet — the API, the web app, scheduling, and the device relay — is closed-source SaaS, with a free tier for personal use. See [netdefense.io/pricing](https://netdefense.io/pricing) for details.

## Links

- Docs: https://netdefense.io/docs/ndcli/getting-started/
- MCP setup: https://netdefense.io/docs/mcp/
- Security model: https://netdefense.io/security
- NDAgent (the firewall-side agent, also open source): https://github.com/netdefense-io/NDAgent
- https://netdefense.io

## License

Apache License 2.0 — see [LICENSE](LICENSE).