From c135e7816fb304ae6a4c97627d0905015ae0874f Mon Sep 17 00:00:00 2001 From: TCeason <33082201+TCeason@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:53:00 +0800 Subject: [PATCH] fix(query): fix show user err: auth_string column not fount (#13158) * fix(query): fix show user err: auth_string column not fount * delete auth_string in show doc --- .../00-ddl/30-user/01-user-create-user.md | 30 +++++++++---------- .../00-ddl/30-user/02-user-show-users.md | 8 ++--- .../00-ddl/30-user/03-user-alter-user.md | 30 +++++++++---------- .../doc/14-sql-commands/40-show/show-users.md | 14 ++++----- src/query/sql/src/planner/binder/binder.rs | 2 +- src/query/storages/system/src/users_table.rs | 2 ++ .../base/01_system/01_0001_system_tables | 2 +- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/docs/doc/14-sql-commands/00-ddl/30-user/01-user-create-user.md b/docs/doc/14-sql-commands/00-ddl/30-user/01-user-create-user.md index 2dc2d6a94e6d..284df2f03f2c 100644 --- a/docs/doc/14-sql-commands/00-ddl/30-user/01-user-create-user.md +++ b/docs/doc/14-sql-commands/00-ddl/30-user/01-user-create-user.md @@ -41,11 +41,11 @@ For more information about MySQL authentication plugins, see [A Tale of Two Pass CREATE USER user1 IDENTIFIED BY 'abc123'; SHOW USERS; -+-----------+----------+----------------------+------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-----------+----------+----------------------+------------------------------------------+---------------+ -| user1 | % | double_sha1_password | 6691484ea6b50ddde1926a220da01fa9e575c18a | NO | -+-----------+----------+----------------------+------------------------------------------+---------------+ ++-----------+----------+----------------------+---------------+ +| name | hostname | auth_type | is_configured | ++-----------+----------+----------------------+---------------+ +| user1 | % | double_sha1_password | NO | ++-----------+----------+----------------------+---------------+ ``` ### Creating User with sha256_password auth_type @@ -54,11 +54,11 @@ SHOW USERS; CREATE USER user1 IDENTIFIED WITH sha256_password BY 'abc123'; SHOW USERS; -+-----------+----------+----------------------+------------------------------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-----------+----------+----------------------+------------------------------------------------------------------+---------------+ -| user1 | % | sha256_password | 6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090 | NO | -+-----------+----------+----------------------+------------------------------------------------------------------+---------------+ ++-----------+----------+----------------------+---------------+ +| name | hostname | auth_type | is_configured | ++-----------+----------+----------------------+---------------+ +| user1 | % | sha256_password | NO | ++-----------+----------+----------------------+---------------+ ``` ### Creating User with Network Policy @@ -67,9 +67,9 @@ SHOW USERS; CREATE USER user1 IDENTIFIED BY 'abc123' WITH SET NETWORK POLICY='test_policy'; SHOW USERS; -+-----------+----------+----------------------+------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-----------+----------+----------------------+------------------------------------------+---------------+ -| user1 | % | double_sha1_password | 6691484ea6b50ddde1926a220da01fa9e575c18a | NO | -+-----------+----------+----------------------+------------------------------------------+---------------+ ++-----------+----------+----------------------+---------------+ +| name | hostname | auth_type | is_configured | ++-----------+----------+----------------------+---------------+ +| user1 | % | double_sha1_password | NO | ++-----------+----------+----------------------+---------------+ ``` \ No newline at end of file diff --git a/docs/doc/14-sql-commands/00-ddl/30-user/02-user-show-users.md b/docs/doc/14-sql-commands/00-ddl/30-user/02-user-show-users.md index 97afe7e97c34..58ed9aac0db2 100644 --- a/docs/doc/14-sql-commands/00-ddl/30-user/02-user-show-users.md +++ b/docs/doc/14-sql-commands/00-ddl/30-user/02-user-show-users.md @@ -17,8 +17,8 @@ SHOW USERS; SHOW USERS; --- -| name | hostname | auth_type | auth_string | is_configured | -|---------------------------|----------|----------------------|------------------------------------------|---------------| -| sqluser_johnappleseed | % | double_sha1_password | 147dee8f648a745805ee8dda80bb8e277559f55b | NO | -| johnappleseed@example.com | % | jwt | | NO | +| name | hostname | auth_type | is_configured | +|---------------------------|----------|----------------------|---------------| +| sqluser_johnappleseed | % | double_sha1_password | NO | +| johnappleseed@example.com | % | jwt | NO | ``` \ No newline at end of file diff --git a/docs/doc/14-sql-commands/00-ddl/30-user/03-user-alter-user.md b/docs/doc/14-sql-commands/00-ddl/30-user/03-user-alter-user.md index 0a68ba65c703..749feb5b40bb 100644 --- a/docs/doc/14-sql-commands/00-ddl/30-user/03-user-alter-user.md +++ b/docs/doc/14-sql-commands/00-ddl/30-user/03-user-alter-user.md @@ -31,29 +31,29 @@ ALTER USER WITH UNSET NETWORK POLICY CREATE USER user1 IDENTIFIED BY 'abc123'; SHOW USERS; -+-----------+----------+----------------------+------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-----------+----------+----------------------+------------------------------------------+---------------+ -| user1 | % | double_sha1_password | 6691484ea6b50ddde1926a220da01fa9e575c18a | NO | -+-----------+----------+----------------------+------------------------------------------+---------------+ ++-----------+----------+----------------------+---------------+ +| name | hostname | auth_type | is_configured | ++-----------+----------+----------------------+---------------+ +| user1 | % | double_sha1_password | NO | ++-----------+----------+----------------------+---------------+ ALTER USER user1 IDENTIFIED WITH sha256_password BY '123abc'; SHOW USERS; -+-------+----------+-----------------+------------------------------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-------+----------+-----------------+------------------------------------------------------------------+---------------+ -| user1 | % | sha256_password | dd130a849d7b29e5541b05d2f7f86a4acd4f1ec598c1c9438783f56bc4f0ff80 | NO | -+-------+----------+-----------------+------------------------------------------------------------------+---------------+ ++-------+----------+-----------------+---------------+ +| name | hostname | auth_type | is_configured | ++-------+----------+-----------------+---------------+ +| user1 | % | sha256_password | NO | ++-------+----------+-----------------+---------------+ ALTER USER 'user1' IDENTIFIED WITH no_password; show users; -+-------+----------+-------------+-------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+-------+----------+-------------+-------------+---------------+ -| user1 | % | no_password | | NO | -+-------+----------+-------------+-------------+---------------+ ++-------+----------+-------------+---------------+ +| name | hostname | auth_type | is_configured | ++-------+----------+-------------+---------------+ +| user1 | % | no_password | NO | ++-------+----------+-------------+---------------+ ``` ### Setting & Unsetting Network Policy diff --git a/docs/doc/14-sql-commands/40-show/show-users.md b/docs/doc/14-sql-commands/40-show/show-users.md index 83da6dc6eaa6..51ccae21e33d 100644 --- a/docs/doc/14-sql-commands/40-show/show-users.md +++ b/docs/doc/14-sql-commands/40-show/show-users.md @@ -14,11 +14,11 @@ SHOW USERS ```sql SHOW USERS; -+------+----------+----------------------+------------------------------------------+---------------+ -| name | hostname | auth_type | auth_string | is_configured | -+------+----------+----------------------+------------------------------------------+---------------+ -| root | % | double_sha1_password | 23ae809ddacaf96af0fd78ed04b6a265e05aa257 | YES | -+------+----------+----------------------+------------------------------------------+---------------+ -| test | % | double_sha1_password | 3081f32caef285c232d066033c89a78d88a6d8a5 | NO | -+------+----------+----------------------+------------------------------------------+---------------+ ++------+----------+----------------------+---------------+ +| name | hostname | auth_type | is_configured | ++------+----------+----------------------+---------------+ +| root | % | double_sha1_password | YES | ++------+----------+----------------------+---------------+ +| test | % | double_sha1_password | NO | ++------+----------+----------------------+---------------+ ``` diff --git a/src/query/sql/src/planner/binder/binder.rs b/src/query/sql/src/planner/binder/binder.rs index 342d81b6722c..959fb3de28b9 100644 --- a/src/query/sql/src/planner/binder/binder.rs +++ b/src/query/sql/src/planner/binder/binder.rs @@ -324,7 +324,7 @@ impl<'a> Binder { if_exists: *if_exists, user: user.clone(), })), - Statement::ShowUsers => self.bind_rewrite_to_query(bind_context, "SELECT name, hostname, auth_type, auth_string, is_configured FROM system.users ORDER BY name", RewriteKind::ShowUsers).await?, + Statement::ShowUsers => self.bind_rewrite_to_query(bind_context, "SELECT name, hostname, auth_type, is_configured FROM system.users ORDER BY name", RewriteKind::ShowUsers).await?, Statement::AlterUser(stmt) => self.bind_alter_user(stmt).await?, // Roles diff --git a/src/query/storages/system/src/users_table.rs b/src/query/storages/system/src/users_table.rs index a550705fa83d..c20f2077328c 100644 --- a/src/query/storages/system/src/users_table.rs +++ b/src/query/storages/system/src/users_table.rs @@ -99,6 +99,8 @@ impl AsyncSystemTable for UsersTable { impl UsersTable { pub fn create(table_id: u64) -> Arc { + // QUERY show user is rewrite to `SELECT name, hostname, auth_type, is_configured FROM system.users ORDER BY name` + // If users table column has been modified, need to check the show user query. let schema = TableSchemaRefExt::create(vec![ TableField::new("name", TableDataType::String), TableField::new("hostname", TableDataType::String), diff --git a/tests/sqllogictests/suites/base/01_system/01_0001_system_tables b/tests/sqllogictests/suites/base/01_system/01_0001_system_tables index 5cec82b67c7f..f7b77f8fede7 100644 --- a/tests/sqllogictests/suites/base/01_system/01_0001_system_tables +++ b/tests/sqllogictests/suites/base/01_system/01_0001_system_tables @@ -1,5 +1,5 @@ statement ok -SELECT * from system.tables where name = 'tables' and created_on > '2022-07-01 12:16:58.630 +0000' +SELECT * from system.tables where name = 'tables' and created_on > '2022-07-01 12:16:58.630' query T select * from (select name from system.tables where database='system') where name='tables'