Skip to content

[9.2] Revert fail-fast TLS certificate checks (#2999, #3522) - #231

Closed
madolson wants to merge 2 commits into
9.2from
revert-tls-fail-fast-9.2
Closed

madolson wants to merge 2 commits into
9.2from
revert-tls-fail-fast-9.2

Conversation

@madolson

Copy link
Copy Markdown
Owner

Fixes valkey-io#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 valkey-io#2999 and valkey-io#3522, which the TSC decided were a breaking change: valkey-io#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.

AI generated details

Problem

createSSLContext() on upstream/9.2 validates every certificate it loads and aborts the whole TLS configuration if any one of them is expired or not yet valid: src/tls.c:653 for the server and client certificates, src/tls.c:675 for the alternate server certificate, src/tls.c:719 for the contents of the X509 store after tls-ca-cert-file and tls-ca-cert-dir are loaded. areAllCaCertsValid() at src/tls.c:586 walks the whole store and returns false on the first expired entry.

That makes a normal CA rotation fatal. A bundle that still carries the retired root alongside the current one worked on 9.1 and earlier, because OpenSSL simply does not build chains through an expired cert, and nothing in the handshake path cares that it is present. On 9.2.0 the same files stop the server from starting. From valkey-io#5506, same config and same cert files on both versions:

== 9.1.3
* Ready to accept connections tls
== 9.2.0
# One or more loaded CA certificates are invalid. Aborting TLS configuration.
# Failed to configure TLS. Check logs for more info.

The same applies at runtime, where CONFIG SET tls-ca-cert-file on such a bundle now fails and keeps the old configuration.

History

Affected releases: 9.2.0 only. Not 9.1.x, where valkey-io#3572 removed it, and not 8.x, which predates valkey-io#2999. Target release for this revert is 9.2.1.

Fix

Two commits, in the order the dependency requires, so each can be read against a plain git revert.

Revert "Fail fast on empty CA directory at TLS config load (valkey-io/valkey#3522)" is byte-for-byte a plain git revert 13c66b82e: no later commit touched those hunks. It has to come first because its abort lives inside loadCaCertDir(), which valkey-io#2999 introduced.

Revert "Fail fast on invalid certificates at TLS config load (valkey-io/valkey#2999)" conflicts with six later 9.2-only commits and is resolved by hand, per file:

File Resolution
src/tls.c Removed isCertValid(), loadCaCertDir(), areAllCaCertsValid() and all four call sites. Kept #include <dirent.h> and #include <limits.h>, which a plain revert drops but valkey-io#2913's tlsUpdateCertInfoFromDir() still needs (src/tls.c:389, src/tls.c:397). Restored the CA block to 9.1's single combined condition, which is now character-identical to upstream/9.1:src/tls.c. Everything valkey-io#3717, valkey-io#4663, valkey-io#4664, valkey-io#4577 and valkey-io#2913 added to createSSLContext() is untouched.
src/tls.c:43 #include <openssl/x509_vfy.h> is left in place even though this revert removes its last direct consumers (X509_STORE_get0_objects, X509_OBJECT_*, X509_LU_X509, and valkey-io#4064's X509_V_ERR_ERROR_IN_CERT_NOT_{BEFORE,AFTER}_FIELD). The line belongs to valkey-io#3717, which is not being reverted, and ssl.h pulls the header in transitively anyway, so dropping it is a cleanup outside this revert rather than part of it. Say the word and it goes; 9.1 does not have it.
src/tls.c (valkey-io#4064) valkey-io#4064 only improved the OpenSSL 4.0 error logging inside isCertValid(), so it goes with the function. isCertValid() has no caller that is not a fail-fast abort, so there is nothing left to keep it for.
tests/unit/tls.tcl Removed both test_tls_cert_rejection* procs and both tests. The plain revert conflicts because a later commit swapped [file normalize ./src/valkey-tls.so] for $::VALKEY_TLS_MODULE and ./src/valkey-server for $::VALKEY_SERVER_BIN inside the removed block. Nothing else in the repo references the certs these tests used.
utils/gen-test-certs.sh Removed the whole invalid-certificate generation section and the five header lines describing its output. Kept valkey-io#2999's wider header-comment column, because valkey-io#3717, valkey-io#4383 and the NUL-CN test all added lines in that column and narrowing it back would churn them for no reason.
tests/README.md Restored the pre-valkey-io/valkey#2999 wording.

One call a reviewer may want to make differently: src/tls.c:675, the alternate-certificate abort, is not from valkey-io#2999. valkey-io#3717 added secondary certificate support in 9.2 and copied valkey-io#2999's check for the second certificate, so a plain revert of valkey-io#2999 would leave it behind. Keeping it would mean the primary certificate's expiry is ignored at config load while the secondary's is fatal, on the same server, in the same function, five lines apart. That is a worse surface to explain and support than either consistent choice, so it goes with the rest. Reinstating it for 10.0 is one line and belongs with the rest of the fail-fast work that unstable already carries.

Behavior

Every cell is a server started with --tls-port, a valid tls-cert-file/tls-key-file unless the row says otherwise, and the listed CA configuration. The cell is the log line the server printed. Base is upstream/9.2 at d23684e3, built locally; 9.1.3 and 9.2.0 are the official valkey/valkey images. Raw output is below.

Input base d23684e3 / 9.2.0 this branch 9.1.3
valid bundle (tls-ca-cert-file ca.crt) Ready to accept connections tls Ready to accept connections tls Ready to accept connections tls
bundle with an expired extra CA (tls-ca-cert-file) One or more loaded CA certificates are invalid. Aborting TLS configuration. Ready to accept connections tls Ready to accept connections tls
expired extra CA in tls-ca-cert-dir One or more loaded CA certificates are invalid. Aborting TLS configuration. Ready to accept connections tls Ready to accept connections tls
empty tls-ca-cert-dir No CA certificates loaded from directory: <dir> Ready to accept connections tls Ready to accept connections tls
expired tls-cert-file Server TLS certificate is invalid. Aborting TLS configuration. Ready to accept connections tls Ready to accept connections tls
expired tls-alt-cert-file Alternate server TLS certificate is invalid. Aborting TLS configuration. Ready to accept connections tls n/a, tls-alt-cert-file does not exist in 9.1

The branch column matches the 9.1.3 column in every row where 9.1.3 has a value. The base column is identical to the released 9.2.0 column in every row, so the local base build is a faithful stand-in.

The expired-CA rows use a bundle of the valid test CA plus a separately-issued expired CA with a different subject, which is the reporter's rotation case: nothing chains through the expired cert.

One capability does go away with loadCaCertDir()

Reverting valkey-io#2999 removes the eager tls-ca-cert-dir load, which means OpenSSL is back to its documented -CApath contract: certificates in that directory are found by subject-hash symlink, not by filename. 9.2.0 accidentally made a directory of plain-named .crt files work for peer verification, because loadCaCertDir() pushed every parseable file straight into the X509 store. Verified by handshaking a client certificate against a server configured with tls-ca-cert-dir only and tls-auth-clients yes:

[BASE]   tls-ca-cert-dir, hashed links (ca-dir)   -> started; PING: PONG
[BASE]   tls-ca-cert-dir, plain filenames only    -> started; PING: PONG
[BRANCH] tls-ca-cert-dir, hashed links (ca-dir)   -> started; PING: PONG
[BRANCH] tls-ca-cert-dir, plain filenames only    -> started; PING: Error: Server closed the connection
[9.1.3]  tls-ca-cert-dir, hashed links (ca-dir)   -> started; PING: PONG
[9.1.3]  tls-ca-cert-dir, plain filenames only    -> started; PING: Error: Server closed the connection
[9.2.0]  tls-ca-cert-dir, hashed links (ca-dir)   -> started; PING: PONG
[9.2.0]  tls-ca-cert-dir, plain filenames only    -> started; PING: PONG

The branch matches 9.1.3, which is the point of the revert, and utils/gen-test-certs.sh already builds the hashed ca-dir/ the tests use. Keeping loadCaCertDir() just for this would keep the eager scan whose zero-cert case is exactly what valkey-io#3522 then turned into an abort, so it goes.

Nobody on the 9.1 to 9.2.1 path can be relying on this, but somebody on the 9.2.0 to 9.2.1 path can, and for them the regression is silent: SSL_CTX_load_verify_locations registers a directory lazily, so the server starts normally and then fails every handshake with certificate verify failed. That is the same silent-misconfiguration shape valkey-io#3522 was written to prevent. It is narrow, since it needs a dir-only CA config that actually verifies peers (tls-auth-clients not no, or tls-cluster/tls-replication), and the capability was never documented or tested as "plain filenames work". It does mean the 9.2.1 note has to name it rather than just say the checks were reverted.

### BASE = upstream/9.2 @ d23684e3ec302240754664417e3b99df23e8e4c9 (local build, ubuntu:24.04 / OpenSSL 3.0.13)
### [BASE] valid bundle (tls-ca-cert-file ca.crt)
Ready to accept connections tls

### [BASE] bundle with an expired extra CA (tls-ca-cert-file)
Failed to configure TLS. Check logs for more info.
One or more loaded CA certificates are invalid. Aborting TLS configuration.

### [BASE] expired extra CA in tls-ca-cert-dir
Failed to configure TLS. Check logs for more info.
One or more loaded CA certificates are invalid. Aborting TLS configuration.

### [BASE] empty tls-ca-cert-dir
Failed to configure TLS. Check logs for more info.
No CA certificates loaded from directory: /mtls/ca-empty-dir

### [BASE] expired server cert (tls-cert-file)
 Server TLS certificate is invalid. Aborting TLS configuration.
Failed to configure TLS. Check logs for more info.

### [BASE] expired alternate server cert (tls-alt-cert-file)
 Alternate server TLS certificate is invalid. Aborting TLS configuration.
Failed to configure TLS. Check logs for more info.

### BRANCH = revert-tls-fail-fast-9.2 (local build, same container)
### [BRANCH] valid bundle (tls-ca-cert-file ca.crt)
Ready to accept connections tls

### [BRANCH] bundle with an expired extra CA (tls-ca-cert-file)
Ready to accept connections tls

### [BRANCH] expired extra CA in tls-ca-cert-dir
Ready to accept connections tls

### [BRANCH] empty tls-ca-cert-dir
Ready to accept connections tls

### [BRANCH] expired server cert (tls-cert-file)
Ready to accept connections tls

### [BRANCH] expired alternate server cert (tls-alt-cert-file)
Ready to accept connections tls

### valkey/valkey:9.1.3 (official image)
### [9.1.3] valid bundle (tls-ca-cert-file ca.crt)
Ready to accept connections tls

### [9.1.3] bundle with an expired extra CA (tls-ca-cert-file)
Ready to accept connections tls

### [9.1.3] expired extra CA in tls-ca-cert-dir
Ready to accept connections tls

### [9.1.3] empty tls-ca-cert-dir
Ready to accept connections tls

### [9.1.3] expired server cert (tls-cert-file)
Ready to accept connections tls

### [9.1.3] expired alternate server cert (tls-alt-cert-file)

### valkey/valkey:9.2.0 (official image)
### [9.2.0] valid bundle (tls-ca-cert-file ca.crt)
Ready to accept connections tls

### [9.2.0] bundle with an expired extra CA (tls-ca-cert-file)
Failed to configure TLS. Check logs for more info.
One or more loaded CA certificates are invalid. Aborting TLS configuration.

### [9.2.0] expired extra CA in tls-ca-cert-dir
Failed to configure TLS. Check logs for more info.
One or more loaded CA certificates are invalid. Aborting TLS configuration.

### [9.2.0] empty tls-ca-cert-dir
Failed to configure TLS. Check logs for more info.
No CA certificates loaded from directory: /mtls/ca-empty-dir

### [9.2.0] expired server cert (tls-cert-file)
 Server TLS certificate is invalid. Aborting TLS configuration.
Failed to configure TLS. Check logs for more info.

### [9.2.0] expired alternate server cert (tls-alt-cert-file)
 Alternate server TLS certificate is invalid. Aborting TLS configuration.
Failed to configure TLS. Check logs for more info.

The 9.1.3 alternate-certificate row is blank because 9.1 has no such config and exits before TLS setup:

*** FATAL CONFIG FILE ERROR (Version 9.1.3) ***
Reading the configuration file, at line 7
>>> 'tls-alt-cert-file "/mtls/valkey-ec-expired.crt"'
Bad directive or wrong number of arguments

Alternative considered

Warn instead of fail, as valkey-io#3153 proposed. It is strictly better than aborting, and it is the shape the eventual 10.0 behavior should probably take, but it still changes what 9.2.1 logs and what operators' log scrapers see relative to 9.1, for a check the TSC decided does not belong in a minor release at all. It also leaves loadCaCertDir() in place, which means 9.2 keeps eagerly scanning tls-ca-cert-dir at config load, a behavior change of its own that 9.1 does not have, and that is where valkey-io#3522's empty-directory abort grew from.

An opt-out config such as tls-verify-cert-validity-at-load. That puts a new user-visible config into a patch release, which needs a TSC vote on its own, and 10.0 would then have to deprecate it the moment the fail-fast behavior becomes the documented default. A knob whose only purpose is to undo a change we have already decided to undo is worse than undoing the change.

Neither option gets 9.2 back to the behavior its users had in 9.1, which is the actual requirement for a patch release.

Testing

No new regression test. This restores behavior that 9.1 never had a test for, on a release branch whose unstable counterpart deliberately asserts the opposite. A test that pins "starting with an expired CA in the bundle succeeds" would have to be deleted again when 10.0 lands the fail-fast checks. The matrix above is the evidence instead.

The tests removed with valkey-io#2999 were the only coverage of these paths, and they asserted exactly the aborts being removed, so there is nothing left in tests/unit/tls.tcl that can detect this change in either direction.

./runtest --tls --single unit/tls --loops 3: 93 passed, 0 failed. make BUILD_TLS=module plus ./runtest --tls-module --single unit/tls: 26 passed, 0 failed. Both builds clean with no new warnings, in an ubuntu:24.04 container with OpenSSL 3.0.13 and tcl-tls.

Release notes

Not touched here, and 00-RELEASENOTES needs more than one line when 9.2.1 is cut. The 9.2.0 GA section currently advertises two of the three behaviors this removes, and both are false on 9.2.1:

285: * Reject an empty `tls-ca-cert-dir` at startup and `CONFIG SET` time instead of silently accepting it and failing every client handshake later by @yang-z-o (#3522)
318: * Log a warning when a TLS certificate has an invalid notBefore or notAfter field on OpenSSL 4.0 builds by @pkhartsk (#4064)

valkey-io#2999 itself appears nowhere in the file, so the main fail-fast behavior is undocumented in both directions. The historical 9.2.0 section should not be edited; the 9.2.1 entry should cover all three removals, including the tls-ca-cert-dir hash-name requirement above, which is the one with a silent failure mode.

This was generated by AI but verified, with love, by a human.

…#3522)"

This reverts commit 13c66b8.

Refusing to configure TLS when tls-ca-cert-dir holds no certificates is a
breaking change, and the TSC decided the fail-fast certificate checks wait
for a major release. The check lives inside loadCaCertDir(), which valkey-io#2999
added, so it has to go before valkey-io#2999 can be reverted.

Related to valkey-io#5506.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
…io#2999)"

This reverts commit eb3f465.

Refusing to configure TLS when any loaded certificate is outside its validity
period breaks configurations that worked in 9.1 and earlier. An expired
intermediate or root left in a tls-ca-cert-file bundle after a CA rotation is
normal and harmless, since OpenSSL simply does not build chains through it, but
the check walks the whole X509_STORE and rejects the configuration on the first
expired entry, so a server that served traffic fine on 9.1.3 refuses to start on
9.2.0.

The TSC decided these checks are a breaking change that waits for a major
release, and reverted them from 9.1 in valkey-io#3572. The next release turned out to be
9.2 rather than 10.0, and the revert was never carried over, so 9.2.0 shipped
them. Restore the 9.1 behavior on 9.x. unstable keeps the checks for 10.0.

The alternate-certificate check that valkey-io#3717 added is removed along with the
primary one, so both server certificates behave the same way on 9.x.

Reported-by: Philippe <31954718+Qwarctick@users.noreply.github.com>
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
@madolson madolson added bug Something isn't working needs-review Staged work waiting on madolson's review labels Nov 23, 2026
@madolson madolson added promoted Change has been promoted upstream and removed needs-review Staged work waiting on madolson's review labels Nov 23, 2026
@madolson

Copy link
Copy Markdown
Owner Author

Promoted upstream: valkey-io#5550

@madolson madolson closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working promoted Change has been promoted upstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant