public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Shannon Sterz <s.sterz@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] applied: [PATCH proxmox-backup] auth: add locking to `PbsAuthenticator` to avoid race conditions
Date: Mon, 3 Jun 2024 11:02:21 +0200	[thread overview]
Message-ID: <zu6zhwremnbminpgaft7o2mlmmkyagmrc7gudh5bh6mj6sjr42@q5l6a76o6ym5> (raw)
In-Reply-To: <20240523112559.257547-1-s.sterz@proxmox.com>

applied, thanks

On Thu, May 23, 2024 at 01:25:59PM GMT, Shannon Sterz wrote:
> currently we don't lock the shadow file when removing or storing a
> password. by adding locking here we avoid a situation where storing
> and/or removing a password concurrently could lead to a race
> condition. in this scenario it is possible that a password isn't
> persisted or a password isn't removed. we already do this for
> the "token.shadow" file, so just use the same mechanism here.
> 
> Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
> ---
>  src/auth.rs | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/auth.rs b/src/auth.rs
> index 21468d4b..5134e41e 100644
> --- a/src/auth.rs
> +++ b/src/auth.rs
> @@ -9,6 +9,7 @@ use std::pin::Pin;
>  use anyhow::{bail, Error};
>  use futures::Future;
>  use once_cell::sync::{Lazy, OnceCell};
> +use pbs_config::open_backup_lockfile;
>  use proxmox_router::http_bail;
>  use serde_json::json;
>  
> @@ -31,6 +32,7 @@ pub const TERM_PREFIX: &str = "PBSTERM";
>  struct PbsAuthenticator;
>  
>  pub(crate) const SHADOW_CONFIG_FILENAME: &str = configdir!("/shadow.json");
> +pub(crate) const SHADOW_LOCK_FILENAME: &str = configdir!("/shadow.json.lock");
>  
>  impl Authenticator for PbsAuthenticator {
>      fn authenticate_user<'a>(
> @@ -69,6 +71,8 @@ impl Authenticator for PbsAuthenticator {
>          _client_ip: Option<&IpAddr>,
>      ) -> Result<(), Error> {
>          let enc_password = proxmox_sys::crypt::encrypt_pw(password)?;
> +
> +        let _guard = open_backup_lockfile(SHADOW_LOCK_FILENAME, None, true);
>          let mut data = proxmox_sys::fs::file_get_json(SHADOW_CONFIG_FILENAME, Some(json!({})))?;
>          data[username.as_str()] = enc_password.into();
>  
> @@ -85,6 +89,8 @@ impl Authenticator for PbsAuthenticator {
>      }
>  
>      fn remove_password(&self, username: &UsernameRef) -> Result<(), Error> {
> +        let _guard = open_backup_lockfile(SHADOW_LOCK_FILENAME, None, true);
> +
>          let mut data = proxmox_sys::fs::file_get_json(SHADOW_CONFIG_FILENAME, Some(json!({})))?;
>          if let Some(map) = data.as_object_mut() {
>              map.remove(username.as_str());
> -- 
> 2.39.2


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


      parent reply	other threads:[~2024-06-03  9:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 11:25 [pbs-devel] " Shannon Sterz
2024-05-23 11:46 ` Gabriel Goller
2024-05-23 12:06   ` Shannon Sterz
2024-06-03  9:00   ` Wolfgang Bumiller
2024-06-03  9:12     ` Gabriel Goller
2024-06-03  9:02 ` Wolfgang Bumiller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=zu6zhwremnbminpgaft7o2mlmmkyagmrc7gudh5bh6mj6sjr42@q5l6a76o6ym5 \
    --to=w.bumiller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=s.sterz@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal