How the Database Server Manages an End-User Security Context

When a client driver sends an EndUserSecurityContext payload during a SQL operation, or when a principal logs on directly, the database server automatically executes the steps described in this section.

Use the information provided here for reference and diagnostic purposes; no administrator action is required during this process.

Scenario 1: Token-Based (IAM-Managed) Principal

If your end users or applications authenticate using OAuth 2.0 access tokens issued by IAM (such as Microsoft Entra ID or OCI IAM), the database must validate these tokens to ensure that the request originates from a trusted source.

This scenario has the following three variants, depending on how an end user or application connects to the database:

Scenario 1a — Through an application

This flow triggers when your application sends the EndUserSecurityContext payload using a client driver. The payload contains a database-access token and, optionally, an IAM-issued end-user token.

Scenario 1b — Direct logon as the end user

If your users require direct SQL access without an application, they can log in using their end-user token. When a user presents an end-user token for direct logon, the database first looks for a standard schema mapped to that user. If no schema match is found, the server executes the direct-logon flow. It performs the following tasks:

  1. Matches data roles: The server retrieves all the data roles whose MAPPED TO clause matches the role claims inside the end-user token.

  2. Retrieves database roles: For every matching data role, the server retrieves all standard database roles granted to it.

  3. Evaluates privileges and establishes security context: If any of those database roles contain the CREATE SESSION privilege, the server permits the direct logon and establishes the end-user security context with those data roles active.

    With direct logon, the end-user security context is destroyed when the database session closes.

Note:

About OCI IAM auth token sessions

For OCI IAM, a session can be established with an OCI IAM auth token, scoped to the end user and supplied by the end user’s client, instead of OAuth 2.0 tokens. The database validates the token at runtime by calling OCI IAM (the identity data plane, IDDP), not by checking the aud claim as it does for an OAuth 2.0 token. It then resolves data roles from the end user’s OCI IAM groups mapped with IAM_GROUP_NAME. If no mapped global database user or application identity of the same name as the connecting user exists, and a resolved data role carries the CREATE SESSION privilege through a granted database role, the database permits the session creation as a direct logon of the end user and establishes the end-user security context. The security context can then enforce data grants without requiring a mapped database schema for the end user.

An OCI IAM auth token is a scoped proof-of-possession token issued by OCI IAM for database authentication. See Key Terminology.

Scenario 1c — Direct logon as the application identity

If an application or AI agent connects directly as its own application identity, the database establishes an end-user security context whose identity is the application identity itself. The server performs the following steps:

  1. Validates the database-access token: The application authenticates to IAM with its client credentials and presents a database-access token that identifies the application and includes the database as its audience. The server checks the token’s signature and expiration and validates the aud claim. For the configurable OAuth 2.0 provider, the application’s client identifier comes from the claim specified by application_id_claim and can differ from sub.

  2. Resolves the application identity: The server looks for a global schema mapped to the token subject. If no mapped schema exists, the server looks for a database application identity mapped to the token’s application client ID, and creates a schema-less lightweight session for the application identity.

  3. Establishes the security context: The server establishes an end-user security context whose identity is the application identity. It activates the data roles granted directly to the application identity, together with the data roles mapped to the application’s IAM roles. SQL executed on the connection is enforced according to those data roles, so the application retrieves only the data its application identity is authorized to access. The application identity must hold the CREATE SESSION and CREATE END USER SECURITY CONTEXT privileges, granted through a data role. When the connection closes, the database destroys the application identity’s lightweight session and its security context.

    If the application later attaches an end user’s security context payload to this session, the database replaces the application identity’s security context with the end user’s security context and manages this security context as described in Scenario 1a. When the end user’s security context is detached, the server reattaches the original application identity security context.

Note:

Oracle Deep Data Security (Deep Sec) session behavior

Scenario 2: Locally Managed End User

When end users are managed locally (with no IAM system involved), the database server resolves the end-user identity and data roles entirely within the database.

This scenario has the following two variants, depending on how an end user connects to the database:

Scenario 2a — Through an application

This flow triggers when your application sends the EndUserSecurityContext payload using a client driver. The payload contains an end-user name, an optional security context lookup key, a database-access token, and any valid application-supplied data roles. Behind the scenes, the database server performs the following steps:

  1. Verifies the local application user: The server checks if a local end user matching the user name in the EndUserSecurityContext payload exists in the database. If no match is found, the server raises an error.

  2. Searches for an existing security context: If the end user is present, the server looks for an existing end-user security context that matches the provided security context lookup key.

  3. Creates a new security context (if necessary): If no matching security context exists, the server creates a new one using the local end user’s identity and their explicitly granted data roles.

  4. Attaches the security context: Finally, the server attaches the security context (along with any provided end-user context attributes) to the active session.

  5. Handles security context attach, detach, and cleanup: The database automatically manages the detachment and reattachment of an end-user security context to a database session through the following mechanisms:

    • Connection release: When your application code releases the connection, the security context is detached from the database session.

    • Security context replacement: When your application reuses a connection, the database seamlessly replaces the previous security context with the new one. If the incoming request does not use an end-user security context, the server simply detaches the old one.

    • Garbage collection: The database automatically garbage-collects any end-user security contexts that remain inactive (not attached to any database session) after a timeout duration of one hour.

Scenario 2b — Direct logon (password authentication)

If your end users created in the database log in directly using a SQL client, the database server performs the following tasks:

  1. Validates identity: The server verifies the end user using credential-based password authentication.

  2. Completes multifactor authentication (MFA): If the end user has a configured second factor, the server sends a push notification to the configured external authenticator. Authentication continues only after the end user approves the push notification.

  3. Identifies data roles: The server identifies the end user’s assigned data roles.

  4. Retrieves database roles: For each identified data role, the server retrieves all standard database roles granted to it.

  5. Evaluates privileges and establishes security context: If any of those database roles contain the CREATE SESSION privilege, the server permits the direct logon and establishes the end-user security context with those data roles active.

    With direct logon, the end-user security context is destroyed when the database session closes.