Repository navigation
fix(agentvault): strip monotonic reading from leaf cert expiration - #435
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
time.Until on a time.Now()-derived expiration uses the monotonic clock, which stops while the host sleeps, so cached leaf certs were reused past NotAfter after a laptop woke up. Co-Authored-By: jake <jake@infisical.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
[Low impact] Strips monotonic clock reading from certificate expiration times. The fix appears safe to merge, with a non-blocking request for focused regression tests. Findings
|
| } | ||
|
|
||
| notAfter := time.Now().Add(leafTTL) | ||
| notAfter := time.Now().Add(leafTTL).Round(0) |
There was a problem hiding this comment.
Clock fix lacks regression tests
Neither package tests the clock detail this fix depends on. Existing leaf tests check certificate reuse or validity, so removing .Round(0) would not fail them and could silently restore expired-certificate reuse after sleep.
Add a test here and in packages/agentproxy that mints a leaf with an issuer valid beyond leafTTL, then asserts that its cached expiration == expiration.Round(0). This guards the fix without changing the machine clock or waiting through sleep.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Description 📣
mintLeafcaches each leaf cert withexpiration: notAfter, wherenotAfter := time.Now().Add(leafTTL). Because that value carries Go's monotonic clock reading, the reuse checktime.Until(entry.expiration) > leafReuseMarginuses the monotonic clock. That clock doesn't advance while the host is asleep. So after a laptop sleeps overnight, the proxy keeps serving a cached leaf whose realNotAfterhas already passed, and clients reject it until the proxy restarts. Machines that never sleep (e.g. a Mac mini) aren't affected.Fix:
.Round(0)strips the monotonic reading, so the cache compares against wall-clock time. This is applied inpackages/agentvault/ca.goand also inpackages/agentproxy/ca.go, which has the same pattern. The issuer-clamp branch (rootCert.NotAfter/interCert.NotAfter) already comes from a parsed cert, so it has no monotonic reading.Type ✨
Tests 🛠️
go test -race ./packages/agentproxy/reports a data race inTestClientAbortIsNotLoggedAsError(forward_test.go). The same race shows up onmainwithout this change, and CI doesn't run that package.Link to Devin session: https://app.devin.ai/sessions/d5c116c867554261b9c04b1833f86eb9
Open in Devin Desktop: https://app.devin.ai/desktop/session/d5c116c867554261b9c04b1833f86eb9?variant=devin