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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 048946C04E for ; Fri, 19 Mar 2021 14:35:11 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EC7EF22F9C for ; Fri, 19 Mar 2021 14:35:10 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C0B4E22F91 for ; Fri, 19 Mar 2021 14:35:09 +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 5E0E646359 for ; Fri, 19 Mar 2021 14:35:09 +0100 (CET) From: Dylan Whyte To: pbs-devel@lists.proxmox.com Date: Fri, 19 Mar 2021 14:35:03 +0100 Message-Id: <20210319133503.5398-1-d.whyte@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [lib.rs, http.rs] Subject: [pbs-devel] [PATCH proxmox-backup] fix #3296: allow set subscription through proxy 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: Fri, 19 Mar 2021 13:35:11 -0000 when setting a subscription key, use http(s)_proxy as tunnel if evironment variable is set. Signed-off-by: Dylan Whyte --- * required packages can be found in nasi/iso/packages/hyper-proxy Note that proxy authorization/authentication is not implemented yet. hyper-proxy implements it using the 'headers' crate, which we do not have as a direct dependency. I figured i'd leave it for a follow up patch, just in case we decide not to use hyper-proxy afterall. Cargo.toml | 3 ++- src/tools/http.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9483831c..5a8bcc81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ path = "src/lib.rs" [dependencies] apt-pkg-native = "0.3.2" -base64 = "0.12" +base64 = "0.13" bitflags = "1.2.1" bytes = "1.0" crc32fast = "1" @@ -74,6 +74,7 @@ xdg = "2.2" zstd = { version = "0.4", features = [ "bindgen" ] } nom = "5.1" crossbeam-channel = "0.5" +hyper-proxy = { version = "0.9", default-features = false, features = ["openssl-tls"] } [features] default = [] diff --git a/src/tools/http.rs b/src/tools/http.rs index d08ce451..057f2abb 100644 --- a/src/tools/http.rs +++ b/src/tools/http.rs @@ -7,6 +7,7 @@ use std::pin::Pin; use hyper::{Uri, Body}; use hyper::client::{Client, HttpConnector}; +use hyper_proxy::{Proxy, ProxyConnector, Intercept}; use http::{Request, Response}; use openssl::ssl::{SslConnector, SslMethod}; use futures::*; @@ -77,10 +78,33 @@ pub async fn post( .header(hyper::header::CONTENT_TYPE, content_type) .body(body)?; + let mut http_proxy = "".to_string(); + if let Ok(proxy) = std::env::var("https_proxy") { + http_proxy = proxy; + } else if let Ok(proxy) = std::env::var("http_proxy") { + http_proxy = proxy; + } - HTTP_CLIENT.request(request) - .map_err(Error::from) - .await + if !http_proxy.is_empty() { + let proxy = format!("http://{}/", http_proxy); + let proxy = { + let proxy_uri = proxy.parse().unwrap(); + let proxy = Proxy::new(Intercept::All, proxy_uri); + let connector = HttpConnector::new(); + let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap(); + proxy_connector + }; + + let client = Client::builder().build(proxy); + + client.request(request) + .map_err(Error::from) + .await + } else { + HTTP_CLIENT.request(request) + .map_err(Error::from) + .await + } } #[derive(Clone)] -- 2.20.1