Skip to content

feat: nodkey broker config-diff lists config changes by meaning - #180

Merged
groupsky merged 1 commit into
mainfrom
feat/174-config-diff
Nov 11, 2026
Merged

groupsky merged 1 commit into
mainfrom
feat/174-config-diff

Conversation

@groupsky

@groupsky groupsky commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #174.

What

nodkey broker config-diff [--short] [--max-chars N] OLD NEW lists the changes from one broker config to another by what they mean.

  • OLD and NEW are each a config file, or a directory with broker.toml and known_hosts (as nodkey broker check --files). For a file, known_hosts is read from the directory of the file. Both are read with the parser of the start and of nodkey broker check: config.ReadBrokerFiles (from feat: nodkey broker check checks a config without a start #178). No copy of the config code.
  • config.Diff (internal/config/diff.go) compares the two parsed configs. Comments, order and spaces are no change; lists of clients and hosts are sets.
  • One line per change, sorted by group (top keys and sections, clients, stores, secrets, SSH keys, known_hosts) and name. A line that widens access or weakens a control starts with ⚠.
  • A change that the code does not know as narrowing is marked. A field of the config that the code does not compare by name is still compared by a reflection catch-all (unknown, compared, zeroCompared), and its change is marked "a change that config-diff does not know". TestDiffComparesEveryField fails when a field is in neither list.
  • --short (at most --max-chars, 3500 by default) puts the ⚠ lines first and cuts the rest with "and N more". When the ⚠ lines do not all fit, it gives one line with their count, and says to read the full list.
  • Exit 0 same meaning, 1 different, 2 a config cannot be read or is not valid, 64 wrong usage. No root, no credentials, no network.
  • Text from a config is quoted (strconv.Quote) and each line is cleaned with claim.Line.

Tests

  • TestDiffMarksWidening: one subtest for each kind of widening change in the issue (37 cases): new client; a secret or a key for another client; a new secret; a never rule; always to window; a longer window; wider hours and no hours; a higher and no max_per_day; notify off; more hosts and any host; preapprove; standing; a new [standing]; a longer [standing] and [preapprove] limit; another approver, notice chat, bot token file; a longer timeout; a new pin; another store program, token and password file; a secret in another store or item; another key file; listen, tls_key, audit_log, known_hosts path; a new host; a new host key; update check off.
  • TestDiffNtfy: the channel switch and each [ntfy] setting.
  • TestDiffUnknownIsMarked, TestDiffComparesEveryField: the catch-all.
  • TestDiffSameMeaning: comments, spaces, the order of sections, clients and known_hosts lines give no change.
  • TestDiffNarrowing: narrowing changes are plain lines.
  • TestConfigDiff (exit codes 0, 1, 2; directories and files; as a user that is not root, without credentials), TestConfigDiffUsage, TestConfigDiffShort (the short form keeps every ⚠ line or says they do not fit, and never passes --max-chars).

Security review

The security-reviewer agent found 1 medium and 3 low points. All are fixed: a config file now reads the known_hosts next to it (not the live one at the path in the config, which would hide a new host key; test with two files); notify, max_per_day and hours are compared only between two never rules (a move to never lists them on its marked line); the error hints give the real nodkey broker check command; the short form counts UTF-16 code units, as Telegram does. Its last small style point is fixed too. No open finding.

Progress

  • config.Diff and its tests
  • The command, the short form, exit codes
  • DESIGN.md section 15, THREAT-MODEL.md, docs/setup.md section 7
  • Lint and all tests
  • Security review
  • CI green

🤖 Generated with Claude Code

It reads two configs with the parser of the start, compares them by
meaning, and marks each change that widens access or weakens a control,
and each change it does not know as narrowing. --short fits one
Telegram message and never drops a widening line silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky merged commit c6d8d6d into main Nov 11, 2026
7 checks passed
@groupsky
groupsky deleted the feat/174-config-diff branch November 11, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: nodkey broker config-diff — list config changes by meaning, mark the ones that widen access

1 participant