volume(rs): require the Extended Master Secret on outgoing HTTPS in FIPS mode (#13111)

The outgoing client took reqwest's rustls configuration, which leaves
require_ems at rustls's default: off for a provider that is not
FIPS-validated. A TLS 1.2 peer without EMS was accepted where Go's FIPS
mode refuses it. In FIPS mode the configuration is now built with the same
roots, CA and identity, and require_ems set.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-29 13:56:59 -08:00
1 parent 760f88e294
commit 276be51d04
3 files changed
+101 -21

No files matched your search

+1
View File
@@ -4662,6 +4662,7 @@ dependencies = [
"tracing",
"tracing-subscriber",
"uuid",
"webpki-roots",
"windows-sys 0.61.2",
"x509-parser",
"xxhash-rust",
+1
View File
@@ -68,6 +68,7 @@ jsonwebtoken = { version = "10", features = ["rust_crypto"] }
rustls = "0.23"
tokio-rustls = "0.26"
rustls-pemfile = "2"
webpki-roots = "1"
# LevelDB (via RocksDB for better Rust support)
# Using rusty-leveldb for pure Rust LevelDB
+99 -21
View File
@@ -169,28 +169,22 @@ fn build_outgoing_http_client(
));
}
let mut builder = outgoing_client_builder(redirect_policy);
if !config.https_client_ca_file.is_empty() {
let ca_pem = std::fs::read(&config.https_client_ca_file).map_err(|e| {
let ca_pem = if config.https_client_ca_file.is_empty() {
None
} else {
Some(std::fs::read(&config.https_client_ca_file).map_err(|e| {
format!(
"Failed to read HTTPS client CA file '{}': {}",
config.https_client_ca_file, e
)
})?;
let cert = reqwest::Certificate::from_pem(&ca_pem).map_err(|e| {
format!(
"Failed to parse HTTPS client CA PEM '{}': {}",
config.https_client_ca_file, e
)
})?;
builder = builder.add_root_certificate(cert);
}
})?)
};
match (
let identity = match (
config.https_client_cert_file.is_empty(),
config.https_client_key_file.is_empty(),
) {
(true, true) => {}
(true, true) => None,
(false, false) => {
let cert_pem = std::fs::read(&config.https_client_cert_file).map_err(|e| {
format!(
@@ -204,6 +198,45 @@ fn build_outgoing_http_client(
config.https_client_key_file, e
)
})?;
Some((cert_pem, key_pem))
}
_ => {
return Err(format!(
"HTTPS client requires both cert and key, got cert='{}' key='{}'",
config.https_client_cert_file, config.https_client_key_file
)
.into());
}
};
let mut builder = outgoing_client_builder(redirect_policy);
if seaweed_common::fips::process_mode().is_fips() {
let tls = fips_outgoing_tls_config(
ca_pem.as_deref(),
identity.as_ref().map(|(cert, key)| (cert.as_slice(), key.as_slice())),
Arc::new(seaweed_common::tls::crypto_provider()),
)
.map_err(|e| {
format!(
"Failed to build the HTTPS client TLS configuration (ca '{}', cert '{}', key '{}'): {}",
config.https_client_ca_file,
config.https_client_cert_file,
config.https_client_key_file,
e
)
})?;
builder = builder.use_preconfigured_tls(tls);
} else {
if let Some(ca_pem) = &ca_pem {
let cert = reqwest::Certificate::from_pem(ca_pem).map_err(|e| {
format!(
"Failed to parse HTTPS client CA PEM '{}': {}",
config.https_client_ca_file, e
)
})?;
builder = builder.add_root_certificate(cert);
}
if let Some((cert_pem, key_pem)) = identity {
let mut identity_pem = cert_pem;
if !identity_pem.ends_with(b"\n") {
identity_pem.push(b'\n');
@@ -217,18 +250,45 @@ fn build_outgoing_http_client(
})?;
builder = builder.identity(identity);
}
_ => {
return Err(format!(
"HTTPS client requires both cert and key, got cert='{}' key='{}'",
config.https_client_cert_file, config.https_client_key_file
)
.into());
}
}
Ok((builder.build()?, scheme.to_string()))
}
/// The outgoing HTTPS client configuration in FIPS mode: the roots, CA and
/// identity reqwest would use, with the Extended Master Secret required on
/// TLS 1.2 as Go requires it. reqwest leaves `require_ems` at rustls's
/// default, which is off for a provider that is not FIPS-validated.
fn fips_outgoing_tls_config(
ca_pem: Option<&[u8]>,
identity: Option<(&[u8], &[u8])>,
provider: Arc<rustls::crypto::CryptoProvider>,
) -> Result<rustls::ClientConfig, Box<dyn std::error::Error>> {
use rustls::pki_types::pem::PemObject;
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
let mut roots = rustls::RootCertStore::empty();
roots.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
if let Some(ca) = ca_pem {
for cert in CertificateDer::pem_slice_iter(ca) {
roots.add(cert?)?;
}
}
let builder = rustls::ClientConfig::builder_with_provider(provider)
.with_safe_default_protocol_versions()?
.with_root_certificates(roots);
let mut tls = match identity {
Some((cert, key)) => {
let chain = CertificateDer::pem_slice_iter(cert).collect::<Result<Vec<_>, _>>()?;
builder.with_client_auth_cert(chain, PrivateKeyDer::from_pem_slice(key)?)?
}
None => builder.with_no_client_auth(),
};
tls.alpn_protocols = vec![b"http/1.1".to_vec()];
tls.require_ems = true;
Ok(tls)
}
fn tls_policy_is_configured(policy: &TlsPolicy) -> bool {
!policy.min_version.is_empty()
|| !policy.max_version.is_empty()
@@ -1281,6 +1341,24 @@ mod tests {
assert_eq!(started.elapsed(), super::OUTGOING_CONNECT_TIMEOUT);
}
#[test]
fn fips_outgoing_tls_requires_ems() {
let provider = std::sync::Arc::new(seaweed_common::tls::provider_for(
seaweed_common::fips::FipsMode::On,
));
let tls = super::fips_outgoing_tls_config(
Some(TEST_CA_PEM.as_bytes()),
Some((TEST_LEAF_PEM.as_bytes(), TEST_LEAF_KEY_PEM.as_bytes())),
provider.clone(),
)
.unwrap();
assert!(tls.require_ems);
assert_eq!(tls.alpn_protocols, vec![b"http/1.1".to_vec()]);
let malformed_ca = b"-----BEGIN CERTIFICATE-----\nAAAA\n-----END CERTIFICATE-----\n";
assert!(super::fips_outgoing_tls_config(Some(malformed_ca), None, provider).is_err());
}
fn write_pem(dir: &tempfile::TempDir, name: &str, body: &str) -> String {
let path = dir.path().join(name);
std::fs::write(&path, body).unwrap();