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

Aperta
#10,861 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@nltgpeterskoglund ci sta già lavorando.

Dal 20/11/2026.

  • #10862 di @nltgpeterskoglund — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
powershell
Ambito
databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?
Lingua principale
PowerShell
Stelle
2.9k
Fork
869
Merge medio
2g 4h
PR unite (30g)
38

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dataplat/dbatools

Tutte le issue di dataplat/dbatools

Issue simili

Altre issue su Databases

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.