其他分享
首页 > 其他分享> > KingbaseES V8R6 账号异常登录锁定案例

KingbaseES V8R6 账号异常登录锁定案例

作者:互联网

数据库版本:

test=> select version();
                                                       version                                                    
    
-----------------------------------------------------------------------------------------------------------
 KingbaseES V008R006C005B0054 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

官方文档:https://help.kingbase.com.cn/stage-api/profile/document/kes/v8r6/html/safety/safety-guide/safety-identification.html#id9
帐户异常登录锁定
帐户异常登录锁定是指如果用户连续若干次不能正确的登录数据库,那么这个用户的帐户将被系统禁用。系统允许的用户连续错误登录次数由数据库管理员指定。被禁用的帐户可以由安全员利用 SQL 命令使其重新可用或者等待一段时间自动解锁。
KingbaseES通过插件的方式来进行帐户异常登录锁定以及账户登录信息显示。这种方式更为灵活,当数据库的实用场景需要进行帐户异常登录锁定以及账户登录信息显示时,加载插件即可。而不需要该功能时,卸载插件即可。
插件名为sys_audlog,相关参数由数据库安全员负责配置。
3.3.1. 加载插件
修改 kingbase.conf 文件中 shared_preload_libraries 参数。

shared_preload_libraries = 'sys_audlog'
create extension sys_audlog;

3.3.2. 参数配置

\c test sso
ALTER SYSTEM SET sys_audlog.max_error_user_connect_times = 10;
CALL sys_reload_conf();
\c test sso
ALTER SYSTEM SET sys_audlog.error_user_connect_times = 6;
CALL sys_reload_conf();
\c test sso
ALTER SYSTEM SET sys_audlog.error_user_connect_interval = 60;
CALL sys_reload_conf();

3.3.3. 解除锁定
超过时间间隔自动解除用户封锁。
用户可由具有alter user权限的用户通过SQL语句进行手动解锁,解锁后用户登录的信息自动删除。

\c test sso
alter user username with login;

Tip
1.超过时间间隔后自动解锁用户需要登录成功,若达到解锁时间后重新登录且再次失败,用户会继续锁定。
2.登录时若不加-W时会自动进行一次不带密码的登录尝试,因此会多增加一次失败记录,且在解锁用户时使用不加-W的方式登录,会导致再次被锁定,因此在解锁用户时注意加-W参数进行登录尝试。

测试案例:

1、配置kingbase.conf和sys_hba.conf

配置kingbase.conf:(加载extension)

[kingbase@node1 data]$ cat kingbase.conf |grep sys_audlog
shared_preload_libraries = 'liboracle_parser, synonym, plsql, force_view, kdb_flashback,plugin_debugger, plsql_plugin_debugger, plsql_plprofiler, ora_commands,kdb_ora_expr, sepapower, dblink, sys_kwr, sys_ksh, sys_spacequota, sys_stat_statements, backtrace, kdb_utils_function, auto_bmr, sys_squeeze,sys_audlog'

配置sys_hba.conf:

=默认,local(本地)登录,不对用户身份进行认证,使用trust。=

# Allow replication connections from localhost, by a user with the
local   all             all                                     scram-sha-256

2、重新启动数据库后,sso用户配置相关参数

[kingbase@node1 bin]$ ./ksql -U sso test -p 54322
ksql (V8.0)
Type "help" for help.

test=> show sys_audlog.error_user_connect_interval ;
 sys_audlog.error_user_connect_interval 
----------------------------------------
 0
(1 row)

test=> show sys_audlog.error_user_connect_times;  
 sys_audlog.error_user_connect_times 
-------------------------------------
 0
(1 row)

test=> alter system set sys_audlog.error_user_connect_times=5; 
ALTER SYSTEM

test=> alter system set sys_audlog.error_user_connect_interval =3;
ALTER SYSTEM

test=> select sys_reload_conf();
 sys_reload_conf 
-----------------
 t
(1 row)

test=> show sys_audlog.error_user_connect_times;
 sys_audlog.error_user_connect_times 
-------------------------------------
 5
(1 row)

test=> show sys_audlog.error_user_connect_interval;   
 sys_audlog.error_user_connect_interval 
----------------------------------------
 3
(1 row)

3、创建用户测试

test=# create user tom with password 'tom';  
CREATE ROLE
test=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 sao       | No inheritance                                             | {}
 sso       | No inheritance                                             | {}
 system    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 tom       |                                                            | {}

4、用户登录测试

[kingbase@node1 bin]$ ./ksql -U tom -W test -p 54322
Password: 
ksql: error: could not connect to server: FATAL:  password authentication failed for user "tom"
NOTICE:  This is the 1 login failed. There are 4 left.

[kingbase@node1 bin]$ ./ksql -U tom -W test -p 54322
Password: 
ksql: error: could not connect to server: FATAL:  password authentication failed for user "tom"
NOTICE:  This is the 2 login failed. There are 3 left.

[kingbase@node1 bin]$ ./ksql -U tom -W test -p 54322
Password: 
ksql: error: could not connect to server: FATAL:  password authentication failed for user "tom"
NOTICE:  This is the 3 login failed. There are 2 left.

[kingbase@node1 bin]$ ./ksql -U tom -W test -p 54322
Password: 
ksql: error: could not connect to server: FATAL:  password authentication failed for user "tom"
NOTICE:  This is the 4 login failed. There are 1 left.

[kingbase@node1 bin]$ ./ksql -U tom -W test -p 54322
Password: 
ksql (V8.0)
Type "help" for help.

4、测试总结:
在KingbaseES V008R006C005B0054测试中,账号锁定符合参数(sys_audlog.error_user_connect_times)既定的策略。

标签:V8R6,账号,sys,user,error,test,KingbaseES,audlog,connect
来源: https://www.cnblogs.com/kingbase/p/16265840.html