Repository navigation
controlplane: refuse damaged operator key files, keep reports written during GC - #947
Conversation
pruneCatalog picked the reports to drop from a snapshot taken before it listed the admitted nodes, then deleted them from the live map. A node whose session had lapsed could enroll again and report between the list and the delete, and lose its fresh report until its next push. Drop only an entry that is still the one the snapshot saw, and log the one kept.
pem.Decode skips a block whose body or BEGIN/END line is damaged and returns the next one, so a damaged first key left the second key signing, and a file read mid-write lost its last block, all without an error. The file is now refused unless every block it marks decodes, so a reload keeps the keys in use and counts the failure, as documented. Reading the keyring back after an install no longer turns a read error into an empty valid_after list: the failure is logged with its error.
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of node garbage collection and operator signing key management. In node_gc.go, the pruneCatalog function is updated to prevent dropping service reports of nodes that were re-admitted and reported during the sweep. In signingkeys.go, PEM decoding is made stricter by ensuring all marked PEM blocks decode successfully, preventing damaged or truncated keys from being silently skipped. Additionally, keyring reconciliation now properly handles and logs read-back failures instead of reporting empty keyrings. Corresponding unit tests have been added to verify these behaviors. I have no feedback to provide.
|
Looks good overall — all three fixes are clear, well-tested, and match the codebase conventions. One small nit in internal/controlplane/node_gc.go: if s.catalog[peerID] was already evicted during the sweep (e.g., via dropCatalogEntry on revoke), ok is false and the loop still increments dropped and logs a drop. Guarding if !ok { continue } right before the ReportedAt.Equal check avoids over-counting. Optional: covering reconcileES256Keyring alongside reconcileEd25519Keyring in TestReconcileKeyringLogsAFailedReadBack would round out the test. |
A report a ban evicted after the sweep's snapshot is already gone when the sweep gets to it; it is logged at debug and not counted as dropped. The read-back log test covers the ES256 keyring too.
|
Thanks, both done in 4798c97:
|
Three control plane fixes in operator signing keys and node GC, each with a regression test that failed on the previous code.
pem.Decodeskips a block whose body or BEGIN/END line does not decode and returns the next one, so a damaged first key left the second key signing, and a file read mid-write lost its last block, without an error. The file is now refused unless every block it marks decodes, so a reload keeps the keys in use and counts the failure, assigningkeys.godocuments.valid_afterlist in the install log line. The failure is now logged with its error instead.pruneCatalogdeleted entries picked from a snapshot taken before it listed the admitted nodes, so a node that re-enrolled and reported in between lost its fresh report until its next push. Only an entry that is still the one the snapshot saw is dropped.go test -race ./internal/controlplane/ ./internal/standalone/andgo vetpass on Linux.