]> git.proxmox.com Git - proxmox-backup.git/commitdiff
fix #3853: tape cli: add force flag to key change-passphrase
authorStefan Sterz <s.sterz@proxmox.com>
Thu, 10 Feb 2022 14:23:25 +0000 (15:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Feb 2022 08:52:20 +0000 (09:52 +0100)
Adds the '--force' flag to the proxmox-tape command allowing users
with root privileges to overwrite the passphrase of a given key.

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
src/bin/proxmox_tape/encryption_key.rs

index 156295fde09d2bda67680d94e6bd83f79348b7cf..71df9ffa003a6cc4c415909efb996d5a86c7fac6 100644 (file)
@@ -146,11 +146,18 @@ fn show_key(
             hint: {
                 schema: PASSWORD_HINT_SCHEMA,
             },
+            force: {
+                optional: true,
+                type: bool,
+                description: "Reset the passphrase for a tape key, without asking for the old one.",
+                default: false,
+            },
         },
     },
 )]
 /// Change the encryption key's password.
 fn change_passphrase(
+    force: bool,
     mut param: Value,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
@@ -159,11 +166,15 @@ fn change_passphrase(
         bail!("unable to change passphrase - no tty");
     }
 
-    let password = tty::read_password("Current Tape Encryption Key Password: ")?;
+    if force {
+        param["force"] = serde_json::Value::Bool(true);
+    } else {
+        let password = tty::read_password("Current Tape Encryption Key Password: ")?;
+        param["password"] = String::from_utf8(password)?.into();
+    }
 
     let new_password = tty::read_and_verify_password("New Tape Encryption Key Password: ")?;
 
-    param["password"] = String::from_utf8(password)?.into();
     param["new-password"] = String::from_utf8(new_password)?.into();
 
     let info = &api2::config::tape_encryption_keys::API_METHOD_CHANGE_PASSPHRASE;