End-User Security Context Issues
Troubleshoot issues with establishing end-user security contexts.
Topics:
End-User Security Context Not Attached to Session
If the database session does not reflect the end user’s identity, the end-user security context may not have been established.
Issue description
The following query returns an empty JSON object ({}) instead of the expected end-user identity (the upn claim for Entra ID tokens, the sub claim for OCI IAM tokens, or the claim specified by username_claim for the configurable OAuth 2.0 provider):
SELECT ORA_END_USER_CONTEXT.username FROM dual;
Probable causes
-
A valid end-user security context has not been established. The session operates under standard database privileges and bypasses Oracle Deep Data Security (Deep Sec) enforcement.
-
For direct logon with external end users (OCI IAM or Microsoft Entra ID), the same end user is enabled for both Deep Sec direct logon and database global-user authentication. This happens when the user falls under a data-role mapping (the
MAPPED TOclause of a data role) and also under a database global-user mapping (anIDENTIFIED GLOBALLY ASclause that resolves to a database schema). In this situation, global-user authentication takes precedence. The session connects as the database global user, runs with that schema’s privileges, and an end-user security context is not established.
Resolution procedures
- Review the database and application configuration. See Configure the Database.
-
For IAM direct logon scenarios, check whether the affected end user is also mapped to a database global user through an
IDENTIFIED GLOBALLY ASclause. If so, remove or alter that mapping so the end user is governed by Deep Sec alone, then start a new session and confirm thatORA_END_USER_CONTEXT.usernamereturns the expected end-user identity. - If the issue persists, enable diagnostic tracing and examine the trace output. See Enable Diagnostic Tracing.
Invalid Database-Access Token
If the database rejects a database-access token during security context payload attachment, the token’s audience claim may not match the database’s identity provider configuration.
Issue description
When the application attempts to attach an end-user security context payload to the database session, the database raises the following error:
Invalid database-access token in the end-user security context: Failed to verify claims
Probable cause
The audience claim in the database-access token does not match the corresponding field in the database’s identity provider configuration.
Resolution procedure
-
Decode the database-access token (for example, using a JSON Web Token (JWT) decoder) and inspect the audience (
aud) claim. -
For Entra ID
v1tokens, verify that the token’saudclaim matches theapplication_id_urifield in the database’sIDENTITY_PROVIDER_CONFIG. Forv2tokens, verify that it matches theapp_idfield. -
For OCI IAM identity domain tokens:
-
Confirm that a credential named
OCI_IAM_DOMAIN_DB_CRED$has been created using theDBMS_CREDENTIAL.CREATE_CREDENTIALprocedure. -
Confirm that the
app_idfield inIDENTITY_PROVIDER_OAUTH_CONFIGmatches the token’sresource_app_idclaim. -
Confirm that the
domain_urlinIDENTITY_PROVIDER_OAUTH_CONFIGmatches the token’stenant_issclaim.
-
-
For the configurable OAuth 2.0 provider, verify that the database-access token’s
audclaim matches audience inIDENTITY_PROVIDER_CONFIG. Ifaudis an array, at least one value must match. -
Correct any mismatched configuration values in the database’s identity provider settings, and retry the
setEndUserSecurityContextcall from the application.
Data Role in the Database Is Not Mapped to IAM Application Role
If an IAM application role present in the access token does not activate the expected data role in an end-user security context, the role mapping in the database may be missing or incorrectly formatted.
Issue description
The IAM access token contains a valid application role, but after the application calls setEndUserSecurityContext, the corresponding data role does not appear in the V$END_USER_DATA_ROLE view. Consequently, the end user does not have the expected data access privileges.
Probable cause
There is no data role in the database that is mapped to the application role in the IAM token.
Note: The database does not raise an error when a role mapping is missing. Instead, it silently ignores the unmapped role and logs a warning in the database trace file (if tracing is enabled).
Resolution procedure
-
Decode the access token to identify the exact application roles present in the token’s claims.
-
Query the
DBA_DATA_ROLESview for the data role that was expected to be enabled, and check itsMAPPED_TOvalue. -
Depending on your token provider, ensure the
MAPPED_TOstring matches the correct format.-
For Microsoft Entra ID tokens, the mapping must use one of the following formats:
'AZURE_APP=<access_token_aud_claim>:AZURE_ROLE=<azure_role>'or
'AZURE_ROLE=<azure_role>'Context: The database first checks for the
AZURE_APPprefix. If it is not present, it defaults to checkingAZURE_ROLE. The optionalAZURE_APPprefix uses the token’s audience claim to distinguish between identically named application roles defined in different application registrations. -
For Oracle Cloud Infrastructure (OCI) IAM tokens, the mapping must use the following format:
'IAM_OAUTH_GROUP=<oci_iam_group_name>'Context: In an OCI IAM identity domain use case, an application identifier prefix is not needed because the group is shared across applications within the same domain, and the database can only configure a single domain.
-
For the configurable OAuth 2.0 provider, use
ROLE=<realm_role_name>. Verify that the realm role appears in the top-level array claim specified byroles_claiminIDENTITY_PROVIDER_CONFIG. The default claim name isroles.
-
-
Alter the data role definition to correct any missing or mismatched
MAPPED_TOvalues. -
Establish a new session (or detach and re-attach the end-user security context) and query
V$END_USER_DATA_ROLEto verify that the data role is now active.
Data Role Granted to an Application Is Not Enabled
If a data role granted to an application does not take effect after the end-user security context is established, the application identity mapping or the default enablement setting on the role grant may be incorrect.
Issue description
A data role granted to an application does not appear in the V$END_USER_DATA_ROLE view after the end-user security context is established. End users connecting through the application do not inherit the data role’s privileges.
Probable causes
-
The application name in the database is mapped to an incorrect IAM client ID.
-
The data role granted to the application is not configured to be enabled by default.
Resolution procedure
-
Decode the database-access token to locate the application identity claim. The specific claim depends on your token type:
-
Entra ID
v1tokens: Look for theappidclaim. -
Entra ID
v2tokens: Look for theazpclaim. -
OCI IAM client credentials tokens: Look for the
client_idclaim. -
Configurable OAuth 2.0 provider: Look for the claim specified by
application_id_claiminIDENTITY_PROVIDER_CONFIG.
-
-
Query the
DBA_APPLICATION_IDENTITIESview to inspect theMAPPED_TOcolumn for the row corresponding to your application. -
Validate and correct the mapping format based on your token provider.
-
For Entra ID tokens (
v1andv2), verify the mapping matches the following format, where<ENTRA_ID_APP_ID>is the value of theappidorazpclaim:'AZURE_CLIENT_ID=<ENTRA_ID_APP_ID>' Example: 'AZURE_CLIENT_ID=2edc9c9f-8e1e-4ade-8a4a-cc286ed1b899' -
For OCI IAM tokens, verify the mapping matches the following format, where
<OCI_IAM_CLIENT_ID>is the value of theclient_idclaim:'IAM_OAUTH_CLIENT_ID=<OCI_IAM_CLIENT_ID>' Example: 'IAM_OAUTH_CLIENT_ID=e83a43ac80d94637bb1958b06929ac32' -
For the configurable OAuth 2.0 provider, verify that the mapping uses
CLIENT_ID=<client_id>, where<client_id>is the application’s client identifier found in step 1.CLIENT_ID=ords_client
-
-
Alter the application identity definition to correct any misconfigurations in the
MAPPED_TOvalue. -
Verify the data role grant configuration. Ensure the data role granted to the application is enabled by default. If it is not enabled by default, you must either alter the role grant to enable it or explicitly pass it in the
EndUserSecurityContextpayload’s optional data roles list. -
Establish a new session (or detach and re-attach the end-user security context) and query
V$END_USER_DATA_ROLEto verify the data role is now enabled.
ORA-00406 Error When Querying End-User Context
If querying ORA_END_USER_CONTEXT raises a COMPATIBLE parameter error, the database instance may be running at a compatibility level that does not support this feature.
Issue description
After an end-user security context has been established, running the following query raises an error:
SQL> SELECT ORA_END_USER_CONTEXT.username FROM dual;
ERROR at line 1:
ORA-00406: COMPATIBLE parameter needs to be 20.0 or greater
Probable cause
The database instance’s COMPATIBLE initialization parameter is set to a value lower than 20.0.
Resolution procedure
-
Check the current value of the
COMPATIBLEinitialization parameter:SHOW PARAMETER compatible; -
If the value is below 20.0, update the initialization parameter to 20.0 or higher. Consult the Oracle AI Database Upgrade Guide for the procedure to modify this parameter.