oracle默認賬號是沒有限制ip的,這樣的隱患就在於,如果我知道了oracle賬號用戶名密碼,我只要能連接到db,就可以對db進行操作,這樣對於線上的db來說是很危險的,因為有些非dba人員,比如開發人員、測試人員一不小心誤刪除了線上的數據,就慘了,坑太大不敢看。所以查了查,找到一種辦法,在一些重要的表上加觸發器來限制用戶對線上db的表的操作。
如果開全局的sql審計,消耗性能太大,不太合適,想來只有在某些重要的表上做限制,初步解決問題了。
1) 驗證ip:(sys_context('userenv','ip_address')not in('192.168.120.211')
2) 驗證用戶名:selects.USERNAME into v_username from v$session s where s.audsid=(selectuserenv('SESSIONID') from dual) and rownum<2
3) 樣例存儲過程如下:
create or replace triggerpri_stu_test_limit before update or delete or insert on stu.zzz_test DECLARE PRAGMA AUTONOMOUS_TRANSACTION; v_username varchar2(200) default ''; BEGIN select s.USERNAME into v_username from v$session s wheres.audsid=(select userenv('SESSIONID') from dual) and rownum<2; IFdeleting AND (sys_context('userenv','ip_address') not in('192.168.120.211') OR 'stuuser' like v_username) THEN RAISE_APPLICATION_ERROR(-20001, 'can not delete the table '); ELSIF inserting AND (sys_context('userenv','ip_address') not in('192.168.120.211') OR 'stuuser' like v_username) THEN RAISE_APPLICATION_ERROR(-20001, 'can not insert the table '); ELSIF updating AND (sys_context('userenv','ip_address') not in('192.168.120.211') OR 'stuuser' like v_username) THEN RAISE_APPLICATION_ERROR(-20001, 'can not update the table '); END IF; END;
SQL> SQL> insert into stu.zzz_testvalues(3,'zhuren33'); insert into stu.zzz_testvalues(3,'zhuren33') ORA-20001: can not insert the table ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 18 ORA-04088: error during execution oftrigger 'stuuser.PRI_STU_ACCT_LIMIT' SQL> commit; Commit complete SQL> SQL> update stu.zzz_test setremark='zhuren33_up' where id=3; update stu.zzz_test setremark='zhuren33_up' where id=3 ORA-20001: can not update the table ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 22 ORA-04088: error during execution oftrigger 'stuuser.PRI_STU_ACCT_LIMIT' SQL> commit; Commit complete SQL> SQL> delete from stu.zzz_test where id=3; delete from stu.zzz_test where id=3 ORA-20001: can not delete the table ORA-06512: at"stuuser.PRI_STU_ACCT_LIMIT", line 14 ORA-04088: error during execution oftrigger 'stuuser.PRI_STU_ACCT_LIMIT' SQL> commit; Commit complete SQL>
OK增刪改都可以被限制住了,應該暫時解決了問題所在,後續還是有很多問題需要一起解決的。