Skip to content

Commit 4b342cb

Browse files
authored
Fix distconf audit log (#17518) (#17557)
1 parent 239c220 commit 4b342cb

File tree

4 files changed

+40
-68
lines changed

4 files changed

+40
-68
lines changed

ydb/core/blobstorage/nodewarden/distconf_audit.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

ydb/core/blobstorage/nodewarden/distconf_audit.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

ydb/core/blobstorage/nodewarden/distconf_invoke_common.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include "distconf_audit.h"
21
#include "distconf_invoke.h"
32

3+
#include <ydb/core/audit/audit_log.h>
4+
#include <ydb/core/util/address_classifier.h>
5+
46
namespace NKikimr::NStorage {
57

68
using TInvokeRequestHandlerActor = TDistributedConfigKeeper::TInvokeRequestHandlerActor;
@@ -191,20 +193,43 @@ namespace NKikimr::NStorage {
191193
return;
192194
}
193195

194-
const auto& replaceConfig = Event->Get()->Record.GetReplaceStorageConfig();
195-
TStringBuilder oldConfig;
196-
oldConfig << Self->MainConfigYaml << (Self->StorageConfigYaml ? *Self->StorageConfigYaml : "");
197-
TStringBuilder newConfig;
198-
newConfig << *NewYaml << (NewStorageYaml ? *NewStorageYaml : "");
199-
NACLib::TUserToken userToken = NACLib::TUserToken{replaceConfig.GetUserToken()};
200-
AuditLogReplaceConfig(
201-
/* peer = */ replaceConfig.GetPeerName(),
202-
/* userSID = */ userToken.GetUserSID(),
203-
/* sanitizedToken = */ userToken.GetSanitizedToken(),
204-
/* oldConfig = */ oldConfig,
205-
/* newConfig = */ newConfig,
206-
/* reason = */ {},
207-
/* success = */ true);
196+
if (const auto& record = Event->Get()->Record; record.HasReplaceStorageConfig()) {
197+
AUDIT_LOG(
198+
const auto& replaceConfig = record.GetReplaceStorageConfig();
199+
200+
const TString oldConfig = TStringBuilder()
201+
<< Self->MainConfigYaml
202+
<< Self->StorageConfigYaml.value_or("");
203+
204+
TStringBuilder newConfig;
205+
if (replaceConfig.HasYAML()) {
206+
newConfig << replaceConfig.GetYAML();
207+
} else {
208+
newConfig << Self->MainConfigYaml;
209+
}
210+
if (replaceConfig.HasStorageYAML()) {
211+
newConfig << replaceConfig.GetStorageYAML();
212+
} else if (replaceConfig.HasSwitchDedicatedStorageSection() && !replaceConfig.GetSwitchDedicatedStorageSection()) {
213+
// dedicated storage YAML is switched off by this operation -- no storage config will be set
214+
} else if (Self->StorageConfigYaml) {
215+
newConfig << *Self->StorageConfigYaml;
216+
}
217+
218+
NACLib::TUserToken userToken(replaceConfig.GetUserToken());
219+
220+
auto wrapEmpty = [](const TString& value) { return value ? value : TString("{none}"); };
221+
222+
AUDIT_PART("component", TString("distconf"))
223+
AUDIT_PART("remote_address", wrapEmpty(NKikimr::NAddressClassifier::ExtractAddress(replaceConfig.GetPeerName())))
224+
AUDIT_PART("subject", wrapEmpty(userToken.GetUserSID()))
225+
AUDIT_PART("sanitized_token", wrapEmpty(userToken.GetSanitizedToken()))
226+
AUDIT_PART("status", TString("SUCCESS"))
227+
AUDIT_PART("reason", TString(), false)
228+
AUDIT_PART("operation", TString("REPLACE CONFIG"))
229+
AUDIT_PART("old_config", oldConfig)
230+
AUDIT_PART("new_config", newConfig)
231+
);
232+
}
208233

209234
Self->CurrentProposedStorageConfig.emplace(std::move(*config));
210235

ydb/core/blobstorage/nodewarden/ya.make

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ SRCS(
55
group_stat_aggregator.h
66
distconf.cpp
77
distconf.h
8-
distconf_audit.h
9-
distconf_audit.cpp
108
distconf_binding.cpp
119
distconf_console.cpp
1210
distconf_dynamic.cpp

0 commit comments

Comments
 (0)