Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased — post-audit maintenance (Plans 320–325)
## Unreleased — post-audit maintenance (Plans 320–328)

No version has been published from this work; the Rust line stays on `0.5.x`
and the wheel on `0.2.5` until a maintainer chooses a release.
Expand Down Expand Up @@ -34,8 +34,9 @@ and the wheel on `0.2.5` until a maintainer chooses a release.
budget; exhaustion is a sanitized 503 before response start. A Python
`__next__` that blocks indefinitely still cannot be interrupted.
- **Operator and repository hygiene (Plan 323).** `--public` documentation now
matches the fail-safe CLI (it acknowledges a wildcard bind and does not
change the address). `cargo audit` policy moved to `.cargo/audit.toml` (the
matches the fail-safe CLI (it acknowledged a wildcard bind and did not
change the address; Plan 326 later widened the requirement to any
non-loopback address). `cargo audit` policy moved to `.cargo/audit.toml` (the
dead root `audit.toml` is gone) and `deny.toml` remains the cargo-deny
policy. `eggserve-core` no longer enables the unused `tokio/signal` feature in its
production graph; the six core examples keep a dev-only signal feature.
Expand All @@ -51,6 +52,37 @@ and the wheel on `0.2.5` until a maintainer chooses a release.
pipelines. Identity certificate/key PEM input is bounded to 1 MiB before
parsing, for in-memory and file-path loads. No TLS identity/trust/auth
semantics changed.
- **Public-bind acknowledgment tightening (Plan 326).** Any resolved
non-loopback address — wildcard, LAN, or routable — now requires `--public`
on the CLI and `public=True` through the Python lowlevel surface. The flag
remains acknowledgment-only: it does not select or change the bind address,
and `--public` alone still binds loopback.
- **TLS configuration is provider-deterministic (Plan 327).** `eggnet-tls` and
the H3 QUIC assembler build every rustls configuration with the ring
provider explicitly instead of the process default. A consumer graph that
also enables `aws-lc-rs` no longer panics on a valid certificate pair, and
the Python wheel no longer installs a process-global provider as a
workaround.
- **TLS ALPN is validated against the runtime (Plan 327).** A static
configuration that advertises `h2` while HTTP/2 is disabled (or the build
lacks the `http2` feature) is rejected at build/start instead of completing
the handshake and dropping the connection. Plan 328 extends the same check
to the reload swap.
- **`--header-timeout` now bounds TLS handshakes (Plan 327).** The CLI maps the
flag to both `header_read_timeout` and `tls_handshake_timeout`, matching the
published security policy instead of leaving the handshake at a fixed 10s.
- **The SNI identity ceiling is order-independent (Plan 327).** The optional
default identity no longer counts toward `MAX_TLS_IDENTITIES`, so 64 named
identities are accepted whether the default is configured first or last.
- **H3 QUIC bounds are validated and typed (Plan 327).** Out-of-range receive
windows and idle timeouts are rejected by `Http3Config::validate` with the
field named, and transport configuration failures no longer surface as
`invalid private key`.
- **Reload ALPN coherence is enforced at the swap (Plan 328).**
`ServerHandle::replace_tls_config` / `replace_tls_server_config` reject an
`h2`-advertising snapshot when the runtime cannot serve HTTP/2, before it
becomes live, so the previous identity stays in service instead of every h2
client completing a handshake and being dropped.

## 0.5.1 — `eggserve-static` patch (published 2026-10-23)

Expand Down
9 changes: 9 additions & 0 deletions architecture/eggnet-tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ through `load_tls_config_with_http2` to `http_alpn_protocols(http2)` (offers
non-HTTP transports advertise their own identifiers (empty means no ALPN);
an explicit override wins over the `http2(bool)` convenience (last call wins).

Every configuration is built with the ring provider explicitly
(`crypto_provider()` in `crates/eggnet-tls/src/lib.rs`), never through
rustls's process-default selection. A consumer graph that also enables
`aws-lc-rs` therefore cannot make construction panic, and key validation uses
the same provider as the handshake configuration. EggServe's compatibility
runtime separately validates that a static configuration or a reload snapshot
does not advertise `h2` when its own HTTP/2 capability is disabled or absent,
both at build/start and when the server handle performs the reload swap.

Bounded inputs (`crates/eggnet-tls/src/lib.rs`):

| Bound | Value | Source |
Expand Down
3 changes: 2 additions & 1 deletion architecture/eggserve-bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Canonical grammar is `[OPTIONS] [PORT] [DIRECTORY]` (normative flags in
* `--directory DIR` occupies DIRECTORY; `.` default. `--bind HOST[:PORT]`
(host-only leaves PORT free), `--port PORT`, `--addr HOST:PORT` (cannot
combine with `--bind`); `:PORT` means `0.0.0.0:PORT` (still needs
`--public`). Hostnames resolve once; wildcard results still need `--public`.
`--public`). Hostnames resolve once; any non-loopback result needs
`--public` (acknowledgment only; the flag does not expand the host).
* Two logical slots: PORT then DIRECTORY. Explicit port sources occupy PORT;
the next positional after occupied PORT is DIRECTORY verbatim (even numeric).
`--directory` occupying DIRECTORY leaves a later numeric positional free for
Expand Down
2 changes: 1 addition & 1 deletion architecture/policy-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Users must explicitly opt-in to less restrictive behavior via CLI flags or Pytho
| `--directory-listing` | `DirectoryListingPolicy::Enabled` | Enable directory listing |
| `--follow-symlinks` | `SymlinkPolicy::Follow` | Follow symlinks |
| `--allow-dotfiles` | `DotfilePolicy::Serve` | Serve dotfiles |
| `--public` | Bind to `0.0.0.0` | Accept non-loopback connections |
| `--public` | Acknowledge non-loopback bind | Required for any non-loopback `--bind`/`--addr` (does not expand the host alone) |

## Python API Mapping

Expand Down
64 changes: 56 additions & 8 deletions crates/eggnet-tls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use rustls::ServerConfig;
use rustls_pki_types::pem::PemObject;
use rustls_pki_types::{CertificateDer, CertificateRevocationListDer, PrivateKeyDer};

/// Maximum SNI identities per [`TlsServerConfig`] (exact + wildcard combined).
/// Maximum named SNI identities per [`TlsServerConfig`] (exact + wildcard
/// combined; the optional default identity is separate).
pub const MAX_TLS_IDENTITIES: usize = 64;
/// Maximum DNS length for an SNI identity (DNS limit, without `*.` prefix).
pub const MAX_SNI_LEN: usize = 253;
Expand Down Expand Up @@ -83,6 +84,11 @@ pub enum TlsError {
TrustRootsRequired,
/// The ALPN advertisement was malformed or out of bounds.
InvalidAlpn(String),
/// The configured crypto provider could not serve the requested
/// protocol versions.
InvalidCryptoProvider(String),
/// A transport adapter's TLS configuration was out of range.
InvalidTransportConfig(String),
}

impl fmt::Display for TlsError {
Expand Down Expand Up @@ -116,6 +122,12 @@ impl fmt::Display for TlsError {
write!(f, "client authentication requires at least one trust root")
}
Self::InvalidAlpn(msg) => write!(f, "invalid ALPN protocols: {msg}"),
Self::InvalidCryptoProvider(msg) => {
write!(f, "invalid TLS crypto provider: {msg}")
}
Self::InvalidTransportConfig(msg) => {
write!(f, "invalid transport configuration: {msg}")
}
}
}
}
Expand Down Expand Up @@ -277,6 +289,15 @@ pub fn parse_crls_pem(pem: &[u8]) -> Result<Vec<CertificateRevocationListDer<'st
Ok(crls)
}

/// The rustls crypto provider used for every configuration this crate builds.
///
/// The provider is explicit rather than process-global: construction must not
/// panic when a downstream dependency graph enables both `ring` and
/// `aws-lc-rs`, and key validation must use the same provider as handshakes.
fn crypto_provider() -> Arc<rustls::crypto::CryptoProvider> {
Arc::new(rustls::crypto::ring::default_provider())
}

fn build_single_cert_config(
certs: Vec<CertificateDer<'static>>,
key: PrivateKeyDer<'static>,
Expand All @@ -287,7 +308,9 @@ fn build_single_cert_config(
"certificate chain too long (max {MAX_IDENTITY_CHAIN})"
)));
}
let mut config = ServerConfig::builder()
let mut config = ServerConfig::builder_with_provider(crypto_provider())
.with_safe_default_protocol_versions()
.map_err(|e| TlsError::InvalidCryptoProvider(e.to_string()))?
.with_no_client_auth()
.with_single_cert(certs, key)
.map_err(|e| TlsError::InvalidKey(e.to_string()))?;
Expand Down Expand Up @@ -347,7 +370,7 @@ fn validate_key_pair(
certs: &[CertificateDer<'static>],
key: &PrivateKeyDer<'static>,
) -> Result<(), TlsError> {
let provider = rustls::crypto::ring::default_provider();
let provider = crypto_provider();
let signing_key = provider
.key_provider
.load_private_key(key.clone_key())
Expand Down Expand Up @@ -592,7 +615,7 @@ impl TlsServerConfigBuilder {
certs: Vec<CertificateDer<'static>>,
key: PrivateKeyDer<'static>,
) -> Result<Self, TlsError> {
if self.identities.len() + usize::from(self.default.is_some()) >= MAX_TLS_IDENTITIES {
if self.identities.len() >= MAX_TLS_IDENTITIES {
return Err(TlsError::TooManyIdentities);
}
let (is_wildcard, normalized) = normalize_sni_name(name)?;
Expand Down Expand Up @@ -708,7 +731,7 @@ impl TlsServerConfigBuilder {
if self.client_auth != ClientAuthMode::Disabled && self.roots.is_empty() {
return Err(TlsError::TrustRootsRequired);
}
let provider = rustls::crypto::ring::default_provider();
let provider = crypto_provider();
let mut exact: HashMap<String, Arc<rustls::sign::CertifiedKey>> = HashMap::new();
let mut wildcards: Vec<(String, Arc<rustls::sign::CertifiedKey>)> = Vec::new();
let mut identity_names: Vec<String> = Vec::new();
Expand Down Expand Up @@ -747,7 +770,9 @@ impl TlsServerConfigBuilder {
default,
});
let verifier = build_client_verifier(self.client_auth, &self.roots, self.crls)?;
let mut config = ServerConfig::builder()
let mut config = ServerConfig::builder_with_provider(crypto_provider())
.with_safe_default_protocol_versions()
.map_err(|e| TlsError::InvalidCryptoProvider(e.to_string()))?
.with_client_cert_verifier(verifier)
.with_cert_resolver(resolver);
let alpn = self.alpn.unwrap_or_else(|| http_alpn_protocols(self.http2));
Expand Down Expand Up @@ -782,7 +807,8 @@ fn build_client_verifier(
.add(root.clone())
.map_err(|e| TlsError::InvalidTrustRoots(e.to_string()))?;
}
let builder = WebPkiClientVerifier::builder(Arc::new(store));
let builder =
WebPkiClientVerifier::builder_with_provider(Arc::new(store), crypto_provider());
let builder = if crls.is_empty() {
builder
} else {
Expand Down Expand Up @@ -867,7 +893,8 @@ pub fn http_alpn_protocols(http2: bool) -> Vec<Vec<u8>> {

#[cfg(test)]
mod tests {
use super::{http_alpn_protocols, normalize_sni_name};
use super::{http_alpn_protocols, normalize_sni_name, ClientAuthMode, TlsServerConfig};
use rustls_pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};

#[test]
fn h2_alpn_is_preferred_only_when_enabled() {
Expand Down Expand Up @@ -895,4 +922,25 @@ mod tests {
assert!(!wild);
assert_eq!(norm, "example.com");
}

/// This test binary links both rustls providers (the `tokio-rustls`
/// dev-dependency enables `aws-lc-rs`), so the process-default builder
/// would panic here. Construction must be provider-explicit.
#[test]
fn construction_does_not_require_a_process_default_provider() {
let key_pair = rcgen::KeyPair::generate().expect("key pair");
let params = rcgen::CertificateParams::new(vec!["provider.test".to_owned()])
.expect("certificate params");
let cert = params.self_signed(&key_pair).expect("certificate");
let cert_der: CertificateDer<'static> = cert.into();
let key: PrivateKeyDer<'static> = PrivatePkcs8KeyDer::from(key_pair.serialize_der()).into();
let config = TlsServerConfig::builder()
.single_identity(vec![cert_der.clone()], key)
.expect("identity")
.client_auth_required(vec![cert_der])
.expect("trust roots")
.build()
.expect("provider-explicit build");
assert_eq!(config.client_auth(), ClientAuthMode::Required);
}
}
44 changes: 43 additions & 1 deletion crates/eggnet-tls/tests/neutral_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eggnet_tls::{
http_alpn_protocols, load_identity, load_tls_config_with_alpn, parse_crls_pem,
parse_identity_pem, parse_trust_roots_pem, ClientAuthMode, TlsError, TlsReloadHandle,
TlsServerConfig, MAX_ALPN_PROTOCOLS, MAX_ALPN_PROTOCOL_LEN, MAX_IDENTITY_CHAIN,
MAX_IDENTITY_PEM_BYTES, MAX_TRUST_PEM_BYTES, MAX_TRUST_ROOTS,
MAX_IDENTITY_PEM_BYTES, MAX_TLS_IDENTITIES, MAX_TRUST_PEM_BYTES, MAX_TRUST_ROOTS,
};
use rustls::pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer, ServerName};
use rustls_pki_types::pem::PemObject;
Expand Down Expand Up @@ -350,6 +350,48 @@ async fn custom_alpn_negotiates_end_to_end() {
);
}

/// The named-identity ceiling is order-independent and excludes the optional
/// default identity; a 65th named identity is rejected.
#[test]
fn identity_ceiling_excludes_the_optional_default() {
let shared = identity("shared.test");

let mut builder = TlsServerConfig::builder()
.single_identity(shared.certs.clone(), shared.key.clone_key())
.expect("default identity");
for i in 0..MAX_TLS_IDENTITIES {
builder = builder
.add_identity(
&format!("h{i}.test"),
shared.certs.clone(),
shared.key.clone_key(),
)
.expect("identity within the documented ceiling");
}
let built = builder.build().expect("ceiling build");
assert_eq!(built.identities().len(), MAX_TLS_IDENTITIES);
assert!(built.has_default_identity());

let mut overflow = TlsServerConfig::builder();
for i in 0..MAX_TLS_IDENTITIES {
overflow = overflow
.add_identity(
&format!("o{i}.test"),
shared.certs.clone(),
shared.key.clone_key(),
)
.expect("identity within the documented ceiling");
}
assert!(matches!(
overflow.add_identity(
"overflow.test",
shared.certs.clone(),
shared.key.clone_key()
),
Err(TlsError::TooManyIdentities)
));
}

/// Plan 324: identity PEM input is bounded before parsing, and a valid
/// identity at the ceiling still parses.
#[test]
Expand Down
Loading
Loading