Skip to content

Commit 7a3b3f5

Browse files
authored
Merge pull request #194025 from VanMSFT/updateDDMexample
Update granular permission example
2 parents 982315f + fd29ba8 commit 7a3b3f5

File tree

2 files changed

+166
-6
lines changed

2 files changed

+166
-6
lines changed

articles/azure-sql/database/dynamic-data-masking-configure-portal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ ms.subservice: security
77
ms.custom: sqldbrb=1
88
ms.devlang:
99
ms.topic: how-to
10-
author: DavidTrigano
11-
ms.author: datrigan
10+
author: Madhumitatripathy
11+
ms.author: matripathy
1212
ms.reviewer: kendralittle, vanto, mathoma
13-
ms.date: 04/28/2020
13+
ms.date: 04/05/2022
1414
---
1515
# Get started with SQL Database dynamic data masking with the Azure portal
1616
[!INCLUDE[appliesto-sqldb](../includes/appliesto-sqldb.md)]

articles/azure-sql/database/dynamic-data-masking-overview.md

Lines changed: 163 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ ms.subservice: security
77
ms.custom: sqldbrb=1
88
ms.devlang:
99
ms.topic: conceptual
10-
author: DavidTrigano
11-
ms.author: datrigan
10+
author: Madhumitatripathy
11+
ms.author: matripathy
1212
ms.reviewer: kendralittle, vanto, mathoma
13-
ms.date: 09/12/2021
13+
ms.date: 04/05/2022
1414
tags: azure-synpase
1515
---
1616
# Dynamic data masking
@@ -99,6 +99,166 @@ Write:
9999

100100
To learn more about permissions when using dynamic data masking with T-SQL command, see [Permissions](/sql/relational-databases/security/dynamic-data-masking#permissions)
101101

102+
## Granular permission example
103+
104+
Prevent unauthorized access to sensitive data and gain control by masking it to an unauthorized user at different levels of the database. You can grant or revoke UNMASK permission at the database-level, schema-level, table-level or at the column-level to a user. Using UNMASK permission provides a more granular way to control and limit unauthorized access to data stored in the database and improve data security management.
105+
106+
1. Create schema to contain user tables
107+
108+
```sql
109+
CREATE SCHEMA Data;
110+
GO
111+
```
112+
113+
1. Create table with masked columns
114+
115+
```sql
116+
CREATE TABLE Data.Membership (
117+
MemberID int IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
118+
FirstName varchar(100) MASKED WITH (FUNCTION = 'partial(1, "xxxxx", 1)') NULL,
119+
LastName varchar(100) NOT NULL,
120+
Phone varchar(12) MASKED WITH (FUNCTION = 'default()') NULL,
121+
Email varchar(100) MASKED WITH (FUNCTION = 'email()') NOT NULL,
122+
DiscountCode smallint MASKED WITH (FUNCTION = 'random(1, 100)') NULL,
123+
BirthDay datetime MASKED WITH (FUNCTION = 'default()') NULL
124+
);
125+
```
126+
127+
1. Insert sample data
128+
129+
```sql
130+
INSERT INTO Data.Membership (FirstName, LastName, Phone, Email, DiscountCode, BirthDay)
131+
VALUES
132+
('Roberto', 'Tamburello', '555.123.4567', '[email protected]', 10, '1985-01-25 03:25:05'),
133+
('Janice', 'Galvin', '555.123.4568', '[email protected]', 5,'1990-05-14 11:30:00'),
134+
('Shakti', 'Menon', '555.123.4570', '[email protected]', 50,'2004-02-29 14:20:10'),
135+
('Zheng', 'Mu', '555.123.4569', '[email protected]', 40,'1990-03-01 06:00:00');
136+
```
137+
138+
1. Create schema to contain service tables
139+
140+
```sql
141+
CREATE SCHEMA Service;
142+
GO
143+
```
144+
145+
1. Create service table with masked columns
146+
147+
```sql
148+
CREATE TABLE Service.Feedback (
149+
MemberID int IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
150+
Feedback varchar(100) MASKED WITH (FUNCTION = 'default()') NULL,
151+
Rating int MASKED WITH (FUNCTION='default()'),
152+
Received_On datetime)
153+
);
154+
```
155+
156+
1. Insert sample data
157+
158+
```sql
159+
INSERT INTO Service.Feedback(Feedback,Rating,Received_On)
160+
VALUES
161+
('Good',4,'2022-01-25 11:25:05'),
162+
('Excellent', 5, '2021-12-22 08:10:07'),
163+
('Average', 3, '2021-09-15 09:00:00');
164+
```
165+
166+
1. Create different users in the database
167+
168+
```sql
169+
CREATE USER ServiceAttendant WITHOUT LOGIN;
170+
GO
171+
172+
CREATE USER ServiceLead WITHOUT LOGIN;
173+
GO
174+
175+
CREATE USER ServiceManager WITHOUT LOGIN;
176+
GO
177+
178+
CREATE USER ServiceHead WITHOUT LOGIN;
179+
GO
180+
```
181+
182+
1. Grant read permissions to the users in the database
183+
184+
```sql
185+
ALTER ROLE db_datareader ADD MEMBER ServiceAttendant;
186+
187+
ALTER ROLE db_datareader ADD MEMBER ServiceLead;
188+
189+
ALTER ROLE db_datareader ADD MEMBER ServiceManager;
190+
191+
ALTER ROLE db_datareader ADD MEMBER ServiceHead;
192+
```
193+
194+
1. Grant different UNMASK permissions to users
195+
196+
```sql
197+
--Grant column level UNMASK permission to ServiceAttendant
198+
GRANT UNMASK ON Data.Membership(FirstName) TO ServiceAttendant;
199+
200+
-- Grant table level UNMASK permission to ServiceLead
201+
GRANT UNMASK ON Data.Membership TO ServiceLead;
202+
203+
-- Grant schema level UNMASK permission to ServiceManager
204+
GRANT UNMASK ON SCHEMA::Data TO ServiceManager;
205+
GRANT UNMASK ON SCHEMA::Service TO ServiceManager;
206+
207+
--Grant database level UNMASK permission to ServiceHead;
208+
GRANT UNMASK TO ServiceHead;
209+
```
210+
211+
1. Query the data under the context of user `ServiceAttendant`
212+
213+
```sql
214+
EXECUTE AS USER='ServiceAttendant';
215+
SELECT MemberID,FirstName,LastName,Phone,Email,BirthDay FROM Data. Membership;
216+
SELECT MemberID,Feedback,Rating FROM Service.Feedback;
217+
REVERT;
218+
```
219+
220+
1. Query the data under the context of user `ServiceLead`
221+
222+
```sql
223+
EXECUTE AS USER='ServiceLead';
224+
SELECT MemberID,FirstName,LastName,Phone,Email,BirthDay FROM Data. Membership;
225+
SELECT MemberID,Feedback,Rating FROM Service.Feedback;
226+
REVERT;
227+
```
228+
229+
1. Query the data under the context of user `ServiceManager`
230+
231+
```sql
232+
EXECUTE AS USER='ServiceManager';
233+
SELECT MemberID,FirstName,LastName,Phone,Email FROM Data.Membership;
234+
SELECT MemberID,Feedback,Rating FROM Service.Feedback;
235+
REVERT;
236+
```
237+
238+
1. Query the data under the context of user `ServiceHead`
239+
240+
```sql
241+
EXECUTE AS USER='ServiceHead';
242+
SELECT MemberID,FirstName,LastName,Phone,Email,BirthDay FROM Data.Membership;
243+
SELECT MemberID,Feedback,Rating FROM Service.Feedback;
244+
REVERT;
245+
```
246+
247+
248+
1. To revoke UNMASK permissions, use the following T-SQL statements:
249+
250+
```sql
251+
REVOKE UNMASK ON Data.Membership(FirstName) FROM ServiceAttendant;
252+
253+
REVOKE UNMASK ON Data.Membership FROM ServiceLead;
254+
255+
REVOKE UNMASK ON SCHEMA::Data FROM ServiceManager;
256+
257+
REVOKE UNMASK ON SCHEMA::Service FROM ServiceManager;
258+
259+
REVOKE UNMASK FROM ServiceHead;
260+
```
261+
102262
## See also
103263

104264
- [Dynamic Data Masking](/sql/relational-databases/security/dynamic-data-masking) for SQL Server.

0 commit comments

Comments
 (0)