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:
-
END_USER_NAME: The name of the end user or application whose security context was active during the operation. When a token-based payload omits the separate end-user token, the database obtains this name from the database-access token. -
END_USER_SECURITY_CONTEXT_ID: The unique identifier of the end-user security context associated with the operation. You can queryDBA_END_USER_SECURITY_CONTEXTSto view the security context and itsCONTEXT_IDas long as the end-user security context is active in the database. -
APPLICATION_ID: The application ID in the identity and access management (IAM) system, such as Microsoft Entra ID or OCI IAM. This value identifies the application that created the end-user security context; it is not the name of the application identity in the database. -
END_USER_SECURITY_CONTEXT: A JSON document stored as a CLOB in the audit record for theCREATE END USER SECURITY CONTEXTaction. The document describes the security context when it is created. -
END_USER_CONTEXT_ATTRIBUTES: The custom context attributes in JSON format at the time the audited SQL statement executes. Token attributes are recorded inEND_USER_SECURITY_CONTEXTwhen the security context is created and are not included in this column.
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
- The Microsoft Entra ID v1 token contains the claim
"appid": "2edc9c9f-8e1e-4ade-8a4a-cc286ed19099". -
The following statement maps the database application identity
hcmto that client ID.CREATE APPLICATION IDENTITY hcm MAPPED TO 'AZURE_CLIENT_ID=2edc9c9f-8e1e-4ade-8a4a-cc286ed19099'; - The
APPLICATION_IDcolumn records2edc9c9f-8e1e-4ade-8a4a-cc286ed19099.
OCI IAM example
- The OCI IAM token contains the claim
"client_id": "d81e88c61f3e4fe8a8b869f1a81d78b8". -
The following statement maps the database application identity
hcm_iamto that client ID.CREATE APPLICATION IDENTITY hcm_iam MAPPED TO 'IAM_OAUTH_CLIENT_ID=d81e88c61f3e4fe8a8b869f1a81d78b8'; - The
APPLICATION_IDcolumn recordsd81e88c61f3e4fe8a8b869f1a81d78b8.
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:
application_data_roles: Enabled data roles granted to the application, including roles specified by the client and roles enabled by default.end_user_data_roles: Data roles mapped from role claims in the end-user token.database_roles: The flattened list of enabled database roles obtained through the application and the end-user token.attributes: The token and custom context attributes at security context creation.application_id: The application’s ID in the IAM system.
The information recorded depends on how the end user connects:
- For an IAM-managed end user connecting through an application, the security context includes application data roles, user data roles, database roles, and token and custom attributes.
- For a local end user connecting through an application, the security context includes application data roles, database roles, and custom attributes.
- For an IAM-managed end user connecting directly, the security context includes user data roles, database roles, and token attributes.
- For a local end user connecting directly, the security context includes database roles.
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.