Skip to main content

Apply row level security (RLS) in the Peliqan data warehouse

Install the Data App template “Row Level Security (RLS)”, update the configuration section and run the Data App. This will enforce RLS on a given table, directly in the Peliqan data warehouse. RLS Data App Template

Apply row level security (RLS) in code

If the above scenario is not possible (applying RLS directly in the DWH), you can also apply RLS in code, for example in a Data App or in a custom MCP Server.

User authentication

In order to apply row-level permissions, each individual user must be authenticated and known to Peliqan. This means that a shared API key cannot be used. Instead SSO (Single Sign On) with OAuth is appropriate. More info: Publish & Embed apps Custom MCP with OAuth

Implementation of RLS in code

Row level access is implemented by providing the client with a set of views, making sure each view has a fixed column on which permissions can be applied (e.g. user_role). The views are invoked with a filter (e.g. a filter on user_role) and then prepended as CTEs to the SQL query that the client wants to execute.

Example

In this example, we assume that users have one single user role, user roles have permissions on zero, one or more departments and all resources are linked to one single department. Example description of the Data model which is exposed to the client:
Example table invoices: Example table with mapping of permissions: Example table with users, each user has one user_role:
useruser_role
BobHR Manager
AnneFinance Manager
Example access views to apply permissions:
In this example we assume the user is using a Custom MCP Server. The user asks for the “Sum of invoices”. The MCP Server converts the question using text-to-SQL into the following SQL query:
All available access views are prepended (including a filter to apply the permissions) to the SQL query from the user:
Below is the final executed query for Bob, with user_role = ‘HR Manager’:
Result for Bob: Final executed query for Anne, with user_role = ‘Finance Manager’:
Result for Anne: Here is the source code for the custom MCP server, which applies the above Row Level Security method, see function execute_query():