Skip to content

KIKIMR-20597 Implemented tvm authentication for wilson uploader #768

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
merged 5 commits into from
Dec 30, 2023
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
3 changes: 3 additions & 0 deletions ydb/core/driver_lib/run/factories.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ydb/library/yql/providers/pq/cm_client/client.h>

#include <ydb/library/actors/core/actorsystem.h>
#include <ydb/library/actors/wilson/wilson_uploader.h>

#include <functional>
#include <unordered_map>
Expand Down Expand Up @@ -55,6 +56,8 @@ struct TModuleFactories {
std::shared_ptr<NHttpProxy::IAuthFactory> DataStreamsAuthFactory;
std::vector<NKikimr::NMiniKQL::TComputationNodeFactory> AdditionalComputationNodeFactories;

std::unique_ptr<NWilson::IGrpcSigner>(*WilsonGrpcSignerFactory)(const NKikimrConfig::TTracingConfig::TAuthConfig&);

~TModuleFactories();
};

Expand Down
17 changes: 14 additions & 3 deletions ydb/core/driver_lib/run/kikimr_services_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ static bool IsServiceInitialized(NActors::TActorSystemSetup* setup, TActorId ser
return false;
}

TBasicServicesInitializer::TBasicServicesInitializer(const TKikimrRunConfig& runConfig)
TBasicServicesInitializer::TBasicServicesInitializer(const TKikimrRunConfig& runConfig, std::shared_ptr<TModuleFactories> factories)
: IKikimrServicesInitializer(runConfig)
, Factories(std::move(factories))
{
}

Expand Down Expand Up @@ -827,10 +828,20 @@ void TBasicServicesInitializer::InitializeServices(NActors::TActorSystemSetup* s

if (Config.HasTracingConfig()) {
const auto& tracing = Config.GetTracingConfig();
std::unique_ptr<NWilson::IGrpcSigner> grpcSigner;
if (tracing.HasAuthConfig() && Factories && Factories->WilsonGrpcSignerFactory) {
grpcSigner = Factories->WilsonGrpcSignerFactory(tracing.GetAuthConfig());
}
auto wilsonUploader = NWilson::WilsonUploaderParams {
.Host = tracing.GetHost(),
.Port = static_cast<ui16>(tracing.GetPort()),
.RootCA = tracing.GetRootCA(),
.ServiceName = tracing.GetServiceName(),
.GrpcSigner = std::move(grpcSigner),
}.CreateUploader();
setup->LocalServices.emplace_back(
NWilson::MakeWilsonUploaderId(),
TActorSetupCmd(NWilson::CreateWilsonUploader(tracing.GetHost(), tracing.GetPort(), tracing.GetRootCA(), tracing.GetServiceName()),
TMailboxType::ReadAsFilled, appData->BatchPoolId));
TActorSetupCmd(wilsonUploader, TMailboxType::ReadAsFilled, appData->BatchPoolId));
}
}

Expand Down
4 changes: 3 additions & 1 deletion ydb/core/driver_lib/run/kikimr_services_initializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class TBasicServicesInitializer : public IKikimrServicesInitializer {

static ISchedulerThread* CreateScheduler(const NKikimrConfig::TActorSystemConfig::TScheduler &config);

std::shared_ptr<TModuleFactories> Factories;

public:
TBasicServicesInitializer(const TKikimrRunConfig& runConfig);
TBasicServicesInitializer(const TKikimrRunConfig& runConfig, std::shared_ptr<TModuleFactories> factories);

void InitializeServices(NActors::TActorSystemSetup *setup, const NKikimr::TAppData *appData) override;
};
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/driver_lib/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ TIntrusivePtr<TServiceInitializersList> TKikimrRunner::CreateServiceInitializers
}

if (serviceMask.EnableBasicServices) {
sil->AddServiceInitializer(new TBasicServicesInitializer(runConfig));
sil->AddServiceInitializer(new TBasicServicesInitializer(runConfig, ModuleFactories));
}
if (serviceMask.EnableIcbService) {
sil->AddServiceInitializer(new TImmediateControlBoardInitializer(runConfig));
Expand Down
23 changes: 23 additions & 0 deletions ydb/core/protos/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1517,10 +1517,33 @@ message TCompactionConfig {
}

message TTracingConfig {
message TAuthConfig {
message TTvm {
optional string Host = 1;
optional uint32 Port = 2;

required uint32 SelfTvmId = 3;
required uint32 TracingTvmId = 4;

optional string DiskCacheDir = 5;

oneof Secret {
string PlainTextSecret = 6;
string SecretFile = 7;
string SecretEnvironmentVariable = 8;
}
}

oneof Method {
TTvm Tvm = 1;
}
}

optional string Host = 1;
optional uint32 Port = 2;
optional string RootCA = 3;
optional string ServiceName = 4;
optional TAuthConfig AuthConfig = 5;
}

message TFailureInjectionConfig {
Expand Down
24 changes: 16 additions & 8 deletions ydb/library/actors/wilson/wilson_uploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h>
#include <util/stream/file.h>
#include <util/string/hex.h>
#include <grpc++/grpc++.h>
#include <chrono>

namespace NWilson {
Expand All @@ -32,6 +31,7 @@ namespace NWilson {
std::unique_ptr<NServiceProto::TraceService::Stub> Stub;
grpc::CompletionQueue CQ;

std::unique_ptr<IGrpcSigner> GrpcSigner;
std::unique_ptr<grpc::ClientContext> Context;
std::unique_ptr<grpc::ClientAsyncResponseReader<NServiceProto::ExportTraceServiceResponse>> Reader;
NServiceProto::ExportTraceServiceResponse Response;
Expand All @@ -53,11 +53,12 @@ namespace NWilson {
bool WakeupScheduled = false;

public:
TWilsonUploader(TString host, ui16 port, TString rootCA, TString serviceName)
: Host(std::move(host))
, Port(std::move(port))
, RootCA(std::move(rootCA))
, ServiceName(std::move(serviceName))
TWilsonUploader(WilsonUploaderParams params)
: Host(std::move(params.Host))
, Port(std::move(params.Port))
, RootCA(std::move(params.RootCA))
, ServiceName(std::move(params.ServiceName))
, GrpcSigner(std::move(params.GrpcSigner))
{}

~TWilsonUploader() {
Expand Down Expand Up @@ -142,6 +143,9 @@ namespace NWilson {

ScheduleWakeup(NextSendTimestamp);
Context = std::make_unique<grpc::ClientContext>();
if (GrpcSigner) {
GrpcSigner->SignClientContext(*Context);
}
Reader = Stub->AsyncExport(Context.get(), std::move(request), &CQ);
Reader->Finish(&Response, &Status, nullptr);
}
Expand Down Expand Up @@ -192,8 +196,12 @@ namespace NWilson {

} // anonymous

IActor *CreateWilsonUploader(TString host, ui16 port, TString rootCA, TString serviceName) {
return new TWilsonUploader(std::move(host), port, std::move(rootCA), std::move(serviceName));
IActor* CreateWilsonUploader(WilsonUploaderParams params) {
return new TWilsonUploader(std::move(params));
}

IActor* WilsonUploaderParams::CreateUploader() && {
return CreateWilsonUploader(std::move(*this));
}

} // NWilson
18 changes: 17 additions & 1 deletion ydb/library/actors/wilson/wilson_uploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
#include <ydb/library/actors/core/event_local.h>
#include <ydb/library/actors/core/events.h>
#include <opentelemetry/proto/trace/v1/trace.pb.h>
#include <grpc++/grpc++.h>

namespace NWilson {
struct IGrpcSigner {
virtual void SignClientContext(grpc::ClientContext& context) = 0;

virtual ~IGrpcSigner() = default;
};

struct TEvWilson : NActors::TEventLocal<TEvWilson, NActors::TEvents::TSystem::Wilson> {
opentelemetry::proto::trace::v1::Span Span;
Expand All @@ -19,6 +25,16 @@ namespace NWilson {
return NActors::TActorId(0, TStringBuf("WilsonUpload", 12));
}

NActors::IActor *CreateWilsonUploader(TString host, ui16 port, TString rootCA, TString serviceName);
struct WilsonUploaderParams {
TString Host;
ui16 Port;
TString RootCA;
TString ServiceName;
std::unique_ptr<IGrpcSigner> GrpcSigner;

NActors::IActor* CreateUploader() &&;
};

NActors::IActor* CreateWilsonUploader(WilsonUploaderParams params);

} // NWilson
42 changes: 34 additions & 8 deletions ydb/tools/cfg/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ def __init__(
)
self._enable_cms_config_cache = template.get("enable_cms_config_cache", enable_cms_config_cache)
if "tracing" in template:
tracing = template["tracing"]
self.__tracing = (
template["tracing"]["host"],
template["tracing"]["port"],
template["tracing"]["root_ca"],
template["tracing"]["service_name"],
tracing["host"],
tracing["port"],
tracing["root_ca"],
tracing["service_name"],
tracing.get("auth_config")
)
else:
self.__tracing = None
Expand Down Expand Up @@ -1121,12 +1123,36 @@ def __generate_sys_txt(self):
def __generate_tracing_txt(self):
pb = config_pb2.TAppConfig()
if self.__tracing:
tracing_pb = pb.TracingConfig
(
pb.TracingConfig.Host,
pb.TracingConfig.Port,
pb.TracingConfig.RootCA,
pb.TracingConfig.ServiceName,
tracing_pb.Host,
tracing_pb.Port,
tracing_pb.RootCA,
tracing_pb.ServiceName,
auth_config
) = self.__tracing

if auth_config:
auth_pb = tracing_pb.AuthConfig
if "tvm" in auth_config:
tvm = auth_config.get("tvm")
tvm_pb = auth_pb.Tvm

if "host" in tvm:
tvm_pb.Host = tvm["host"]
if "port" in tvm:
tvm_pb.Port = tvm["port"]
tvm_pb.SelfTvmId = tvm["self_tvm_id"]
tvm_pb.TracingTvmId = tvm["tracing_tvm_id"]
tvm_pb.DiskCacheDir = tvm["disk_cache_dir"]

if "plain_text_secret" in tvm:
tvm_pb.PlainTextSecret = tvm["plain_text_secret"]
elif "secret_file" in tvm:
tvm_pb.SecretFile = tvm["secret_file"]
elif "secret_environment_variable" in tvm:
tvm_pb.SecretEnvironmentVariable = tvm["secret_environment_variable"]

self.__proto_configs["tracing.txt"] = pb

def __generate_sys_txt_advanced(self):
Expand Down
1 change: 1 addition & 0 deletions ydb/tools/cfg/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
port=dict(type="integer"),
root_ca=dict(type="string"),
service_name=dict(type="string"),
auth_config=dict(type="object"),
),
required=[
"host",
Expand Down