Using Regular Expressions to Build a Microsoft Purview Custom Sensitive Information Type
Introduction
A colleague of mine needed to create a Microsoft Purview custom Sensitive Information Type (SIT) for a client– The client wanted to use this SIT as part of their implementation of Microsoft Purview. The client needed the SIT to match on occurrences of an organizational identifier that met specific criteria. There is a library of available SITs, but none of them were applicable. SITs are leveraged by several components in the Purview product family and in other areas of the Microsoft compliance universe.
This article will show how you can use Regular Expressions (RegEx) to help create a matching pattern in the “Primary Element” of a custom SIT. We will not be discussing how to configure the other three (3) components of the pattern in the SIT. We will begin with what a SIT is and how they are used in the Microsoft Purview solution suite to protect organizations and their priceless information assets. Microsoft Purview is a cornerstone solution that eGroup | Enabling Technologies uses to help our customers implement and maintain our overriding information security and compliance philosophy:
Sensitive Information Types
Sensitive Information Types (SITs) are used to identify and classify sensitive “items” that are in your organization’s data inventory. There are four (4) types of SIT:
Microsoft Purview Data Loss Prevention Policies
Sensitivity labels
Retention Labels
Insider Risk Management
Communication Compliance
Auto-Labelling Policies
Microsoft Priva
SITs are used to detect sensitive information in an organization’s documents, files, emails, chats, etc. Policies can be created to take an action if the SIT gets a match. For example, a policy:
Detect and manage the transfer of an employee’s personal data within the organization as required by the General Data Protection Regulation (GDPR), California Consumer Privacy Act (CCPA) and other similar regulations Every SIT has a Name, Description, and a Pattern. The Pattern is the definition of what the SIT is looking for. It is composed of four (4) components:
Primary Element: This is what is being looked for. It can be a RegEx, keyword list, keyword dictionary or a function.
What are Regular Expressions (RegEx)?
Regular Expressions (RegEx) have been around since 1951. The concept was originated by mathematician Stephen Cole Kleene. It is a syntax that can be used to search for a pattern in text. They can be used in “find” or “find and replace” operations. They first came into popular use in Unix text-processing utilities. RegEx has been incorporated into most common programming languages including:
If you aren’t confused at this point, the SITs have some additional RegEx validation rules that you need to be aware of. Believe me, if you violate any of these rules, Microsoft 365 will let you know!
At eGroup | Enabling Technologies, we have been using RegEx for over a decade. RegEx has been the required syntax when creating telephone number Normalization Rules in Dial Plans from the days of Live Communications Server 2005 through Lync, Skype for Business, and Microsoft Teams. Some Session Border Controllers also use RegEx in their manipulation engines. The most common Dial Plan Normalization Rules translate four (4) digit telephone extensions (5100) dialed by a user into twelve (12) digit e.164 phone numbers (+14436255100).
There are many sources and resources available on the web as well as those old-fashioned things called books! RegEx is supported in many programming languages. If you want to learn RegEx in general, avoid using a resource specific to a programming language, you won’t get the full picture. Creating the Custom Sensitive Information Type
You can create a custom SIT in the Microsoft Purview Compliance Portal. They can also be created offline in an XML file called a rule package. A colleague of ours wrote about this a few years ago, How to Create Data Loss Prevention Custom Sensitive Information Types.
Client Criteria and Initial RegEx RuleThe client asked us to create a SIT that would produce a match if a number in a document, e-mail, chat, etc. matched the definition of an organizational identifier with these criteria:
Digits can be repeated sequentially up to three (3) times Here are examples of numeric strings that meet the criteria:
1234567891
1112211122 And non-matching numeric strings:
0234567891
Creating the Custom SIT1. Sign in and navigate to the Microsoft Purview Compliance Portal, https://compliance.microsoft.com/homepage 2. Click on “Data classification” 3. Click on “Sensitive info types”
Click “Create sensitive info type”
Type in a name in the “Name” field for the SIT
Add a description to the “Description” field. Descriptions are required.
Click the “Next” button
Click “Create pattern”
Click the “+ Add primary element” drop-down
Click on “Regular Expression”
In the “ID” field, type in a name for the Regular Expression
Paste the RegEx into the Regular Expression field. Obviously, even though the rule’s syntax was fine in the tool we used to create it, Microsoft 365 didn’t like the syntax. We’ll discuss this below.
Select “String Match”. A match will occur even if the matched number is contained within preceding and/or ending text. The rule would match for “ID:1234567891Number”. If you select “Word Match”, the rule will only match instances of the string that “stand” by themselves. The example string would not match if you had selected “Word Match”.
After fixing the syntax, the errors will clear
Click the “Done” button
Change the “Character proximity” as needed
Add “Supporting Elements”
Click the “Create” button
Click the “Next” button
Select a Confidence level
Click the “Next” button
Click the “Create” button
Wait for the SIT to be created then click the “Done” button
Testing the Custom SIT1. Click in the “Search” box and type in part of the name of the new rule 2. Double-click on the name of the rule 3. Click the “Test” button
Click “Upload file”
Select the test file.
Click the “Open” button.
Click the “Test” button.
Wait for the test to complete, review the results.
Click the “Finish” button.
Correct the SIT as needed.
The Primary Element’s RegEx Rule of the SIT
(?!\d{0,6}(0{4}|1{4}|2{4}|3{4}|4{4}|5{4}|6{4}|7{4}|8{4}|9{4})\d{0,6})(?!(0))\d{9}(?!(0))\d
All these risk reductions are real, they are valuable, and they should be a part of any discussion about moving systems or applications to the cloud. This isn’t to minimize the shared responsibility model that we all need to follow (see Microsoft’s diagram of this below), but up to half (half!!) of the boxes below are Microsoft’s responsibility, depending on the system. Oh, except for on-premises. You have to manage that. All on your own….
High-Level Breakdown of the RegEx Rule1. Look for a string of numbers that begins with zero (0) to six (6) digits and ends in zero (0) to six (6) digits. 2. If this group of numbers contains any digit that has repeated four (4) times, the match fails. 3. If the match is still possible, check to see if the first digit is a zero (0), if it is, the match fails. 4. If the match is still possible, match on a string of numbers, nine (9) digits long. If there are fewer than nine (9) digits, the rule fails. 5. If the match is still possible, check if there is a tenth digit. If there isn’t, the match fails. 6. If the match is still possible, check to see if the tenth digit is a zero (0), if so, the match fails. 7. The match succeeds with the string of numbers matching the criteria for the organizational identifier. First Matching Section Detail(?!\d{0,6}(0{4}|1{4}|2{4}|3{4}|4{4}|5{4}|6{4}|7{4}|8{4}|9{4})\d{0,6})
The entire section is enclosed with (?!……). This construct says that if there is a match based on the RegEx that appears between the “?!” and the “)”, the entire RegEx expression fails. If this first construct fails, don’t even bother trying the rest of the constructs, the rule fails and does not match the submitted numeric string. Second Matching Section Detail(?!(0))
Having passed the first test, this section asks if the first digit in the numeric string is a zero (0).
If it is, this construct fails, don’t bother testing the rest of the rule and fail the match. Third Matching Section Detail\d{9}
This section looks for any nine (9) digits. These can be any digit between zero (0) and nine (9).
If there are fewer than nine (9) digits, the construct and the rule will fail. Fourth Matching Section Detail(?!(0))\d
If we’ve made it this far, we have matched nine (9) digits where:
This rule checks to make sure the tenth digit is not a zero (0). If it is, the construct and the rule will fail to make a match. Summary
Sensitive Information Types (SIT) are fundamental elements in an organization’s implementation of the Microsoft Security and Compliance suite of products.
eGroup | Enabling Technologies is available and ready to help you harden and protect your organization and its information assets. SITs and custom SITs are basic components used by many of the security and compliance tools in the Microsoft product family. Determining which SITs you need to leverage or create is not always straightforward.
We have been writing RegEx rules for the Microsoft Unified Communications products and using them in various programming projects, PowerShell scripts, etc. for over fifteen (15) years. The need to use RegEx when creating custom SITs is something we are very comfortable with and ready to assist our customers in their implementation.
This series is part of our effort to help our customers implement a “Trust No One and Harden Everything” security infrastructure. If you need help in planning and implementing your organizational security infrastructure, please contact us!
John MillerCloud Solutions Architect - eGroup | Enabling Technologies
The post Using Regular Expressions to Build a Microsoft Purview Custom Sensitive Information Type appeared first on eGroup.