Skip to content

obfuscate logs merge stream-nb-24-3 #11379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TMonitoringRestServiceActor : public NActors::TActor<TMonitoringRestServic
.Build()
);
auto ticket = CredentialsProvider->GetAuthInfo();
LOG_D(httpRequest->GetRawData() << " using ticket " << NKikimr::MaskTicket(ticket));
LOG_D(httpRequest->GetObfuscatedData() << " using ticket " << NKikimr::MaskTicket(ticket));
httpRequest->Set("Authorization", ticket);

auto httpSenderId = Register(NYql::NDq::CreateHttpSenderActor(SelfId(), HttpProxyId, NYql::NDq::THttpSenderRetryPolicy::GetNoRetryPolicy()));
Expand All @@ -83,7 +83,7 @@ class TMonitoringRestServiceActor : public NActors::TActor<TMonitoringRestServic
forwardResponse->Issues.AddIssue(error);
Send(request->Sender, forwardResponse.release(), 0, request->Cookie);
return;
}
}

try {
NJson::TJsonReaderConfig jsonConfig;
Expand Down
100 changes: 54 additions & 46 deletions ydb/library/actors/http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,58 @@ class THttpResponse {
};

template <typename HeaderType, typename BufferType>
class THttpParser : public HeaderType, public BufferType {
class THttpBase : public HeaderType, public BufferType {
protected:
// Returns raw, non-obfuscated data
TStringBuf GetRawData() const {
return TStringBuf(BufferType::Data(), BufferType::Size());
}

public:
TString GetObfuscatedData() const {
THeaders headers(HeaderType::Headers);
TStringBuf authorization(headers["Authorization"]);
TStringBuf cookie(headers["Cookie"]);
TStringBuf set_cookie(headers["Set-Cookie"]);
TStringBuf x_ydb_auth_ticket(headers["x-ydb-auth-ticket"]);
TStringBuf x_yacloud_subjecttoken(headers["x-yacloud-subjecttoken"]);
TString data(GetRawData());
if (!authorization.empty()) {
auto pos = data.find(authorization);
if (pos != TString::npos) {
data.replace(pos, authorization.size(), TString("<obfuscated>"));
}
}
if (!cookie.empty()) {
auto pos = data.find(cookie);
if (pos != TString::npos) {
data.replace(pos, cookie.size(), TString("<obfuscated>"));
}
}
if (!set_cookie.empty()) {
auto pos = data.find(set_cookie);
if (pos != TString::npos) {
data.replace(pos, set_cookie.size(), TString("<obfuscated>"));
}
}
if (!x_ydb_auth_ticket.empty()) {
auto pos = data.find(x_ydb_auth_ticket);
if (pos != TString::npos) {
data.replace(pos, x_ydb_auth_ticket.size(), TString("<obfuscated>"));
}
}
if (!x_yacloud_subjecttoken.empty()) {
auto pos = data.find(x_yacloud_subjecttoken);
if (pos != TString::npos) {
data.replace(pos, x_yacloud_subjecttoken.size(), TString("<obfuscated>"));
}
}
return data;
}
};

template <typename HeaderType, typename BufferType>
class THttpParser : public THttpBase<HeaderType, BufferType> {
public:
enum class EParseStage : ui8 {
Method,
Expand Down Expand Up @@ -236,8 +287,7 @@ class THttpParser : public HeaderType, public BufferType {
std::optional<size_t> TotalSize;

THttpParser(const THttpParser& src)
: HeaderType(src)
, BufferType(src)
: THttpBase<HeaderType, BufferType>(src)
, Stage(src.Stage)
, LastSuccessStage(src.LastSuccessStage)
, Line()
Expand Down Expand Up @@ -403,44 +453,6 @@ class THttpParser : public HeaderType, public BufferType {
Advance(size);
}

TStringBuf GetRawData() const {
return TStringBuf(BufferType::Data(), BufferType::Size());
}

TString GetObfuscatedData() const {
THeaders headers(HeaderType::Headers);
TStringBuf authorization(headers["Authorization"]);
TStringBuf cookie(headers["Cookie"]);
TStringBuf x_ydb_auth_ticket(headers["x-ydb-auth-ticket"]);
TStringBuf x_yacloud_subjecttoken(headers["x-yacloud-subjecttoken"]);
TString data(GetRawData());
if (!authorization.empty()) {
auto pos = data.find(authorization);
if (pos != TString::npos) {
data.replace(pos, authorization.size(), TString("<obfuscated>"));
}
}
if (!cookie.empty()) {
auto pos = data.find(cookie);
if (pos != TString::npos) {
data.replace(pos, cookie.size(), TString("<obfuscated>"));
}
}
if (!x_ydb_auth_ticket.empty()) {
auto pos = data.find(x_ydb_auth_ticket);
if (pos != TString::npos) {
data.replace(pos, x_ydb_auth_ticket.size(), TString("<obfuscated>"));
}
}
if (!x_yacloud_subjecttoken.empty()) {
auto pos = data.find(x_yacloud_subjecttoken);
if (pos != TString::npos) {
data.replace(pos, x_yacloud_subjecttoken.size(), TString("<obfuscated>"));
}
}
return data;
}

static EParseStage GetInitialStage();

THttpParser()
Expand All @@ -460,7 +472,7 @@ class THttpParser : public HeaderType, public BufferType {
};

template <typename HeaderType, typename BufferType>
class THttpRenderer : public HeaderType, public BufferType {
class THttpRenderer : public THttpBase<HeaderType, BufferType> {
public:
enum class ERenderStage {
Init,
Expand Down Expand Up @@ -654,10 +666,6 @@ class THttpRenderer : public HeaderType, public BufferType {
}
Y_ABORT_UNLESS(size == BufferType::Size());
}

TStringBuf GetRawData() const {
return TStringBuf(BufferType::Data(), BufferType::Size());
}
};

template <>
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/actors/http/http_proxy_incoming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TIncomingConnectionActor : public TActor<TIncomingConnectionActor<TSocketI
<< ","
<< Address
<< ") Response: "
<< TString(response->GetRawData()).substr(0, MAX_LOGGED_SIZE));
<< response->GetObfuscatedData().substr(0, MAX_LOGGED_SIZE));
}
THolder<TEvHttpProxy::TEvReportSensors> sensors(BuildIncomingRequestSensors(request, response));
ctx.Send(Endpoint->Owner, sensors.Release());
Expand Down
Loading