Managing Grants

Use data grants to authorize database and object storage operations for public, authenticated, and custom data roles.

In the Console, use Database > Table Editor > Grants to manage table grants. Use Database > SQL Editor to run the SQL examples in this chapter.

The examples use the BAAS_USER schema. Replace that prefix with your project schema. The screenshots show a separate development project using TESTUSER and a PVII_ARTICLES test table.

Understanding Data Grants

Oracle DeepSec data grants enforce authorization on database schema objects. A data grant identifies the allowed operations, target object, optional columns and predicates, and data roles that receive access.

Applicable ordinary data grants are additive. A restrictive grant doesn’t override access authorized by another grant. Review all applicable grants before relying on a predicate or column restriction. A request without an applicable grant doesn’t receive access to protected data.

Operations

Data grants can authorize SELECT, INSERT, UPDATE, and DELETE operations. A single grant can authorize more than one operation, such as INSERT, UPDATE.

Objects

Data grants apply to database schema objects. The examples grant access to ARTICLES and the storage backing table, BAAS_STORAGE_OBJECTS.

Predicates

Use a WHERE predicate to restrict the rows or requests that a data grant authorizes. A predicate can compare object columns and attributes from the End User Security Context.

Data Roles

A data grant assigns access to one or more data roles with a TO clause. Projects provide the <SCHEMA>$NOAUTH_ROLE and <SCHEMA>$AUTHENTICATED_ROLE roles by default and can use schema-prefixed custom roles.

Prerequisites

Complete the DeepSec setup in Installing and Configuring Oracle Backend with Supabase APIs before testing application access. The project’s IAM identity domain must match the IDCS domain URL supplied to the fusabase enable-dds command.

Complete the following setup tasks:

  1. Expose a TCPS service to the PDB, and configure ORDS to connect to the database only through that service. DeepSec uses this secure JDBC connection.
  2. Register the database as a resource server in Oracle IAM and configure each ORDS instance as a confidential application with access to that resource server.
  3. Make the Oracle IAM identity domain signing key publicly available.
  4. Configure ORDS and the database for application-based DeepSec connections:

    ./bin/ords --config path/to/config fusabase enable-dds
  5. Enable the project schema:

    EXEC obaas_admin.obaas_enable_schema('USER1');

The procedures and examples in this chapter have the following prerequisites:

Viewing Data Grants

To view table grants in the Console, follow these steps:

  1. In the Console, select Database > Table Editor > Grants.
  2. Review the grant name, target object, actions, and grantees. Use Search grants to find a grant.
  3. In a grant’s Actions menu, select Edit to inspect its column scope, row condition, and generated SQL. Select Cancel when you finish inspecting it.

To inspect grants owned by the project schema, including storage grants, open Database > SQL Editor and query USER_DATA_GRANTS:

SELECT grant_name, privilege, column_name,
       granted_with_all_columns_except,
       object_owner, object_name, grantee, predicate
FROM user_data_grants
ORDER BY grant_name, privilege, grantee, column_name;

A grant can produce multiple rows because the view describes its privileges, columns, and grantees. To inspect a grant, filter by its exact name:

SELECT grant_name, privilege, column_name, grantee, predicate
FROM user_data_grants
WHERE grant_name = 'public articles'
ORDER BY privilege, grantee, column_name;

Creating a Data Grant

To create a table grant in the Console, follow these steps:

  1. In the Console, select Database > Table Editor > Grants.
  2. Select Create grant.
  3. In Grant name, enter a name for the grant.
  4. Select Object type and Target object.
  5. In Roles, select the data roles that receive access.
  6. Select the required actions: SELECT, INSERT, UPDATE, or DELETE.
  7. Select All columns, Selected columns, or All columns except selected. If you restrict the columns, select the column names.
  8. Select All rows, Matching rows, or Custom condition. For matching rows, select a column, an operator, and a value.
  9. Review the generated statement in SQL editor.
  10. Select Create grant. Confirm that the grant appears in the list.
  11. Verify access through your application before relying on the grant.

Description of the illustration data-grant-scopes.png

Description of the illustration data-grant-generated-sql.png

The selected column and row scopes apply to every selected action. Use separate grants when actions need different restrictions.

To create a grant with SQL, open Database > SQL Editor and run CREATE OR REPLACE DATA GRANT. This example authorizes authenticated users to select from ARTICLES:

CREATE OR REPLACE DATA GRANT "restricted reads for myrecords" AS
  SELECT ON ARTICLES
  WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.is_authenticated = 'true'
  TO BAAS_USER$AUTHENTICATED_ROLE;

Controlling Row and Column Access

Add a WHERE predicate to restrict rows. Specify columns after an operation, or use ALL COLUMNS EXCEPT, to restrict column access.

ALL COLUMNS EXCEPT also includes columns added to the table later. Use an explicit permitted-column list when future columns must remain inaccessible by default.

The following grant lets verified authenticated users read every ARTICLES column except PUBLISHED_DATE:

CREATE OR REPLACE DATA GRANT "verified user to read articles" AS
  SELECT(ALL COLUMNS EXCEPT PUBLISHED_DATE) ON ARTICLES
  WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.email_verified = 'true'
  TO BAAS_USER$AUTHENTICATED_ROLE;

Using the End User Security Context

Reference request attributes in a data grant predicate with this prefix:

ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.<attribute-chain>

For each request, the service creates or refreshes the context with server-verified authentication, project, and request values. Oracle DeepSec evaluates data grants against the active data roles and these context attributes.

The defaults in the following tables are defined by the database context schema. Unauthenticated requests use the authentication defaults. The service populates project and request attributes for each request.

Authentication Attributes

Authentication attributes describe the application user and authentication state.

Attribute Type Default Value
auth.is_authenticated string "false" true or false as a string
auth.sub string "" Subject identifier from the user token. For BASE password sign-in, this is the user’s email address.
auth.user_id string "" Application user ID
auth.user_displayname string "" Display name of the user
auth.idp_name string "" Identity-provider name. BASE password sign-in uses UserNamePassword; other values depend on the configured provider.
auth.email_verified string "false" true or false as a string
auth.scope string "" baas-database baas-auth baas-storage or baas-snapshot
auth.iat integer 0 Token issue time as a UNIX timestamp in seconds
auth.exp integer 0 Token expiration time as a UNIX timestamp in seconds

Project Attributes

Project attributes identify the project and its configured services.

Attribute Type Default Value
project.id string "" Project ID in the request
project.auth_type string "" base, ldap, idcs, or e-idcs (External IDCS)
project.auth_id string "" Authentication server ID
project.objs_type string "" base, dbfs, or oci
project.objs_id string "" Object store server ID
project.project_owner string "" Project owner schema
project.project_tag string "RELATIONAL" COLLECTION or RELATIONAL

Request Attributes

Request attributes identify the service and operation for the current request.

Attribute Type Default Value
request.service string "" db or objs
request.operation string "" For db: insert, upsert, update, delete, select, or rpc. For objs: head, get, delete, put, list, create-signed-url, create-upload-signed-url, start-multipart, multipart-add, multipart-commit, or multipart-abort.

Data Grant Examples

The following examples illustrate separate access policies. Apply only the policies your application requires. Don’t run every example as a cumulative security configuration.

In Database > SQL Editor, create the sample table as the project-schema owner:

CREATE TABLE ARTICLES (
  ID NUMBER PRIMARY KEY,
  CONTENT VARCHAR2(2000),
  EXCERPT VARCHAR2(1000),
  PUBLISHED_BY VARCHAR2(256),
  PUBLISHED_DATE TIMESTAMP WITH TIME ZONE
);

To create two rows for the access check, insert the following sample data:

INSERT INTO ARTICLES (ID, CONTENT, EXCERPT, PUBLISHED_BY)
VALUES (1, 'Private article content', 'Public excerpt', 'APP_USER_ID');

INSERT INTO ARTICLES (ID, CONTENT, EXCERPT, PUBLISHED_BY)
VALUES (2, 'Another article', 'Another excerpt', 'OTHER_USER_ID');

COMMIT;

Replace the following values:

Public and Authenticated Access

The following grant permits authenticated users to select from ARTICLES:

CREATE OR REPLACE DATA GRANT "restricted reads for myrecords" AS
  SELECT ON ARTICLES
  WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.is_authenticated = 'true'
  TO BAAS_USER$AUTHENTICATED_ROLE;

The following grant permits public and authenticated roles to select images under public/images/ from object storage:

CREATE OR REPLACE DATA GRANT "public image file reads" AS
  SELECT ON BAAS_STORAGE_OBJECTS
  WHERE object_name LIKE 'public/images/%'
    AND content_type LIKE 'image/%'
  TO BAAS_USER$NOAUTH_ROLE, BAAS_USER$AUTHENTICATED_ROLE;

Mutation examples can also require a SELECT grant for columns read by query filters, value expressions, or returned data. Use the authenticated read policy when appropriate, or grant only the read columns and rows required by the application.

Access to User-Owned Data

Compare an ownership column with auth.user_id to restrict access to data that belongs to the current user. This example permits updates when PUBLISHED_BY matches the authenticated user’s ID:

CREATE OR REPLACE DATA GRANT "restricted updates for authors" AS
  UPDATE ON ARTICLES
  WHERE PUBLISHED_BY = ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.user_id
  TO BAAS_USER$AUTHENTICATED_ROLE;

To require custom author membership as well as ownership, use BAAS_USER$AUTHOR_ROLE in the TO clause instead. Use one version of this policy. Retaining the authenticated-role grant also authorizes access without the custom role.

Authentication Attribute Restrictions

Use authentication attributes to restrict an operation to a particular identity or identity provider.

The following example permits a particular administrator identity to delete from ARTICLES:

CREATE OR REPLACE DATA GRANT "admin delete" AS DELETE
ON ARTICLES
WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.sub = 'admin_grp@example.com'
TO BAAS_USER$AUTHENTICATED_ROLE;

The following example permits users authenticated through Google or users with a verified Gmail address to insert into ARTICLES:

CREATE OR REPLACE DATA GRANT "google published articles" AS INSERT
ON ARTICLES
WHERE
ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.idp_name = 'google'
OR
(ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.sub LIKE '%@gmail.com'
 AND
 ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.email_verified = 'true')
TO BAAS_USER$AUTHENTICATED_ROLE;

Access Through Custom Data Roles

Assign a grant to a schema-prefixed custom role to give that role access. The following examples give authors upload access and administrators delete access to object storage:

CREATE OR REPLACE DATA GRANT "author uploads" AS
  INSERT, UPDATE ON BAAS_STORAGE_OBJECTS
  WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.request.operation <> 'create-upload-signed-url'
  TO BAAS_USER$AUTHOR_ROLE;

CREATE OR REPLACE DATA GRANT "delete files" AS
  DELETE ON BAAS_STORAGE_OBJECTS
  TO BAAS_USER$ADMIN_ROLE;

Column Restrictions

Specify a column list after the operation to grant access to only those columns. You can also exclude columns with ALL COLUMNS EXCEPT.

The following grant permits unauthenticated users to read selected columns from the row whose ID is 1:

CREATE OR REPLACE DATA GRANT "public articles" AS SELECT(ID, EXCERPT, PUBLISHED_BY)
ON ARTICLES
WHERE ID = 1
TO BAAS_USER$NOAUTH_ROLE;

The following grant permits members of the custom BAAS_USER$ADMIN_ROLE role to update PUBLISHED_DATE. Create and assign that role before running the statement:

CREATE OR REPLACE DATA GRANT "admin update for articles" AS UPDATE(PUBLISHED_DATE)
ON ARTICLES
TO BAAS_USER$ADMIN_ROLE;

The following example permits verified authenticated users to read every column except PUBLISHED_DATE:

CREATE OR REPLACE DATA GRANT "verified user to read articles" AS
  SELECT(ALL COLUMNS EXCEPT PUBLISHED_DATE) ON ARTICLES
  WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.auth.email_verified = 'true'
  TO BAAS_USER$AUTHENTICATED_ROLE;

Request Operation Restrictions

Use request context attributes to restrict a grant to specific service operations.

CREATE OR REPLACE DATA GRANT "only upserts on articles" AS INSERT, UPDATE
ON ARTICLES
WHERE ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.request.service = 'db' AND
ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.request.operation IN ('insert', 'upsert')
TO BAAS_USER$AUTHENTICATED_ROLE;

This statement doesn’t remove other grants. A separate grant can still authorize an ordinary update request. Review those grants before using this example to permit only inserts and upserts.

Storage File Paths and Metadata

Create grants on BAAS_STORAGE_OBJECTS to authorize storage operations. Predicates can restrict object paths, content types, and request operations.

This example allows authenticated users to insert or update image files under uploads/ for single-file put operations:

CREATE OR REPLACE DATA GRANT "authenticated image uploads" AS
  INSERT, UPDATE ON BAAS_STORAGE_OBJECTS
  WHERE object_name LIKE 'uploads/%'
    AND content_type LIKE 'image/%'
    AND ORA_END_USER_CONTEXT.BAASSYS.EU_CONTEXT.request.operation = 'put'
  TO BAAS_USER$AUTHENTICATED_ROLE;

Updating a Data Grant

To update a table grant in the Console, follow these steps:

  1. In the Console, select Database > Table Editor > Grants.
  2. In the grant’s Actions menu, select Edit.
  3. Revise the restrictions. To change the SQL statement directly, select Edit beside SQL editor.
  4. Review the statement in SQL editor.
  5. To apply the change, select Create grant.

In Database > SQL Editor, use CREATE OR REPLACE DATA GRANT with the existing grant name and the revised operations, predicates, columns, or roles. For example, this version retains the public column restriction and adds a row condition:

CREATE OR REPLACE DATA GRANT "public articles" AS
  SELECT(ID, EXCERPT, PUBLISHED_BY) ON ARTICLES
  WHERE ID = 1 AND EXCERPT IS NOT NULL
  TO BAAS_USER$NOAUTH_ROLE;

You can’t change the ON object with OR REPLACE. Create a separately named grant for another object, then review whether the original grant is still needed.

Verify both permitted and excluded access after changing a grant.

Dropping a Data Grant

Dropping a data grant removes the access authorized by that grant. Access authorized by other grants can remain available.

To drop a table grant in the Console, follow these steps:

  1. In the Console, select Database > Table Editor > Grants.
  2. Find the grant and select Delete in its Actions menu.
  3. Review the grant name in the confirmation and select Delete.
  4. Confirm that the grant no longer appears and retest application access.

To drop a grant owned by the project schema, open Database > SQL Editor and use DROP DATA GRANT:

DROP DATA GRANT IF EXISTS "public articles";

IF EXISTS avoids an error when the grant is absent. Use the exact grant name, including case for a quoted name.

Verifying Access

Oracle DeepSec evaluates the request against the active data roles, data grants, and End User Security Context. Test with application credentials, rather than the schema-owner session in the Console SQL Editor.

To verify the public row and column policy, follow these steps:

  1. Use the sample ARTICLES table with rows 1 and 2 in a development project.
  2. Apply only the public articles grant to the unauthenticated role for this table. Check USER_DATA_GRANTS for other applicable grants.
  3. Initialize the JavaScript database client with the project’s application configuration. Use a client with no signed-in application user.
  4. Query the permitted columns:

    const publicRows = await client
      .from("ARTICLES")
      .select("ID,EXCERPT,PUBLISHED_BY")
      .order("ID", { ascending: true });
    
    if (publicRows.error) throw publicRows.error;
    console.log(publicRows.data);

    Confirm that only row 1 is returned.

  5. Query ID = 2 separately and confirm that no rows are returned.
  6. Query CONTENT and confirm that the private content is not disclosed:

    const privateColumns = await client
      .from("ARTICLES")
      .select("ID,CONTENT");
    
    console.log(privateColumns.error, privateColumns.data);

    An inaccessible column can be returned as null, and a filtered query can succeed with an empty result. An HTTP success response alone doesn’t prove access.

To verify ownership, sign in as the application user whose ID is stored in PUBLISHED_BY. Apply the required authenticated read grant and ownership update grant, then test an owned row and another user’s row.

const updateResult = await client
  .from("ARTICLES")
  .update({ EXCERPT: "Updated excerpt" })
  .eq("ID", 1);

console.log(updateResult.error, updateResult.data?.rowsUpdated);

When the request succeeds, check updateResult.data.rowsUpdated, then query the data again. A request can succeed with zero rows updated.

To test custom-role assignment, use the ownership grant with BAAS_USER$AUTHOR_ROLE as its grantee. Confirm that no equivalent authenticated-role update grant remains. Assign or remove the custom role, sign in again, and repeat the permitted and excluded operations.

To verify storage access, use the application’s configured bucket and a test file. Use an unused object name for each test, including tests of excluded paths and content types.

With the image-upload policy, an authorized upload under uploads/ must succeed. An upload with another path or content type must not create an object with object_status = 'committed'.

const uploadResult = await client.storage
  .from(bucketName)
  .upload("uploads/access-check.png", imageFile, {
    contentType: "image/png"
  });

if (uploadResult.error) throw uploadResult.error;

Replace the following values:

Verify the resulting object with an authorized download or the Console. Repeat the test with excluded paths and content types, checking both the response and whether an object was created.

Troubleshooting Access

When application access differs from the intended policy, check the following:

An authorization failure doesn’t have one guaranteed HTTP status across database and storage operations. Preserve the response details when investigating a failure.