Skip to content

Commit 943f673

Browse files
authored
Merge bd3ac9b into 9cd2117
2 parents 9cd2117 + bd3ac9b commit 943f673

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

ydb/core/grpc_services/audit_log.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,19 @@ void AuditLog(ui32 status, const TAuditLogParts& parts)
5555
);
5656
}
5757

58+
void AuditLogConnectDbAccessDenied(const IRequestProxyCtx* ctx, const TString& database, const TString& userSID, const TString& sanitizedToken)
59+
{
60+
if (::NKikimr::NAudit::AUDIT_LOG_ENABLED.load()) {
61+
AuditLog(Ydb::StatusIds::UNAUTHORIZED, {
62+
{"remote_address", NKikimr::NAddressClassifier::ExtractAddress(ctx->GetPeerName())},
63+
{"subject", userSID},
64+
{"sanitized_token", (!sanitizedToken.empty() ? sanitizedToken : EmptyValue)},
65+
{"database", database},
66+
{"operation", ctx->GetRequestName()},
67+
{"reason", "No permission to connect to the database"},
68+
});
69+
}
70+
}
71+
5872
}
5973
}

ydb/core/grpc_services/audit_log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using TAuditLogParts = TVector<std::pair<TString, TString>>;
1414

1515
// grpc "operations" log
1616
void AuditLog(ui32 status, const TAuditLogParts& parts);
17+
void AuditLogConnectDbAccessDenied(const IRequestProxyCtx* reqCtx, const TString& database, const TString& userSID, const TString& sanitizedToken);
1718

1819
}
1920
}

ydb/core/grpc_services/grpc_request_check_actor.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class TGrpcRequestCheckActor
172172
{
173173
auto [error, issue] = CheckConnectRight();
174174
if (error) {
175+
AuditLogConnectDbAccessDenied(GrpcRequestBaseCtx_, CheckedDatabaseName_, TBase::GetUserSID(), TBase::GetSanitizedToken());
175176
ReplyUnauthorizedAndDie(*issue);
176177
return;
177178
}
@@ -554,21 +555,22 @@ class TGrpcRequestCheckActor
554555
return {false, std::nullopt};
555556
}
556557

557-
const TString error = TStringBuilder()
558-
<< "User has no permission to perform query on this database"
559-
<< ", database: " << CheckedDatabaseName_
560-
<< ", user: " << TBase::GetUserSID()
561-
<< ", from ip: " << GrpcRequestBaseCtx_->GetPeerName();
562-
LOG_INFO(*TlsActivationContext, NKikimrServices::GRPC_PROXY_NO_CONNECT_ACCESS, "%s", error.c_str());
563-
564558
Counters_->IncDatabaseAccessDenyCounter();
565559

566560
if (!AppData()->FeatureFlags.GetCheckDatabaseAccessPermission()) {
567561
return {false, std::nullopt};
568562
}
569563

570-
LOG_INFO(*TlsActivationContext, NKikimrServices::GRPC_SERVER, "%s", error.c_str());
571-
return {true, MakeIssue(NKikimrIssues::TIssuesIds::ACCESS_DENIED, error)};
564+
const TString error = "No permission to connect to the database";
565+
LOG_INFO_S(TlsActivationContext->AsActorContext(), NKikimrServices::GRPC_SERVER,
566+
"AUDIT: "
567+
<< error
568+
<< ": " << CheckedDatabaseName_
569+
<< ", user: " << TBase::GetUserSID()
570+
<< ", from ip: " << GrpcRequestBaseCtx_->GetPeerName()
571+
);
572+
573+
return {true, MakeIssue(NKikimrIssues::TIssuesIds::ACCESS_DENIED, error)};;
572574
}
573575

574576
const TActorId Owner_;

ydb/services/ydb/ydb_login_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Y_UNIT_TEST_SUITE(TGRpcAuthentication) {
169169
UNIT_ASSERT_NO_EXCEPTION(token = loginProvider->GetAuthInfo());
170170
UNIT_ASSERT(!token.empty());
171171

172-
loginConnection.TestConnectRight(token, "User has no permission");
172+
loginConnection.TestConnectRight(token, "No permission to connect to the database");
173173

174174
loginConnection.Stop();
175175
}

0 commit comments

Comments
 (0)