Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Introducing Microsoft SQL Server 2019
  • Table Of Contents Toc
Introducing Microsoft SQL Server 2019

Introducing Microsoft SQL Server 2019

By : Kellyn Gorman , Allan Hirt , Dave Noderer , Mitchell Pearson, James Rowland-Jones , Dustin Ryan , Arun Sirpal , Buck Woody
close
close
Introducing Microsoft SQL Server 2019

Introducing Microsoft SQL Server 2019

By: Kellyn Gorman , Allan Hirt , Dave Noderer , Mitchell Pearson, James Rowland-Jones , Dustin Ryan , Arun Sirpal , Buck Woody

Overview of this book

Microsoft SQL Server comes equipped with industry-leading features and the best online transaction processing capabilities. If you are looking to work with data processing and management, getting up to speed with Microsoft Server 2019 is key. Introducing SQL Server 2019 takes you through the latest features in SQL Server 2019 and their importance. You will learn to unlock faster querying speeds and understand how to leverage the new and improved security features to build robust data management solutions. Further chapters will assist you with integrating, managing, and analyzing all data, including relational, NoSQL, and unstructured big data using SQL Server 2019. Dedicated sections in the book will also demonstrate how you can use SQL Server 2019 to leverage data processing platforms, such as Apache Hadoop and Spark, and containerization technologies like Docker and Kubernetes to control your data and efficiently monitor it. By the end of this book, you'll be well versed with all the features of Microsoft SQL Server 2019 and understand how to use them confidently to build robust data management solutions.
Table of Contents (15 chapters)
close
close

Row-Level Security

Row-level security (RLS) gives database administrators and developers the ability to allow fine-grained access control over rows within tables. Rows can be filtered based on the execution context of a query. Central to this feature is the concept of a security policy where, via an inline table-valued function, you would write your filtering logic to control access with complete transparency to the application. Real-world examples include situations in which you would like to prevent unauthorized access to certain rows for specific logins, for example, only giving access to a super-user to view all rows within a sensitive table and allowing other users to see rows that only the super-user should see. The following example shows how simple it is to implement RLS via T-SQL. At a high level, access to a specific table called rls.All_Patient is defined by a column called GroupAccessLevel, which is mapped to two SQL logins called GlobalManager and General. As you can imagine, the General login will not be able to view the data that GlobalManager is authorized to see.

The following code is the T-SQL required to create the table-value function and the security policy with the state set to ON:

CREATE FUNCTION rls.fn_securitypredicate(@GroupAccessLevel AS sysname)  
    RETURNS TABLE  
WITH SCHEMABINDING  
AS  
    RETURN SELECT 1 AS fn_securitypredicate_result
WHERE @GroupAccessLevel = USER_NAME() OR USER_NAME() = 'GlobalManager'; 
GO
CREATE SECURITY POLICY UserFilter  
ADD FILTER PREDICATE RLS.fn_securitypredicate(GroupAccessLevel)
ON rls.All_Patient
WITH (STATE = ON);  
GO
GRANT SELECT ON RLS.fn_securitypredicate TO GlobalManager;  
GRANT SELECT ON RLS.fn_securitypredicate TO General  

Running the code as the GlobalManager user will return all rows within the table, in contrast with the General user, who will only see the rows that they are entitled to see:

EXECUTE AS USER = 'GlobalManager';  
  SELECT * FROM rls.All_Patient 
  ORDER BY AreaID
REVERT;

The following screenshot confirms the data that the General user can only see:

Figure 2.41: A table with access set to GlobalManager
Figure 2.26: A table with access set to GlobalManager

Executing the following code switches the execution context to the General user:

EXECUTE AS USER = 'General';  
  SELECT * FROM rls.All_Patient 
  ORDER BY AreaID
REVERT;
Figure 2.27: The same table with access set to General
Figure 2.27: The same table with access set to General

If you check the properties of the clustered index scan, you will see the predicate being evaluated:

Figure 2.43: Selecting properties of clustered index scan
Figure 2.28: Selecting properties of clustered index scan
Figure 2.44: The predicate evaulation dialogue box

Figure 2.29: The predicate evaulation dialog box

This type of predicate is called a filter predicate, but you also can create a block predicate to explicitly block write operations (such as AFTER INSERT, AFTER UPDATE, BEFORE UPDATE, and BEFORE DELETE) that violate the predicate.

For administration purposes, you can query the following system tables to see the security policies and security predicates that have been defined:

SELECT * FROM sys.security_policies
Figure 2.45: Output of a security_policies query
Figure 2.30: Output of a security_policies query
SELECT * FROM sys.security_predicates
Figure 2.46: Output of a security_predicates query
Figure 2.31: Output of a security_predicates query

To maintain the best performance, it is best practice to not involve many table joins within the predicate function, to avoid type conversions, and to avoid recursion.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Introducing Microsoft SQL Server 2019
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon