mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user