@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
SQL Server 2016.
Meet the Row Level Security.
Practical notes
Damian Widera + Dominika Widera
Microsoft Data Platform MVP
EUVIC
@damianwidera
http://sqlplayer.net
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Many thanks to our sponsors & partners!
GOLD
SILVER
PARTNERS
PLATINUM
POWERED BY
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Damian Widera
Project Manager & Technical Lead | EUVIC (www.euvic.pl)
MVP | MCT | MCSE | MCITP
damian.widera@euvic.pl
+48 665-229-227
@damian.widera
facebook.com/damian.widera.10
http://sqlplayer.net
Channel9
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
EUVIC
PALO ALTO
NOWY JORK
WARSZAWA
KATOWICE
GLIWICE
BIELSKO BIAŁA
WROCŁAW
CZĘSTOCHOWA
GDYNIA
KRAKÓW
BYDGOSZCZ
WIEDEŃ
BIAŁYSTOK
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Agenda
• Problem statement(s)
• Dirty solution (pre-SQL Server 2016)
• Clean and nice solution (SQL Server 2016+)
• Is it really clean & nice?
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Problem statement no.1
• You have a multi-tenant e-commerce website and
different companies registered on your website and
you have centralized single database for all clients.
• Your responsibility is that one tenant’s data should
not be available to another tenant.
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Problem statement no.2
• You have hospital database in which you have login
user of different doctors and nurses.
• You should show data to doctor or nurses of their
patients to whom they are giving treatment
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Problem statement no.3
• We have a SQL Server table which stores supplier
and order information. This data is critical to our
business and we want to restrict access for some
employees.
• We want employees to only see the orders they
processed based on their employee ID
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Dirty solution
• Implementation of the row-level access logic using
• Views
• Stored procedures or functions
• Parametrized views
• Customized application code
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Dirty solution
• Suppose you have web application, mobile solution,
Excel file
• Then the same logic is implemented in many
applications
• Must be maintained…
• Upgrade… - all at once?
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Clean & nice solution
• Learn & implement & use the RLS
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
RLS setup
• Create Users and grant them necessary permissions on a table
• INSERT, UPDATE, DELETE, SELECT
• Create a new Inline Table-Valued Function(*) that will contain the Filter/Block
Predicate for that table. This function can have a sophisticated business logic
with multiple JOINs or just a simple WHERE condition
• Create a new Security Policy for this table and add the above Function (Filter)
Predicate to it.
• Please note that these Functions & Security Policies should be unique for a
table. So to create RLS for an another table, you will need to create separate
Function & Security Policy.
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Filter / Block predicate
• Filter Predicate it will filter / exclude the rows which do not
satisfy the predicate – SELECT, UPDATE or DELETE
• For example: Suppose, you want to restrict doctor to see other
doctor’s patient data then in such case you can apply filter
predicate.
• Block Predicate helps in implementing policy by which INSERT,
UPDATE or DELETE operations will prevent saving data.
• For example, you have multi-tenant application and you want
to restrict one tenant user to insert or update other tenant’s
data.
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Permissions
• Create / Alter a policy:
• ALTER ANY SECURITY POLICY, ALTER SCHEMA
• Access the data:
• SELECT and REFERENCES on function
• SELECT on a table
• REFERENCES on a table
• REFERENCES on all columns (arguments to a function)
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Is it really clean & nice?
• Performance?
• Limitations?
• Known problems?
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Performance
• Use Query Store to monitor queries
• Performance – same as a view
• Inline function is applied
• Columnstore – you might end up with ROW mode
• FTS – CONTAINSTABLE, FREETEXT will be slower
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Limitations
• Filestream, Polybase – not working
• DBCC – show unfiltered data
• Temporal tables – predicates must be applied manually on
the historic table
• Partitioned views – no blocking predicate allowed
• Indexed views - cannot be created on top of tables that have
a security policy, because row lookups via the index would
bypass the policy
• CDC – can leak the entire rows that should be filtered
• CT – can leak the PK of rows that should be filtered to users
with both SELECT and VIEW CHANGE TRACKING permission.
Actual data are not leaked
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Known problems
• Crafted query
• SELECT 1 / (Salary – 10000) FROM Payrol
• WHERE Name = ’John Doe’;
• You will observe divide-by-zero exception
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
What if?
• I need to limit access based on AD group
• Use IS_MEMBER() funtion
• We use only one login in the application
• Use SESSION_CONTEXT
@ITCAMPRO #ITCAMP18Community Conference for IT Professionals
Q & A

More Related Content

PDF
Azure SQL Database From A Developer's Perspective - Alex Mang
PPTX
Take Your Reports to Any Screen with Telerik Reporting
PPTX
Building and Delivering Reports from your Web and Mobile Apps with Telerik Re...
PDF
Business Processes in Microsoft Dynamics CRM - Nicu Aleman
PPT
Christiane Kurz - The new Mobile Challenge: Offline-Enablement for Web Applic...
PPTX
Zetta js Hands on IoT
PPTX
Reporting Solution for ASP.NET Application with Telerik reporting
PPTX
How to Maintain Traceability - While Using Jira
Azure SQL Database From A Developer's Perspective - Alex Mang
Take Your Reports to Any Screen with Telerik Reporting
Building and Delivering Reports from your Web and Mobile Apps with Telerik Re...
Business Processes in Microsoft Dynamics CRM - Nicu Aleman
Christiane Kurz - The new Mobile Challenge: Offline-Enablement for Web Applic...
Zetta js Hands on IoT
Reporting Solution for ASP.NET Application with Telerik reporting
How to Maintain Traceability - While Using Jira

Similar to ITCamp 2018 - Damian Widera - SQL Server 2016. Meet the Row Level Security. Practical notes (20)

PDF
ITCamp 2018 - Damian Widera U-SQL in great depth
PPTX
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
PPTX
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
PDF
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
PDF
Travelling in time with SQL Server 2016 - Damian Widera
PPTX
It camp 2015 how to scale above clouds limits, radu vunvulea
PDF
One Azure Monitor to Rule Them All? - Marius Zaharia
PPTX
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
PDF
Scaling face recognition with big data - Bogdan Bocse
PDF
ITCamp 2018 - Tobiasz Koprowski - Secure your data at rest - on demand, now!
PPTX
Scaling Face Recognition with Big Data
PDF
Testing your PowerShell code with Pester - Florin Loghiade
PPTX
SQL TUNING 101
PPTX
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
PDF
Azure licensing (not) so easy - Laurynas Dovydaitis
PDF
Creating Web and Mobile Apps with Angular 2 - George Saadeh
PDF
Blockchain for mere mortals - understand the fundamentals and start building ...
PPTX
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
PPTX
Optimizing Access with SQL Server
PDF
EAS-SEC Project
ITCamp 2018 - Damian Widera U-SQL in great depth
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
Travelling in time with SQL Server 2016 - Damian Widera
It camp 2015 how to scale above clouds limits, radu vunvulea
One Azure Monitor to Rule Them All? - Marius Zaharia
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
Scaling face recognition with big data - Bogdan Bocse
ITCamp 2018 - Tobiasz Koprowski - Secure your data at rest - on demand, now!
Scaling Face Recognition with Big Data
Testing your PowerShell code with Pester - Florin Loghiade
SQL TUNING 101
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
Azure licensing (not) so easy - Laurynas Dovydaitis
Creating Web and Mobile Apps with Angular 2 - George Saadeh
Blockchain for mere mortals - understand the fundamentals and start building ...
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
Optimizing Access with SQL Server
EAS-SEC Project
Ad

More from ITCamp (20)

PDF
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
PDF
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
PDF
ITCamp 2019 - Peter Leeson - Managing Skills
PDF
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
PDF
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
PPTX
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
PPTX
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
PPTX
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
PPTX
ITCamp 2019 - Andy Cross - Business Outcomes from AI
PDF
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
PDF
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
PPTX
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
PPTX
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
PDF
ITCamp 2019 - Peter Leeson - Vitruvian Quality
PDF
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
PDF
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
PDF
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
PDF
ITCamp 2018 - Magnus Mårtensson - Azure Global Application Perspectives
PDF
ITCamp 2018 - Magnus Mårtensson - Azure Resource Manager For The Win
PDF
ITCamp 2018 - Ionut Balan - A beginner’s guide to Windows Mixed Reality
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Magnus Mårtensson - Azure Global Application Perspectives
ITCamp 2018 - Magnus Mårtensson - Azure Resource Manager For The Win
ITCamp 2018 - Ionut Balan - A beginner’s guide to Windows Mixed Reality
Ad

Recently uploaded (20)

PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PPTX
Internet of Everything -Basic concepts details
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
STKI Israel Market Study 2025 version august
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
4 layer Arch & Reference Arch of IoT.pdf
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Build Your First AI Agent with UiPath.pptx
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Internet of Everything -Basic concepts details
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Training Program for knowledge in solar cell and solar industry
STKI Israel Market Study 2025 version august
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
sustainability-14-14877-v2.pddhzftheheeeee
OpenACC and Open Hackathons Monthly Highlights July 2025
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
NewMind AI Weekly Chronicles – August ’25 Week IV
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Convolutional neural network based encoder-decoder for efficient real-time ob...
4 layer Arch & Reference Arch of IoT.pdf
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Custom Battery Pack Design Considerations for Performance and Safety

ITCamp 2018 - Damian Widera - SQL Server 2016. Meet the Row Level Security. Practical notes

  • 1. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals SQL Server 2016. Meet the Row Level Security. Practical notes Damian Widera + Dominika Widera Microsoft Data Platform MVP EUVIC @damianwidera http://sqlplayer.net
  • 2. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  • 3. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Damian Widera Project Manager & Technical Lead | EUVIC (www.euvic.pl) MVP | MCT | MCSE | MCITP [email protected] +48 665-229-227 @damian.widera facebook.com/damian.widera.10 http://sqlplayer.net Channel9
  • 4. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals EUVIC PALO ALTO NOWY JORK WARSZAWA KATOWICE GLIWICE BIELSKO BIAŁA WROCŁAW CZĘSTOCHOWA GDYNIA KRAKÓW BYDGOSZCZ WIEDEŃ BIAŁYSTOK
  • 5. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Agenda • Problem statement(s) • Dirty solution (pre-SQL Server 2016) • Clean and nice solution (SQL Server 2016+) • Is it really clean & nice?
  • 6. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Problem statement no.1 • You have a multi-tenant e-commerce website and different companies registered on your website and you have centralized single database for all clients. • Your responsibility is that one tenant’s data should not be available to another tenant.
  • 7. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Problem statement no.2 • You have hospital database in which you have login user of different doctors and nurses. • You should show data to doctor or nurses of their patients to whom they are giving treatment
  • 8. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Problem statement no.3 • We have a SQL Server table which stores supplier and order information. This data is critical to our business and we want to restrict access for some employees. • We want employees to only see the orders they processed based on their employee ID
  • 9. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Dirty solution • Implementation of the row-level access logic using • Views • Stored procedures or functions • Parametrized views • Customized application code
  • 10. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Dirty solution • Suppose you have web application, mobile solution, Excel file • Then the same logic is implemented in many applications • Must be maintained… • Upgrade… - all at once?
  • 11. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Clean & nice solution • Learn & implement & use the RLS
  • 12. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals RLS setup • Create Users and grant them necessary permissions on a table • INSERT, UPDATE, DELETE, SELECT • Create a new Inline Table-Valued Function(*) that will contain the Filter/Block Predicate for that table. This function can have a sophisticated business logic with multiple JOINs or just a simple WHERE condition • Create a new Security Policy for this table and add the above Function (Filter) Predicate to it. • Please note that these Functions & Security Policies should be unique for a table. So to create RLS for an another table, you will need to create separate Function & Security Policy.
  • 13. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Filter / Block predicate • Filter Predicate it will filter / exclude the rows which do not satisfy the predicate – SELECT, UPDATE or DELETE • For example: Suppose, you want to restrict doctor to see other doctor’s patient data then in such case you can apply filter predicate. • Block Predicate helps in implementing policy by which INSERT, UPDATE or DELETE operations will prevent saving data. • For example, you have multi-tenant application and you want to restrict one tenant user to insert or update other tenant’s data.
  • 14. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Permissions • Create / Alter a policy: • ALTER ANY SECURITY POLICY, ALTER SCHEMA • Access the data: • SELECT and REFERENCES on function • SELECT on a table • REFERENCES on a table • REFERENCES on all columns (arguments to a function)
  • 15. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Is it really clean & nice? • Performance? • Limitations? • Known problems?
  • 16. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Performance • Use Query Store to monitor queries • Performance – same as a view • Inline function is applied • Columnstore – you might end up with ROW mode • FTS – CONTAINSTABLE, FREETEXT will be slower
  • 17. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Limitations • Filestream, Polybase – not working • DBCC – show unfiltered data • Temporal tables – predicates must be applied manually on the historic table • Partitioned views – no blocking predicate allowed • Indexed views - cannot be created on top of tables that have a security policy, because row lookups via the index would bypass the policy • CDC – can leak the entire rows that should be filtered • CT – can leak the PK of rows that should be filtered to users with both SELECT and VIEW CHANGE TRACKING permission. Actual data are not leaked
  • 18. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Known problems • Crafted query • SELECT 1 / (Salary – 10000) FROM Payrol • WHERE Name = ’John Doe’; • You will observe divide-by-zero exception
  • 19. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals What if? • I need to limit access based on AD group • Use IS_MEMBER() funtion • We use only one login in the application • Use SESSION_CONTEXT
  • 20. @ITCAMPRO #ITCAMP18Community Conference for IT Professionals Q & A