Skip to content

controlplane: refuse damaged operator key files, keep reports written during GC - #947

Open
ersinkoc wants to merge 2 commits into
google:mainfrom
ersinkoc:audit/controlplane-keys
Open

ersinkoc wants to merge 2 commits into
google:mainfrom
ersinkoc:audit/controlplane-keys

Conversation

@ersinkoc

Copy link
Copy Markdown

Three control plane fixes in operator signing keys and node GC, each with a regression test that failed on the previous code.

  • Refuse an operator key file with a damaged PEM block. pem.Decode skips 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, as signingkeys.go documents.
  • Log a failed keyring read-back. After an install, a read error turned into an empty valid_after list in the install log line. The failure is now logged with its error instead.
  • Keep a catalog report written during the GC sweep. pruneCatalog deleted 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/ and go vet pass on Linux.

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.
@ersinkoc
ersinkoc requested a review from aojea as a code owner November 25, 2026 20:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
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