Skip to content

Commit 17fc060

Browse files
committed
Address review: gofmt the minter cert literal + test the wall-clock deadline
- gofmt: re-align the x509.Certificate{} literal. The prior edit de-aligned NotBefore:/NotAfter: to one space; gofmt -l flagged minter.go (CI missed it because go-fmt pre-commit only covers proxy-init/). - test: add TestMinter_CacheDeadlineIsWallClock, asserting the cache freshness deadline carries no monotonic reading (exp == exp.Round(0)) — directly guarding the .Round(0) suspend fix, which the existing test did not exercise. Clarify that TestMinter_ReMintsWallClockExpiredLeaf covers the NotAfter backstop (a state normal operation cannot produce). Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
1 parent afc9fc3 commit 17fc060

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

authbridge/authlib/tlsbridge/minter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ func (m *Minter) mint(host string) (*tls.Certificate, error) {
118118
tmpl := &x509.Certificate{
119119
SerialNumber: serial,
120120
Subject: pkix.Name{CommonName: host},
121-
NotBefore: time.Now().Add(-time.Minute),
121+
NotBefore: time.Now().Add(-time.Minute),
122122
// Leaf validity outlasts the cache deadline (now+ttl) by renewBefore so
123123
// a cached leaf is always re-minted before it can serve past expiry.
124-
NotAfter: time.Now().Add(m.ttl + renewBefore),
124+
NotAfter: time.Now().Add(m.ttl + renewBefore),
125125
KeyUsage: x509.KeyUsageDigitalSignature,
126126
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
127127
}

authbridge/authlib/tlsbridge/minter_test.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ func TestMinter_LRUEvictsOldest(t *testing.T) {
124124
}
125125
}
126126

127-
// TestMinter_ReMintsWallClockExpiredLeaf is the regression guard for the
128-
// suspend/VM-pause bug: the cached leaf is expired by the wall clock, but the
129-
// process monotonic clock froze during suspend so the cache deadline still
130-
// reads as fresh. The minter must gate on the leaf's real NotAfter and
131-
// re-mint, never serve a leaf the client will reject as expired.
127+
// TestMinter_ReMintsWallClockExpiredLeaf exercises the NotAfter backstop: if a
128+
// cached leaf is ever wall-clock-expired while the cache deadline still reads
129+
// fresh, Get must gate on the leaf's real NotAfter and re-mint rather than
130+
// serve a cert the client rejects. (The primary suspend fix — the wall-clock
131+
// cache deadline — is guarded by TestMinter_CacheDeadlineIsWallClock.)
132132
func TestMinter_ReMintsWallClockExpiredLeaf(t *testing.T) {
133133
m, _ := newTestMinter(t) // LeafTTL=time.Hour, so the cache deadline stays "fresh"
134134
c1, err := m.GetCertificateForHost("h.example.com")
@@ -158,3 +158,23 @@ func TestMinter_ReMintsWallClockExpiredLeaf(t *testing.T) {
158158
t.Fatal("re-minted leaf is not valid")
159159
}
160160
}
161+
162+
// TestMinter_CacheDeadlineIsWallClock guards the actual suspend fix: the cache
163+
// freshness deadline must carry NO monotonic clock reading, so the freshness
164+
// check falls back to the wall clock and expires correctly across a host
165+
// suspend (where the monotonic clock freezes but wall time advances). A
166+
// monotonic-carrying deadline is exactly what made the cache keep serving a
167+
// wall-clock-expired leaf. time.Time's == compares the monotonic reading too,
168+
// so a deadline that still carried one would not equal its .Round(0) form.
169+
func TestMinter_CacheDeadlineIsWallClock(t *testing.T) {
170+
m, _ := newTestMinter(t)
171+
if _, err := m.GetCertificateForHost("h.example.com"); err != nil {
172+
t.Fatalf("mint: %v", err)
173+
}
174+
m.mu.Lock()
175+
exp := m.items["h.example.com"].Value.(*cacheEntry).expires
176+
m.mu.Unlock()
177+
if exp != exp.Round(0) {
178+
t.Errorf("cache deadline carries a monotonic clock reading; must be wall-clock (.Round(0)) to survive suspend")
179+
}
180+
}

0 commit comments

Comments
 (0)