Skip to content

fix(snmp): ask for the old community per device, not once - #29

Merged
Gerrrt merged 1 commit into
mainfrom
fix/snmp-verify-per-device-old
Aug 19, 2026
Merged

fix(snmp): ask for the old community per device, not once#29
Gerrrt merged 1 commit into
mainfrom
fix/snmp-verify-per-device-old

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Follow-up to #28, which noted this as deliberately out of scope.

What changed

--old prompted once and tested that single string against every device. It now
asks each device separately.

Why

One prompt was correct when a single community was shared across all four
devices. After the rotation each has its own predecessor, so:

  • a string entered once proves nothing about the three devices it never
    belonged to, and
  • there was no way at all to check a device whose old community differed from
    the rest — which is exactly the case for neo.

Enter skips a device, since the usual case is checking the one you just rotated.
Skipping every device is now an error rather than a silent pass: a run that
checked nothing must not print all SNMP targets verified.

Implementation note

The prompt reads from /dev/tty explicitly. The loop’s stdin is the device
inventory, so a bare read would have consumed a device row instead of waiting
for input — the loop would have silently eaten its own work list.

The terminal requirement is unchanged, and each community still reaches net-snmp
only through a 0600 snmp.conf inside a 0700 directory removed on every exit
path, including Ctrl-C.

Blast radius

One script and one runbook section. No config, no service, no credential, no
segmentation change.

  • No change to network segmentation or firewall rules
  • No new port published to a VLAN that could not already reach the service
  • No credential added outside secrets/*.sops.yaml

Verification

All three branches exercised against the live lab, through a pty so the terminal
requirement stayed honest.

A deliberately wrong community — correctly reported as refused:

  old community for neo        (not echoed, Enter to skip):
  PASS neo        10.7.7.2     rejected

A community the device does still accept — correctly caught, run fails:

  FAIL neo        10.7.7.2     STILL ACCEPTED — the device added the new community alongside the old one; delete the old entry

snmp verification failed

Every device skipped — refuses to claim success:

error: no old community entered for any device — nothing was checked

shellcheck clean, ./scripts/validate.sh passes, markdownlint-cli2 clean.

  • make validate passes
  • Deployed to the lab and confirmed working
  • Docs updated (docs/runbooks/rotate-snmp-community.md §2.5)

Refs #9

--old prompted once and tested that one string against every device. That was
right when a single community was shared across all four. It is not right now:
each device has its own predecessor, so one string proves nothing about the
three it never belonged to, and there was no way to check a device whose old
community differed from the rest.

Each device that passed its current-community check is now asked separately.
Enter skips one, because the usual case is checking the single device you just
rotated. Skipping every device is an error rather than a silent pass — a run
that checked nothing must not print "all SNMP targets verified".

The prompt reads from /dev/tty explicitly: the loop's stdin is the inventory,
so a bare `read` would have consumed a device row instead of waiting for input.
The terminal requirement is unchanged, and each community still reaches
net-snmp only through a 0600 snmp.conf that is removed on every exit path.

Verified against all three branches: a wrong community reports `rejected`, a
community the device still accepts is caught as `STILL ACCEPTED` and fails the
run, and skipping everything refuses to claim success.

Refs #9

Co-Authored-By: Claude Opus 5 <[email protected]>
@Gerrrt
Gerrrt merged commit dcb82b7 into main Aug 19, 2026
3 checks passed
@Gerrrt
Gerrrt deleted the fix/snmp-verify-per-device-old branch August 19, 2026 03:16
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.

1 participant