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 B9F54673DF for ; Mon, 9 Nov 2020 16:02:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B17291853A for ; Mon, 9 Nov 2020 16:01:36 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0575418532 for ; Mon, 9 Nov 2020 16:01:36 +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 C307246046 for ; Mon, 9 Nov 2020 16:01:35 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 9 Nov 2020 16:01:21 +0100 Message-Id: <20201109150130.4956-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201109150130.4956-1-d.csapak@proxmox.com> References: <20201109150130.4956-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.385 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 Subject: [pbs-devel] [PATCH proxmox-backup 01/10] api2/node/tasks: add check_job_store and use it 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: Mon, 09 Nov 2020 15:02:06 -0000 to easily check the store of a worker_id this fixes the issue that one could not filter by type 'syncjob' and datastore simultaneously Signed-off-by: Dominik Csapak --- src/api2/node/tasks.rs | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index 4e023fbf..3f06ec70 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -71,6 +71,36 @@ fn check_job_privs(auth_id: &Authid, user_info: &CachedUserInfo, upid: &UPID) -> bail!("not a scheduled job task"); } +// get the store out of the worker_id +fn check_job_store(upid: &UPID, store: &str) -> bool { + match (upid.worker_type.as_str(), &upid.worker_id) { + (workertype, Some(workerid)) if workertype.starts_with("verif") => { + if let Some(captures) = VERIFICATION_JOB_WORKER_ID_REGEX.captures(&workerid) { + if let Some(jobstore) = captures.get(1) { + return store == jobstore.as_str(); + } + } else { + return workerid == store; + } + } + ("syncjob", Some(workerid)) => { + if let Some(captures) = SYNC_JOB_WORKER_ID_REGEX.captures(&workerid) { + if let Some(local_store) = captures.get(3) { + return store == local_store.as_str(); + } + } + } + ("prune", Some(workerid)) + | ("backup", Some(workerid)) + | ("garbage_collection", Some(workerid)) => { + return workerid == store || workerid.starts_with(&format!("{}:", store)); + } + _ => {} + }; + + false +} + fn check_task_access(auth_id: &Authid, upid: &UPID) -> Result<(), Error> { let task_auth_id = &upid.auth_id; if auth_id == task_auth_id @@ -455,21 +485,8 @@ pub fn list_tasks( } if let Some(store) = store { - // Note: useful to select all tasks spawned by proxmox-backup-client - let worker_id = match &info.upid.worker_id { - Some(w) => w, - None => return None, // skip - }; - - if info.upid.worker_type == "backup" || info.upid.worker_type == "restore" || - info.upid.worker_type == "prune" - { - let prefix = format!("{}:", store); - if !worker_id.starts_with(&prefix) { return None; } - } else if info.upid.worker_type == "garbage_collection" { - if worker_id != store { return None; } - } else { - return None; // skip + if !check_job_store(&info.upid, store) { + return None; } } -- 2.20.1