Audit End-User Activity

Just as you audit regular database users, you can configure audit policies for operations such as SELECT, INSERT, UPDATE, and DELETE to capture the actions performed by Oracle Deep Data Security (Deep Sec) end users.

The following columns in UNIFIED_AUDIT_TRAIL describe the end user and the security context associated with an audited operation:

The following examples show how each database application identity maps to the client ID in the application’s database-access token. The APPLICATION_ID column records that client ID.

Microsoft Entra ID example

OCI IAM example

For more information, see Create Application Identity.

Deep Sec audit records use the Standard audit type. For audited operations performed in an end-user security context, END_USER_NAME and END_USER_SECURITY_CONTEXT_ID identify the end user and the security context. APPLICATION_ID and END_USER_CONTEXT_ATTRIBUTES provide the application ID and custom attributes, as applicable. These details enable you to trace end-user activity even when multiple users share a database connection through a connection pool.

END_USER_SECURITY_CONTEXT is populated in the audit record for security context creation, rather than in each subsequent operation’s audit record.

The APPLICATION_ID, END_USER_SECURITY_CONTEXT, and END_USER_CONTEXT_ATTRIBUTES columns are available starting with Oracle AI Database 26ai, Release Update 23.26.4.

Note: Deep Sec configuration actions (such as CREATE END USER or CREATE DATA GRANT) are performed by database administrators, not end users. These actions do not populate the END_USER_NAME or END_USER_SECURITY_CONTEXT_ID columns in the audit trail.

Review Failed Operations

You can use the END_USER_NAME column to filter for operations performed in an end-user security context.

Failed access attempts in the audit trail are particularly valuable to review. They typically indicate misconfigured data grants, missing role assignments, or incorrect security context attributes. They can also point to malicious attempts by end users to access data outside their authorization.

The following query returns failed operations performed in an end-user security context:

SELECT SQL_TEXT,
       END_USER_NAME,
       END_USER_SECURITY_CONTEXT_ID,
       APPLICATION_ID,
       END_USER_CONTEXT_ATTRIBUTES,
       ACTION_NAME,
       OBJECT_NAME,
       RETURN_CODE
  FROM UNIFIED_AUDIT_TRAIL
 WHERE END_USER_NAME IS NOT NULL
   AND RETURN_CODE <> 0;

Use END_USER_CONTEXT_ATTRIBUTES in an operation’s audit record to examine the custom attributes at statement execution time. Changes made through the client driver or by updating the custom end-user context are reflected in this column on subsequent audited operations.

Note: END_USER_CONTEXT_ATTRIBUTES has datatype VARCHAR2(4000). If the JSON representation of the custom context attributes exceeds the column’s size limit, the column contains a JSON error object instead of the attribute values.

Examine the Associated Security Context

To investigate an operation recorded in the audit trail, examine the roles and attributes recorded when its end-user security context was created. Use END_USER_SECURITY_CONTEXT_ID to associate the operation’s audit record with the security context creation record. Custom attributes can change after security context creation, so use the operation’s END_USER_CONTEXT_ATTRIBUTES value to examine those attributes at statement execution time.

To audit end-user security context creation, explicitly include CREATE END USER SECURITY CONTEXT in an audit policy and enable the policy.

The following example creates and enables an audit policy for CREATE END USER SECURITY CONTEXT. Specify this action explicitly because ACTIONS ALL excludes it.

CREATE AUDIT POLICY deep_sec_context_pol
  ACTIONS CREATE END USER SECURITY CONTEXT;

AUDIT POLICY deep_sec_context_pol;

This policy captures security context creation through a client driver or a direct database connection. To audit subsequent end-user activity, include the required SQL operations in an enabled audit policy.

Example: Retrieve the recorded security context

The following query retrieves audited security context creation records for an end user within a specified time window. Replace the sample END_USER_NAME and the start and end EVENT_TIMESTAMP values with the values you want to query. The creation records must have been audited and retained for the query to return them.

SELECT END_USER_NAME,
       APPLICATION_ID,
       END_USER_SECURITY_CONTEXT_ID,
       END_USER_SECURITY_CONTEXT
  FROM UNIFIED_AUDIT_TRAIL
 WHERE ACTION_NAME = 'CREATE END USER SECURITY CONTEXT'
   AND RETURN_CODE = 0
   AND END_USER_NAME = 'emma.baker@supremo.onmicrosoft.com'
   AND EVENT_TIMESTAMP >= TIMESTAMP '2026-11-23 00:00:00'
   AND EVENT_TIMESTAMP <  TIMESTAMP '2026-11-24 00:00:00'
 ORDER BY EVENT_TIMESTAMP;

The JSON document in END_USER_SECURITY_CONTEXT contains the following information, as applicable:

The information recorded depends on how the end user connects:

Example: List application data roles from the recorded security context

The preceding query returns the complete security context JSON for each matching creation record. To display application data roles as individual rows, use JSON_TABLE as shown in the following example. Replace the sample hexadecimal value with the END_USER_SECURITY_CONTEXT_ID returned for the creation record you want to examine.

SELECT jt.data_role
  FROM UNIFIED_AUDIT_TRAIL a,
       JSON_TABLE(
         a.END_USER_SECURITY_CONTEXT,
         '$.application_data_roles[*]'
         COLUMNS (
           data_role VARCHAR2(128) PATH '$'
         )
       ) jt
 WHERE a.ACTION_NAME = 'CREATE END USER SECURITY CONTEXT'
   AND a.RETURN_CODE = 0
   AND a.END_USER_SECURITY_CONTEXT_ID =
       HEXTORAW('54847C891ABEDDB7E06314955E6477DE');

To list data roles mapped from the end-user token, replace $.application_data_roles[*] with $.end_user_data_roles[*].

For a complete description of the UNIFIED_AUDIT_TRAIL view and its columns, see UNIFIED_AUDIT_TRAIL in Oracle AI Database Reference.