大數據“復活”記
1152
2025-03-31
數據庫安全對數據庫系統來說至關重要。GaussDB(DWS)將用戶對數據庫的所有操作寫入審計日志。數據庫安全管理員可以利用這些日志信息,重現導致數據庫現狀的一系列事件,找出非法操作的用戶、時間和內容等。設置數據庫審計可參考產品文檔中設置數據庫審計日志章節。建議用戶在使用時合理配置審計項,對于一些數據敏感的業務和場景,強烈建議打開對表的DDL和DML審計。
說明:本帖中涉及的數據和用戶信息均為測試環境信息。
1. 審計日志保存和轉儲
目前,常用的審計日志保存方式為記錄到表中和記錄到OS文件中兩種方式。但是表是數據庫對象,如果采用記錄到表中的方式,容易出現用戶非法操作審計表的情況,審計記錄的準確性難以保證,因此,從數據庫安全角度出發,GaussDB(DWS)采用記錄到OS文件的方式來保存審計結果,保證了審計結果的可靠性。
由于審計日志會占用一定磁盤空間,為了防止本地文件過大,GaussDB(DWS)支持審計日志轉儲,具體方法可參考轉儲數據庫審計日志章節。
審計日志有兩種保存策略,由參數audit_resource_policy控制:
● on表示采用空間優先策略,最多存儲audit_space_limit大小的日志。
● off表示采用時間優先策略,最少存儲audit_file_remain_time長度時間的日志。
2. 審計日志查看
首先要確保當前審計總開關audit_enabled和對應的審計項開關均已開啟(表的DML操作審計由audit_dml_state控制,默認關閉,如需查看表上的dml操作,需提前打開該開關,同時,建議審計日志保留策略audit_resource_policy設置為on)。
只有擁有AUDITADMIN屬性的用戶才可以查看審計記錄,審計日志需通過數據庫接口pg_query_audit和pgxc_query_audit查看。pg_query_audit可以查看當前CN的審計日志,pgxc_query_audit可以查看所有CN的審計日志,使用時一般用pgxc_query_audit接口查看審計。二者函數原型為:
pg_query_audit(timestamptz startime,timestamptz endtime, audit_log) pgxc_query_audit(timestamptz startime,timestamptz endtime)
其中,startime和endtime表示查看審計記錄的開始時間和結束時間,滿足審計條件的記錄為startime ≤ 審計記錄時間 < endtime;audit_log表示所查看的審計日志信息所在的物理文件路徑,當不指定audit_log時,默認查看連接當前實例的審計日志信息。
函數返回的字段如下:
用戶可以根據type類型或object_name對審計結果進行過濾,根據需要查看。
常見的審計操作類型為:
unknown
login_success
login_failed
user_logout
system_start
system_stop
system_recover
system_switch
lock_user
unlock_user
grant_role
revoke_role
user_violation
ddl_database
ddl_directory
ddl_tablespace
ddl_schema
ddl_user
ddl_table
ddl_index
ddl_view
ddl_trigger
ddl_function
ddl_resourcepool
ddl_workload
ddl_serverforhadoop
ddl_datasource
ddl_nodegroup
ddl_rowlevelsecurity
ddl_synonym
ddl_type
ddl_textsearch
dml_action
dml_action_select
internal_event
function_exec
copy_to
copy_from
set_parameter
3. 審計日志使用示例
示例1:用戶被鎖,報錯:FATAL: ?The account has been locked,如何查看用戶被鎖的原因:
postgres=# select * from pgxc_query_audit('20201230 18:00:00',current_timestamp) where type = 'login_failed'; time | type | result | username | database | client_conninfo | object_name | detail_info | node_name | thread_id | local_port | remote_port ------------------------+--------------+--------+----------+----------+--------------------------+-------------+---------------------------------------------------------------+--------------+---------------------------------+------------+------------- 2020-12-30 18:59:07+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641147918967 | 32000 | 49687 2020-12-30 18:59:11+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641151174956 | 32000 | 49689 2020-12-30 18:59:13+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641153871953 | 32000 | 49691 2020-12-30 18:59:16+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641156887905 | 32000 | 49692 2020-12-30 18:59:20+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641160061866 | 32000 | 49696 2020-12-30 18:59:23+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641163187840 | 32000 | 49698 2020-12-30 18:59:25+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641165671562 | 32000 | 49699 2020-12-30 18:59:28+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641168137151 | 32000 | 49700 2020-12-30 18:59:31+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641171124971 | 32000 | 49702 2020-12-30 18:59:33+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,authentication for user(doubi)failed | coordinator1 | 140508124395264@662641173650325 | 32000 | 49858 2020-12-30 18:59:36+08 | login_failed | failed | doubi | postgres | [unknown]@10.144.118.217 | postgres | login db(postgres)failed,the account(doubi)has been locked | coordinator1 | 140508124395264@662641176080044 | 32000 | 51402 (11 rows)
根據審計結果可以看到,IP為10.144.118.217的用戶連續輸入密碼錯誤超過10次,導致doubi賬戶被鎖。
示例2:某張表數據為空,通過審計日志查看在該表上的操作(前提:已打開表的DML和DDL審計):
postgres=# select * from pgxc_query_audit('20201230 19:15:00',current_timestamp) where object_name = 't1'; time | type | result | username | database | client_conninfo | object_name | detail_info | node_name | thread_id | local_port | remote_port ------------------------+------------+--------+----------+----------+----------------------------+-------------+-------------------------------------------------+--------------+---------------------------------+------------+------------- 2020-12-30 19:16:40+08 | dml_action | ok | dbadmin | postgres | Data Studio@10.144.118.217 | t1 | insert into t1 values (1,2) | coordinator1 | 140722584413952@662642200541821 | 32000 | 50437 2020-12-30 19:17:01+08 | dml_action | ok | dbadmin | postgres | Data Studio@10.144.118.217 | t1 | insert into t1 values (generate_series(1,10),2) | coordinator1 | 140722584413952@662642200541821 | 32000 | 50437 2020-12-30 19:17:11+08 | dml_action | ok | dbadmin | postgres | Data Studio@10.144.118.217 | t1 | delete from t1 | coordinator1 | 140722584413952@662642200541821 | 32000 | 50437 (3 rows)
通過審計日志可以看到,19:17:01 時刻,IP為10.144.118.217的用戶通過Data Studio客戶端向t1表中插入了數據,19:17:11 時該用戶又對該表執行了delete操作導致數據為空。
EI企業智能 Gauss AP 數據倉庫服務 GaussDB(DWS)
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。