Fail fast on empty CA directory at TLS config load#3522
Fail fast on empty CA directory at TLS config load#3522yang-z-o wants to merge 1 commit intovalkey-io:unstablefrom
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?
|
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-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>