get credentials from environment variables for clickhouse-client

include CLICKHOUSE_USER, CLICKHOUSE_PASSWORD
This commit is contained in:
freedomDR 2022-02-28 05:33:14 +00:00
parent bfd2ad4e9a
commit 43ac214dc5
3 changed files with 37 additions and 0 deletions

View File

@ -371,6 +371,13 @@ void Client::initialize(Poco::Util::Application & self)
configReadClient(config(), home_path);
const char * env_user = getenv("CLICKHOUSE_USER");
const char * env_password = getenv("CLICKHOUSE_PASSWORD");
if (env_user)
config().setString("user", env_user);
if (env_password)
config().setString("password", env_password);
// global_context->setApplicationType(Context::ApplicationType::CLIENT);
global_context->setQueryParameters(query_parameters);

View File

@ -37,6 +37,24 @@
<database>db1</database>
</allow_databases>
</has_access>
<env_user_with_password>
<password>clickhouse</password>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</env_user_with_password>
<env_user_not_with_password>
<password></password>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</env_user_not_with_password>
</users>
<quotas>

View File

@ -70,3 +70,15 @@ def test_user_zero_database_access(start_cluster):
["bash", "-c", "/usr/bin/clickhouse client --user 'default' --query 'DROP DATABASE test2'"], user='root')
except Exception as ex:
assert False, "user with full access rights can't drop database test2"
try:
node.exec_in_container(
["bash", "-c", "export CLICKHOUSE_USER=env_user_not_with_password && /usr/bin/clickhouse client --query 'SELECT 1'"], user='root')
except Exception as ex:
assert False, "set env CLICKHOUSE_USER can not connect server"
try:
node.exec_in_container(
["bash", "-c", "export CLICKHOUSE_USER=env_user_with_password && export CLICKHOUSE_PASSWORD=clickhouse && /usr/bin/clickhouse client --query 'SELECT 1'"], user='root')
except Exception as ex:
assert False, "set env CLICKHOUSE_USER CLICKHOUSE_PASSWORD can not connect server"