hub/docs/cli.md
trvon c100f89cad
All checks were successful
release / build (push) Successful in 4m8s
hub edr: strawberry summary per host from /v1/edr
One block per host: version, status, rule age, feed state and finding counts,
then up to five findings. Exit 1 when rules are stale, status is not ok or a
high/critical finding is open. A 404 says the controller needs the update
(exit 3). edr_* hints in hub findings point here.
2026-11-14 13:20:20 -07:00

10 KiB

hub: operator CLI

One static Go binary (standard library only) for the operator of a Security Hub fleet. It reads fleet status over the read-only fleet API and adds host adoption: probe, suggest, diff, plus hub self-update. It never changes the hub: the fleet API is GET-only, hub profile is a read-only probe over ssh. License: GPL-3.0-or-later.

Install

Download hub-<version>-<os>-<arch> and its .sha256 from the release page, or build from source:

make hub-darwin-arm64            # the Mac;  make hub-linux-amd64 for a Linux host;  make hub for this machine
cp bin/hub-darwin-arm64 ~/bin/hub
hub version

Builds use CGO_ENABLED=0 -trimpath; VERSION=x.y.z make hub stamps the version (no VERSION: hub version prints hub 0.0.0-dev+<short sha> when Go recorded the commit, else hub 0.0.0-dev). bin/ is gitignored. Needs Go 1.27, no modules. make test runs go vet, go test and the Python probe tests.

Self-update

hub self-update --check          # current vs newest published release; exit 0 up to date, 1 update available
hub self-update                  # verify and install the newest release
hub self-update --version v0.1.0 # install that release (the only way to downgrade)

The forge defaults to the public release repository (update_url / update_repo in hub.json override it; https only, no token). Verification and replacement order is in docs/releasing.md. It needs the gpg CLI (--check does not). Exit codes: 0 ok, 1 update available (--check), 2 refused (bad signature, hash, version, downgrade, no gpg), 3 forge unreachable.

Config

~/.config/security-hub/hub.json (optional; HUB_CONFIG picks another path):

{"fleet_url": "http://100.64.0.1:8092", "token_file": "~/.config/security-hub/fleet-token",
 "repo_path": "~/ops", "inventory": "~/ops/hosts", "managed_paths_file": "~/ops/managed-paths.txt"}
Setting Default Env override
fleet_url none: fleet commands fail with set fleet_url until it is configured SECURITY_HUB_FLEET_URL, --url
token_file ~/.config/security-hub/fleet-token (mode 0600) HUB_TOKEN_FILE; SECURITY_HUB_FLEET_TOKEN holds the token itself
repo_path found by walking up from the current directory to a directory holding hosts and salt-security-hub/ HUB_REPO
inventory <repo_path>/hosts HUB_INVENTORY
managed_paths_file none: the built-in list HUB_MANAGED_PATHS
update_url, update_repo the public release repository none

repo_path is the repository root (the directory with hosts, local/, salt-security-hub/). Profiles go to <repo_path>/local/profiles/ (gitignored). The token is read from the environment or the file and is never printed.

Exit codes: 0 ok, 1 drift / stale snapshot / rebuild or drift in profile-diff, 2 configuration (bad token, 401, unknown host, missing profile, bad arguments), 3 transport (unreachable, HTTP error, ssh failure). --json goes before the command (it is also accepted after it).

Fleet commands

$ hub status
snapshot 2026-11-08T12:00:00Z age 30s
alpha publish rc=0 60s failed24h=0 highstate 0/118 3600s
server publish rc=0 90s failed24h=0 highstate 0/131 3600s
$ hub drift                      # repo module hashes vs deployed; exit 1 on any mismatch or stale snapshot
match /srv/salt/_modules/security_hub_audit.py repo=0123456789ab live=0123456789ab
$ hub jobs --host server --fun test.ping --limit 5
$ hub backups                    # backup jobs from /v1/backups; exit 1 when a job is failed, never_succeeded or overdue
alpha ok last_success=2026-11-08T11:00:00Z age_h=1.0 max_age_h=26
  pool/home -> backup/alpha/home rc=0 snapshot=2026-11-08T10:59:00Z
alpha-files running last_success=2026-11-07T11:00:00Z age_h=25.0 max_age_h=26
  progress pool/home 1/2 received=1.2 GiB
  previous ok finished 2026-11-07T11:00:00Z
$ hub edr [--host H]             # strawberry (EDR) per host from /v1/edr; exit 1 on stale rules, status not ok or a high/critical finding
alpha strawberry 0.2.5 ok rules 23h feed ok findings 1 (1 low)
  low Example finding last_seen 2026-11-14T08:00:00Z
$ hub findings [--host H]        # ranked flags per host; exit 1 when any flag or stale host, 2 unknown host
fleet-wide: third_party_updates_pending (w3) on 2 hosts -- apply package updates (update playbook, human-run)
beta critical_priority score=23
  ssh_root_login_not_disabled        w4  open 2d4h    queue remediate-ssh-root-login-host
  disk_space_low                     w2  open 3h12m   find what grew: du / docker system df
  backup nightly failed reason=disk full
  actions: remediate-ssh-root-login-host (aq-0006 failed), security-harden-host
gamma STALE last_report=2026-10-01T18:51:56Z
$ hub --json status              # the API envelope, sorted keys, indent 2

hub findings joins /v1/posture (required), /v1/alerts?state=open&limit=200, /v1/queue and /v1/backups. Hosts are sorted by severity (critical_priority, high_priority, stale_audit, others), score descending, name. Flags are ranked by weight descending, then name (weights copied from the triage script; backup_failed:<job> weighs 3, unknown flags 1). A flag present on every non-stale host (at least two hosts) is printed once as fleet-wide: and left out of the host blocks. open is the age of the open alert for that host and flag (- without one); the last column is a short next step. actions: lists the host's suggested actions except security-audit-host and security-validate-host, with the newest queue entry for that action and host as (id status). Flagged backup jobs (failed, never_succeeded, overdue; not running) are listed under the host that reports them. A stale host prints STALE last_report=<ts> only. A 404 on alerts, queue or backups drops that part and adds one note: line; a 404 on posture exits 3. Exit codes: 0 no flag and no stale host, 1 otherwise, 2 config or unknown --host, 3 transport.

hub --json findings prints the model with sorted-by-struct keys: generated_at, fleet_wide (flag, weight, hosts, hint), hosts (host, severity, score, stale, last_report_at, flags (flag, weight, opened_at, open_seconds, hint; the first two timing keys are omitted without an alert), actions (action_id, queue {id, status} when queued), backups (job, state, overdue, reason)), notes.

hub edr prints one block per host with strawberry enabled: <host> strawberry <version> <status> rules <age>h feed <ok|stale> findings <total> (<severity counts>), then up to 5 <severity> <title> last_seen <ts> lines. feed is stale when the API reports rules_stale or a failed feed. Exit codes: 0 all hosts healthy (or section unavailable, or no host has edr), 1 any host with rules_stale, a status other than ok, or a high/critical finding in the lookback window, 3 transport (including HTTP 404 from an older controller: /v1/edr is missing). --json prints the API envelope. edr_* hints in hub findings point at hub edr.

backups against an older controller (HTTP 404) prints that /v1/backups is missing and exits 3. status appends accepted but silent: a, b if the API returns a silent_hosts list (forward compatible; today it does not). drift --repo-root DIR overrides <repo_path>/salt-security-hub.

Adopting a host

hub profile <host>               # ssh BatchMode, probe on stdin, 90 s, 2 MiB; writes local/profiles/<host>-<UTC>.json and <host>-latest.json (0600)
hub suggest <host>               # from <host>-latest.json + inventory
hub profile-diff <host>          # two newest dated profiles

hub profile resolves ansible_host, ansible_user and ansible_port from the inventory (hosts without ansible_host use their name, so an ssh alias works), then runs ssh -o BatchMode=yes -o ConnectTimeout=10 -p PORT USER@ADDR python3 - with probe/hostprobe.py (embedded, byte for byte) on stdin. Address and user must be plain values (no leading -, no spaces). The profile is checked against schema 1 before anything is stored; a failed probe leaves no file. Contract: docs/adopting-a-host.md.

hub suggest prints four parts (--json gives the same data):

  • GROUPS: apt/yum, ci (forgejo-runner unit), protected_services (Forgejo image), managed_admin; ok marks groups the host is already in.
  • PILLAR: compose_projects from containers with a compose project label (containers without one, such as FORGEJO-ACTIONS-TASK-*, are ignored). services: the service named like the project first, then alphabetical. allowed_ports: distinct non-loopback published host ports (IPv4 and IPv6 collapse), [] when a project publishes nothing, omitted with a comment above 16 ports (open lab). forbid_root: true when every compose container has a non-root user. expected_nopasswd_users is rendered for the per-host pillar file (pillar/security_hub/<host>.sls, dashes become underscores) when sudo -n works. Nothing is written; review and paste.
  • BLOCKERS: inventory address not on tailscale0, no sudo -n, sshd AllowUsers/AllowGroups set (or unreadable), salt-minion id differs from the inventory name, hostname differs from syslog_hostname.
  • CANDIDATES: hand-made scripts (path, owner:group, mode, sha256, unit) and units, non-loopback listening ports (consecutive ports collapsed), sshd PasswordAuthentication yes / PermitRootLogin yes, fail2ban missing or inactive, no active firewall, privileged containers, anything the probe could not read. Paths that Salt already installs are left out. They come from managed_paths_file: a text file with one absolute path per line (blank lines and # comments ignored; any other line, or a file without paths, is an error). Without that setting a built-in list of the paths a Security Hub rollout installs is used (suggest.DefaultManagedPaths); a configured file replaces it.

hub profile-diff prints REBUILD: lines when the machine-id prefix or the host key set changed, then drift: containers, listening sockets, units, candidate hashes and a few sshd/sudo settings (+ added, - removed, ~ changed). Exit 1 on a rebuild or any drift.

Layout

cmd/hub (command registry), internal/{config,fleet,inventory,probe,suggest,pillar}, internal/{selfupdate,version}, probe/embed.go (go:embed of probe/hostprobe.py, the single source of truth). New views add a route and a renderer to internal/fleet and one entry in commands(); transport, auth and exit codes are shared.

Tests use httptest servers and a fake ssh first on PATH; no host or Forgejo is contacted.