Repository navigation
Node trusted key pruning - #945
Conversation
A trusted key's age counted from when the node first received it, and a
/keys sync kept that time. Pruning keeps only the newest key past the
grace period, so a key the control plane still lists in its rotation grace
period was dropped a day after the node first saw it, even when it signed
the node's own identity. The next start then failed the role check
("biscuit: invalid signature") on a valid identity, and if the control
plane could not be reached at that moment, both recoveries failed too.
- mergeTrustedKeys: every key a /keys answer lists counts as vouched for
at that sync, so pruning only drops keys the control plane stopped
listing, or ones the node could not confirm for longer than the grace
period.
- pruneTrustedKeys: keeps every key with the latest time, since a /keys
answer vouches for all its keys at once and its order says nothing about
which is current, and never drops the key that signed the node's current
identity.
- NewAgentMeshNode: the configured key re-added next to persisted keys gets
a fixed old time (the zero time is not stored and read back as now), so
it cannot outrank the control plane's newer keys after a restart.
- Start returns *StaleIdentityError when the stored identity fails the role
check and neither recovery renews it. It unwraps to the role, refresh and
recovery errors, so callers can tell a refusal (*RefreshError with its
status) from a control plane that never answered.
Use mustGenerateKey instead of ignoring ed25519.GenerateKey's error, and report a failed store close (errcheck).
Apply the review of google#917: - Remove mergeTrustedKeys; syncTrustedKeys gives each key of the /keys answer the time of the sync. - Log each key that pruning drops, with its last vouched time and the grace period. - Remove the keep parameter, signedOwnIdentity, neverVouched and StaleIdentityError, and their tests: google#916 does not need them. - Correct the meaning of receive_time in api/agentmesh.proto and of --key-grace-period in the node reference. - Test the sequence of the issue (sync, then prune) and add a row for the keys of one sync to TestPruneTrustedKeys.
There was a problem hiding this comment.
Code Review
This pull request updates the control plane key pruning logic so that keys are aged based on when the control plane last vouched for them (i.e., when they were last seen in a /keys sync or rotation event) rather than when they were first learned. It removes the key-merging logic, updates documentation, and adds corresponding tests. The review feedback suggests optimizing slice allocation in syncTrustedKeys and updating test assertions in controlplane_test.go to comply with the repository style guide by explicitly stating both observed and expected values.
| synced := make([]TrustedKey, 0, len(keys)) | ||
| for _, key := range keys { | ||
| synced = append(synced, TrustedKey{Key: key, ReceivedAt: now}) | ||
| } |
There was a problem hiding this comment.
Since the size of keys is exactly known, we can pre-allocate the slice with the correct length and assign elements directly by index instead of using append. This avoids slice growth checks and is more efficient.
| synced := make([]TrustedKey, 0, len(keys)) | |
| for _, key := range keys { | |
| synced = append(synced, TrustedKey{Key: key, ReceivedAt: now}) | |
| } | |
| synced := make([]TrustedKey, len(keys)) | |
| for i, key := range keys { | |
| synced[i] = TrustedKey{Key: key, ReceivedAt: now} | |
| } |
| if containsTrustedKey(n.trustedKeys, expiredPub) { | ||
| t.Error("a key /keys does not list stayed in the trust set") | ||
| } |
There was a problem hiding this comment.
According to Section 3, Rule 8 of the Repository Style Guide, assertion messages must state both the observed and the expected value. Let's update the assertion message to explicitly show what was observed and what was expected.
| if containsTrustedKey(n.trustedKeys, expiredPub) { | |
| t.Error("a key /keys does not list stayed in the trust set") | |
| } | |
| if containsTrustedKey(n.trustedKeys, expiredPub) { | |
| t.Errorf("syncTrustedKeys kept expired key %x, want it removed", expiredPub) | |
| } |
References
- Section 3, Rule 8 of the Repository Style Guide requires assertion messages to state both the observed and the expected value. (link)
| if len(got) != 2 || !containsTrustedKey(got, retiredPub) || !containsTrustedKey(got, currentPub) { | ||
| t.Errorf("pruning kept %d keys, want the retired and the current key that /keys lists", len(got)) | ||
| } |
There was a problem hiding this comment.
According to Section 3, Rule 8 of the Repository Style Guide, assertion messages must state both the observed and the expected value. Let's update this assertion message to explicitly show the observed number of keys and the expected keys.
| if len(got) != 2 || !containsTrustedKey(got, retiredPub) || !containsTrustedKey(got, currentPub) { | |
| t.Errorf("pruning kept %d keys, want the retired and the current key that /keys lists", len(got)) | |
| } | |
| if len(got) != 2 || !containsTrustedKey(got, retiredPub) || !containsTrustedKey(got, currentPub) { | |
| t.Errorf("pruning kept %d keys (%v), want 2 keys: retired (%x) and current (%x)", len(got), got, retiredPub, currentPub) | |
| } |
References
- Section 3, Rule 8 of the Repository Style Guide requires assertion messages to state both the observed and the expected value. (link)
No description provided.