oracle細粒度審計

安佰勝發表於2010-12-28

細粒度審計:

       細粒度審計必須是在CBO模式下才能準確生效,所以統計資訊和優化器的選擇是使用細粒度審計必須要注意的事情。

    細粒度審計 (FGA)(通過 Oracle9i 引入)可以理解為“基於政策的審計”。 就可以使用DBMS_FGA可以對指定的表的SELECT語句進行審計,但是在9i中只能對select語句進行審計,在10g中可以實現對DML的審計功能。FGA 可用於指定生成審計記錄必需的條件:

 

SQL> desc dbms_fga

PROCEDURE ADD_POLICY

 Argument Name                  Type                    In/Out Default?

 ------------------------------ ----------------------- ------ --------

 OBJECT_SCHEMA                  VARCHAR2                IN     DEFAULT

 OBJECT_NAME                    VARCHAR2                IN

 POLICY_NAME                    VARCHAR2                IN

 AUDIT_CONDITION                VARCHAR2                IN     DEFAULT

 AUDIT_COLUMN                   VARCHAR2                IN     DEFAULT

 HANDLER_SCHEMA                 VARCHAR2                IN     DEFAULT

 HANDLER_MODULE                 VARCHAR2                IN     DEFAULT

 ENABLE                         BOOLEAN                 IN     DEFAULT

 STATEMENT_TYPES                VARCHAR2                IN     DEFAULT

 AUDIT_TRAIL                    BINARY_INTEGER          IN     DEFAULT

 AUDIT_COLUMN_OPTS              BINARY_INTEGER          IN     DEFAULT

PROCEDURE DISABLE_POLICY

 Argument Name                  Type                    In/Out Default?

 ------------------------------ ----------------------- ------ --------

 OBJECT_SCHEMA                  VARCHAR2                IN     DEFAULT

 OBJECT_NAME                    VARCHAR2                IN

 POLICY_NAME                    VARCHAR2                IN

PROCEDURE DROP_POLICY

 Argument Name                  Type                    In/Out Default?

 ------------------------------ ----------------------- ------ --------

 OBJECT_SCHEMA                  VARCHAR2                IN     DEFAULT

 OBJECT_NAME                    VARCHAR2                IN

 POLICY_NAME                    VARCHAR2                IN

PROCEDURE ENABLE_POLICY

 Argument Name                  Type                    In/Out Default?

 ------------------------------ ----------------------- ------ --------

 OBJECT_SCHEMA                  VARCHAR2                IN     DEFAULT

 OBJECT_NAME                    VARCHAR2                IN

 POLICY_NAME                    VARCHAR2                IN

 ENABLE                         BOOLEAN                 IN     DEFAULT

 

Dbms_fga包支援對細粒度審計規則的新增、刪除、生效和實效的功能。其中新增規則更加詳細,可以指定規則到很詳細的程度。

該過程有許多引數,具體含義如下:

 

OBJECT_SCHEMA                   對其定義了 FGA 策略的表或檢視的所有者

OBJECT_NAME                     表或檢視的名稱

POLICY_NAME                       策略的名稱,由使用者自定義

AUDIT_CONDITION                 審計條件(謂語動詞),預設全部

AUDIT_COLUMN                     表示審計那些列,預設全部,如果指定列,那麼只有select或者是where指定該列的時候才被審計

HANDLER_SCHEMA              我們還可以規定在策略執行的時候,執行一個指定使用者的儲存過程,這裡是儲存過程的所有者

HANDLER_MODULE              指定這個策略執行的時候,執行的儲存過程的名稱

ENABLE                         是否馬上生效

STATEMENT_TYPES              審計型別INSERT, UPDATE, DELETE, SELECT10g後)

AUDIT_TRAIL                    審計形勢,類似於標準審計引數

AUDIT_COLUMN_OPTS           欄位被審計條件

 

 

SQL> BEGIN

  2  dbms_fga.add_policy( object_schema => 'user_an',

  3                       object_name => 'table_test',

  4                       policy_name => 'polic_tt',

  5                       audit_condition => 'a = 1',

  6                       audit_column => 'b',

  7                       enable => TRUE );

  8  END;

  9  /

規則新增後可以在dba_audit_policies中查詢

 

SQL> desc DBA_AUDIT_POLICIES

 Name                                      Null?    Type

 ----------------------------------------- -------- -----------------

 OBJECT_SCHEMA                             NOT NULL VARCHAR2(30)

 OBJECT_NAME                               NOT NULL VARCHAR2(30)

 POLICY_NAME                               NOT NULL VARCHAR2(30)

 POLICY_TEXT                                        VARCHAR2(4000)

 POLICY_COLUMN                                      VARCHAR2(30)

 PF_SCHEMA                                          VARCHAR2(30)

 PF_PACKAGE                                         VARCHAR2(30)

 PF_FUNCTION                                        VARCHAR2(30)

 ENABLED                                            VARCHAR2(3)

 SEL                                                VARCHAR2(3)

 INS                                                VARCHAR2(3)

 UPD                                                VARCHAR2(3)

 DEL                                                VARCHAR2(3)

 AUDIT_TRAIL                                        VARCHAR2(11)

 POLICY_COLUMN_OPTIONS                              VARCHAR2(11)

 

SQL>  select * from dba_audit_policies;

 

OBJECT_SCH OBJECT_NAM POLICY_NAM POLICY_TEX POLICY_COL PF_SCHEMA  PF_PACKAGE PF_FUNCTIO ENA SEL INS UPD DEL AUDIT_TRAIL POLICY_COLU

---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --- --- --- --- --- ----------- -----------

AN         AA         POLIC_AA   id = 1     ID                                          YES YES NO  NO  NO  DB_EXTENDED ANY_COLUMNS

 

詳細審計結果記錄在Dba_Fga_Audit_Trail

SQL> desc Dba_Fga_Audit_Trail

 Name                                      Null?    Type

 ----------------------------------------- -------- ----------------------------

 SESSION_ID                                NOT NULL NUMBER

 TIMESTAMP                                          DATE

 DB_USER                                            VARCHAR2(30)

 OS_USER                                            VARCHAR2(255)

 USERHOST                                           VARCHAR2(128)

 CLIENT_ID                                          VARCHAR2(64)

 EXT_NAME                                           VARCHAR2(4000)

 OBJECT_SCHEMA                                      VARCHAR2(30)

 OBJECT_NAME                                        VARCHAR2(128)

 POLICY_NAME                                        VARCHAR2(30)

 SCN                                                NUMBER

 SQL_TEXT                                           NVARCHAR2(2000)

 SQL_BIND                                           NVARCHAR2(2000)

 COMMENT$TEXT                                       VARCHAR2(4000)

 STATEMENT_TYPE                                     VARCHAR2(7)

 EXTENDED_TIMESTAMP                                 TIMESTAMP(6) WITH TIME ZONE

 PROXY_SESSIONID                                    NUMBER

 GLOBAL_UID                                         VARCHAR2(32)

 INSTANCE_NUMBER                                    NUMBER

 OS_PROCESS                                         VARCHAR2(16)

 TRANSACTIONID                                      RAW(8)

 STATEMENTID                                        NUMBER

 ENTRYID                                      

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/13177610/viewspace-682702/,如需轉載,請註明出處,否則將追究法律責任。

相關文章