[pbs-devel] [PATCH proxmox-backup] fix #3867: server/api: send emails on certificate renewal failure

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Mar 22 15:37:39 CET 2022


On 08.03.22 13:02, Stefan Sterz wrote:
> the superuser's email will be used to notify them that certificate
> renewal has failed. also adds support for a notification setting to
> `node.cfg` and the api so that emails are sent either always, on
> error or never(similar to datastore notifications).
> 
> Signed-off-by: Stefan Sterz <s.sterz at proxmox.com>
> ---
> not sure if adding this setting to the gui is usefull and if so, where
> should we put it? if we put it next to the acme account setting, users
> might be confused as to which email will be used for notifications
> (acme vs. superuser's).

hmm, on a second thought I'd really prefer to start out as fixed, non-configurable,
on-error setting internally, we can always add the config option transparently later
on, if really requested.

To answer the original question: If we'd add it the gui entry would be useful, most
settings without gui are hidden for ~ over 90% of our users.

> @@ -536,11 +537,23 @@ fn spawn_certificate_worker(
>      let auth_id = rpcenv.get_auth_id().unwrap();
>  
>      WorkerTask::spawn(name, None, auth_id, true, move |worker| async move {
> -        if let Some(cert) = order_certificate(worker, &node_config).await? {
> -            crate::config::set_proxy_certificate(&cert.certificate, &cert.private_key_pem)?;
> -            crate::server::reload_proxy_certificate().await?;
> -        }
> -        Ok(())
> +        let work = || async {
> +            if let Some(cert) = order_certificate(worker, &node_config).await? {
> +                crate::config::set_proxy_certificate(&cert.certificate, &cert.private_key_pem)?;
> +                crate::server::reload_proxy_certificate().await?;
> +            }
> +
> +            Ok(())
> +        };
> +
> +        let res = work().await;
> +
> +        send_certificate_renewal_mail(
> +            node_config.renewal_notification.unwrap_or(Notify::Error),
> +            &res,
> +        )?;
> +
> +        res
>      })
>  }
>  

> diff --git a/src/config/node.rs b/src/config/node.rs
> index 0ba87450..87046ad4 100644
> --- a/src/config/node.rs
> +++ b/src/config/node.rs

> @@ -210,6 +216,10 @@ pub struct NodeConfig {
>      /// Default language used in the GUI
>      #[serde(skip_serializing_if = "Option::is_none")]
>      pub default_lang: Option<String>,
> +
> +    /// Whether to report certificate renewale on failure, always, never

typo: s/renewale/renewal/

> +    #[serde(skip_serializing_if = "Option::is_none")]
> +    pub renewal_notification: Option<Notify>,

IMO an ambiguous option name for the node.cfg, i.e., if I read this in the config 
I cannot know "what" gets renewed, so iff we'd have such a config it should probably
be named "acme_renewal_notify", but as written above, I'd avoid it for now and set
on-error

>  }
>  
>  impl NodeConfig {
> diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs
> index 4d734368..347bc25d 100644
> --- a/src/server/email_notifications.rs
> +++ b/src/server/email_notifications.rs

> +
> +const ACME_CERTIFICATE_ERR_RENEWAL: &str = r###"
> +
> +Proxmox Backup Server was not able to renew a TLS certificate.

maybe: s/a/its/ 

> +
> +Encountered an error: {{error}}

Just "Error: {{error}}"

or

"... renew its TLS certificate:

{{error}}


Please..."

but not too hard feelings on that one.

> +
> +Please visit the web interface for further details:
> +
> +<https://{{fqdn}}:{{port}}/#pbsCertificateConfiguration>
> +
> +"###;
> +
>  lazy_static::lazy_static!{
>  
>      static ref HANDLEBARS: Handlebars<'static> = {







More information about the pbs-devel mailing list