Share via

RLS in synapse server-less SQL pool using views

Sri Challa 0 Reputation points
2025-03-24T13:26:22.47+00:00

Hi,

Issue: In synapse serverless SQL pool when I try to access view data created from file stored in ADLS with AD/Entra users having "Synapse SQL pool admin" rights on the synapse workspace and no direct access to files in ADLS, I am getting error that "event.csv" cannot be opened because it does not exist or it is used by another process". How can this be resolved, so that row level security (RLS) works on top of the view without allowing ad/entra users to access adls files directly?

Below is what I have implemented

  1. In azure synapse serverless SQL pool I have created a database "events_db"
  2. I have two entra/AD users user1 and user2
  3. I have created an external table "user_access" in synapse serverless sql pool with 2 columns "username" and "can_see_hidden" of type varchar(25) from user_access.csv file stored in ADLS. "can_see_hidden" can be either 0 or 1. "username" is populated with org/company email values.
  4. I then created a view "vw_events_rls" from file events.csv stored in ADLS and joined the external table created in step-3 as below"
create view vw_events_rls
SELECT v.* FROM OPENROWSET (
   	BULK '/events.csv',
   	DATA_SOURCE = 'events_src', 
 	FORMAT = 'CSV',
    FIRSTROW = 2, 
 	FIELDTERMINATOR = ',',   
 	ROWTERMINATOR = '\n',
	PARSER_VERSION = '2.0'
)
WITH (
 event_id INT,
 event_date VARCHAR(25),
 event_name VARCHAR(25),
 event_show VARCHAR(25)
) AS v
JOIN user_access u ON u.user_name = SUSER_SNAME()
WHERE (v.event_show = 'show')  OR (v.event_show = 'hide' AND u.can_see_hidden = 1);

  1. The views has columns "event_id", "event_date", "event_name", "event_show". If event_show = "hide" these rows should be hidden from entra user "user2" entra user "user1" must see all the rows irrespective of "event_show = show" or "event_show = hide"
  2. Azure synapse User Managed identity has "storage data contributor" rights on ADLS tied to synapse
  3. AD/Entra user1 and user2 has "Synapse SQL administrator" rights on the synapse workspace
  4. AD/Entra user1 and user2 should not go and directly access the files stored in ADLS. They should only access data in the files via the view. And they indeed dont have access to ADLS.

Thanks in advance

Azure Synapse Analytics
Azure Synapse Analytics

An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.


1 answer

Sort by: Most helpful
  1. Sri Challa 0 Reputation points
    2025-03-26T01:36:26.78+00:00

    @Venkat Reddy Navari Thanks for your response!!! The approach you have suggested i.e. creation and use of credential = "Manged identity" did not work.

    1. I have created DB scope credential as below:- CREATE DATABASE SCOPED CREDENTIAL [umi-credential-name] WITH IDENTITY = 'synapse-umi-managed-identity' I then used the credential within CREATE EXTERNAL DATA SOURCE as below:- CREATE EXTERNAL DATA SOURCE events_srcLOCATION = 'https://yourstorageaccount.dfs.core.windows.net/container', CREDENTIAL = umi-credential-name);

    Above was throwing error for DB scope credential with message: syntax error near IDENTITY. When I did R&D on the error, I found that SAS token is supported, but use of UMI is not supported. But at org level use of "access token" and "sas token" is disabled via azure policy. So forced to use UMI only.

    1. I have also directly specified credential of synapse workspace umi inside CREATE EXTERNAL DATA SOURCE as below, but it din't work either:-

    CREATE EXTERNAL DATA SOURCE events_srcLOCATION = 'https://yourstorageaccount.dfs.core.windows.net/container',

    CREDENTIAL = 'synapse-umi-managed-identity');

    So the issue havent resolved yet. I know that this can be solved, if we go with synapse Dedicated SQL pool. But the cost of DWH is very high.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.