Repository navigation
fix(namespace): reload rotated mTLS certificates in the REST client - #8456
Conversation
| /// Create a new REST namespace from builder | ||
| pub(crate) fn from_builder(builder: RestNamespaceBuilder) -> Self { | ||
| // Build reqwest client WITHOUT default headers - we'll apply headers per-request | ||
| let mut client_builder = reqwest::Client::builder(); |
There was a problem hiding this comment.
Looks like this changes the behavior on startup. Before a bad CA didn’t drop a valid cert/key, and vice versa. read_material() now fails the whole load, and new() falls back to empty material.
Reload being atomic makes sense to me, but I think construction should probably keep the old behavior and load the identity and CA independently but i can be convinced otherwise. WDYT?
There was a problem hiding this comment.
Yeah, you're right, that wasn't intentional. Atomicity is there to protect a client that's already working, and at startup there isn't one - so failing the whole load just means one bad path takes out the good pieces too. Worst case someone has a stale tls.ssl_ca_cert lying around that doesn't matter today, and now it kills their mTLS identity as well.
Fixed: construction loads the identity and the CA separately again, and warns with the file name when one of them fails instead of dropping it silently like the old code did. Reload stays atomic since it has a working client to fall back on.
`RestNamespace::from_builder` read the mTLS certificate, key and CA once and baked them into a long-lived `reqwest::Client`. A `reqwest::Identity` cannot be swapped inside a live client, so a process kept presenting the certificate it read at startup forever. Environments that rotate short-lived certificates on disk - SPIFFE/Istio, Vault PKI, cert-manager, Netflix Metatron - therefore broke once the loaded certificate passed its `notAfter`, with every request failing on a received `CertificateExpired` alert until the process restarted. The client is now published through an `ArcSwap` and rebuilt when the content of the configured PEM files changes. The check runs on the request path, gated by `tls.reload_interval_seconds` (default 300, `0` disables reloading), and compares the digest of the file content rather than modification times, since rotation is commonly an atomic rename or a symlink swap. Unchanged content leaves the client and its connection pool untouched, and material that fails to load or build keeps the current client instead of downgrading it mid-rotation. Construction degrades per piece instead, since it has no working client to keep: a CA certificate that cannot be loaded no longer drops a usable client identity, and each piece that is skipped is logged with the file that caused it. The digest is left unset whenever something was skipped, so the next check retries it and upgrades to the complete material once the missing file lands. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
4ac3159 to
1b4be07
Compare
There was a problem hiding this comment.
Since the earlier assessment, the startup correction from this review thread now loads the client identity and CA independently, preserves each usable piece, and leaves incomplete material retryable. Request-path reloads still publish only a complete generation and keep the working client on partial or invalid rotations.
The remaining operational risk is verification breadth: unit tests cover reload timing, content changes, startup degradation, and retry, but not a peer-observed mTLS handshake through identity/CA rotation or a concurrent cutover. A local end-to-end mTLS rotation test would make that contract durable.
The REST namespace loads its client identity with `reqwest::Identity::from_pem`, which only produces a rustls identity. `lance-namespace-impls` enables only reqwest's rustls features, but when another crate in the same build enables reqwest's `default-tls` (native-tls), reqwest's `ClientBuilder` defaults to native-tls and rejects the identity when the client is built. In the workspace this happens through `lance-examples` (via `hf-hub`'s default features), which is why the four `rest::tls` tests from #8456 fail in the Linux CI jobs on `main`. Downstream builds hit the same thing whenever any dependency pulls in reqwest's default features, and then mTLS stops working. `build_client` now selects rustls explicitly, so the identity and CA certificate are always applied by the backend that parsed them. `test_malformed_ca_certificate_is_dropped_on_its_own` no longer requires the malformed CA certificate to be rejected at build time. With native-tls compiled in, reqwest parses the certificate when it is read, so it is dropped at load time instead. The test still checks that the identity survives and that the dropped material is retried. Checked with `cargo test -p lance-namespace-impls -p lance-examples --features lance-namespace-impls/rest --lib rest` on Linux (4 failures on `main`, all pass here) and on macOS, and with `--features rest` alone.
Problem
Trino x Lance plugin started throwing
CertificateExpiredexception when trying to talk to iceberg rest catalog and the certs in trino co-ordinator instance got rotated.RestNamespace::from_builderreads the mTLS certificate, key and CA once at constructionand bakes them into a single long-lived
reqwest::Client. Areqwest::Identitycannot behot-swapped inside a live client, so the process keeps presenting the certificate it read at
startup forever.
Any environment that rotates short-lived certificates on disk therefore breaks once the
loaded certificate passes its
notAfter. The server rejects the handshake and the clientsees a received TLS alert:
(
receivedmatters: the peer is rejecting our client cert. A stale CA bundle or bad servercert would surface locally as
InvalidCertificate(Expired)/UnknownIssuer.)Fix
RestClientnow holds the client in anArcSwap<reqwest::Client>and hands it out by value(cheap —
reqwest::Clientis a handle around anArc). Alongside it, the cert/key/CA paths,the digest of the last-loaded content and the last-checked
Instantare kept so the clientcan be rebuilt.
The check is lazy, on the request path, gated by an interval:
the content changed. Content, not mtime: rotation is often a symlink swap or an atomic
rename. A digest keeps the comparison cheap without retaining private key bytes.
authenticated with the old certificate) and exactly why it is gated on a real change.
check, so a truncated read mid-rotation can't replace a working identity with one the
server would reject.
std::fs::readat most once per interval.arc-swapwas already a workspace dependency; no new dependencies.New property
tls.reload_interval_seconds, parsed alongside the othertls.*keys, with amatching builder setter.
0disables reloading. Properties pass through the Python and Javabindings opaquely, so both pick this up without binding changes; the
tls.*list inRestNamespace's javadoc is updated.Verification