From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 056057DF65 for ; Tue, 9 Nov 2021 17:59:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D7985115AB for ; Tue, 9 Nov 2021 17:59:04 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 52ECA114E9 for ; Tue, 9 Nov 2021 17:59:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 066C0469CC for ; Tue, 9 Nov 2021 17:54:34 +0100 (CET) From: Stoiko Ivanov To: pbs-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 16:54:21 +0000 Message-Id: <20211109165422.311089-8-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109165422.311089-1-s.ivanov@proxmox.com> References: <20211109165422.311089-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.332 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [acme.rs, plugin.rs] Subject: [pbs-devel] [PATCH proxmox-backup 5/6] acme: plugin: add 'use-proxy' property X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 16:59:35 -0000 this patch adds an optional 'use-proxy' property to the dns challenge plugins. If set to true and the node has configured an http_proxy the proxy is set as 'http_proxy' and 'https_proxy' environment variable by the plugin caller (and then used by curl) Signed-off-by: Stoiko Ivanov --- src/acme/plugin.rs | 21 +++++++++++++++++++++ src/api2/config/acme.rs | 12 ++++++++++++ src/config/acme/plugin.rs | 8 ++++++++ 3 files changed, 41 insertions(+) diff --git a/src/acme/plugin.rs b/src/acme/plugin.rs index 65eb60d1..d31c2b8f 100644 --- a/src/acme/plugin.rs +++ b/src/acme/plugin.rs @@ -13,6 +13,7 @@ use proxmox_acme_rs::{Authorization, Challenge}; use crate::acme::AcmeClient; use crate::api2::types::AcmeDomain; +use crate::config::node; use proxmox_rest_server::WorkerTask; use crate::config::acme::plugin::{DnsPlugin, PluginData}; @@ -111,6 +112,26 @@ impl DnsPlugin { stdin_data.push(b'\n'); } + let proxy_config = match self.core.use_proxy { + Some(true) => { + if let Ok((node_config, _digest)) = node::config() { + node_config.http_proxy() + } else { + None + } + } + Some(false) => None, + None => None, + }; + + if let Some(proxy_config) = proxy_config { + if let Ok(proxystr) = proxy_config.to_proxy_string() { + stdin_data.extend( + format!("http_proxy={}\nhttps_proxy={}\n", proxystr, proxystr).as_bytes(), + ); + stdin_data.push(b'\n'); + } + } let mut command = Command::new("/usr/bin/setpriv"); #[rustfmt::skip] diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index a37a9358..c52edd57 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -473,6 +473,10 @@ pub struct PluginConfig { /// Flag to disable the config. #[serde(skip_serializing_if = "Option::is_none", default)] disable: Option, + + /// Flag indicating if this plugin should use the node-wide proxy setting. + #[serde(skip_serializing_if = "Option::is_none", default)] + use_proxy: Option, } // See PMG/PVE's $modify_cfg_for_api sub @@ -639,6 +643,8 @@ pub enum DeletableProperty { disable, /// Delete the validation-delay property validation_delay, + /// Delete the use-proxy property + use_proxy, } #[api( @@ -716,6 +722,9 @@ pub fn update_plugin( DeletableProperty::disable => { plugin.core.disable = None; } + DeletableProperty::use_proxy => { + plugin.core.use_proxy = None; + } } } } @@ -731,6 +740,9 @@ pub fn update_plugin( if update.disable.is_some() { plugin.core.disable = update.disable; } + if update.use_proxy.is_some() { + plugin.core.use_proxy = update.use_proxy; + } *entry = serde_json::to_value(plugin)?; } diff --git a/src/config/acme/plugin.rs b/src/config/acme/plugin.rs index 6ba5bcf7..8eade7c1 100644 --- a/src/config/acme/plugin.rs +++ b/src/config/acme/plugin.rs @@ -52,6 +52,10 @@ impl Default for StandalonePlugin { minimum: 0, maximum: 2 * 24 * 60 * 60, }, + "use-proxy": { + optional: true, + default: false, + }, }, )] /// DNS ACME Challenge Plugin core data. @@ -74,6 +78,10 @@ pub struct DnsPluginCore { /// Flag to disable the config. #[serde(skip_serializing_if = "Option::is_none", default)] pub disable: Option, + + /// Flag indicating if this plugin should use the node-wide proxy setting. + #[serde(skip_serializing_if = "Option::is_none", default)] + pub use_proxy: Option, } #[api( -- 2.30.2