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
+10 -3
View File
@@ -1,4 +1,5 @@
use crate::certs::ManagedMitmCa;
use crate::config::NetworkMitmCaConfig;
use crate::config::NetworkMode;
use crate::mitm_hook::HookEvaluation;
use crate::mitm_hook::MitmHookActions;
@@ -63,6 +64,7 @@ pub struct MitmState {
pub(crate) struct MitmUpstreamConfig {
pub(crate) allow_upstream_proxy: bool,
pub(crate) external_ca: Option<NetworkMitmCaConfig>,
}
#[derive(Clone)]
@@ -108,9 +110,14 @@ impl MitmState {
// and host-specific hooks both need visibility after CONNECT is established. We
// generate a process-local CA and issue per-host leaf certs so we can terminate TLS and
// apply policy.
let ca = ManagedMitmCa::load_or_create()?;
let upstream_tls_root_store =
crate::certs::upstream_tls_root_store(&crate::certs::ca_env_from_process())?;
let ca = match config.external_ca.as_ref() {
Some(ca) => ManagedMitmCa::load_from_files(ca)?,
None => ManagedMitmCa::load_or_create()?,
};
let upstream_tls_root_store = crate::certs::upstream_tls_root_store_for_cert_path(
ca.certificate_path(),
&crate::certs::ca_env_from_process(),
)?;
Ok(Self {
ca,