Skip to content

Fail fast on empty CA directory at TLS config load - #3522

Merged
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
yang-z-o:validate-empty-ca-dir
Sep 11, 2026
Merged

zuiderkwast merged 1 commit into
valkey-io:unstablefrom
yang-z-o:validate-empty-ca-dir

Conversation

@yang-z-o

Copy link
Copy Markdown
Contributor

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.

Config argument OpenSSL function Fails on empty path
tls-ca-cert-file SSL_CTX_load_verify_locations (file) Yes
tls-ca-cert-dir SSL_CTX_load_verify_locations (CApath) No

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

Scenario Before After
Startup with empty tls-ca-cert-dir Server starts, clients fail at handshake Server refuses to start with a clear log message
CONFIG SET tls-ca-cert-dir <empty-dir> Returns OK, clients fail at handshake Returns error, previous config preserved

Signed-off-by: Yang Zhao <zymy701@gmail.com>
@codecov

codecov Bot commented Apr 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.43%. Comparing base (087280e) to head (42a927f).
⚠️ Report is 341 commits behind head on unstable.

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     
Files with missing lines Coverage Δ
src/tls.c 17.64% <ø> (ø)

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/tls.c
return false;
}

int loaded = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we rename this to be a little more descriptive like loaded_ca_certs_count?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scope of this variable is just within the function named loadCaCertDir, so I think it's clear enough from the context.

@yang-z-o
yang-z-o requested a review from zuiderkwast April 18, 2026 02:42
@zuiderkwast zuiderkwast added the major-decision-pending Major decision pending by TSC team label Apr 21, 2026
@zuiderkwast

Copy link
Copy Markdown
Contributor

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?

@yang-z-o

Copy link
Copy Markdown
Contributor Author

But what we want to catch here is an administrator mistake...

Yes, this change is specifically targeting administrator mistakes during configuration

The auto-reload will fail if the directory is empty?

Yes, the reload would fail with error and server keeps using original context

@madolson madolson added major-decision-approved Major decision approved by TSC team and removed major-decision-pending Major decision pending by TSC team labels Apr 27, 2026
@madolson madolson moved this to Needs Review in Valkey 9.2 May 10, 2026
@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Sep 11, 2026
@zuiderkwast
zuiderkwast merged commit 13c66b8 into valkey-io:unstable Sep 11, 2026
165 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Merged in Valkey 9.2 Sep 11, 2026
@madolson madolson added breaking-change Indicates a possible backwards incompatible change and removed breaking-change Indicates a possible backwards incompatible change labels Sep 11, 2026
zuiderkwast pushed a commit to tartelettie/valkey that referenced this pull request Sep 15, 2026
### 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>
madolson added a commit that referenced this pull request Nov 24, 2026
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>
ranshid pushed a commit that referenced this pull request Nov 26, 2026
> [!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team release-notes This issue should get a line item in the release notes

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

4 participants