Skip to content

Audit log: No permission to connect to the database #12287

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 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions ydb/core/grpc_services/audit_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,19 @@ void AuditLog(ui32 status, const TAuditLogParts& parts)
);
}

void AuditLogConnectDbAccessDenied(const IRequestProxyCtx* ctx, const TString& database, const TString& userSID, const TString& sanitizedToken)
{
if (::NKikimr::NAudit::AUDIT_LOG_ENABLED.load()) {
AuditLog(Ydb::StatusIds::UNAUTHORIZED, {
{"remote_address", NKikimr::NAddressClassifier::ExtractAddress(ctx->GetPeerName())},
{"subject", userSID},
{"sanitized_token", (!sanitizedToken.empty() ? sanitizedToken : EmptyValue)},
{"database", database},
{"operation", ctx->GetRequestName()},
{"reason", "No permission to connect to the database"},
});
}
}

}
}
1 change: 1 addition & 0 deletions ydb/core/grpc_services/audit_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using TAuditLogParts = TVector<std::pair<TString, TString>>;

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

}
}
20 changes: 11 additions & 9 deletions ydb/core/grpc_services/grpc_request_check_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class TGrpcRequestCheckActor
{
auto [error, issue] = CheckConnectRight();
if (error) {
AuditLogConnectDbAccessDenied(GrpcRequestBaseCtx_, CheckedDatabaseName_, TBase::GetUserSID(), TBase::GetSanitizedToken());
ReplyUnauthorizedAndDie(*issue);
return;
}
Expand Down Expand Up @@ -554,21 +555,22 @@ class TGrpcRequestCheckActor
return {false, std::nullopt};
}

const TString error = TStringBuilder()
<< "User has no permission to perform query on this database"
<< ", database: " << CheckedDatabaseName_
<< ", user: " << TBase::GetUserSID()
<< ", from ip: " << GrpcRequestBaseCtx_->GetPeerName();
LOG_INFO(*TlsActivationContext, NKikimrServices::GRPC_PROXY_NO_CONNECT_ACCESS, "%s", error.c_str());

Counters_->IncDatabaseAccessDenyCounter();

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

LOG_INFO(*TlsActivationContext, NKikimrServices::GRPC_SERVER, "%s", error.c_str());
return {true, MakeIssue(NKikimrIssues::TIssuesIds::ACCESS_DENIED, error)};
const TString error = "No permission to connect to the database";
LOG_INFO_S(TlsActivationContext->AsActorContext(), NKikimrServices::GRPC_SERVER,
"AUDIT: "
<< error
<< ": " << CheckedDatabaseName_
<< ", user: " << TBase::GetUserSID()
<< ", from ip: " << GrpcRequestBaseCtx_->GetPeerName()
);

return {true, MakeIssue(NKikimrIssues::TIssuesIds::ACCESS_DENIED, error)};;
}

const TActorId Owner_;
Expand Down
2 changes: 1 addition & 1 deletion ydb/services/ydb/ydb_login_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Y_UNIT_TEST_SUITE(TGRpcAuthentication) {
UNIT_ASSERT_NO_EXCEPTION(token = loginProvider->GetAuthInfo());
UNIT_ASSERT(!token.empty());

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

loginConnection.Stop();
}
Expand Down
Loading