From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 8E7DD1FF0B7 for ; Fri, 13 Nov 2026 16:09:45 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2A32921751; Fri, 13 Nov 2026 16:08:58 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 04/55] notify: use ConfigDigest instead of raw byte arrays Date: Fri, 13 Nov 2026 16:07:37 +0100 Message-ID: <20261113150828.756836-5-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113150828.756836-1-l.wagner@proxmox.com> References: <20261113150828.756836-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794582523435 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.214 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: ZDVN6C7GBLKZDWSSYC3YA6ZXWD67IJ4D X-Message-ID-Hash: ZDVN6C7GBLKZDWSSYC3YA6ZXWD67IJ4D X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The proxmox-config-digest crate did not exist when proxmox-notify was written, hence it used raw byte slices for checking the digest. This is a breaking change; users of proxmox-notify need to be adapted. Signed-off-by: Lukas Wagner --- proxmox-notify/Cargo.toml | 2 +- proxmox-notify/src/api/gotify.rs | 9 ++++--- proxmox-notify/src/api/matcher.rs | 43 +++++++++++++++++------------- proxmox-notify/src/api/mod.rs | 17 ++++++------ proxmox-notify/src/api/sendmail.rs | 9 ++++--- proxmox-notify/src/api/smtp.rs | 9 ++++--- proxmox-notify/src/api/webhook.rs | 9 ++++--- proxmox-notify/src/config.rs | 9 ++++--- proxmox-notify/src/lib.rs | 5 ++-- 9 files changed, 63 insertions(+), 49 deletions(-) diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index 6796c2915..8968a14f8 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -19,7 +19,6 @@ http = { workspace = true, optional = true } lettre = { workspace = true, optional = true } tracing.workspace = true mail-parser = { workspace = true, optional = true } -openssl.workspace = true percent-encoding = { workspace = true, optional = true } regex.workspace = true serde = { workspace = true, features = ["derive"] } @@ -29,6 +28,7 @@ thiserror.workspace = true proxmox-api-macro.workspace = true proxmox-base64 = { workspace = true, optional = true } +proxmox-config-digest = { workspace = true, features = ["openssl"] } proxmox-http = { workspace = true, features = ["client-sync"], optional = true } proxmox-http-error.workspace = true proxmox-human-byte.workspace = true diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs index 5155fd2c8..c3149c152 100644 --- a/proxmox-notify/src/api/gotify.rs +++ b/proxmox-notify/src/api/gotify.rs @@ -1,3 +1,4 @@ +use proxmox_config_digest::ConfigDigest; use proxmox_http_error::HttpError; use crate::Config; @@ -78,7 +79,7 @@ pub fn update_endpoint( endpoint_config_updater: GotifyConfigUpdater, private_endpoint_config_updater: GotifyPrivateConfigUpdater, delete: Option<&[DeleteableGotifyProperty]>, - digest: Option<&[u8]>, + digest: Option, ) -> Result<(), HttpError> { super::verify_digest(config, digest)?; @@ -220,7 +221,7 @@ mod tests { Default::default(), Default::default(), None, - Some(&[0; 32]) + Some(ConfigDigest::from([0; 32])) ) .is_err() ); @@ -233,7 +234,7 @@ mod tests { let mut config = empty_config(); add_default_gotify_endpoint(&mut config)?; - let digest = config.digest; + let digest = config.digest.clone(); update_endpoint( &mut config, @@ -247,7 +248,7 @@ mod tests { token: Some("changedtoken".into()), }, None, - Some(&digest), + Some(digest), )?; let endpoint = get_endpoint(&config, "gotify-endpoint")?; diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs index 84131be3c..3302c2c31 100644 --- a/proxmox-notify/src/api/matcher.rs +++ b/proxmox-notify/src/api/matcher.rs @@ -1,3 +1,4 @@ +use proxmox_config_digest::ConfigDigest; use proxmox_http_error::HttpError; use crate::Config; @@ -105,7 +106,7 @@ pub fn update_matcher( name: &str, matcher_updater: MatcherConfigUpdater, delete: Option<&[DeleteableMatcherProperty]>, - digest: Option<&[u8]>, + digest: Option, ) -> Result<(), HttpError> { super::verify_digest(config, digest)?; @@ -251,7 +252,7 @@ matcher: matcher2 "matcher1", Default::default(), None, - Some(&[0u8; 32]) + Some(ConfigDigest::from([0u8; 32])) ) .is_err() ); @@ -266,7 +267,7 @@ matcher: matcher2 let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); update_matcher( &mut config, @@ -282,7 +283,7 @@ matcher: matcher2 ..Default::default() }, None, - Some(&digest), + Some(digest.clone()), )?; let matcher = get_matcher(&config, "matcher1")?; @@ -303,7 +304,7 @@ matcher: matcher2 DeleteableMatcherProperty::Target, DeleteableMatcherProperty::Comment, ]), - Some(&digest), + Some(digest), )?; let matcher = get_matcher(&config, "matcher1")?; @@ -323,7 +324,7 @@ matcher: matcher2 fn test_matcher_update() -> Result<(), HttpError> { let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); update_matcher( &mut config, @@ -335,7 +336,7 @@ matcher: matcher2 ..Default::default() }, None, - Some(&digest), + Some(digest.clone()), )?; let matcher = get_matcher(&config, "matcher1")?; @@ -352,7 +353,7 @@ matcher: matcher2 DeleteableMatcherProperty::Comment, DeleteableMatcherProperty::Expression, ]), - Some(&digest), + Some(digest), )?; let matcher = get_matcher(&config, "matcher1")?; @@ -378,7 +379,7 @@ matcher: matcher2 #[cfg(feature = "legacy-matchers")] fn test_update_matcher_mutually_exclusive_with_expression() -> Result<(), HttpError> { let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); let proto = MatcherConfigUpdater { expression: Some(valid_expression_string()), @@ -388,17 +389,23 @@ matcher: matcher2 let mut updater = proto.clone(); updater.match_field = Some(vec!["exact:foo=bar".parse().unwrap()]); - assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err()); + assert!( + update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err() + ); let mut updater = proto.clone(); updater.match_calendar = Some(vec!["mon..sun 12-13".parse().unwrap()]); - assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err()); + assert!( + update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err() + ); let mut updater = proto.clone(); updater.match_severity = Some(vec!["info,warning".parse().unwrap()]); - assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err()); + assert!( + update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err() + ); Ok(()) } @@ -406,7 +413,7 @@ matcher: matcher2 #[test] fn test_update_invalid_expression() -> Result<(), HttpError> { let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); assert!( update_matcher( @@ -417,7 +424,7 @@ matcher: matcher2 ..Default::default() }, None, - Some(&digest), + Some(digest), ) .is_err() ); @@ -437,7 +444,7 @@ matcher: matcher2 #[test] fn test_update_minifies_pretty_printed_expression() -> Result<(), HttpError> { let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); let expr = nested_expression(); let pretty = serde_json::to_string_pretty(&expr).unwrap(); @@ -451,7 +458,7 @@ matcher: matcher2 ..Default::default() }, None, - Some(&digest), + Some(digest), )?; let matcher = get_matcher(&config, "matcher1")?; @@ -466,7 +473,7 @@ matcher: matcher2 #[test] fn test_update_normalizes_expression_with_extra_whitespace() -> Result<(), HttpError> { let mut config = config_with_two_matchers(); - let digest = config.digest; + let digest = config.digest.clone(); // Same expression as `nested_expression`, but handwritten, with all sorts of // odd whitespace characters. @@ -481,7 +488,7 @@ matcher: matcher2 ..Default::default() }, None, - Some(&digest), + Some(digest), )?; let matcher = get_matcher(&config, "matcher1")?; diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs index 7f823bc7c..bd73eac65 100644 --- a/proxmox-notify/src/api/mod.rs +++ b/proxmox-notify/src/api/mod.rs @@ -1,5 +1,6 @@ use std::collections::HashSet; +use proxmox_config_digest::ConfigDigest; use serde::{Deserialize, Serialize}; use proxmox_http_error::HttpError; @@ -132,14 +133,14 @@ pub fn get_targets(config: &Config) -> Result, HttpError> { Ok(targets) } -fn verify_digest(config: &Config, digest: Option<&[u8]>) -> Result<(), HttpError> { - if let Some(digest) = digest { - if config.digest != *digest { - http_bail!( - BAD_REQUEST, - "detected modified configuration - file changed by other user? Try again." - ); - } +fn verify_digest(config: &Config, digest: Option) -> Result<(), HttpError> { + if let Some(digest) = digest + && config.digest != digest + { + http_bail!( + BAD_REQUEST, + "detected modified configuration - file changed by other user? Try again." + ); } Ok(()) diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs index eaafd0012..2d54608cd 100644 --- a/proxmox-notify/src/api/sendmail.rs +++ b/proxmox-notify/src/api/sendmail.rs @@ -1,3 +1,4 @@ +use proxmox_config_digest::ConfigDigest; use proxmox_http_error::HttpError; use crate::Config; @@ -71,7 +72,7 @@ pub fn update_endpoint( name: &str, updater: SendmailConfigUpdater, delete: Option<&[DeleteableSendmailProperty]>, - digest: Option<&[u8]>, + digest: Option, ) -> Result<(), HttpError> { super::verify_digest(config, digest)?; @@ -216,7 +217,7 @@ pub mod tests { ..Default::default() }, None, - Some(&[0; 32]), + Some(ConfigDigest::from([0; 32])), ) .is_err() ); @@ -229,7 +230,7 @@ pub mod tests { let mut config = empty_config(); add_sendmail_endpoint_for_test(&mut config, "sendmail-endpoint")?; - let digest = config.digest; + let digest = config.digest.clone(); update_endpoint( &mut config, @@ -243,7 +244,7 @@ pub mod tests { ..Default::default() }, None, - Some(&digest), + Some(digest), )?; let endpoint = get_endpoint(&config, "sendmail-endpoint")?; diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs index 41a94581b..456cbc31e 100644 --- a/proxmox-notify/src/api/smtp.rs +++ b/proxmox-notify/src/api/smtp.rs @@ -1,3 +1,4 @@ +use proxmox_config_digest::ConfigDigest; use proxmox_http_error::HttpError; use crate::Config; @@ -89,7 +90,7 @@ pub fn update_endpoint( updater: SmtpConfigUpdater, private_endpoint_config_updater: SmtpPrivateConfigUpdater, delete: Option<&[DeleteableSmtpProperty]>, - digest: Option<&[u8]>, + digest: Option, ) -> Result<(), HttpError> { super::verify_digest(config, digest)?; @@ -276,7 +277,7 @@ pub mod tests { Default::default(), Default::default(), None, - Some(&[0; 32]), + Some(ConfigDigest::from([0; 32])), ) .is_err() ); @@ -289,7 +290,7 @@ pub mod tests { let mut config = empty_config(); add_smtp_endpoint_for_test(&mut config, "smtp-endpoint")?; - let digest = config.digest; + let digest = config.digest.clone(); update_endpoint( &mut config, @@ -308,7 +309,7 @@ pub mod tests { }, Default::default(), None, - Some(&digest), + Some(digest), )?; let endpoint = get_endpoint(&config, "smtp-endpoint")?; diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs index 1d29dcc89..e79eeb7e9 100644 --- a/proxmox-notify/src/api/webhook.rs +++ b/proxmox-notify/src/api/webhook.rs @@ -2,6 +2,7 @@ //! //! All methods assume that the caller has already done any required permission checks. +use proxmox_config_digest::ConfigDigest; use proxmox_http_error::HttpError; use proxmox_schema::property_string::PropertyString; @@ -136,7 +137,7 @@ pub fn update_endpoint( name: &str, config_updater: WebhookConfigUpdater, delete: Option<&[DeleteableWebhookProperty]>, - digest: Option<&[u8]>, + digest: Option, ) -> Result<(), HttpError> { super::verify_digest(config, digest)?; @@ -337,7 +338,7 @@ mod tests { "webhook-endpoint", Default::default(), None, - Some(&[0; 32]) + Some(ConfigDigest::from([0; 32])) ) .is_err() ); @@ -350,7 +351,7 @@ mod tests { let mut config = empty_config(); add_default_webhook_endpoint(&mut config)?; - let digest = config.digest; + let digest = config.digest.clone(); update_endpoint( &mut config, @@ -371,7 +372,7 @@ mod tests { ..Default::default() }, None, - Some(&digest), + Some(digest), )?; let endpoint = get_endpoint(&config, "webhook-endpoint")?; diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs index c280e8285..176bc46b7 100644 --- a/proxmox-notify/src/config.rs +++ b/proxmox-notify/src/config.rs @@ -1,5 +1,6 @@ use std::sync::OnceLock; +use proxmox_config_digest::ConfigDigest; use proxmox_schema::{ApiType, ObjectSchema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; @@ -120,8 +121,8 @@ fn private_config_init() -> SectionConfig { config } -pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> { - let digest = openssl::sha::sha256(raw_config.as_bytes()); +pub fn config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> { + let digest = ConfigDigest::from_slice(raw_config.as_bytes()); let data = config_parser() .parse("notifications.cfg", raw_config) .map_err(Error::config_deserialization)?; @@ -129,8 +130,8 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> Ok((data, digest)) } -pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> { - let digest = openssl::sha::sha256(raw_config.as_bytes()); +pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> { + let digest = ConfigDigest::from_slice(raw_config.as_bytes()); let data = private_config_parser() .parse("priv/notifications.cfg", raw_config) .map_err(Error::config_deserialization)?; diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs index 846e8315e..0a851239d 100644 --- a/proxmox-notify/src/lib.rs +++ b/proxmox-notify/src/lib.rs @@ -11,6 +11,7 @@ use serde_json::Value; use serde_json::json; use tracing::{error, info}; +use proxmox_config_digest::ConfigDigest; use proxmox_schema::api; use proxmox_section_config::SectionConfigData; use proxmox_uuid::Uuid; @@ -204,7 +205,7 @@ impl Notification { pub struct Config { config: SectionConfigData, private_config: SectionConfigData, - digest: [u8; 32], + digest: ConfigDigest, } impl Config { @@ -292,7 +293,7 @@ impl Config { /// Returns the SHA256 digest of the configuration. /// The digest is only computed once when the configuration deserialized. - pub fn digest(&self) -> &[u8; 32] { + pub fn digest(&self) -> &ConfigDigest { &self.digest } } -- 2.47.3