From: Shan Shaji <s.shaji@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-access-control] fix #6528: tfa: update user config on removal of TFA
Date: Tue, 29 Jul 2025 10:30:10 +0200 [thread overview]
Message-ID: <20250729083010.39570-1-s.shaji@proxmox.com> (raw)
When removing TFA from a user via the command line, the change was not
reflected in the GUI or in the output of `pveum user list`. Both
continued to show that TFA was enabled for the user. Fixed the issue
by updating the user configuration file.
Signed-off-by: Shan Shaji <s.shaji@proxmox.com>
---
Tested Cases:
- Case 1:
- Added one TFA for a user.
- Delete with CLI `pveum user tfa delete <user>`
- Verified if the UI and CLI outputs are updated.
- Case 2:
- Add two TFA for a user.
- Delete with CLI `pveum user tfa delete <user>`
- Verified if the UI and CLI outputs are updated.
- Case 3:
- Add two TFA for a user.
- Delete with CLI `pveum user tfa delete <user> --id <id>`
- Verified if the UI and CLI outputs are updated.
src/PVE/CLI/pveum.pm | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/PVE/CLI/pveum.pm b/src/PVE/CLI/pveum.pm
index 0645a6d..87e68df 100755
--- a/src/PVE/CLI/pveum.pm
+++ b/src/PVE/CLI/pveum.pm
@@ -141,16 +141,28 @@ __PACKAGE__->register_method({
my $userid = extract_param($param, "userid");
my $tfa_id = extract_param($param, "id");
+ my $update_user_config;
PVE::AccessControl::lock_tfa_config(sub {
my $tfa_cfg = cfs_read_file('priv/tfa.cfg');
if (defined($tfa_id)) {
- $tfa_cfg->api_delete_tfa($userid, $tfa_id);
+ my $has_entries_left = $tfa_cfg->api_delete_tfa($userid, $tfa_id);
+ $update_user_config = !$has_entries_left;
} else {
- $tfa_cfg->remove_user($userid);
+ my $needs_user_saving = $tfa_cfg->remove_user($userid);
+ $update_user_config = $needs_user_saving;
}
cfs_write_file('priv/tfa.cfg', $tfa_cfg);
});
+
+ if ($update_user_config) {
+ PVE::AccessControl::lock_user_config(sub {
+ my $user_cfg = cfs_read_file('user.cfg');
+ my $user = $user_cfg->{users}->{$userid};
+ $user->{keys} = undef;
+ cfs_write_file('user.cfg', $user_cfg);
+ });
+ }
return;
},
});
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next reply other threads:[~2025-07-29 8:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 8:30 Shan Shaji [this message]
2025-07-29 9:45 ` Fabian Grünbichler
2025-07-29 10:26 ` Shan Shaji
2025-07-29 10:40 ` Fabian Grünbichler
2025-07-29 11:06 ` Shan Shaji
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=20250729083010.39570-1-s.shaji@proxmox.com \
--to=s.shaji@proxmox.com \
--cc=pve-devel@lists.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