Support caller-provided MITM CAs in the network proxy (#47132)

## What changed

- Add optional `network.mitm_ca` configuration with `certificate_file` and
  `private_key_file` for trusted proxy configuration. Require MITM to be enabled
  and retain the generated CA when no external CA is configured.
- Validate absolute paths, regular files, file sizes, certificate/key matching,
  and Unix private-key permissions. Reject symlinks on Unix, private keys embedded
  in certificate files, and external private keys on non-Unix platforms.
- Store derived external-CA trust bundles in the proxy artifact directory,
  include only certificates, and skip inherited generated bundles to avoid
  retaining stale roots.
- Preserve MITM for external CAs when disabling credential brokerage. Reject
  external CA configuration for remote execution, even when the proxy is disabled,
  and reject unknown fields in `NetworkProxyConfig`.
- Default the upstream request version adapter to HTTP/1.1 and remove the request
  URI from upstream request failure context.

## Testing

Add regression coverage for external CA configuration, mismatched keys, embedded
private keys, non-Unix rejection, trust-bundle placement and contents, stale-root
exclusion, credential-broker toggling, and remote configuration rejection.

GitOrigin-RevId: cb209295c19fbe53a9fa0194f11ff06acccabef6
This commit is contained in:
viyatb-oai
2026-09-21 23:43:52 +00:00
committed by copyberry
parent cf6754e682
commit e4dba902ab
13 changed files with 470 additions and 68 deletions
+3 -4
View File
@@ -13,6 +13,7 @@ use rama_core::service::BoxService;
use rama_http::Body;
use rama_http::Request;
use rama_http::Response;
use rama_http::Version;
use rama_http::layer::version_adapter::RequestVersionAdapter;
use rama_http_backend::client::HttpClientService;
use rama_http_backend::client::HttpConnector;
@@ -199,7 +200,6 @@ impl Service<Request<Body>> for UpstreamClient {
req.extensions_mut().insert(proxy);
}
let uri = req.uri().clone();
let connect_started_at = Instant::now();
let EstablishedClientConnection {
input: mut req,
@@ -238,8 +238,7 @@ impl Service<Request<Body>> for UpstreamClient {
"HTTP upstream response headers failed (target={authority}, elapsed_ms={})",
request_started_at.elapsed().as_millis()
);
Err(OpaqueError::from_boxed(err)
.context(format!("http request failure for uri: {uri}")))
Err(OpaqueError::from_boxed(err).context("HTTP upstream request failed"))
}
}
}
@@ -264,7 +263,7 @@ fn build_http_connector(
let tls = TlsConnectorLayer::auto()
.with_connector_data(tls_config)
.into_layer(proxy);
let tls = RequestVersionAdapter::new(tls);
let tls = RequestVersionAdapter::new(tls).with_default_version(Version::HTTP_11);
let connector = HttpConnector::new(tls);
connector.boxed()
}