# 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---` 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+` 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): ```json {"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 | `/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 `/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 --json status # the API envelope, sorted keys, indent 2 ``` `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 `/salt-security-hub`. ## Adopting a host ``` hub profile # ssh BatchMode, probe on stdin, 90 s, 2 MiB; writes local/profiles/-.json and -latest.json (0600) hub suggest # from -latest.json + inventory hub profile-diff # 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/.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.