summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/security_token.cpp
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2021-07-23 21:15:43 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-24 20:15:57 +0000
commitfa7f62a12393d89646d8131cf72d91b8ba57d8c5 (patch)
tree4141bce654004aab1d4174b8ad10521df65fecca /src/mongo/db/auth/security_token.cpp
parent6e12fe76eb373483338c4e94293fe94e269f903c (diff)
downloadmongo-fa7f62a12393d89646d8131cf72d91b8ba57d8c5.tar.gz
SERVER-59463 Add tenant ID to log messages
Diffstat (limited to 'src/mongo/db/auth/security_token.cpp')
-rw-r--r--src/mongo/db/auth/security_token.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/auth/security_token.cpp b/src/mongo/db/auth/security_token.cpp
index 334d18e8fa2..14cdb0458c3 100644
--- a/src/mongo/db/auth/security_token.cpp
+++ b/src/mongo/db/auth/security_token.cpp
@@ -31,9 +31,13 @@
#include "mongo/db/auth/security_token.h"
+#include <boost/optional.hpp>
+
#include "mongo/base/init.h"
+#include "mongo/bson/oid.h"
#include "mongo/db/server_feature_flags_gen.h"
#include "mongo/logv2/log.h"
+#include "mongo/logv2/log_detail.h"
namespace mongo {
namespace auth {
@@ -43,6 +47,18 @@ MONGO_INITIALIZER(SecurityTokenOptionValidate)(InitializerContext*) {
uassert(ErrorCodes::BadValue,
"acceptOpMsgSecurityToken may not be specified if featureFlagMongoStore is not enabled",
!gAcceptOpMsgSecurityToken || gFeatureFlagMongoStore.isEnabledAndIgnoreFCV());
+ if (gAcceptOpMsgSecurityToken) {
+ logv2::detail::setGetTenantIDCallback([]() -> boost::optional<OID> {
+ auto* client = Client::getCurrent();
+ auto* opCtx = client ? client->getOperationContext() : nullptr;
+ auto token = getSecurityToken(opCtx);
+ if (token) {
+ return token->getTenant();
+ } else {
+ return boost::none;
+ }
+ });
+ }
}
} // namespace