Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
I have a fact table inside my lakehouse and another user mapping table/file, how do I create a role which applies dynamic RLS based on the fact table’s user_id equivalent to the user mapping table/file’s id?
I’m trying to use the following SQL script but unfortunately, it won’t allow subqueries:
SELECT *
FROM dbo.test_fact_table
WHERE owner_id IN (
SELECT id
FROM dbo.user_mapping_file
WHERE name = CURRENT_USER()
)
Any help is appreciated. Thank you!
Solved! Go to Solution.
Hi @Jaize ,
The RLS rules don't allow subqueries, or the full SQL langauge at all for that matter.
All rules must be in this form:
SELECT * FROM {schema_name}.{table_name} WHERE {column_level_boolean_1}{column_level_boolean_2}...{column_level_boolean_N}
I hope this is improved when OneLake Security goes GA.
For now, the best option is to add the user column to the table you are filtering in your ETL process.
If you want to learn more about OneLake Security, there's a live event happening on Tuesday at 18:00 UTC in the Fabric Discord server! https://discord.com/invite/RVFRmQyX?event=1487504921761677557
Proud to be a Super User! | |
+1 to @tayloramy that you can’t use subqueries or joins in OneLake / Fabric SQL RLS (as of today).
Regarding USERPRINCIPALNAME(), unfortunately there is no equivalent of USERPRINCIPALNAME() (DAX) available for OneLake / Lakehouse SQL RLS (as of today), this may work in Power BI DAX RLS with USERPRINCIPALNAME() but not in OneLake/Lakehouse.
My only suggestion is the same as @tayloramy's above, bring your user data (e.g. owner_email) into your fact table.
Hi @Jaize
Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to @tayloramy , @rizalard0684 , @BHANUPURAM and @anuragccsu for sharing valuable insights.
Could you please confirm if your query has been resolved by the provided solution?If you have any more questions, please let us know and we’ll be happy to help.
Regards,
Microsoft Fabric Community Support Team.
Hi @Jaize
Following up since we haven't heard back regarding our previous message. Have you had a chance to review the information above? Please let us know if you have any further questions.
Regards,
Microsoft Fabric Community Support Team.
In Microsoft Fabric's SQL Analytics Endpoint, you cannot apply a raw SELECT statement directly as a filter. This is same as explained by @BHANUPURAM .
You must:
1. Create a Security Function and then
2. Apply a Security Policy.
Why USERPRINCIPALNAME() won't work:
USERPRINCIPALNAME() is a DAX function used in Power BI measures and Power BI-side RLS.
Fabric SQL Analytics Endpoint uses the T-SQL engine.
https://learn.microsoft.com/en-us/fabric/data-warehouse/row-level-security
Hello Jaize,
STEP 2: Create a Table value function as follows:
Ensure that rows where fact.owner_id exists for the current user in user_mapping_file
Step 3:
please give KUDOS if you like my solutions
Regards,
Bhanu Priya
Hi @Jaize ,
The RLS rules don't allow subqueries, or the full SQL langauge at all for that matter.
All rules must be in this form:
SELECT * FROM {schema_name}.{table_name} WHERE {column_level_boolean_1}{column_level_boolean_2}...{column_level_boolean_N}
I hope this is improved when OneLake Security goes GA.
For now, the best option is to add the user column to the table you are filtering in your ETL process.
If you want to learn more about OneLake Security, there's a live event happening on Tuesday at 18:00 UTC in the Fabric Discord server! https://discord.com/invite/RVFRmQyX?event=1487504921761677557
Proud to be a Super User! | |
Thank you for your response, tayloramy.
I was just wondering.. is there an equivalent to the USERPRINCIPALNAME() DAX function to fetch the UPN or email address of the viewer I can equate to my username/email column? Apparently, CURRENT_USER() is not working either.
+1 to @tayloramy that you can’t use subqueries or joins in OneLake / Fabric SQL RLS (as of today).
Regarding USERPRINCIPALNAME(), unfortunately there is no equivalent of USERPRINCIPALNAME() (DAX) available for OneLake / Lakehouse SQL RLS (as of today), this may work in Power BI DAX RLS with USERPRINCIPALNAME() but not in OneLake/Lakehouse.
My only suggestion is the same as @tayloramy's above, bring your user data (e.g. owner_email) into your fact table.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 5 | |
| 5 |
| User | Count |
|---|---|
| 33 | |
| 17 | |
| 12 | |
| 10 | |
| 6 |