atomic masker in channel

This commit is contained in:
Mikhail Filimonov 2019-07-19 09:44:18 +02:00
parent 9c2ae4513d
commit f13e18d4fb
5 changed files with 9 additions and 11 deletions

View File

@ -527,7 +527,8 @@ String Context::getUserFilesPath() const
void Context::setSensitiveDataMasker(std::unique_ptr<SensitiveDataMasker> sensitive_data_masker)
{
if (sensitive_data_masker->rulesCount() > 0) {
if (sensitive_data_masker->rulesCount() > 0)
{
auto lock = getLock();
shared->sensitive_data_masker = std::move(sensitive_data_masker);
}

View File

@ -28,14 +28,13 @@
#include <Interpreters/InterpreterSetQuery.h>
#include <Interpreters/ReplaceQueryParameterVisitor.h>
#include <Interpreters/executeQuery.h>
#include <Common/ProfileEvents.h>
#include <Interpreters/DNSCacheUpdater.h>
#include <Processors/Transforms/LimitsCheckingTransform.h>
#include <Processors/Transforms/MaterializingTransform.h>
#include <Processors/Formats/IOutputFormat.h>
#include <Common/ProfileEvents.h>
namespace ProfileEvents
{
extern const Event QueryMaskingRulesMatch;

View File

@ -102,7 +102,7 @@ insert into sensitive select number as id, toDate('2019-01-01') as date, 'abcd'
insert into sensitive select number as id, toDate('2019-01-01') as date, 'find_me_TOPSECRET=TOPSECRET' as value1, rand() as valuer from numbers(10);
insert into sensitive select number as id, toDate('2019-01-01') as date, 'abcd' as value1, rand() as valuer from numbers(10000);
select * from sensitive WHERE value1 = 'find_me_TOPSECRET=TOPSECRET' FORMAT Null;
drop table sensetive;" --log_queries=1 --ignore-error --multiquery >$tmp_file 2>&1
drop table sensitive;" --log_queries=1 --ignore-error --multiquery >$tmp_file 2>&1
grep 'find_me_\[hidden\]' $tmp_file >/dev/null || echo 'fail 8a'
grep 'TOPSECRET' $tmp_file && echo 'fail 8b'

View File

@ -19,10 +19,10 @@ void OwnSplitChannel::log(const Poco::Message & msg)
if (channels.empty() && (logs_queue == nullptr || msg.getPriority() > logs_queue->max_priority))
return;
if (sensitive_data_masker)
if (auto masker = sensitive_data_masker.load())
{
auto message_text = msg.getText();
auto matches = sensitive_data_masker->wipeSensitiveData(message_text);
auto matches = masker->wipeSensitiveData(message_text);
if (matches > 0)
{
logSplit({msg, message_text}); // we will continue with the copy of original message with text modified
@ -73,8 +73,7 @@ void OwnSplitChannel::logSplit(const Poco::Message & msg)
void OwnSplitChannel::setMasker(DB::SensitiveDataMasker * _sensitive_data_masker)
{
std::lock_guard lock(mutex);
sensitive_data_masker = _sensitive_data_masker;
sensitive_data_masker.store(_sensitive_data_masker);
}
void OwnSplitChannel::addChannel(Poco::AutoPtr<Poco::Channel> channel)

View File

@ -1,6 +1,6 @@
#pragma once
#include <atomic>
#include <vector>
#include <memory>
#include <Poco/AutoPtr.h>
#include <Poco/Channel.h>
#include "ExtendedLogChannel.h"
@ -30,8 +30,7 @@ private:
/// Handler and its pointer casted to extended interface
using ExtendedChannelPtrPair = std::pair<ChannelPtr, ExtendedLogChannel *>;
std::vector<ExtendedChannelPtrPair> channels;
DB::SensitiveDataMasker * sensitive_data_masker = nullptr; // global context owns that object, pointer should be reset before context destroying.
std::mutex mutex;
std::atomic<DB::SensitiveDataMasker *> sensitive_data_masker = nullptr; // global context owns that object, pointer should be reset before context destroying.
};
}