Skip to content

volume/csi: Cache CA certificate pool in CSI TLS verification - #1344

Draft
hajiler wants to merge 1 commit into
agent-substrate:mainfrom
hajiler:csi-tls-cache
Draft

volume/csi: Cache CA certificate pool in CSI TLS verification#1344
hajiler wants to merge 1 commit into
agent-substrate:mainfrom
hajiler:csi-tls-cache

Conversation

@hajiler

@hajiler hajiler commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1182

Description

In resolveTLSConfig, TLS verification was configured to dynamically read and parse the CA trust bundle on every handshake to support zero-downtime CA rotation. However, reading and parsing PEM certificates from disk on every connection causes unnecessary disk I/O and CPU overhead.

This PR introduces an in-memory caching mechanism for the CA certificate pool:

  • Adds a thread-safe caPoolCache that caches the parsed *x509.CertPool in memory.
  • Uses stat-matching (os.SameFile, modtime, size) and earliest NotAfter expiration tracking to determine when a reload is needed.
  • Re-reads and parses from disk only when the file identity/content changes (such as projected volume symlink rotation by kubelet) or when certificates expire.
  • Adds comprehensive unit tests for cache hits, file modification reloads, and certificate expiry reloads.

Verification

  • go test -v -race ./internal/volume/csi/...
  • go test ./...
  • make fmt

Previously, resolveTLSConfig configured VerifyConnection to re-read
the CA trust bundle from disk and rebuild the *x509.CertPool on every
TLS handshake. This caused unnecessary filesystem I/O and PEM decoding
overhead on repeated connections.

This change introduces a thread-safe caPoolCache that caches the parsed
cert pool in memory and checks file metadata (stat matching) and certificate
expiration (earliest NotAfter) to avoid redundant disk reads while preserving
automatic CA rotation pickup.

TAG=agy
CONV=08b81b20-9977-45df-b98e-9e340bc55e2d
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.

CSI TLS verification lacks caching, causing performance degradation

1 participant