Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classification

オープン
#10,861 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@nltgpeterskoglund がすでに取り組んでいます。

2026年11月20日 から。

  • #10862 @nltgpeterskoglund による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
powershell
領域
databases

調査の方向性

Start with bin/datamasking/pii-patterns.json and bin/datamasking/pii-knownnames.json, then read the PII scan tests in tests/Invoke-DbaDbPiiScan.Tests.ps1. The issue describes ready branches for pattern fixes and Nordic aliases, with synthetic cases and expected matches to guide the changes. Run the named tests; done means the listed patterns match valid samples, Nordic column names are recognized, and the stated false positives are not.

索引モデルが issue の本文から書いたものです。

説明

Summarize Functionality

I would like to contribute to the PII scan and data classification commands, so that they can be used for GDPR work, also against production, without reading row data.

  1. Bug fix: several shipped data patterns in bin/datamasking/pii-patterns.json never match valid values. I have a branch ready.
  2. Enhancement: Swedish, Norwegian, Danish and Finnish column names in bin/datamasking/pii-knownnames.json, including a known-name rule for national IDs. I have a branch ready.
  3. Proposals I would like your direction on before I write code, as CONTRIBUTING asks:
    • a metadata-only mode and protection status for Invoke-DbaDbPiiScan;
    • a native store (sys.sensitivity_classifications) for *-DbaDbDataClassification;
    • a new Get-DbaDbUnmaskPermission.
Is there a command that is similiar or close to what you are looking for?

Yes

Technical Details
1. Bugs in pii-patterns.json (branch ready)

I checked the shipped patterns with synthetic values, using -match the same way Invoke-DbaDbPiiScan does:

Pattern Problem Synthetic value Matches today
Creditcard (All) Uses \\| (a literal pipe) instead of | (alternation), so only AMEX can match 4111111111111111, 5555555555554444 No
Website (All) Same \\| problem in the scheme alternation https://example.com/page No
National ID (US) The trailing \b is a JSON backspace character. \2 refers to the inner ([0-6]\d) group, not the separator. 123-45-6789 No
Zipcode (DE) The trailing \b is a JSON backspace character 10115 No
National ID (FR) The opening [ is missing (1,2][), and []? is an empty class 1 85 05 78 006 084 36 No
National ID (PL) Typo [0-9} 44051401359 Yes, by accident
National ID (FI) No support for the century signs added in 2023 (Y X W V U, B C D E F) 010594Y9032 No
National ID (SE) Only YYMMDD-NNNN. It misses the 12-digit form and accepts any month or day. 191212121212 / 20231301-1234 No / Yes
IBAN Number "with spaces" (All) The pattern is identical to the "without spaces" entry SE45 5000 0000 0583 9825 7466 No
National ID (Bulgaria) The CountryCode is Bg. ISO 3166 is BG. -CountryCode filtering is case-insensitive, so the fix is not breaking. n/a n/a

The SE pattern deliberately does not match 10 digits without a separator, because that collides with Swedish mobile numbers (07xxxxxxxx). The fixed US pattern requires a separator for the same reason: without one, it matches every 9-digit number.

2. Nordic known names (branch ready)
  • Current gap: the known names cover English, German, French, Spanish and Dutch, but no Nordic languages. There is no known-name rule for national IDs at all.
  • What I add:
    • Nordic aliases to the existing entries: First name, Last name, Date, Gender, E-mail, Nationality, Address, City, Phone and Zipcode;
    • a new entry, "National ID": personnummer, samordningsnummer, fødselsnummer, CPR, henkilötunnus.
  • Encoding: every non-ASCII alias also has an ASCII form, the same way as Staatsangehörigkeit|Staatsangehorigkeit, because Windows PowerShell reads the file as ANSI.
  • Tests: a new UnitTests context in tests/Invoke-DbaDbPiiScan.Tests.ps1 covers:
    • no duplicate patterns, no control characters, ISO country codes;
    • Nordic names found, and the false positives Reposted, Konto, Ikon, CprStatus and Hetupdate not found;
    • every data pattern in the table above.
  • Local result: 52 passed, 0 failed in Windows PowerShell 5.1 and PowerShell 7. Invoke-DbatoolsFormatter leaves the file unchanged.
3. Known issue, not in the branch: \\| in known-name patterns
  • The problem: many of the second-line known-name patterns use \\| as well, e.g. (?>dob\\|dtofb\\|...) and ((tele?)?phone)\\|(co?nta?ct..., so they never match.
  • Why I left them alone: turning them into real alternation would start new matches, some of them false positives (e.g. b_?(date?|day) matches JobDate).
  • Related false positives that already exist, because the first-line patterns are not anchored:
    • pass → Password matches PassengerCount and PassportTypeId;
    • ip → IPAddress matches TripId, Description and ShipDate;
    • land → Country matches IslandCode.
  • Question: would you accept a separate PR that fixes these one at a time, with tests?
4. Proposal: metadata-only scan and protection status in Invoke-DbaDbPiiScan

Today the scan reads TOP (SampleCount) rows from every column. For GDPR work, reading production data is often not acceptable at all. I would like to add:

  • -SkipDataScan: only data type, column name and classification are used, and no rows are read.
  • Classification as a source: FoundWith = 'Classification', read from sys.sensitivity_classifications (SQL Server 2019+ and Azure SQL), or from the SSMS extended properties used by Get-DbaDbDataClassification on older versions.
  • New output properties:
    • IsMasked (sys.masked_columns);
    • IsEncrypted (Always Encrypted);
    • RowCount;
    • SensitivityLabel and InformationType.
    • With these, the output shows which findings are already protected.
  • Fixes along the way:
    • The sample query uses -SqlInstance $instance, which opens a new connection per column. It could reuse the $server connection.
    • Identifiers are wrapped in [...] without escaping ].
    • When -Database is not given, the scan could cover all accessible user databases, with -ExcludeDatabase.
  • No breaking changes: existing parameters and properties stay as they are.
5. Proposal: native store in Get-, Set- and Remove-DbaDbDataClassification (follow-up to #6316)
  • The gap: the commands from #6316 use extended properties. Defender for SQL, Purview and SQL Audit (data_sensitivity_information) read sys.sensitivity_classifications.
  • New parameter: -Store Native|ExtendedProperty|Auto. Auto means native on SQL Server 2019+ and Azure SQL, otherwise extended properties.
  • Native store:
    • write with ADD SENSITIVITY CLASSIFICATION ... WITH (LABEL, LABEL_ID, INFORMATION_TYPE, INFORMATION_TYPE_ID, RANK);
    • remove with DROP SENSITIVITY CLASSIFICATION;
    • read from sys.sensitivity_classifications.
  • Also:
    • -Rank, for the native store only;
    • -InputObject, so findings from Invoke-DbaDbPiiScan can be piped in.
  • Open question: should Auto become the default, or should the extended-property behavior stay the default for compatibility?
6. Proposal: new command Get-DbaDbUnmaskPermission
  • What it does: lists the principals that can read data unmasked when Dynamic Data Masking is in use, through any of:
    • UNMASK at database, schema, object or column level (granular UNMASK, SQL Server 2022 and Azure SQL);
    • CONTROL on the database;
    • db_owner, including through nested role membership;
    • sysadmin or CONTROL SERVER.
  • Output: ComputerName, InstanceName, SqlInstance, Database, Principal, PrincipalType, Source, Scope, Via.
  • Why a new command: Get-DbaPermission shows explicit grants, but it does not resolve nested roles into effective UNMASK. I could not find an existing command that covers this. If you prefer, I can open it as a separate "New Command" issue.
Your direction
  1. Are you OK with items 1 and 2 as one PR (rule files and tests), or would you prefer two?
  2. Do items 4, 5 and 6 fit the module, and do you agree with the parameter and command names?
主要言語
PowerShell
スター
2.9k
フォーク
869
平均マージ
2日 4時間
マージ済み PR(30日)
38

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dataplat/dbatools のほかの issue

dataplat/dbatools の issue をすべて見る

似ている issue

Databases の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。