mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Redacting sensitive fields in debug logs.
PiperOrigin-RevId: 537407555
This commit is contained in:
@@ -22,5 +22,6 @@ cc_binary(
|
||||
"//pkg/sentry/seccheck/points:points_cc_proto",
|
||||
"@com_google_absl//absl/cleanup",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_protobuf//:protobuf",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -27,11 +27,13 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/cleanup/cleanup.h"
|
||||
#include "absl/strings/str_replace.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "pkg/sentry/seccheck/points/common.pb.h"
|
||||
#include "pkg/sentry/seccheck/points/container.pb.h"
|
||||
#include "pkg/sentry/seccheck/points/sentry.pb.h"
|
||||
#include "pkg/sentry/seccheck/points/syscall.pb.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
|
||||
typedef std::function<void(absl::string_view buf)> Callback;
|
||||
|
||||
@@ -56,6 +58,14 @@ void log(const char* fmt, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::string shortfmt(T msg) {
|
||||
std::string short_text_msg;
|
||||
google::protobuf::TextFormat::PrintToString(msg, &short_text_msg);
|
||||
return absl::StrReplaceAll(short_text_msg,
|
||||
{{"\r\n", " "}, {"\n", " "}, {"\r", " "}});
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void unpackSyscall(absl::string_view buf) {
|
||||
T evt;
|
||||
@@ -63,8 +73,7 @@ void unpackSyscall(absl::string_view buf) {
|
||||
err(1, "ParseFromString(): %.*s", static_cast<int>(buf.size()), buf.data());
|
||||
}
|
||||
log("%s %s %s\n", evt.has_exit() ? "X" : "E",
|
||||
evt.GetMetadata().descriptor->name().c_str(),
|
||||
evt.ShortDebugString().c_str());
|
||||
evt.GetMetadata().descriptor->name().c_str(), shortfmt(evt).c_str());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -74,7 +83,7 @@ void unpack(absl::string_view buf) {
|
||||
err(1, "ParseFromString(): %.*s", static_cast<int>(buf.size()), buf.data());
|
||||
}
|
||||
log("%s => %s\n", evt.GetMetadata().descriptor->name().c_str(),
|
||||
evt.ShortDebugString().c_str());
|
||||
shortfmt(evt).c_str());
|
||||
}
|
||||
|
||||
// List of dispatchers indexed based on MessageType enum values.
|
||||
|
||||
Reference in New Issue
Block a user