From 78ba20a6cbb6b161cca20ee3b1d59ccdad7f1cc4 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Thu, 23 Nov 2023 11:52:36 +0200 Subject: [PATCH] Added new configuration 'use_proxy' (#2076) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added new configuration 'use_proxy' that lets user disable usage of http/s proxy by mirrord even when env is set * config docs * Update mirrord/config/src/lib.rs Co-authored-by: Michał Smolarek <34063647+Razz4780@users.noreply.github.com> * aa. * .. * f. --------- Co-authored-by: Michał Smolarek <34063647+Razz4780@users.noreply.github.com> --- changelog.d/+use_proxy.added.md | 1 + mirrord-schema.json | 8 ++++++++ mirrord/cli/src/execution.rs | 9 +++++++++ mirrord/config/src/lib.rs | 11 +++++++++++ 4 files changed, 29 insertions(+) create mode 100644 changelog.d/+use_proxy.added.md diff --git a/changelog.d/+use_proxy.added.md b/changelog.d/+use_proxy.added.md new file mode 100644 index 00000000000..22398bcb181 --- /dev/null +++ b/changelog.d/+use_proxy.added.md @@ -0,0 +1 @@ +Added new configuration 'use_proxy' that lets user disable usage of http/s proxy by mirrord even when env is set \ No newline at end of file diff --git a/mirrord-schema.json b/mirrord-schema.json index 69b1411d861..a9c9492c63c 100644 --- a/mirrord-schema.json +++ b/mirrord-schema.json @@ -135,6 +135,14 @@ "boolean", "null" ] + }, + "use_proxy": { + "title": "use_proxy {#root-use_proxy}", + "description": "When disabled, mirrord will remove `HTTP[S]_PROXY` env variables before doing any network requests. This is useful when the system sets a proxy but you don't want mirrord to use it. This also applies to the mirrord process (as it just removes the env). If the remote pod sets this env, the mirrord process will still use it.", + "type": [ + "boolean", + "null" + ] } }, "additionalProperties": false, diff --git a/mirrord/cli/src/execution.rs b/mirrord/cli/src/execution.rs index cae086a39b3..02eff523e91 100644 --- a/mirrord/cli/src/execution.rs +++ b/mirrord/cli/src/execution.rs @@ -132,6 +132,15 @@ impl MirrordExecution { { let lib_path = extract_library(None, progress, true)?; + if !config.use_proxy { + for (key, _val) in std::env::vars() { + let lower_key = key.to_lowercase(); + if lower_key == "http_proxy" || lower_key == "https_proxy" { + std::env::remove_var(key) + } + } + } + let (connect_info, mut connection) = create_and_connect(config, progress, analytics) .await .inspect_err(|_| analytics.set_error(AnalyticsError::AgentConnection))?; diff --git a/mirrord/config/src/lib.rs b/mirrord/config/src/lib.rs index 8957a065e92..bd438627860 100644 --- a/mirrord/config/src/lib.rs +++ b/mirrord/config/src/lib.rs @@ -299,6 +299,16 @@ pub struct LayerConfig { /// # internal_proxy {#root-internal_proxy} #[config(nested)] pub internal_proxy: InternalProxyConfig, + + /// ## use_proxy {#root-use_proxy} + /// + /// When disabled, mirrord will remove `HTTP[S]_PROXY` env variables before + /// doing any network requests. This is useful when the system sets a proxy + /// but you don't want mirrord to use it. + /// This also applies to the mirrord process (as it just removes the env). + /// If the remote pod sets this env, the mirrord process will still use it. + #[config(env = "MIRRORD_PROXY", default = true)] + pub use_proxy: bool, } impl LayerConfig { @@ -744,6 +754,7 @@ mod tests { sip_binaries: None, kube_context: None, internal_proxy: None, + use_proxy: None, }; assert_eq!(config, expect);