This commit is contained in:
Nikolay Degterinsky 2023-09-13 03:14:02 +00:00
parent 268c45d900
commit 0998b0bbc7
3 changed files with 20 additions and 3 deletions

View File

@ -14,6 +14,7 @@ ALTER USER [IF EXISTS] name1 [ON CLUSTER cluster_name1] [RENAME TO new_name1]
[, name2 [ON CLUSTER cluster_name2] [RENAME TO new_name2] ...]
[NOT IDENTIFIED | IDENTIFIED {[WITH {no_password | plaintext_password | sha256_password | sha256_hash | double_sha1_password | double_sha1_hash}] BY {'password' | 'hash'}} | {WITH ldap SERVER 'server_name'} | {WITH kerberos [REALM 'realm']} | {WITH ssl_certificate CN 'common_name'}]
[[ADD | DROP] HOST {LOCAL | NAME 'name' | REGEXP 'name_regexp' | IP 'address' | LIKE 'pattern'} [,...] | ANY | NONE]
[VALID UNTIL datetime]
[DEFAULT ROLE role [,...] | ALL | ALL EXCEPT role [,...] ]
[GRANTEES {user | role | ANY | NONE} [,...] [EXCEPT {user | role} [,...]]]
[SETTINGS variable [= value] [MIN [=] min_value] [MAX [=] max_value] [READONLY | WRITABLE] | PROFILE 'profile_name'] [,...]

View File

@ -165,7 +165,7 @@ ClickHouse treats `user_name@'address'` as a username as a whole. Thus, technica
## VALID UNTIL Clause
Allows you to specify the expiration date and, optionally, the time for a user. It accepts a string as a parameter. It is recommended to use the `YYYY-MM-DD [hh:mm:ss] [timezone]` format for datetime.
Allows you to specify the expiration date and, optionally, the time for user credentials. It accepts a string as a parameter. It is recommended to use the `YYYY-MM-DD [hh:mm:ss] [timezone]` format for datetime. By default, this parameter equals `'infinity'`.
Examples:

View File

@ -1,4 +1,6 @@
import pytest
from datetime import datetime, timedelta
from time import sleep
from helpers.cluster import ClickHouseCluster
@ -32,7 +34,7 @@ def test_basic(started_cluster):
)
assert node.query("SELECT 1", user="user_basic") == "1\n"
# 3. With invalid VALID UNTIL
# 3. With expired VALID UNTIL
node.query("ALTER USER user_basic VALID UNTIL '06/11/2010 08:03:20 Z+3'")
assert (
@ -48,6 +50,20 @@ def test_basic(started_cluster):
assert node.query("SHOW CREATE USER user_basic") == "CREATE USER user_basic\n"
assert node.query("SELECT 1", user="user_basic") == "1\n"
node.query("DROP USER user_basic")
# 5. Make VALID UNTIL expire
until_datetime = datetime.today() + timedelta(0, 10)
until_string = until_datetime.strftime("%Y-%m-%d %H:%M:%S")
node.query(f"CREATE USER user_basic VALID UNTIL '{until_string}'")
assert node.query("SELECT 1", user="user_basic") == "1\n"
sleep(12)
error = "Authentication failed"
assert error in node.query_and_get_error("SELECT 1", user="user_basic")
def test_details(started_cluster):
@ -64,5 +80,5 @@ def test_details(started_cluster):
assert (
node.query("SHOW CREATE USER user_details_time_only")
== "CREATE USER user_details_time_only VALID UNTIL \\'2000-01-01 22:03:40\\'\n"
== "CREATE USER user_details_time_only VALID UNTIL \\'2023-01-01 22:03:40\\'\n"
)