mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Merge pull request #35705 from ClickHouse/is-secure-client-info
Added `is_secure` column to `query_log`
This commit is contained in:
commit
8cc18c851d
@ -69,6 +69,7 @@ public:
|
|||||||
/// All below are parameters related to initial query.
|
/// All below are parameters related to initial query.
|
||||||
|
|
||||||
Interface interface = Interface::TCP;
|
Interface interface = Interface::TCP;
|
||||||
|
bool is_secure = false;
|
||||||
|
|
||||||
/// For tcp
|
/// For tcp
|
||||||
String os_user;
|
String os_user;
|
||||||
|
@ -86,6 +86,7 @@ NamesAndTypesList QueryLogElement::getNamesAndTypes()
|
|||||||
{"initial_query_start_time", std::make_shared<DataTypeDateTime>()},
|
{"initial_query_start_time", std::make_shared<DataTypeDateTime>()},
|
||||||
{"initial_query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
{"initial_query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
||||||
{"interface", std::make_shared<DataTypeUInt8>()},
|
{"interface", std::make_shared<DataTypeUInt8>()},
|
||||||
|
{"is_secure", std::make_shared<DataTypeUInt8>()},
|
||||||
{"os_user", std::make_shared<DataTypeString>()},
|
{"os_user", std::make_shared<DataTypeString>()},
|
||||||
{"client_hostname", std::make_shared<DataTypeString>()},
|
{"client_hostname", std::make_shared<DataTypeString>()},
|
||||||
{"client_name", std::make_shared<DataTypeString>()},
|
{"client_name", std::make_shared<DataTypeString>()},
|
||||||
@ -275,6 +276,7 @@ void QueryLogElement::appendClientInfo(const ClientInfo & client_info, MutableCo
|
|||||||
columns[i++]->insert(client_info.initial_query_start_time_microseconds);
|
columns[i++]->insert(client_info.initial_query_start_time_microseconds);
|
||||||
|
|
||||||
columns[i++]->insert(UInt64(client_info.interface));
|
columns[i++]->insert(UInt64(client_info.interface));
|
||||||
|
columns[i++]->insert(static_cast<UInt64>(client_info.is_secure));
|
||||||
|
|
||||||
columns[i++]->insert(client_info.os_user);
|
columns[i++]->insert(client_info.os_user);
|
||||||
columns[i++]->insert(client_info.client_hostname);
|
columns[i++]->insert(client_info.client_hostname);
|
||||||
|
@ -56,6 +56,7 @@ NamesAndTypesList QueryThreadLogElement::getNamesAndTypes()
|
|||||||
{"initial_query_start_time", std::make_shared<DataTypeDateTime>()},
|
{"initial_query_start_time", std::make_shared<DataTypeDateTime>()},
|
||||||
{"initial_query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
{"initial_query_start_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
|
||||||
{"interface", std::make_shared<DataTypeUInt8>()},
|
{"interface", std::make_shared<DataTypeUInt8>()},
|
||||||
|
{"is_secure", std::make_shared<DataTypeUInt8>()},
|
||||||
{"os_user", std::make_shared<DataTypeString>()},
|
{"os_user", std::make_shared<DataTypeString>()},
|
||||||
{"client_hostname", std::make_shared<DataTypeString>()},
|
{"client_hostname", std::make_shared<DataTypeString>()},
|
||||||
{"client_name", std::make_shared<DataTypeString>()},
|
{"client_name", std::make_shared<DataTypeString>()},
|
||||||
|
@ -243,7 +243,7 @@ void Session::shutdownNamedSessions()
|
|||||||
NamedSessionsStorage::instance().shutdown();
|
NamedSessionsStorage::instance().shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::Session(const ContextPtr & global_context_, ClientInfo::Interface interface_)
|
Session::Session(const ContextPtr & global_context_, ClientInfo::Interface interface_, bool is_secure)
|
||||||
: auth_id(UUIDHelpers::generateV4()),
|
: auth_id(UUIDHelpers::generateV4()),
|
||||||
global_context(global_context_),
|
global_context(global_context_),
|
||||||
interface(interface_),
|
interface(interface_),
|
||||||
@ -251,6 +251,7 @@ Session::Session(const ContextPtr & global_context_, ClientInfo::Interface inter
|
|||||||
{
|
{
|
||||||
prepared_client_info.emplace();
|
prepared_client_info.emplace();
|
||||||
prepared_client_info->interface = interface_;
|
prepared_client_info->interface = interface_;
|
||||||
|
prepared_client_info->is_secure = is_secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::~Session()
|
Session::~Session()
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
/// Stops using named sessions. The method must be called at the server shutdown.
|
/// Stops using named sessions. The method must be called at the server shutdown.
|
||||||
static void shutdownNamedSessions();
|
static void shutdownNamedSessions();
|
||||||
|
|
||||||
Session(const ContextPtr & global_context_, ClientInfo::Interface interface_);
|
Session(const ContextPtr & global_context_, ClientInfo::Interface interface_, bool is_secure = false);
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
Session(const Session &&) = delete;
|
Session(const Session &&) = delete;
|
||||||
|
@ -922,7 +922,7 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
|
|||||||
setThreadName("HTTPHandler");
|
setThreadName("HTTPHandler");
|
||||||
ThreadStatus thread_status;
|
ThreadStatus thread_status;
|
||||||
|
|
||||||
session = std::make_unique<Session>(server.context(), ClientInfo::Interface::HTTP);
|
session = std::make_unique<Session>(server.context(), ClientInfo::Interface::HTTP, request.isSecure());
|
||||||
SCOPE_EXIT({ session.reset(); });
|
SCOPE_EXIT({ session.reset(); });
|
||||||
std::optional<CurrentThread::QueryScope> query_scope;
|
std::optional<CurrentThread::QueryScope> query_scope;
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ void TCPHandler::runImpl()
|
|||||||
setThreadName("TCPHandler");
|
setThreadName("TCPHandler");
|
||||||
ThreadStatus thread_status;
|
ThreadStatus thread_status;
|
||||||
|
|
||||||
session = std::make_unique<Session>(server.context(), ClientInfo::Interface::TCP);
|
session = std::make_unique<Session>(server.context(), ClientInfo::Interface::TCP, socket().secure());
|
||||||
extractConnectionSettingsFromContext(server.context());
|
extractConnectionSettingsFromContext(server.context());
|
||||||
|
|
||||||
socket().setReceiveTimeout(receive_timeout);
|
socket().setReceiveTimeout(receive_timeout);
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
1 0
|
||||||
|
1 1
|
||||||
|
2 0
|
||||||
|
2 1
|
22
tests/queries/0_stateless/02246_is_secure_query_log.sh
Executable file
22
tests/queries/0_stateless/02246_is_secure_query_log.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Tags: no-fasttest
|
||||||
|
|
||||||
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
# shellcheck source=../shell_config.sh
|
||||||
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
|
${CLICKHOUSE_CLIENT} --log_queries=1 --query_id "2246_${CLICKHOUSE_DATABASE}_client_nonsecure" -q "select 1 Format Null"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "system flush logs"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "select interface, is_secure from system.query_log where query_id = '2246_${CLICKHOUSE_DATABASE}_client_nonsecure' and type = 'QueryFinish' and current_database = currentDatabase()"
|
||||||
|
|
||||||
|
${CLICKHOUSE_CLIENT_SECURE} --log_queries=1 --query_id "2246_${CLICKHOUSE_DATABASE}_client_secure" -q "select 1 Format Null"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "system flush logs"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "select interface, is_secure from system.query_log where query_id = '2246_${CLICKHOUSE_DATABASE}_client_secure' and type = 'QueryFinish' and current_database = currentDatabase()"
|
||||||
|
|
||||||
|
${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&log_queries=1&query_id=2246_${CLICKHOUSE_DATABASE}_http_nonsecure" -d "select 1 Format Null"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "system flush logs"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "select interface, is_secure from system.query_log where query_id = '2246_${CLICKHOUSE_DATABASE}_http_nonsecure' and type = 'QueryFinish' and current_database = currentDatabase()"
|
||||||
|
|
||||||
|
${CLICKHOUSE_CURL} -sSk "${CLICKHOUSE_URL_HTTPS}&log_queries=1&query_id=2246_${CLICKHOUSE_DATABASE}_http_secure" -d "select 1 Format Null"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "system flush logs"
|
||||||
|
${CLICKHOUSE_CLIENT} -q "select interface, is_secure from system.query_log where query_id = '2246_${CLICKHOUSE_DATABASE}_http_secure' and type = 'QueryFinish' and current_database = currentDatabase()"
|
Loading…
Reference in New Issue
Block a user