Audit DML Statements

Embed Size (px)

Citation preview

  • 8/11/2019 Audit DML Statements

    1/15

    Copyright 2009, Oracle. All rights reserved.

    Auditing DML Statements

  • 8/11/2019 Audit DML Statements

    2/15

    Copyright 2009, Oracle. All rights reserved.5 - 2

    Objectives

    After completing this lesson, you should be able to do thefollowing:

    Implement fine-grained auditing (FGA)

    Maintain FGA policies

    Implement an FGA audit event handler Read FGA audit events from the FGA audit trail

  • 8/11/2019 Audit DML Statements

    3/15

    Copyright 2009, Oracle. All rights reserved.5 - 3

    Fine-Grained Auditing (FGA)

    Policies: Monitor data access based on content

    Audit SELECT, INSERT, UPDATE, or DELETE

    Are created on tables or views

    May fire an event handler procedure Are administered with the DBMS_FGApackage

    employees

    Policy:AUDIT_EMPS_SALARY

    SELECT name, salaryFROM employees

    WHERE

    department_id = 10;

  • 8/11/2019 Audit DML Statements

    4/15

    Copyright 2009, Oracle. All rights reserved.5 - 4

    FGA Policy

    Defines: Audit criteria

    Audit action

    Is created with

    DBMS_FGA.ADD_POLICY

    dbms_fga.add_policy (

    object_schema => 'hr',

    object_name => 'employees',

    policy_name =>

    'audit_emps_salary',

    audit_condition=>

    'department_id=10',

    audit_column => 'salary',handler_schema => sec',

    handler_module => 'log_emps_salary',

    enable => TRUE,

    statement_types=> 'select' );

    SELECT name, job_id

    FROM employees;

    SELECT name, salary

    FROM employees

    WHERE

    department_id = 10;

    SEC.LOG_

    EMPS_SALARY

    employees FGA audit trail

  • 8/11/2019 Audit DML Statements

    5/15

    Copyright 2009, Oracle. All rights reserved.5 - 6

    Triggering Audit Events

    The following SQL statements cause an audit:

    The following statement does not cause an audit:

    SELECT count(*)

    FROM hr.employees

    WHERE department_id = 10

    AND salary > &v_salary;

    SELECT salaryFROM hr.employees;

    SELECT last_nameFROM hr.employees

    WHERE department_id = 10;

  • 8/11/2019 Audit DML Statements

    6/15

    Copyright 2009, Oracle. All rights reserved.5 - 7

    Data Dictionary Views

    All FGA policies in the databaseDBA_AUDIT_POLICIES

    USER_AUDIT_POLICIES

    ALL_AUDIT_POLICIES

    DBA_FGA_AUDIT_TRAIL

    View Name

    All FGA events

    All FGA policies for objects in the current

    user schema

    All FGA policies for objects that the current

    user can access

    Description

  • 8/11/2019 Audit DML Statements

    7/15Copyright 2009, Oracle. All rights reserved.5 - 8

    DBA_FGA_AUDIT_TRAIL

    SQL> SELECT to_char(timestamp, 'YYMMDDHH24MI')2 AS timestamp,3 db_user,4 policy_name,5 sql_bind,6 sql_text7 FROM dba_fga_audit_trail;

    TIMESTAMP DB_USER POLICY_NAME SQL_BIND---------- ------- ----------------- ----------SQL_TEXT-----------------------------------------------0808272222 HR AUDIT_EMPS_SALARY #1(4):1000

    SELECT COUNT(*) FROM HR.EMPLOYEES WHEREDEPARTMENT_ID = 10 AND SALARY > :B1

    0808272222 HR AUDIT_EMPS_SALARYSELECT salaryFROM hr.employees

  • 8/11/2019 Audit DML Statements

    8/15Copyright 2009, Oracle. All rights reserved.5 - 9

    DBMS_FGAPackage

    Use DBMS_FGAto maintain FGA policies. Grant the EXECUTEprivilege only to administrators.

    The DBMS_FGApackage includes the following

    subprograms:

    Drops an audit policyDROP_POLICY

    Enables an audit policyENABLE_POLICY

    Disables an audit policyDISABLE_POLICY

    Creates an audit policy by using the supplied

    predicate as the audit condition

    ADD_POLICY

    Subprogram Description

  • 8/11/2019 Audit DML Statements

    9/15Copyright 2009, Oracle. All rights reserved.5 - 10

    Enabling and Disabling an FGA Policy

    Enable a policy:

    Disable a policy:

    dbms_fga.enable_policy (

    object_schema => 'hr',

    object_name => 'employees',

    policy_name => 'audit_emps_salary' );

    dbms_fga.disable_policy (

    object_schema => 'hr',

    object_name => 'employees',policy_name => 'audit_emps_salary' );

  • 8/11/2019 Audit DML Statements

    10/15Copyright 2009, Oracle. All rights reserved.5 - 11

    Dropping an FGA Policy

    BEGIN

    dbms_fga.drop_policy (

    object_schema => 'hr',

    object_name => 'employees',

    policy_name => 'audit_emps_salary');

    END;

  • 8/11/2019 Audit DML Statements

    11/15Copyright 2009, Oracle. All rights reserved.5 - 12

    FGA Policy Guidelines

    Setting policy parameters Audit conditions

    To audit all statements, use a nullor TRUEcondition.

    If the audit condition syntax is invalid, an ORA-28112 is

    raised when the audited object is accessed. Audit columns

    If audit column is set to null,all columns are audited.

    If the audit column name is valid but incorrect, the wrong

    statements are audited.

  • 8/11/2019 Audit DML Statements

    12/15Copyright 2009, Oracle. All rights reserved.5 - 13

    FGA Policy Errors

    Policy creation errors occur when: The audited table or view does not exist

    The policy already exists; error ORA-28101 is raised

    The audit column does not exist

    Audited SQL statements fail when: The audit condition is invalid

    The event handler does not exist or is invalid

  • 8/11/2019 Audit DML Statements

    13/15Copyright 2009, Oracle. All rights reserved.5 - 14

    Maintaining the Audit Trail

    Maintaining the audit trail must include: Reviewing and storing old records

    Preventing storage problems

    Avoiding loss of records

  • 8/11/2019 Audit DML Statements

    14/15Copyright 2009, Oracle. All rights reserved.5 - 15

    Practice 5 Overview:

    Implementing Fine-Grained Auditing

    This practice covers the following topics: Creating an FGA policy

    Observing audited records in the database audit table

    Creating an FGA policy with an event handler

  • 8/11/2019 Audit DML Statements

    15/15Copyright 2009 Oracle All rights reserved5 16

    Summary

    In this lesson, you should have learned how to: Implement FGA

    Maintain FGA policies

    Implement an FGA audit event handler

    Read FGA audit events from the FGA audit trail