1. 程式人生 > 其它 >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. 引數配置

  • sys_audlog.error_user_connect_times
    允許使用者連續登入失敗的最大次數,使用者登入失敗的次數大於超過該值,使用者自動鎖定,取值範圍為[0,INT_MAX],預設為 0。
    設定密碼連續最大失敗次數為 10。
\c test sso
ALTER SYSTEM SET sys_audlog.max_error_user_connect_times = 10;
CALL sys_reload_conf();
  • sys_audlog.max_error_user_connect_times
    使用者登入失敗次數的最大值界限,error_user_connect_times的最大取值,取值範圍為[0,INT_MAX],預設為 2147483647。
    設定密碼連續最大失敗次數為 6。
\c test sso
ALTER SYSTEM SET sys_audlog.error_user_connect_times = 6;
CALL sys_reload_conf();
  • sys_audlog.error_user_connect_interval
    使用者被鎖定時間,若使用者被鎖定的時間超過了該引數,則該使用者可自動解鎖。單位是分鐘,取值範圍為[0,INT_MAX],0時關閉自動解鎖功能,需手動解鎖,預設為 0。
    設定被封鎖使用者的自動解封時間為 1 小時。
\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)既定的策略。