Skip to content

Commit 11cf148

Browse files
azatmkmkme
authored andcommitted
Merge pull request ClickHouse#86633 from mkmkme/mkmkme/name-dots
Add support for user names in config containing a dot
1 parent 9f759f2 commit 11cf148

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/Access/UsersConfigAccessStorage.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,20 @@ namespace
114114

115115
UserPtr parseUser(
116116
const Poco::Util::AbstractConfiguration & config,
117-
const String & user_name,
117+
String user_name,
118118
const std::unordered_set<UUID> & allowed_profile_ids,
119119
const std::unordered_set<UUID> & allowed_role_ids,
120120
bool allow_no_password,
121121
bool allow_plaintext_password)
122122
{
123123
const bool validate = true;
124124
auto user = std::make_shared<User>();
125-
user->setName(user_name);
126125
String user_config = "users." + user_name;
126+
127+
/// If the user name contains a dot, it is escaped with a backslash when parsed from the config file.
128+
/// We need to remove the backslash to get the correct user name.
129+
Poco::replaceInPlace(user_name, "\\.", ".");
130+
user->setName(user_name);
127131
bool has_no_password = config.has(user_config + ".no_password");
128132
bool has_password_plaintext = config.has(user_config + ".password");
129133
bool has_password_sha256_hex = config.has(user_config + ".password_sha256_hex");

tests/integration/test_dot_in_user_name/__init__.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<clickhouse>
2+
<users>
3+
<default>
4+
<password/>
5+
<networks>
6+
<ip>::/0</ip>
7+
</networks>
8+
<profile>default</profile>
9+
<quota>default</quota>
10+
</default>
11+
<user.name>
12+
<password/>
13+
<networks>
14+
<ip>::/0</ip>
15+
</networks>
16+
<profile>default</profile>
17+
<quota>default</quota>
18+
</user.name>
19+
</users>
20+
<quotas>
21+
<default/>
22+
</quotas>
23+
</clickhouse>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
3+
from helpers.cluster import ClickHouseCluster
4+
5+
cluster = ClickHouseCluster(__file__)
6+
node = cluster.add_instance(
7+
"node",
8+
user_configs=[
9+
"configs/users.xml",
10+
],
11+
)
12+
13+
14+
@pytest.fixture(scope="module", autouse=True)
15+
def started_cluster():
16+
try:
17+
cluster.start()
18+
yield cluster
19+
finally:
20+
cluster.shutdown()
21+
22+
23+
def test_user_with_dot_in_name():
24+
assert node.query("SELECT count()>0 FROM system.users where name = 'user.name'") == "1\n"
25+
assert node.query("SELECT count()>0 FROM system.users where name = 'user\\.name'") == "0\n"
26+
27+
node.query("DROP USER IF EXISTS 'foo.bar'")
28+
node.query("CREATE USER 'foo.bar'")
29+
assert node.query("SELECT count()>0 FROM system.users where name = 'foo.bar'") == "1\n"
30+
assert node.query("SELECT count()>0 FROM system.users where name = 'foo\\.bar'") == "0\n"
31+
32+
node.query("ALTER USER 'foo.bar' RENAME TO 'foo\\.bar'")
33+
assert node.query("SELECT count()>0 FROM system.users where name = 'foo.bar'") == "0\n"
34+
assert node.query("SELECT count()>0 FROM system.users where name = 'foo\\.bar'") == "1\n"
35+
node.query("DROP USER 'foo\\.bar'")

0 commit comments

Comments
 (0)