Database Security and Audting: Application Data Auditing
Database Security and Audting: Application Data Auditing
AND AUDTING
CHAPTER 8
Application Data Auditing
Introduction:
This chapter covers Oracle 10g fundamentals, built-in oracle auditing capabilities.
It also define and implementation of fine-grained auditing and procedure. We also learn
about data manipulation auditing and application error auditing.
Learning objectives:
Understand the difference between the auditing architecture of DML Action
Auditing Architecture and DML changes.
Create and implement Oracle Trigger.
Define and implement Oracle fine-grained auditing
Create a DML statement audit trail for Oracle
Generate a data manipulation history
Implement a DML statement auditing using a repository
Understand the importance and the implementation of application errors auditing
in Oracle
Implement oracle PL/SQL procedure authorization.
Symbols:
`
8.1 DML Action Auditing Architecture
In this section, we introduce Data Manipulation Language (DML) statements from two
approaches. The first approach, we create an audit trail for DML activities that are
occurring on table. The action is recorded before the statement is applied to the table.
The other approach is to register all column values either before or after the DML
statement is applied to the table, as illustrated in figure
Companies with sensitive data often use auditing architecture for DML changes. DML
changes can be performed on two levels: row level and column level. For suppose, when
an UPDATE statement that modifies only one column is appled to a table, the DML
auditing mechanism can record all values for every column in the table. This is called
row-level auditing. If we are interested in recording the values of the modified columns,
we use column-level auditing. Oracle and other database management system refer to this
as fine-grained auditing.
Oracle Triggers
The main database objects are database triggers. This section discusses the
purpose and syntax of trigger. A formal definition of a trigger, a trigger is a stored
PL/SQL procedure that is executed automatically whenever a DML operation occurs or a
specific database event occurs. Oralce has six DML events, also know as trigger timings
for INSERT, UPDATE, and DELETE.
We need to learn the grammer for creating DML statement triggers. We can use the
CREATE TRIGGER statement on a table by following syntax present in the following
example.
Syntax:
CREATE [or REPLACE ] TRIGGER trigger_name
{ BEFORE | AFTER | INSTEAD OF }
{ INSERT [OR] | UPDATE [ OR] | DELETE }
{ OF col_name]
ON table_name
[FOR EACH ROW]
[REFERENCE {OLD [as] old | NEW [AS] new | PARENT [as} parent}]
WHEN (condition)
{ pl/sql_block | call_procedure_statement };
BEFORE: This indicates that the trigger executes before DML statement is applied on the
affected rows.
AFTER: This indicates that the trigger executes after DML statement is applied on the
affected rows.
INSTEAD OF: This is only applicable to DML statements. It indicates that the trigger
should be executed, instead of DML statement
OF: This specifies the columns that the trigger to fire when the column mentioned in this
OF clause is affected. If we omit the OF clause, the trigger fires when any column in the
table is affected by the statement.
ON: this specifies the table that the trigger affects.
FOR EACH ROW: This indicates that the trigger fires for each row affected by the DML
statement.
REFERNCING: when a trigger contains the FOR EACH ROW clause, oracle offers two
pseudo rows, NEW and OLD. These virtual rows contain the new values of each column
in the row and the old value for each column in the row.
WHEN: this specifies the criterion or condition that the trigger must meet to fire.
Example 1
CREATE OR REPLACE TRIGGER TRG_EMPLOYEES_BUR
BEFORE UPDATE ON APP_TBL2
FOR EACH ROW
DELARE
V_OPERATION VARCHAR2(20);
BEGIN
---- comment lines
inserting , updating and deleting
variables that are set to TRUE automatically
by oracle, based on the action DML operation
That fired the trigger. If an INSERT fires
The trigger, then INSERTING is set TRUE and
So forth for the UPDATE and DELETE.
IF INSERTING THEN
V_OPERATION := ‘INSERT’ ;
ELSEIF UPDATING THEN
V_OPERATION := ‘UPDATE’;
ELSE
V_OPERATION := ‘DELETE’;
….
END;
/
We can view all trigger created on a table by using the USER_TRIGGER data dictionary
view. The body of the trigger is contained in the TRIGGER_BODY column
Syntax:
SQL:> DESC USER_TRIGGER
3. Now we need to add the auditing policies as specified previously. We need to use the
ADD_POLICY procedure found in DBMS_FGA. The procedure requires the following
paramerters:
5. As SYS, we must turn on “auditing” on the DML statements, using the audit
SQL> AUDIT SELECT, INSERT, UPDATE, DELETE on SYS.AUD$ BY
ACCESS;
6. Now we need to perform some DML action on the customer table, like insert,
delete, update on CUSTOMERS table.
For script see chap8_sql folder in that chap8_fga_select.sql;
Audit Trail
DML Action Auditing with Oracle
Oracle 10g provides functionality to implement auditing schemes from basic to
advanced. Oracle uses a combination of database objects, such as triggers, tables, and
stored procedures. The purpose of auditing DML statements is to record the data
change occurring on the table, including the name of the person who mad the data
change, the date, and the time of the change. In this model the before or after value of
the columns are not recorded. Figure represents the data model for this. On the left of
the diagram is the DEPARTMENTS table that will contain application data, whereas
the table on the right is the auditing table APP_AUDIT_DATA that will contain audit
trail of all data change operations on the DEPARTMENTS table.
APP_AUDIT_DATA can be used for other tables that need to be audited.
To implement this model, follow these steps
1. Using a user other than SYSTEM or SYS with privileges to create TABLES,
SEQUENCE, and TRIGGER.
2. use DBSEC schema for this creating.
3. create the DEPARTMENTS table
4. create the auditing table APP_AUDIT_DATA
5. create a sequence object that will be used for the AUDIT_DATA_ID colum
APP_AUDIT_DATA table. The sequence will generate unique values.
6. create the trigger on the DEPARTMENTS table that will record the DML
operations that occur on ti.
7. Now we are ready to see what is recorded to insert, modify, or update on the
DEPARTMENTS table.
8. we will insert some rows
9. now update any row
10. now delete any row
11. To view the contents of the auditing table APP_AUDIT_DATA.
A data manipulation history provides a complete trail of all changes that are applied to
data. The history contains either the before or the after value of the data, as well as a
record of the person who made the change and date and time it occurred. The benefit of
such an audit is to reconcile and verify current values.