Skip to content

Fail fast on invalid certificates at TLS config load - #2999

Merged
zuiderkwast merged 5 commits into
valkey-io:unstablefrom
yang-z-o:tls-fail-fast-expired-cert
Jan 28, 2026
Merged

zuiderkwast merged 5 commits into
valkey-io:unstablefrom
yang-z-o:tls-fail-fast-expired-cert

Conversation

@yang-z-o

@yang-z-o yang-z-o commented Jan 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2997

Overview

This PR adds the certificates validation at TLS load, rejects invalid (expired/not-yet-valid) certificates:

Apply to all TLS config paths:

  • Server certificates tls-cert-file
  • Server-side client certificates tls-client-cert-file
  • CA certificate file tls-ca-cert-file
  • CA certificate directory tls-ca-cert-dir (now eagerly loaded to be consistent with file-based CAs)

Apply to both scenarios:

  • Server startup (initial TLS load)
  • Runtime reload vis CONFIG SET

Implementation

  • Added isCertValid function to check if an X509 certificate is within its validity period (not expired, not future-dated)
  • Added areAllCaCertsValid function to iterate through all loaded CA certificates and validate them
  • Added loadCaCertDir function to eagerly load all certificates from a directory into the X509_STORE
  • Modified createSSLContext to validate:
    • Server/client certificates immediately after loading
    • All CA certificates after loading from file/directory

Test results

1. Server startup (initial TLS load)

tls-cert-file ./tests/tls/server-expired.crt

41522:M 31 Dec 2025 16:13:18.851 # Server TLS certificate is invalid. Aborting TLS configuration.
41522:M 31 Dec 2025 16:13:18.851 # Failed to configure TLS. Check logs for more info.


tls-client-cert-file ./tests/tls/client-expired.crt

41557:M 31 Dec 2025 16:14:43.296 # Client TLS certificate is invalid. Aborting TLS configuration.
41557:M 31 Dec 2025 16:14:43.296 # Failed to configure TLS. Check logs for more info.


tls-ca-cert-file ./tests/tls/ca-expired.crt
tls-ca-cert-dir ./tests/tls/ca-expired

41567:M 31 Dec 2025 16:15:15.635 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
41567:M 31 Dec 2025 16:15:15.635 # Failed to configure TLS. Check logs for more info.

2. Runtime reload via CONFIG SET

127.0.0.1:6379> config set tls-cert-file ./tests/tls/server-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:43.588 # Server TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:43.588 # Failed applying new configuration. Possibly related to new tls-cert-file setting. Restoring previous settings.


127.0.0.1:6379> config set tls-client-cert-file ./tests/tls/client-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-client-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:57.972 # Client TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:57.972 # Failed applying new configuration. Possibly related to new tls-client-cert-file setting. Restoring previous settings.


127.0.0.1:6379> config set tls-ca-cert-file ./tests/tls/ca-expired.crt
127.0.0.1:6379> config set tls-ca-cert-dir ./tests/tls/ca-expired
(error) ERR CONFIG SET failed (possibly related to argument 'tls-ca-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:50.175 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:50.175 # Failed applying new configuration. Possibly related to new tls-ca-cert-file setting. Restoring previous settings.

@codecov

codecov Bot commented Jan 3, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 74.24%. Comparing base (278607b) to head (cb20800).
⚠️ Report is 8 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2999      +/-   ##
============================================
- Coverage     74.38%   74.24%   -0.14%     
============================================
  Files           129      129              
  Lines         71041    71041              
============================================
- Hits          52844    52745      -99     
- Misses        18197    18296      +99     
Files with missing lines Coverage Ξ”
src/tls.c 100.00% <ΓΈ> (ΓΈ)

... 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.

@yang-z-o yang-z-o mentioned this pull request Jan 12, 2026
@yang-z-o
yang-z-o force-pushed the tls-fail-fast-expired-cert branch from 570801b to 51925b4 Compare January 16, 2026 21:02
@yang-z-o

Copy link
Copy Markdown
Contributor Author

Hello @madolson @zuiderkwast @PingXie, I briefly mentioned this PR in last week's weekly meeting.
This PR adds TLS certificate validation at server startup and reloads. Since it introduces a behavior change, it may require core team guidance. Would really appreciate it if you could take a look and share your thoughts. Thanks! πŸ™

@zuiderkwast zuiderkwast moved this to In Progress in Valkey 9.1 Jan 20, 2026
@zuiderkwast

Copy link
Copy Markdown
Contributor

Thanks for the heads up. A small behavior change doesn't necessarily need to be a major decision, if it's backward compatible and doesn't introduce any new public API (configs, commands, etc.) and doesn't break any user scenario. So what exactly is the behavior change?

Before:

  • It was possible to configure expired certificates. CONFIG SET retured OK.
  • The result is that clients can't connect.

After:

  • Not possible to configure expired certificates. CONFIG SET returns an error.
  • Clients can still connect if the old certificates are still valid. When they expire, clients can't connect.

CONFIG SET can now return an error where it previously returned OK, but that OK was silencing a severe admin error resulting in clients unable to connect.

To me, it doesn't seem like a breaking change, so I don't think it needs to be a major decision, but @valkey-io/core-team please speak up if you think otherwise.

I (or someone else) will review this PR soon.

@zuiderkwast zuiderkwast left a comment

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.

Looks good to me in general. I have only minor comments.

We use camelCase for function names and snake_case for variables, so please follow this style in new code. (Sorry, the style is not written anywhere. We're working on it.)

Comment thread src/tls.c Resolved
Comment thread src/tls.c Resolved
Comment thread src/tls.c Resolved

@zuiderkwast zuiderkwast left a comment

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.

Looks good, thank you!

@madolson do you think the behavior change poses any risk?

@zuiderkwast zuiderkwast added release-notes This issue should get a line item in the release notes to-be-merged Almost ready to merge labels Jan 20, 2026
@PingXie

PingXie commented Jan 20, 2026

Copy link
Copy Markdown
Member

The new behavior is better so good from my end.

Btw, @zuiderkwast once we merge #3076 copilot should be able to take care of the coding style review (and we can keep iterating on the instructions).

@zuiderkwast

Copy link
Copy Markdown
Contributor

Btw, @zuiderkwast once we merge #3076 copilot should be able to take care of the coding style review (and we can keep iterating on the instructions).

Gotcha. I approved it now. :)

Copilot AI left a comment

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.

Pull request overview

This PR adds fail-fast validation for TLS certificates at configuration load time, rejecting certificates that are expired or not yet valid. This applies to server certificates, client certificates, and CA certificates (both file and directory-based), and works during both server startup and runtime CONFIG SET operations.

Changes:

  • Added certificate validity checking functions (isCertValid, loadCaCertDir, areAllCaCertsValid) to validate X509 certificates
  • Enhanced TLS configuration to eagerly load and validate all CA certificates from directories
  • Generated test certificates (expired and not-yet-valid) for comprehensive testing
  • Added integration tests to verify rejection of invalid certificates at startup

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/tls.c Implements certificate validation logic with three new functions to check certificate validity, eagerly load CA certificates from directories, and validate all loaded CA certificates
utils/gen-test-certs.sh Extends certificate generation script to create expired and not-yet-valid certificates for testing (server, client, and CA certificates)
tests/unit/tls.tcl Adds integration tests to verify that invalid certificates are rejected at server startup for all certificate types
tests/README.md Updates documentation to mention generation of invalid test certificates

Comment thread src/tls.c Resolved
Comment thread tests/unit/tls.tcl Resolved
madolson pushed a commit that referenced this pull request Jan 21, 2026
### Overview
This PR adds support for automatic background TLS reloading, closes
#2649
TLS validity checks and fail-fast behavior on invalid certificates are
handled separately in #2999.
- New configuration
  - `tls-auto-reload-interval <seconds>`
  - `0` disabled (default, backward compatible)
  - `>0` check interval in seconds
- TLS materials change detection in background
  - SHA-256 fingerprint checking for certificate files
- `inode + mtime` checking for CA certificate directories and key files
- Skips reload if materials haven't changed
`tlsCheckMaterialsAndUpdateCache`
- TLS contexts reload
- CPU-intensive certificate parsing happens in dedicated BIO worker
thread `BIO_TLS_RELOAD`
  - Main thread never blocks, atomically swaps SSL contexts
- Two-phase reload: background preparation `tlsConfigureAsync` + main
thread application `tlsApplyPendingReload`


**Note**: Original TLS load and reload still remain in main thread using
`tlsConfigureSync`, including:
- Initial TLS load (server startup)
- Runtime reload via CONFIG SET


---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
Comment thread tests/unit/tls.tcl Resolved
@yang-z-o

This comment was marked as off-topic.

arshidkv12 pushed a commit to arshidkv12/valkey that referenced this pull request Jan 23, 2026
### Overview
This PR adds support for automatic background TLS reloading, closes
valkey-io#2649
TLS validity checks and fail-fast behavior on invalid certificates are
handled separately in valkey-io#2999.
- New configuration
  - `tls-auto-reload-interval <seconds>`
  - `0` disabled (default, backward compatible)
  - `>0` check interval in seconds
- TLS materials change detection in background
  - SHA-256 fingerprint checking for certificate files
- `inode + mtime` checking for CA certificate directories and key files
- Skips reload if materials haven't changed
`tlsCheckMaterialsAndUpdateCache`
- TLS contexts reload
- CPU-intensive certificate parsing happens in dedicated BIO worker
thread `BIO_TLS_RELOAD`
  - Main thread never blocks, atomically swaps SSL contexts
- Two-phase reload: background preparation `tlsConfigureAsync` + main
thread application `tlsApplyPendingReload`

**Note**: Original TLS load and reload still remain in main thread using
`tlsConfigureSync`, including:
- Initial TLS load (server startup)
- Runtime reload via CONFIG SET

---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: arshidkv12 <arshidkv12@gmail.com>
Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Yang Zhao <zymy701@gmail.com>
@zuiderkwast zuiderkwast removed the to-be-merged Almost ready to merge label Jan 28, 2026
zuiderkwast pushed a commit to valkey-io/valkey-doc that referenced this pull request Feb 3, 2026
Changes include:
- Unify TLS topic naming: previously some references used β€œencryption”
while others used β€œtls”
- Remove source code repo specific information: instructions on building
or running unit tests
- Add information on new TLS feature and behavior:
   - valkey-io/valkey#2999
   - valkey-io/valkey#3020

---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
harrylin98 pushed a commit to harrylin98/valkey_forked that referenced this pull request Feb 19, 2026
### Overview
This PR adds support for automatic background TLS reloading, closes
valkey-io#2649
TLS validity checks and fail-fast behavior on invalid certificates are
handled separately in valkey-io#2999.
- New configuration
  - `tls-auto-reload-interval <seconds>`
  - `0` disabled (default, backward compatible)
  - `>0` check interval in seconds
- TLS materials change detection in background
  - SHA-256 fingerprint checking for certificate files
- `inode + mtime` checking for CA certificate directories and key files
- Skips reload if materials haven't changed
`tlsCheckMaterialsAndUpdateCache`
- TLS contexts reload
- CPU-intensive certificate parsing happens in dedicated BIO worker
thread `BIO_TLS_RELOAD`
  - Main thread never blocks, atomically swaps SSL contexts
- Two-phase reload: background preparation `tlsConfigureAsync` + main
thread application `tlsApplyPendingReload`


**Note**: Original TLS load and reload still remain in main thread using
`tlsConfigureSync`, including:
- Initial TLS load (server startup)
- Runtime reload via CONFIG SET


---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
harrylin98 pushed a commit to harrylin98/valkey_forked that referenced this pull request Feb 19, 2026
This PR adds the certificates validation at TLS load, rejects invalid
(expired/not-yet-valid) certificates:

Apply to all TLS config paths:
- Server certificates `tls-cert-file`
- Server-side client certificates `tls-client-cert-file`
- CA certificate file `tls-ca-cert-file` 
- CA certificate directory `tls-ca-cert-dir` (now eagerly loaded to be
consistent with file-based CAs)

Apply to both scenarios:
- Server startup (initial TLS load)
- Runtime reload vis `CONFIG SET`

### Implementation
- Added `isCertValid` function to check if an X509 certificate is within
its validity period (not expired, not future-dated)
- Added `areAllCaCertsValid` function to iterate through all loaded CA
certificates and validate them
- Added `loadCaCertDir` function to eagerly load all certificates from a
directory into the X509_STORE
- Modified `createSSLContext` to validate:
  - Server/client certificates immediately after loading
  - All CA certificates after loading from file/directory

### Test results

#### 1. Server startup (initial TLS load)
```
tls-cert-file ./tests/tls/server-expired.crt

41522:M 31 Dec 2025 16:13:18.851 # Server TLS certificate is invalid. Aborting TLS configuration.
41522:M 31 Dec 2025 16:13:18.851 # Failed to configure TLS. Check logs for more info.


tls-client-cert-file ./tests/tls/client-expired.crt

41557:M 31 Dec 2025 16:14:43.296 # Client TLS certificate is invalid. Aborting TLS configuration.
41557:M 31 Dec 2025 16:14:43.296 # Failed to configure TLS. Check logs for more info.


tls-ca-cert-file ./tests/tls/ca-expired.crt
tls-ca-cert-dir ./tests/tls/ca-expired

41567:M 31 Dec 2025 16:15:15.635 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
41567:M 31 Dec 2025 16:15:15.635 # Failed to configure TLS. Check logs for more info.
```

#### 2. Runtime reload via CONFIG SET
```
127.0.0.1:6379> config set tls-cert-file ./tests/tls/server-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:43.588 # Server TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:43.588 # Failed applying new configuration. Possibly related to new tls-cert-file setting. Restoring previous settings.


127.0.0.1:6379> config set tls-client-cert-file ./tests/tls/client-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-client-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:57.972 # Client TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:57.972 # Failed applying new configuration. Possibly related to new tls-client-cert-file setting. Restoring previous settings.


127.0.0.1:6379> config set tls-ca-cert-file ./tests/tls/ca-expired.crt
127.0.0.1:6379> config set tls-ca-cert-dir ./tests/tls/ca-expired
(error) ERR CONFIG SET failed (possibly related to argument 'tls-ca-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:50.175 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:50.175 # Failed applying new configuration. Possibly related to new tls-ca-cert-file setting. Restoring previous settings.
```

---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
@yang-z-o
yang-z-o deleted the tls-fail-fast-expired-cert branch March 4, 2026 05:09
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
### Overview
This PR adds support for automatic background TLS reloading, closes
valkey-io#2649
TLS validity checks and fail-fast behavior on invalid certificates are
handled separately in valkey-io#2999.
- New configuration
  - `tls-auto-reload-interval <seconds>`
  - `0` disabled (default, backward compatible)
  - `>0` check interval in seconds
- TLS materials change detection in background
  - SHA-256 fingerprint checking for certificate files
- `inode + mtime` checking for CA certificate directories and key files
- Skips reload if materials haven't changed
`tlsCheckMaterialsAndUpdateCache`
- TLS contexts reload
- CPU-intensive certificate parsing happens in dedicated BIO worker
thread `BIO_TLS_RELOAD`
  - Main thread never blocks, atomically swaps SSL contexts
- Two-phase reload: background preparation `tlsConfigureAsync` + main
thread application `tlsApplyPendingReload`

**Note**: Original TLS load and reload still remain in main thread using
`tlsConfigureSync`, including:
- Initial TLS load (server startup)
- Runtime reload via CONFIG SET

---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
This PR adds the certificates validation at TLS load, rejects invalid
(expired/not-yet-valid) certificates:

Apply to all TLS config paths:
- Server certificates `tls-cert-file`
- Server-side client certificates `tls-client-cert-file`
- CA certificate file `tls-ca-cert-file`
- CA certificate directory `tls-ca-cert-dir` (now eagerly loaded to be
consistent with file-based CAs)

Apply to both scenarios:
- Server startup (initial TLS load)
- Runtime reload vis `CONFIG SET`

### Implementation
- Added `isCertValid` function to check if an X509 certificate is within
its validity period (not expired, not future-dated)
- Added `areAllCaCertsValid` function to iterate through all loaded CA
certificates and validate them
- Added `loadCaCertDir` function to eagerly load all certificates from a
directory into the X509_STORE
- Modified `createSSLContext` to validate:
  - Server/client certificates immediately after loading
  - All CA certificates after loading from file/directory

### Test results

#### 1. Server startup (initial TLS load)
```
tls-cert-file ./tests/tls/server-expired.crt

41522:M 31 Dec 2025 16:13:18.851 # Server TLS certificate is invalid. Aborting TLS configuration.
41522:M 31 Dec 2025 16:13:18.851 # Failed to configure TLS. Check logs for more info.

tls-client-cert-file ./tests/tls/client-expired.crt

41557:M 31 Dec 2025 16:14:43.296 # Client TLS certificate is invalid. Aborting TLS configuration.
41557:M 31 Dec 2025 16:14:43.296 # Failed to configure TLS. Check logs for more info.

tls-ca-cert-file ./tests/tls/ca-expired.crt
tls-ca-cert-dir ./tests/tls/ca-expired

41567:M 31 Dec 2025 16:15:15.635 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
41567:M 31 Dec 2025 16:15:15.635 # Failed to configure TLS. Check logs for more info.
```

#### 2. Runtime reload via CONFIG SET
```
127.0.0.1:6379> config set tls-cert-file ./tests/tls/server-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:43.588 # Server TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:43.588 # Failed applying new configuration. Possibly related to new tls-cert-file setting. Restoring previous settings.

127.0.0.1:6379> config set tls-client-cert-file ./tests/tls/client-expired.crt
(error) ERR CONFIG SET failed (possibly related to argument 'tls-client-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:57.972 # Client TLS certificate is invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:57.972 # Failed applying new configuration. Possibly related to new tls-client-cert-file setting. Restoring previous settings.

127.0.0.1:6379> config set tls-ca-cert-file ./tests/tls/ca-expired.crt
127.0.0.1:6379> config set tls-ca-cert-dir ./tests/tls/ca-expired
(error) ERR CONFIG SET failed (possibly related to argument 'tls-ca-cert-file') - Unable to update TLS configuration. Check server logs.

62975:M 02 Jan 2026 20:10:50.175 # One or more loaded CA certificates are invalid. Aborting TLS configuration.
62975:M 02 Jan 2026 20:10:50.175 # Failed applying new configuration. Possibly related to new tls-ca-cert-file setting. Restoring previous settings.
```

---------

Signed-off-by: Yang Zhao <zymy701@gmail.com>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
@madolson

Copy link
Copy Markdown
Member

@yang-z-o @zuiderkwast We talked about this PR while reviewing #2999, and it came up that this might also be considered a breaking change. We were aligned that it's the right long term behavior that we should reject, but we decided to revert this for 9.1 and move it to 10.0. We'll do this after the RC though.

madolson pushed a commit that referenced this pull request Apr 27, 2026
…#3572)

This reverts commit eb3f465.

As discussed in the TSC Core Meeting, this PR reverts #2999 from Valkey
9.1. We plan to do in next major version as it's a breaking change.

**Note**: Merge conflicts in `src/tls.c` includes were resolved due to
overlapping changes from PR #2913, which added
`tlsUpdateCertInfoFromDir()` with shared header dependencies.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
…o#3572)

Revert of valkey-io#2999 (Prevent invalid TLS certificates from being loaded)
was decided by TSC as it is a breaking change, deferred to next major.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
@madolson madolson moved this to Merged in Valkey 9.2 May 10, 2026
zuiderkwast pushed a commit that referenced this pull request Sep 11, 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 #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 madolson added the breaking-change Indicates a possible backwards incompatible change label Sep 11, 2026
@madolson

Copy link
Copy Markdown
Member

@zuiderkwast @yang-z-o Just to ping folks. We decided to revert this from 9.1 since this felt like a breaking change, we then merged this into unstable thinking the next release was 10.0, but we decided to 9.2. Should we revert this just in 9.2 release branch again?

@zuiderkwast

Copy link
Copy Markdown
Contributor

We decided to revert this from 9.1 since this felt like a breaking change, we then merged this into unstable thinking the next release was 10.0, but we decided to 9.2. Should we revert this just in 9.2 release branch again?

Oh, I missed that and forgot we decided that. I saw it when going over the 9.2 board and saw it was ready. :/

Sure, we can revert it again then. (I don't think it's a problem to release it though. IMO, users relying on misconfiguration, such as empty files/directories, isn't something we need to worry about regarding semver. It's like if anyone is relying on a bug - that doesn't prevent us from fixing bugs.)

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

breaking-change Indicates a possible backwards incompatible change release-notes This issue should get a line item in the release notes

Projects

Status: Done
Status: Merged

Development

Successfully merging this pull request may close these issues.

[NEW] Fail fast on invalid certificates at TLS config load

5 participants