ClickHouse密码设置加密
程序员文章站
2022-03-20 21:58:05
...
拒绝裸奔--ClickHouse用户名密码设置
大家都说大数据有价值,但是,有多少人给大数据加了锁?
ClickHouse集群,目前线上的都是裸奔,如果对方恶意请求数据,甚至删掉某些数据,就悲剧了
Config概览
- 配置文件:user.xml
- 核心配置3部分
- profile配置,最大内存、负载方式等(没有特别关注,可见官方文档)
- 配额设置,单个用户最大能用的资源多少(没有特别关注,可见官方文档)
- 用户设置,包括用户名和密码
- 密码有2种,一种是明文,一种是写sha256sum的Hash值
- 官方不建议直接写明文密码
我们的config文件
<?xml version="1.0"?>
<yandex>
<profiles>
<default>
<max_memory_usage>10000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompressed_cache>
<load_balancing>random</load_balancing>
</default>
<readonly>
<max_memory_usage>10000000000</max_memory_usage>
<use_uncompressed_cache>0</use_uncompressed_cache>
<load_balancing>random</load_balancing>
<readonly>1</readonly>
</readonly>
</profiles>
<quotas>
<!-- Name of quota. -->
<default>
<interval>
<duration>3600</duration>
<queries>0</queries>
<errors>0</errors>
<result_rows>0</result_rows>
<read_rows>0</read_rows>
<execution_time>0</execution_time>
</interval>
</default>
</quotas>
<users>
<default>
<password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</default>
<ck>
<password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>readonly</profile>
<quota>default</quota>
</ck>
</users>
</yandex>
配置解读
-
下图定义了两组设置,名字不同
-
第二组增加了readonly选项
Snip20171120_8
- 下图定义了2个用户,为了方便测试,用了同一个用户名
- ck用户是read模式
Snip20171120_10
如何生成密码
PASSWORD=$(base64 < /dev/urandom | head -c8);
echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
6lYaUiFi
967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e
权限验证
默认用户登陆(可以不用指定用户名)
aaa@qq.com:/data1/clickhouse # clickhouse-client -h 127.0.0.1 -d gaopeng4 -m -u default --password 6lYaUiFi
ClickHouse client version 1.1.54289.
Connecting to database gaopeng4 at 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 1.1.54289.
:) create database test1 ;
CREATE DATABASE test1
Ok.
0 rows in set. Elapsed: 0.002 sec.
:) ^C
ck用户登陆
aaa@qq.com:/data1/clickhouse # clickhouse-client -h 127.0.0.1 -d gaopeng4 -m -u ck --password 6lYaUiFi
ClickHouse client version 1.1.54289.
Connecting to database gaopeng4 at 127.0.0.1:9000 as user ck.
Connected to ClickHouse server version 1.1.54289.
:) create database test2 ;
CREATE DATABASE test2
Received exception from server:
Code: 164. DB::Exception: Received from 127.0.0.1:9000. DB::Exception: Cannot execute query in readonly mode.
0 rows in set. Elapsed: 0.014 sec.
Update
-
如果使用了分布式表,需要在集群的配置文件里,增加分片的用户名密码
Snip20171212_15.png
下一篇: 解读vue生成的文件目录结构及说明