Repository navigation
Conversation
An activation that outlives a servicedns CA rotation kept verifying the egress gateway with the bundle read at NewClient time, so every outbound call failed until the actor was suspended and resumed. The client certificate already reloads through GetClientCertificate, but RootCAs was a fixed pool built once in NewClient. Re-read the bundle on each new gateway connection, keyed by the file's modification time and size, so the steady state costs one stat per dial and no background goroutine or watcher. A bundle caught mid-rotation (empty, truncated, or unreadable) keeps the last known-good pool: a partial write must not take egress down for every actor on the node. Refs agent-substrate#4207 Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
Anish Ramasekar (aramase)
left a comment
There was a problem hiding this comment.
The per-dial reload in runDial is the right place for the #4207 fix. I have one concern about how the reload is built, plus one about the test. Both are inline.
| // rotation. A bundle that is missing, truncated, or empty mid-rotation keeps | ||
| // the last known-good pool: a partial write must not take egress down for | ||
| // every actor on the node. | ||
| func (c *Client) rootCAsForDial() *x509.CertPool { |
There was a problem hiding this comment.
This adds a second stat-keyed trust-pool cache next to credbundle.PoolLoader (internal/credbundle/credbundle.go:145-167), which already does this. ateapiauth uses it for RootCAs (internal/ateapiauth/client.go:61), and #4207 suggested it for this fix. The copy also behaves differently in two ways:
- It drops the
os.SameFilecheck, which handles kubelet's symlink swap of projected files. - Every Stat or Read error and an empty parse silently return the last good pool (lines 165-182).
If the bundle becomes permanently unreadable (mount problem, wrong path after an upgrade), egress keeps trusting the old CA with no log. The first sign is x509: certificate signed by unknown authority once the gateway rotates, which is the #4207 failure with the cause hidden. The partial-write case doesn't come up on the default path: /run/servicedns.podcert.ate.dev/trust-bundle.pem is a projected volume, which kubelet writes atomically.
Suggestion:
- Store
credbundle.PoolLoader(cfg.TrustBundlePath)on the Client and call it once inNewClient, so a missing or empty bundle still fails at construction. - In
runDial, setRootCAsfrom it and fail the dial with a wrapped error when it errors. - If last-good fallback is wanted, put it in
credbundlewith a log line, so every consumer behaves the same.
| // TestClientKeepsLastGoodTrustBundleOnPartialWrite pins the other half of | ||
| // #4207: a bundle caught mid-rotation (truncated, empty, or unreadable) must | ||
| // not take egress down. The last known-good pool keeps verifying. | ||
| func TestClientKeepsLastGoodTrustBundleOnPartialWrite(t *testing.T) { |
There was a problem hiding this comment.
This test also passes with the base client.go: main pins the pool, so an empty file never matters there. AGENTS.md asks that each new test fail without the change. With the PoolLoader change above, a case where the bundle becomes unreadable and the dial fails with a clear error would cover the new behavior, and it fails on main.
Fixes #4207.
Problem
NewClientreadsTrustBundlePathonce and pins it astls.Config.RootCAs(internal/atunnel/egress/client.go, theos.ReadFilebefore theClientliteral). The client certificate already reloads through theGetClientCertificatecallback —acquireConnretires a pooled connection when the certificate changes — but the trust side never does.PrepareEgressbuilds one client per actor activation (internal/atunnel/tunnel.go), so an activation that spans a servicedns CA rotation keeps trusting only the old CA. Once its pooled connection drops, or the gateway restarts holding a certificate from the new CA, every outbound call for that actor fails until it is suspended and resumed. Long-running agent actors and long RL/eval runs are the ones that span a rotation.Fix
Re-read the bundle when the file behind
TrustBundlePathchanges, keyed by modification time and size, and install it on each new connection:Why this shape rather than a ticker or fsnotify:
os.Statper dial. Dials are per-connection, not per-request, so this is negligible next to the handshake itself.Close.rootCAsForDialreturns the last known-good pool (falling back to the pool built inNewClient), so actors keep connecting with the CA they already trust instead of failing closed on a half-written file.Tests
Both live in
internal/atunnel/egress/client_test.go:TestClientReloadsTrustBundleAfterRotation— starts the client pointed at a stale CA so the first handshake fails, rewrites the bundle, and dials again on the sameClient. Without the fix this fails withx509: certificate signed by unknown authority; verified by reverting the one-lineRootCAsassignment.TestClientKeepsLastGoodTrustBundleOnPartialWrite— dials successfully, then replaces the bundle with an empty file and dials again. Must still succeed, pinning the "don't fail closed mid-rotation" half.go test ./internal/atunnel/egress/ -count=1and-raceboth pass;go vetand gofmt clean.Scope
Client-side trust only. The
TrustBundlePathconfig surface, the certificate reload path, and the tunnel/activation lifecycle are unchanged. Alex Bulankou (@AlexBulankou) — this is your report; happy to adjust the reload strategy if you had a different one in mind (a watcher, or reload-on-handshake-failure plus one retry, are both reasonable alternatives).