summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXie Ning <xiening.xll@bytedance.com>2022-06-29 13:27:47 +0300
committerEd Tanous <ed@tanous.net>2023-02-28 03:30:15 +0300
commit9fa06f190a025693af3b7cc76c8b19163afe4d08 (patch)
tree145ccea4b3eaa2ba5c3db554f4ce1b2927344641
parent36ecbf3517ec0a742a9353531472c5ca77513903 (diff)
downloadbmcweb-9fa06f190a025693af3b7cc76c8b19163afe4d08.tar.xz
Remove sessions when user is deleted
An Internal server Error will happen if you delete the login user. Match the "InterfacesRemoved" signal for monitoring the user status and delete the session to fix this bug. Tested: 1. Add a new user such as test 2. Login with the new user in web 3. Delete or rename the user by web and ipmi command 4. Refresh the web and a new user was needed to login in the web Signed-off-by: Xie Ning <xiening.xll@bytedance.com> Change-Id: I2b53edb71d9a4e904c7da54393539f87eeb2d7a3
-rw-r--r--include/sessions.hpp12
-rw-r--r--include/user_monitor.hpp30
-rw-r--r--src/webserver_main.cpp3
3 files changed, 45 insertions, 0 deletions
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 9795719b31..62700bec56 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -7,6 +7,7 @@
#include <nlohmann/json.hpp>
+#include <algorithm>
#include <csignal>
#include <optional>
#include <random>
@@ -323,6 +324,17 @@ class SessionStore
return ret;
}
+ void removeSessionsByUsername(std::string_view username)
+ {
+ std::erase_if(authTokens, [username](const auto& value) {
+ if (value.second == nullptr)
+ {
+ return false;
+ }
+ return value.second->username == username;
+ });
+ }
+
void updateAuthMethodsConfig(const AuthConfigMethods& config)
{
bool isTLSchanged = (authMethodsConfig.tls != config.tls);
diff --git a/include/user_monitor.hpp b/include/user_monitor.hpp
new file mode 100644
index 0000000000..bd8ed24f31
--- /dev/null
+++ b/include/user_monitor.hpp
@@ -0,0 +1,30 @@
+#pragma once
+#include "dbus_singleton.hpp"
+#include "dbus_utility.hpp"
+#include "persistent_data.hpp"
+
+#include <sdbusplus/bus/match.hpp>
+#include <sdbusplus/message/types.hpp>
+
+namespace bmcweb
+{
+
+inline void onUserRemoved(sdbusplus::message::message& msg)
+{
+ sdbusplus::message::object_path p;
+ msg.read(p);
+ std::string username = p.filename();
+ persistent_data::SessionStore::getInstance().removeSessionsByUsername(
+ username);
+}
+
+inline void registerUserRemovedSignal()
+{
+ std::string userRemovedMatchStr =
+ sdbusplus::bus::match::rules::interfacesRemoved(
+ "/xyz/openbmc_project/user");
+
+ static sdbusplus::bus::match_t userRemovedMatch(
+ *crow::connections::systemBus, userRemovedMatchStr, onUserRemoved);
+}
+} // namespace bmcweb
diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp
index 1dbeb061ae..8e3a6f4ca9 100644
--- a/src/webserver_main.cpp
+++ b/src/webserver_main.cpp
@@ -16,6 +16,7 @@
#include "redfish_aggregator.hpp"
#include "security_headers.hpp"
#include "ssl_key_handler.hpp"
+#include "user_monitor.hpp"
#include "vm_websocket.hpp"
#include "webassets.hpp"
@@ -147,6 +148,8 @@ static int run()
crow::hostname_monitor::registerHostnameSignal();
#endif
+ bmcweb::registerUserRemovedSignal();
+
app.run();
io->run();