From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 548831FF16F for ; Tue, 22 Jul 2025 18:35:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 96BF4E995; Tue, 22 Jul 2025 18:36:54 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Tue, 22 Jul 2025 18:36:03 +0200 Message-ID: <20250722163603.1520687-4-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250722163603.1520687-1-c.ebner@proxmox.com> References: <20250722163603.1520687-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753202171360 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.044 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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. [datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/2] datastore: check s3 bucket access before create datastore task 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" In order to give immediate feedback to the caller, so it is not required to re-enter all the datastore configuration if the bucket cannot be accessed. Signed-off-by: Christian Ebner --- src/api2/config/datastore.rs | 78 ++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 2702c7db3..f7b852cb7 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -137,31 +137,28 @@ pub(crate) fn do_create_datastore( match backend_config.ty.unwrap_or_default() { DatastoreBackendType::Filesystem => (), DatastoreBackendType::S3 => { - let s3_client_id = backend_config - .client - .as_ref() - .ok_or_else(|| format_err!("missing required client"))?; - let bucket = backend_config - .bucket - .clone() - .ok_or_else(|| format_err!("missing required bucket"))?; - let (config, _config_digest) = - pbs_config::s3::config().context("failed to get s3 config")?; - let config: S3ClientConf = config - .lookup(S3_CFG_TYPE_ID, s3_client_id) - .with_context(|| format!("no '{s3_client_id}' in config"))?; - let options = S3ClientOptions::from_config( - config.config, - config.secret_key, - bucket, - datastore.name.to_owned(), - ); - let s3_client = S3Client::new(options).context("failed to create s3 client")?; - // Fine to block since this runs in worker task - proxmox_async::runtime::block_on(s3_client.head_bucket()) - .context("failed to access bucket")?; - if !overwrite_in_use { + let s3_client_id = backend_config + .client + .as_ref() + .ok_or_else(|| format_err!("missing required client"))?; + let bucket = backend_config + .bucket + .clone() + .ok_or_else(|| format_err!("missing required bucket"))?; + let (config, _config_digest) = + pbs_config::s3::config().context("failed to get s3 config")?; + let config: S3ClientConf = config + .lookup(S3_CFG_TYPE_ID, s3_client_id) + .with_context(|| format!("no '{s3_client_id}' in config"))?; + let options = S3ClientOptions::from_config( + config.config, + config.secret_key, + bucket, + datastore.name.to_owned(), + ); + let s3_client = S3Client::new(options).context("failed to create s3 client")?; + let object_key = S3ObjectKey::try_from(S3_DATASTORE_IN_USE_MARKER) .context("failed to generate s3 object key")?; if let Some(response) = @@ -180,8 +177,8 @@ pub(crate) fn do_create_datastore( bail!("Bucket already contains datastore in use"); } } + backend_s3_client = Some(Arc::new(s3_client)); } - backend_s3_client = Some(Arc::new(s3_client)); } } } @@ -352,6 +349,37 @@ pub fn create_datastore( }; let store_name = config.name.to_string(); + + let backend_config: DatastoreBackendConfig = config.backend.as_deref().unwrap_or("").parse()?; + match backend_config.ty.unwrap_or_default() { + DatastoreBackendType::Filesystem => (), + DatastoreBackendType::S3 => { + let s3_client_id = backend_config + .client + .as_ref() + .ok_or_else(|| format_err!("missing required client"))?; + let bucket = backend_config + .bucket + .clone() + .ok_or_else(|| format_err!("missing required bucket"))?; + let (config, _config_digest) = + pbs_config::s3::config().context("failed to get s3 config")?; + let config: S3ClientConf = config + .lookup(S3_CFG_TYPE_ID, s3_client_id) + .with_context(|| format!("no '{s3_client_id}' in config"))?; + let options = S3ClientOptions::from_config( + config.config, + config.secret_key, + bucket, + store_name.clone(), + ); + let s3_client = S3Client::new(options).context("failed to create s3 client")?; + // Fine to block since this runs in worker task + proxmox_async::runtime::block_on(s3_client.head_bucket()) + .context("failed to access bucket")?; + } + } + WorkerTask::new_thread( "create-datastore", Some(store_name.clone()), -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel