Handle Redfish PasswordChangeRequired
This enhances BMCWeb authentication to recognize when the user's password is
correct but expired. The Redfish SessionService is enhanced to comply with
the Redfish PasswordChangeRequired spec which allows the session to be
created, but limits that sesion to changing the password only, and includes
the PasswordChangeRequired message in the response body.
Specifically, when the account's password is expired, a successful
authentication via the following interfaces will have these results:
- POST /redfish/v1/SessionService/Sessions -- follows Redfish spec
- POST /login -- creates a session limited to changing the password,
similar to Redfish
- Basic authentication -- continues to treat the password
change required condition as an authentication failure and gives no
indication the password is expired.
- Cookie auth -- works as before
- Token auth -- works as before
This patchset is intended to allow web applications to use the presence
of the Redfish PasswordChangeRequired message or the extendedMessage
field to trigger the password change dialog.
This does not implement the PasswordChangeRequired property in the
ManagerAccount resource.
This implements the Redfish privilege overrides associated with the
ConfigureSelf privilege. Specifically, this correctly implements the
Password property override, and the ManagerAccount Resource URI override.
When an API results in 403 Forbidden and the issuing session has the
PasswordChangeRequired condition, appropriate JSON is given.
Tested:
Yes, see https://github.com/openbmc/bmcweb/issues/103
No, did not run Redfish validator
Signed-off-by: Joseph Reynolds <joseph-reynolds@charter.net>
Change-Id: Ibbf5f6414ac55c0e7bea14c721f6db227b52fe40
diff --git a/include/json_msg_utility.hpp b/include/json_msg_utility.hpp
new file mode 100644
index 0000000..e8c8b7f
--- /dev/null
+++ b/include/json_msg_utility.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "crow/http_response.h"
+
+namespace crow
+{
+namespace msg
+{
+const std::string notFoundMsg = "404 Not Found";
+const std::string badReqMsg = "400 Bad Request";
+const std::string methodNotAllowedMsg = "405 Method Not Allowed";
+const std::string forbiddenMsg = "403 Forbidden";
+const std::string methodFailedMsg = "500 Method Call Failed";
+const std::string methodOutputFailedMsg = "500 Method Output Error";
+const std::string unAuthMsg = "401 Unauthorized"; // Unauthenticated
+
+const std::string notFoundDesc =
+ "org.freedesktop.DBus.Error.FileNotFound: path or object not found";
+const std::string propNotFoundDesc = "The specified property cannot be found";
+const std::string noJsonDesc = "No JSON object could be decoded";
+const std::string methodNotFoundDesc = "The specified method cannot be found";
+const std::string methodNotAllowedDesc = "Method not allowed";
+const std::string forbiddenPropDesc =
+ "The specified property cannot be created";
+const std::string forbiddenResDesc = "The specified resource cannot be created";
+const std::string unAuthDesc = "The authentication could not be applied";
+const std::string forbiddenURIDesc = "The session is not authorized to access URI: ";
+
+} // namespace msg
+
+inline void setErrorResponse(crow::Response &res,
+ boost::beast::http::status result,
+ const std::string &desc, const std::string &msg)
+{
+ res.result(result);
+ res.jsonValue = {{"data", {{"description", desc}}},
+ {"message", msg},
+ {"status", "error"}};
+}
+
+inline void setPasswordChangeRequired(crow::Response &res,
+ const std::string &username)
+{
+ res.jsonValue["extendedMessage"] =
+ "The password for this account must be changed. PATCH the 'Password' "
+ "property for the account under URI: "
+ "/redfish/v1/AccountService/Accounts/" +
+ username;
+}
+
+} // namespace crow
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 7839e65..b063fa6 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -23,6 +23,7 @@
#include <dbus_utility.hpp>
#include <filesystem>
#include <fstream>
+#include <json_msg_utility.hpp>
#include <regex>
#include <sdbusplus/message/types.hpp>
@@ -30,37 +31,10 @@
{
namespace openbmc_mapper
{
-
using GetSubTreeType = std::vector<
std::pair<std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
-const std::string notFoundMsg = "404 Not Found";
-const std::string badReqMsg = "400 Bad Request";
-const std::string methodNotAllowedMsg = "405 Method Not Allowed";
-const std::string forbiddenMsg = "403 Forbidden";
-const std::string methodFailedMsg = "500 Method Call Failed";
-const std::string methodOutputFailedMsg = "500 Method Output Error";
-
-const std::string notFoundDesc =
- "org.freedesktop.DBus.Error.FileNotFound: path or object not found";
-const std::string propNotFoundDesc = "The specified property cannot be found";
-const std::string noJsonDesc = "No JSON object could be decoded";
-const std::string methodNotFoundDesc = "The specified method cannot be found";
-const std::string methodNotAllowedDesc = "Method not allowed";
-const std::string forbiddenPropDesc =
- "The specified property cannot be created";
-const std::string forbiddenResDesc = "The specified resource cannot be created";
-
-void setErrorResponse(crow::Response &res, boost::beast::http::status result,
- const std::string &desc, const std::string &msg)
-{
- res.result(result);
- res.jsonValue = {{"data", {{"description", desc}}},
- {"message", msg},
- {"status", "error"}};
-}
-
void introspectObjects(const std::string &processName,
const std::string &objectPath,
std::shared_ptr<bmcweb::AsyncResp> transaction)
@@ -418,17 +392,19 @@
{
if (!methodFailed)
{
- setErrorResponse(res, boost::beast::http::status::not_found,
- methodNotFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::not_found,
+ crow::msg::methodNotFoundDesc, crow::msg::notFoundMsg);
}
}
else
{
if (outputFailed)
{
- setErrorResponse(
+ crow::setErrorResponse(
res, boost::beast::http::status::internal_server_error,
- "Method output failure", methodOutputFailedMsg);
+ "Method output failure",
+ crow::msg::methodOutputFailedMsg);
}
else
{
@@ -444,8 +420,8 @@
void setErrorStatus(const std::string &desc)
{
- setErrorResponse(res, boost::beast::http::status::bad_request, desc,
- badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ desc, crow::msg::badReqMsg);
}
crow::Response &res;
std::string path;
@@ -1442,7 +1418,7 @@
if (e)
{
- setErrorResponse(
+ crow::setErrorResponse(
transaction->res,
boost::beast::http::status::
bad_request,
@@ -1450,12 +1426,12 @@
}
else
{
- setErrorResponse(
+ crow::setErrorResponse(
transaction->res,
boost::beast::http::status::
bad_request,
"Method call failed",
- methodFailedMsg);
+ crow::msg::methodFailedMsg);
}
return;
}
@@ -1489,24 +1465,24 @@
if (requestDbusData.is_discarded())
{
- setErrorResponse(res, boost::beast::http::status::bad_request,
- noJsonDesc, badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ crow::msg::noJsonDesc, crow::msg::badReqMsg);
res.end();
return;
}
nlohmann::json::iterator data = requestDbusData.find("data");
if (data == requestDbusData.end())
{
- setErrorResponse(res, boost::beast::http::status::bad_request,
- noJsonDesc, badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ crow::msg::noJsonDesc, crow::msg::badReqMsg);
res.end();
return;
}
if (!data->is_array())
{
- setErrorResponse(res, boost::beast::http::status::bad_request,
- noJsonDesc, badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ crow::msg::noJsonDesc, crow::msg::badReqMsg);
res.end();
return;
}
@@ -1523,9 +1499,9 @@
if (ec || interfaceNames.size() <= 0)
{
BMCWEB_LOG_ERROR << "Can't find object";
- setErrorResponse(transaction->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ transaction->res, boost::beast::http::status::not_found,
+ crow::msg::notFoundDesc, crow::msg::notFoundMsg);
return;
}
@@ -1557,9 +1533,10 @@
if (ec || interfaceNames.size() <= 0)
{
BMCWEB_LOG_ERROR << "Can't find object";
- setErrorResponse(res,
- boost::beast::http::status::method_not_allowed,
- methodNotAllowedDesc, methodNotAllowedMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::method_not_allowed,
+ crow::msg::methodNotAllowedDesc,
+ crow::msg::methodNotAllowedMsg);
res.end();
return;
}
@@ -1589,8 +1566,9 @@
std::vector<std::string> &objectPaths) {
if (ec)
{
- setErrorResponse(res, boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::not_found,
+ crow::msg::notFoundDesc, crow::msg::notFoundMsg);
}
else
{
@@ -1628,9 +1606,10 @@
{
BMCWEB_LOG_ERROR << "GetSubTree failed on "
<< transaction->objectPath;
- setErrorResponse(transaction->asyncResp->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
+ crow::setErrorResponse(transaction->asyncResp->res,
+ boost::beast::http::status::not_found,
+ crow::msg::notFoundDesc,
+ crow::msg::notFoundMsg);
return;
}
@@ -1661,8 +1640,9 @@
const GetObjectType &object_names) {
if (ec || object_names.size() <= 0)
{
- setErrorResponse(res, boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::not_found,
+ crow::msg::notFoundDesc, crow::msg::notFoundMsg);
res.end();
return;
}
@@ -1678,8 +1658,9 @@
if (interfaceNames.size() <= 0)
{
- setErrorResponse(res, boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::not_found,
+ crow::msg::notFoundDesc, crow::msg::notFoundMsg);
res.end();
return;
}
@@ -1734,10 +1715,11 @@
{
if (!propertyName->empty() && response->empty())
{
- setErrorResponse(
+ crow::setErrorResponse(
res,
boost::beast::http::status::not_found,
- propNotFoundDesc, notFoundMsg);
+ crow::msg::propNotFoundDesc,
+ crow::msg::notFoundMsg);
}
else
{
@@ -1766,8 +1748,9 @@
{
if (res.jsonValue.empty())
{
- setErrorResponse(res, boost::beast::http::status::forbidden,
- forbiddenMsg, forbiddenPropDesc);
+ crow::setErrorResponse(res, boost::beast::http::status::forbidden,
+ crow::msg::forbiddenMsg,
+ crow::msg::forbiddenPropDesc);
}
res.end();
@@ -1775,8 +1758,9 @@
void setErrorStatus(const std::string &desc)
{
- setErrorResponse(res, boost::beast::http::status::internal_server_error,
- desc, badReqMsg);
+ crow::setErrorResponse(
+ res, boost::beast::http::status::internal_server_error, desc,
+ crow::msg::badReqMsg);
}
crow::Response &res;
@@ -1790,8 +1774,9 @@
{
if (destProperty.empty())
{
- setErrorResponse(res, boost::beast::http::status::forbidden,
- forbiddenResDesc, forbiddenMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::forbidden,
+ crow::msg::forbiddenResDesc,
+ crow::msg::forbiddenMsg);
res.end();
return;
}
@@ -1801,8 +1786,8 @@
if (requestDbusData.is_discarded())
{
- setErrorResponse(res, boost::beast::http::status::bad_request,
- noJsonDesc, badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ crow::msg::noJsonDesc, crow::msg::badReqMsg);
res.end();
return;
}
@@ -1810,8 +1795,8 @@
nlohmann::json::const_iterator propertyIt = requestDbusData.find("data");
if (propertyIt == requestDbusData.end())
{
- setErrorResponse(res, boost::beast::http::status::bad_request,
- noJsonDesc, badReqMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::bad_request,
+ crow::msg::noJsonDesc, crow::msg::badReqMsg);
res.end();
return;
}
@@ -1829,9 +1814,9 @@
const GetObjectType &object_names) {
if (!ec && object_names.size() <= 0)
{
- setErrorResponse(transaction->res,
- boost::beast::http::status::not_found,
- propNotFoundDesc, notFoundMsg);
+ crow::setErrorResponse(
+ transaction->res, boost::beast::http::status::not_found,
+ crow::msg::propNotFoundDesc, crow::msg::notFoundMsg);
return;
}
@@ -1947,7 +1932,7 @@
{
const sd_bus_error *e =
m.get_error();
- setErrorResponse(
+ crow::setErrorResponse(
transaction->res,
boost::beast::http::
status::
@@ -2057,8 +2042,9 @@
return;
}
- setErrorResponse(res, boost::beast::http::status::method_not_allowed,
- methodNotAllowedDesc, methodNotAllowedMsg);
+ crow::setErrorResponse(res, boost::beast::http::status::method_not_allowed,
+ crow::msg::methodNotAllowedDesc,
+ crow::msg::methodNotAllowedMsg);
res.end();
}
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index f211a29..68ce64a 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -48,10 +48,12 @@
}
inline bool pamAuthenticateUser(const std::string_view username,
- const std::string_view password)
+ const std::string_view password,
+ bool& passwordChangeRequired)
{
std::string userStr(username);
std::string passStr(password);
+ passwordChangeRequired = false;
const struct pam_conv localConversation = {
pamFunctionConversation, const_cast<char*>(passStr.c_str())};
pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
@@ -70,12 +72,18 @@
return false;
}
- /* check that the account is healthy */
- if (pam_acct_mgmt(localAuthHandle, PAM_DISALLOW_NULL_AUTHTOK) !=
- PAM_SUCCESS)
+ /* check if the account is healthy */
+ switch (pam_acct_mgmt(localAuthHandle, PAM_DISALLOW_NULL_AUTHTOK))
{
- pam_end(localAuthHandle, PAM_SUCCESS);
- return false;
+ case PAM_SUCCESS:
+ break;
+ case PAM_NEW_AUTHTOK_REQD:
+ passwordChangeRequired = true;
+ break;
+ default:
+ pam_end(localAuthHandle, PAM_SUCCESS);
+ return false;
+ break;
}
if (pam_end(localAuthHandle, PAM_SUCCESS) != PAM_SUCCESS)
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 2900cd5..ebf6360 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -276,6 +276,7 @@
std::string csrfToken;
std::chrono::time_point<std::chrono::steady_clock> lastUpdated;
PersistenceType persistence;
+ bool isConfigureSelfOnly;
/**
* @brief Fills object with data from UserSession's JSON representation
@@ -334,6 +335,7 @@
// this is done temporarily
userSession->lastUpdated = std::chrono::steady_clock::now();
userSession->persistence = PersistenceType::TIMEOUT;
+ userSession->isConfigureSelfOnly = false;
return userSession;
}
@@ -345,7 +347,7 @@
{
public:
std::shared_ptr<UserSession> generateUserSession(
- const std::string_view username,
+ const std::string_view username, bool configureSelfOnly,
PersistenceType persistence = PersistenceType::TIMEOUT)
{
// TODO(ed) find a secure way to not generate session identifiers if
@@ -385,6 +387,7 @@
auto session = std::make_shared<UserSession>(UserSession{
uniqueId, sessionToken, std::string(username), csrfToken,
std::chrono::steady_clock::now(), persistence});
+ session->isConfigureSelfOnly = configureSelfOnly;
auto it = authTokens.emplace(std::make_pair(sessionToken, session));
// Only need to write to disk if session isn't about to be destroyed.
needWrite = persistence == PersistenceType::TIMEOUT;
diff --git a/include/token_authorization_middleware.hpp b/include/token_authorization_middleware.hpp
index 2ff3879..5842ae5 100644
--- a/include/token_authorization_middleware.hpp
+++ b/include/token_authorization_middleware.hpp
@@ -6,6 +6,7 @@
#include <crow/http_response.h>
#include <boost/container/flat_set.hpp>
+#include <error_messages.hpp>
#include <pam_authenticate.hpp>
#include <persistent_data_middleware.hpp>
#include <random>
@@ -129,7 +130,9 @@
BMCWEB_LOG_DEBUG << "[AuthMiddleware] Authenticating user: " << user;
- if (!pamAuthenticateUser(user, pass))
+ bool passwordChangeRequired = false;
+ if (!pamAuthenticateUser(user, pass, passwordChangeRequired) ||
+ passwordChangeRequired)
{
return nullptr;
}
@@ -141,7 +144,8 @@
// This whole flow needs to be revisited anyway, as we can't be
// calling directly into pam for every request
return persistent_data::SessionStore::getInstance().generateUserSession(
- user, crow::persistent_data::PersistenceType::SINGLE_REQUEST);
+ user, false,
+ crow::persistent_data::PersistenceType::SINGLE_REQUEST);
}
const std::shared_ptr<crow::persistent_data::UserSession>
@@ -380,14 +384,17 @@
if (!username.empty() && !password.empty())
{
- if (!pamAuthenticateUser(username, password))
+ bool passwordChangeRequired = false;
+ if (!pamAuthenticateUser(username, password,
+ passwordChangeRequired))
{
res.result(boost::beast::http::status::unauthorized);
}
else
{
auto session = persistent_data::SessionStore::getInstance()
- .generateUserSession(username);
+ .generateUserSession(
+ username, passwordChangeRequired);
if (looksLikeIbm)
{
@@ -421,6 +428,10 @@
// if content type is json, assume json token
res.jsonValue = {{"token", session->sessionToken}};
}
+ if (passwordChangeRequired)
+ {
+ crow::setPasswordChangeRequired(res, session->username);
+ }
}
}
else