Repository navigation
Fail fast on empty CA directory at TLS config load - #3522
Conversation
Signed-off-by: Yang Zhao <zymy701@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3522 +/- ##
============================================
- Coverage 76.47% 76.43% -0.05%
============================================
Files 159 159
Lines 79840 79851 +11
============================================
- Hits 61060 61036 -24
- Misses 18780 18815 +35
🚀 New features to boost your workflow:
|
| return false; | ||
| } | ||
|
|
||
| int loaded = 0; |
There was a problem hiding this comment.
Nit: Can we rename this to be a little more descriptive like loaded_ca_certs_count?
There was a problem hiding this comment.
The scope of this variable is just within the function named loadCaCertDir, so I think it's clear enough from the context.
|
Failing when no CA certificates exists is similar to failing when invalid certificates are present. But maybe it's not exactly the same? If no CA certificates exist, no clients are trusted, but that's true also if there is a self-signed CA certificate that nobody uses. This will also result in no clients being trusted. But what we want to catch here is an administrator mistake... If CA certificates in the directory are added and removed when the server is running and the auto-reload feature is enabled, we can get into the same situation? The auto-reload will fail if the directory is empty? |
Yes, this change is specifically targeting administrator mistakes during configuration
Yes, the reload would fail with error and server keeps using original context |
### Problem When `tls-ca-cert-dir` is configured to a directory that exists but contains no certificates, the server starts successfully and logs no warning. This is because `SSL_CTX_load_verify_locations` with a directory argument is lazy, OpenSSL registers the path without scanning it, returning success even for an empty directory. The failure is only discovered at handshake time, when every connecting client sees `Server closed the connection` and the server logs `Error accepting a client connection: error:0A000086:SSL routines::certificate verify failed`. This is a silent misconfiguration that gives no actionable signal at startup or `CONFIG SET` time. ### Fix `loadCaCertDir` (introduced in valkey-io#2999 for validity checking) already eagerly scans the directory to load certs. This PR extends it to count the certs loaded and fail immediately if zero certs were found. ### Behavior change Scenario 1: Startup with empty `tls-ca-cert-dir`. Before: Server starts, clients fail at handshake. After: Server refuses to start with a clear log message. Scenario 2: `CONFIG SET tls-ca-cert-dir <empty-dir>` Before: Returns OK, clients fail at handshake. After: Returns error, previous config preserved. Signed-off-by: Yang Zhao <zymy701@gmail.com>
Fixes #5506 Since 9.2.0, valkey-server refuses to configure TLS when any certificate it loads is outside its validity period, so an expired old root left in a `tls-ca-cert-file` bundle after a CA rotation stops the server from starting, even though OpenSSL would never build a chain through that cert. 9.1.3 starts fine on the same files. The checks came from #2999 and #3522, which the TSC decided were a breaking change: #3572 reverted them from 9.1 and the plan was to land them in the next major, but the next release turned out to be 9.2 rather than 10.0 and the revert was never carried over. These two commits revert them from the 9.2 branch so 9.x behaves like 9.1 again; `unstable` keeps them for 10.0. This was generated by AI but verified, with love, by a human. --------- Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
> [!CAUTION] > **Opened ready with 1 unresolved security item** (`force_ready` was set): release impact may require higher urgency or security treatment. Security classification is human-owned: settle the urgency and the Security Fixes entries (re-run the cut with them, or edit through review comments) before merging. All 4 flagged items: notes flagged low-confidence; AI triaged PRs without release-notes (confirm include/exclude); release impact may require higher urgency or security treatment; notes credited to a backport. Cuts **9.2.1** onto release line `9.2`. - Promotes the release notes into a dated section, bumps `src/version.h`, and refreshes the running contributor list. - Release notes computed over the range below (`9.2.0..9dc1926`): ``` mode: ga source_ref: 9.2 target_branch: 9.2 base: 9.2.0 @ d23684e head: 9dc1926 @ 9dc1926 ``` ###⚠️ Notes to double-check The generator flagged these notes low-confidence; confirm category and wording before merging: | PR | Category | Why flagged | |----|----------|-------------| | #5366 | Bug Fixes | explicit impact scope omitted: Linux | ###⚠️ Release impact and urgency need review Code detected release-impact terms (availability, memory safety, data integrity, access control, protocol, compatibility) in these PRs; this forces review, it is not a severity classification. The requested urgency is **MODERATE**. Confirm whether these changes require `HIGH`, `CRITICAL`, or `SECURITY`, and whether any need a hand-authored **Security Fixes** entry: <details> <summary>7 PR(s) with impact signals</summary> | PR | Title | Signal | |----|-------|--------| | [#5366](#5366) | Fix double mutex unlock when shrinking IO threads | undefined behavior or unsafe arithmetic | | [#5468](#5468) | Don't resend data to a close_asap client after an IO-thread write | server crash, assertion, or availability failure | | [#5112](#5112) | Pause rehashing of path hash payloads during background iteration | server crash, assertion, or availability failure | | [#4712](#4712) | Fix execGetKeys() dropping the first 256 keys past the static buffer | server crash, assertion, or availability failure | | [#4675](#4675) | Fix cluster bus self-forget use-after-free | memory-safety risk | | [#5452](#5452) | Ignore replica claims that would close a replicaof cycle | server crash, assertion, or availability failure | | [#3245](#3245) | Fix assertion crash in processIOThreadsReadDone when DONT_PARSE client has stale argc | server crash, assertion, or availability failure | </details> ### Triage summary - 8 PR(s) triaged into the notes - 3 PR(s) triaged out Per-PR verdicts (with reasons) are in the run's `triage-verdicts` artifact. To include a wrongly-dropped PR, label it `release-notes` and re-cut. ###⚠️ Notes credited to a backport (original PR not recovered) These notes credit the backport PR, not the change's author; confirm the original PR and correct the credit before merging: | Backport PR | Title | |-------------|-------| | [#5550](#5550) | [9.2] Revert fail-fast TLS certificate checks (#2999, #3522) | ### Wording carried from other release lines A backported change is cut once per release line, and each cut words its notes independently. To keep one commit from being described differently per branch, a note whose source PR another line already published takes that published wording verbatim (joined on the trailing `(#N)`, which always names the original source PR). Only the text is reused; the category, the `by @handle` credit, and the `(#N)` are this cut's own. - Release lines consulted: `9.1`, `9.0`, `8.1`, `8.0`, `7.2`, `7.0`, `6.2`, `6.0`, `5.0`, `4.0`, `3.2`, `3.0`, `2.8`, `2.6`, `2.4`, `2.2` - No note needed its wording replaced. *Generated by valkey-ci-agent. Review before merging into the release line.* Signed-off-by: valkeyrie-bot[bot] <3692572+valkeyrie-bot[bot]@users.noreply.github.com> Co-authored-by: valkeyrie-bot[bot] <3692572+valkeyrie-bot[bot]@users.noreply.github.com>
Problem
When
tls-ca-cert-diris configured to a directory that exists but contains no certificates, the server starts successfully and logs no warning. This is becauseSSL_CTX_load_verify_locationswith a directory argument is lazy, OpenSSL registers the path without scanning it, returning success even for an empty directory.The failure is only discovered at handshake time, when every connecting client sees
Server closed the connectionand the server logsError accepting a client connection: error:0A000086:SSL routines::certificate verify failed.This is a silent misconfiguration that gives no actionable signal at startup or
CONFIG SETtime.tls-ca-cert-fileSSL_CTX_load_verify_locations(file)tls-ca-cert-dirSSL_CTX_load_verify_locations(CApath)Fix
loadCaCertDir(introduced in #2999 for validity checking) already eagerly scans the directory to load certs. This PR extends it to count the certs loaded and fail immediately if zero certs were found.Behavior change
tls-ca-cert-dirCONFIG SET tls-ca-cert-dir <empty-dir>