Skip to content
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

add Vault #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions OneSTools.EventLog.Exporter.Core/ClickHouse/ClickHouseStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ public ClickHouseStorage(string connectionsString, ILogger<ClickHouseStorage> lo
{
_logger = logger;
_connectionString = connectionsString;

Init();
}

public ClickHouseStorage(ILogger<ClickHouseStorage> logger, IConfiguration configuration)
{
_logger = logger;
_connectionString = configuration.GetValue("ClickHouse:ConnectionString", "");

var useVault = configuration.GetValue("Vault:UseVault", false);
if (useVault) {
var vault = new Vault();
var arr = vault.GetSecretWithAppRole(configuration);
var username = arr[0];
var password = arr[1];
_connectionString = _connectionString.Replace("Username=test","Username=" + username).Replace("password=","password=" + password); }
Init();
}

Expand Down
37 changes: 37 additions & 0 deletions OneSTools.EventLog.Exporter.Core/ClickHouse/Vault.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using VaultSharp;
using VaultSharp.V1.AuthMethods;
using VaultSharp.V1.AuthMethods.AppRole;
using VaultSharp.V1.Commons;
using Microsoft.Extensions.Configuration;

namespace OneSTools.EventLog.Exporter.Core.ClickHouse
{
public class Vault
{
public string[] GetSecretWithAppRole(IConfiguration configuration)
{
string vaultAddr = configuration.GetValue("Vault:VaultAddr","");
string path = configuration.GetValue("Vault:Path","");
string mountPoint = configuration.GetValue("Vault:MountPoint","");
string roleId = configuration.GetValue("Vault:RoleId","");
string secretId = configuration.GetValue("Vault:SecreteId","");
string login = configuration.GetValue("Vault:Login","");
string password = configuration.GetValue("Vault:Password","");

IAuthMethodInfo authMethod = new AppRoleAuthMethodInfo(roleId, secretId.ToString());
var vaultClientSettings = new VaultClientSettings(vaultAddr, authMethod);

IVaultClient vaultClient = new VaultClient(vaultClientSettings);

Secret<SecretData> kv2Secret = null;
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path:path , mountPoint: mountPoint).Result;

var arr = new string[2];
string username = kv2Secret.Data.Data[login].ToString();
string pass = kv2Secret.Data.Data[password].ToString();
arr[0] = username;
arr[1] = pass;
return arr;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="NEST" Version="7.10.1" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="5.0.0" />
<PackageReference Include="VaultSharp" Version="1.13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions OneSTools.EventLog.Exporter/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
},
"Exporter": {
"StorageType": 0,
"StorageType": "ClickHouse",
"LogFolder": "",
"Portion": 10000,
"TimeZone": "Europe/Moscow",
Expand All @@ -18,7 +18,7 @@
"SkipEventsBeforeDate": "2022-04-01T00:00:00"
},
"ClickHouse": {
"ConnectionString": "Host=CH_HOST_NAME;Port=8123;Database=DATABASE_NAME;Username=USER_NAME;password=PASSWORD;"
"ConnectionString": "Host=;Port=8123;Username=test;password=;Database=example2;"
},
"ElasticSearch": {
"Nodes": [
Expand All @@ -31,5 +31,15 @@
"Separation": "M",
"MaximumRetries": 2,
"MaxRetryTimeout": 30
}
},
"Vault": {
"UseVault":"True",
"VaultAddr":"",
"Path":"",
"MountPoint":"",
"SecreteId":"",
"RoleId":"",
"Login":"login",
"Password":"password"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
|[OneSTools.EventLog.Exporter.Core](https://github.com/akpaevj/OneSTools.EventLog/tree/master/OneSTools.EventLog.Exporter.Core)|Библиотека-ядро для инструментов экспорта журнала регистрации||
|[EventLogExporter](https://github.com/akpaevj/OneSTools.EventLog/tree/master/OneSTools.EventLog.Exporter)|Служба для экспорта журнала регистрации в [ClickHouse](https://clickhouse.tech/) и [ElasticSearch](https://www.elastic.co/)|![EventLogExporter .NET 5](https://github.com/akpaevj/OneSTools.EventLog/workflows/EventLogExporter%20.NET%205/badge.svg)|
|[EventLogExportersManager](https://github.com/akpaevj/OneSTools.EventLog/tree/master/OneSTools.EventLog.Exporter.Manager)|Служба, выполняющая роль менеджера и наблюдающая каталоги серверов на предмет появления/удаления информационных баз с автоматическим подключением/отключением экспорта их журналов регистраций||
|[Vault](https://github.com/rajanadar/VaultSharp)|HashiCorp Vault — это инструмент с открытым исходным кодом, который обеспечивает безопасный и надежный способ хранения и распространения секретов, таких как ключи API, токены доступа и пароли||

## Get started:

Expand Down