Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions build/golden/Export-MtLegacyTagTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
-Tag CA, -Tag CIS, -ExcludeTag MS.AAD.3.5 and every other 2.x tag keep selecting the same tests, the
module ships a table that maps each 2.x tag to the IDs of the built-in tests that carried it.

The table is derived from two frozen files and nothing else, so the output never changes with tests/:
The table is derived from two frozen files and explicit native test replacements:

powershell/tests/fixtures/golden/tags-and-blocks.json the tags of every built-in test in 2.x
powershell/tests/fixtures/golden/tags-3.0-preview.json tags the 3.0 previews added (for example AI)
powershell/tests/fixtures/golden/tags-3.0-preview.json tags the 3.0 previews added (for example AI)
build/golden/native-test-replacements.psd1 intentional renames and consolidations

Rules:
- A tag is matched case-insensitively; the table keeps the first spelling of the snapshot.
Expand All @@ -22,7 +23,8 @@
obvious one ($Replacements below, and -Severity for Severity:<value>). The engine names it in the
warning it writes when a run selects through the tag.

Tests added after 3.0 are not in the table. The file is generated once and is not edited by hand;
Tests added after 3.0 are not in the table unless they explicitly replace a historical check.
The file is regenerated when native replacements change and is never edited by hand;
powershell/tests/functions/golden/Golden.Tests.ps1 checks that it is what this script produces.

.EXAMPLE
Expand All @@ -49,10 +51,8 @@ $ErrorActionPreference = 'Stop'
$RepoRoot = (Resolve-Path -Path $RepoRoot).Path
$fixtures = Join-Path $RepoRoot 'powershell/tests/fixtures/golden'

# 2.x IDs that have another ID in 3.0.
$RenamedIds = @{
'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0.
}
# Explicit replacements, never a dynamic filter that could hide an accidental test deletion.
$RenamedIds = Import-PowerShellDataFile -LiteralPath (Join-Path $RepoRoot 'build/golden/native-test-replacements.psd1')

# The typed selector that takes the place of a tag. Only tags with an obvious one are listed.
$Replacements = [ordered]@{
Expand Down
9 changes: 9 additions & 0 deletions build/golden/native-test-replacements.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
'MT1060' = 'MT.1060'
'AD-COMP-02' = 'AD-DCOMP-06'
'AD-COMP-09' = 'AD-DCOMP-01'
'AD-COMP-10' = 'AD-DCOMP-03'
'AD-DCOMP-02' = 'AD-DCOMP-01'
'AD-DCOMP-05' = 'AD-DCOMP-04'
'AD-DCOMP-09' = 'AD-DCOMP-08'
}
51 changes: 39 additions & 12 deletions powershell/assets/Maester.LegacyTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@
"AD-CFG-23",
"AD-CFG-24",
"AD-COMP-01",
"AD-COMP-02",
"AD-COMP-03",
"AD-COMP-04",
"AD-COMP-05",
"AD-COMP-06",
"AD-COMP-07",
"AD-COMP-08",
"AD-COMP-09",
"AD-COMP-10",
"AD-DACL-01",
"AD-DACL-02",
"AD-DACL-03",
Expand Down Expand Up @@ -81,14 +78,11 @@
"AD-DCD-03",
"AD-DCD-04",
"AD-DCOMP-01",
"AD-DCOMP-02",
"AD-DCOMP-03",
"AD-DCOMP-04",
"AD-DCOMP-05",
"AD-DCOMP-06",
"AD-DCOMP-07",
"AD-DCOMP-08",
"AD-DCOMP-09",
"AD-DFSR-01",
"AD-DNS-01",
"AD-DNS-02",
Expand Down Expand Up @@ -288,19 +282,55 @@
"AD-USER-29"
]
},
{
"Tag": "AD-COMP-02",
"Tests": [
"AD-DCOMP-06"
]
},
{
"Tag": "AD-COMP-09",
"Tests": [
"AD-DCOMP-01"
]
},
{
"Tag": "AD-COMP-10",
"Tests": [
"AD-DCOMP-03"
]
},
{
"Tag": "AD-DCOMP-02",
"Tests": [
"AD-DCOMP-01"
]
},
{
"Tag": "AD-DCOMP-05",
"Tests": [
"AD-DCOMP-04"
]
},
{
"Tag": "AD-DCOMP-09",
"Tests": [
"AD-DCOMP-08"
]
},
{
"Tag": "AD.Computer",
"Tests": [
"AD-COMP-01",
"AD-COMP-02",
"AD-COMP-03",
"AD-COMP-04",
"AD-COMP-05",
"AD-COMP-06",
"AD-COMP-07",
"AD-COMP-08",
"AD-COMP-09",
"AD-COMP-10"
"AD-DCOMP-01",
"AD-DCOMP-03",
"AD-DCOMP-06"
]
},
{
Expand Down Expand Up @@ -575,14 +605,11 @@
"Tag": "AD.Security",
"Tests": [
"AD-DCOMP-01",
"AD-DCOMP-02",
"AD-DCOMP-03",
"AD-DCOMP-04",
"AD-DCOMP-05",
"AD-DCOMP-06",
"AD-DCOMP-07",
"AD-DCOMP-08",
"AD-DCOMP-09",
"AD-KRBTGT-01",
"AD-KRBTGT-02",
"AD-KRBTGT-03",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ο»Ώfunction Test-MtAdDomainControllerAccount {
<#
.SYNOPSIS
Identifies a DC account from the collected directory server inventory.

.DESCRIPTION
Uses serverReference distinguished names, with DNS fallback only for inventory
entries lacking serverReference. A claimed DC primary group is not DC evidence.
#>
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(Mandatory)]
[object] $Account,

[Parameter(Mandatory)]
[object[]] $DomainControllers
)

if ([string]::IsNullOrWhiteSpace([string]$Account.DistinguishedName)) {
throw 'Account distinguished name is unavailable; DC identity cannot be verified.'
}
if (@($Account.ObjectClass | Where-Object { $_ -in 'msDS-ManagedServiceAccount', 'msDS-GroupManagedServiceAccount', 'msDS-DelegatedManagedServiceAccount' }).Count -gt 0) {
return $false
}
foreach ($dc in $DomainControllers) {
if (-not $dc.ServerReference -and -not $dc.DnsHostName) {
throw 'DC inventory lacks serverReference and DNS identity; DC exclusions cannot be verified.'
}
if ($dc.ServerReference) {
if ([string]$dc.ServerReference -eq [string]$Account.DistinguishedName) { return $true }
}
elseif ($Account.DnsHostName -and ([string]$dc.DnsHostName).TrimEnd('.') -eq ([string]$Account.DnsHostName).TrimEnd('.')) {
return $true
}
}
return $false
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

if ($Value -is [byte[]]) {
switch ($normalizedAttributeName) {
{ $_ -in @('objectsid', 'sidhistory', 'securityidentifier') } {
{ $_ -in @('objectsid', 'sidhistory', 'securityidentifier', 'ms-ds-creatorsid') } {
try {
return New-Object System.Security.Principal.SecurityIdentifier -ArgumentList $Value, 0
}
Expand Down Expand Up @@ -206,7 +206,7 @@
}

if ($Value -is [System.Security.Principal.SecurityIdentifier]) {
if ($normalizedAttributeName -in @('objectsid', 'sidhistory', 'securityidentifier')) {
if ($normalizedAttributeName -in @('objectsid', 'sidhistory', 'securityidentifier', 'ms-ds-creatorsid')) {
return $Value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

if ([string]::IsNullOrWhiteSpace($SearchBase)) { $SearchBase = (Get-MtLdapRootDse -Connection $Connection).DefaultNamingContext }
$attributes = @('distinguishedName', 'name', 'sAMAccountName', 'userAccountControl', 'operatingSystem', 'operatingSystemVersion', 'dNSHostName', 'whenCreated', 'whenChanged', 'lastLogonTimestamp', 'pwdLastSet', 'servicePrincipalName', 'primaryGroupID', 'objectSid', 'isCriticalSystemObject', 'managedBy', 'sIDHistory')
$attributes = @('distinguishedName', 'name', 'sAMAccountName', 'userAccountControl', 'operatingSystem', 'operatingSystemVersion', 'dNSHostName', 'whenCreated', 'whenChanged', 'lastLogonTimestamp', 'pwdLastSet', 'servicePrincipalName', 'primaryGroupID', 'objectSid', 'isCriticalSystemObject', 'managedBy', 'sIDHistory', 'objectClass', 'msDS-AllowedToDelegateTo', 'msDS-AllowedToActOnBehalfOfOtherIdentity', 'mS-DS-CreatorSID')
$entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(objectClass=computer)' -Attributes $attributes)
return @($entries | ForEach-Object {
$uac = if ($null -ne $_.userAccountControl) { ConvertFrom-MtLdapUserAccountControl -UserAccountControl ([int]$_.userAccountControl) } else { $null }
Expand All @@ -20,6 +20,10 @@
PasswordLastSet = $_.pwdLastSet; PasswordExpired = if ($null -ne $uac) { $uac.PasswordExpired } else { $null }; PasswordNeverExpires = if ($null -ne $uac) { $uac.DontExpirePassword } else { $null }
PasswordNotRequired = if ($null -ne $uac) { $uac.PasswordNotRequired } else { $null }; TrustedForDelegation = if ($null -ne $uac) { $uac.TrustedForDelegation } else { $null }
TrustedToAuthForDelegation = if ($null -ne $uac) { $uac.TrustedToAuthForDelegation } else { $null }; ServicePrincipalName = [string[]]@($_.servicePrincipalName | Where-Object { $null -ne $_ })
ObjectClass = @($_.objectClass)
AllowedToDelegateTo = [string[]]@($_.'msDS-AllowedToDelegateTo' | Where-Object { $null -ne $_ })
HasResourceBasedConstrainedDelegation = $null -ne $_.'msDS-AllowedToActOnBehalfOfOtherIdentity'
CreatorSid = $_.'mS-DS-CreatorSID'
PrimaryGroupId = $_.primaryGroupID; Sid = $_.objectSid; UserAccountControl = [int]$_.userAccountControl
IsCriticalSystemObject = if ($null -ne $_.isCriticalSystemObject) { [bool]$_.isCriticalSystemObject } else { $null }; ManagedBy = [string]$_.managedBy; SidHistory = @($_.sIDHistory | Where-Object { $null -ne $_ })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
)

if ([string]::IsNullOrWhiteSpace($SearchBase)) { $SearchBase = (Get-MtLdapRootDse -Connection $Connection).DefaultNamingContext }
$attributes = @('distinguishedName', 'name', 'sAMAccountName', 'dNSHostName', 'whenCreated', 'whenChanged', 'objectSid')
$entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(objectClass=msDS-GroupManagedServiceAccount)' -Attributes $attributes)
return @($entries | ForEach-Object { [PSCustomObject]@{ DistinguishedName = [string]$_.DistinguishedName; Name = [string]$_.name; SamAccountName = [string]$_.sAMAccountName; DnsHostName = [string]$_.dNSHostName; Created = $_.whenCreated; Modified = $_.whenChanged; Sid = $_.objectSid } })
$attributes = @('distinguishedName', 'name', 'sAMAccountName', 'dNSHostName', 'whenCreated', 'whenChanged', 'objectSid', 'objectClass', 'msDS-DelegatedMSAState', 'userAccountControl', 'msDS-AllowedToDelegateTo', 'msDS-AllowedToActOnBehalfOfOtherIdentity')
$entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(|(objectClass=msDS-ManagedServiceAccount)(objectClass=msDS-GroupManagedServiceAccount)(objectClass=msDS-DelegatedManagedServiceAccount))' -Attributes $attributes)
return @($entries | ForEach-Object {
$uac = if ($null -ne $_.userAccountControl) { ConvertFrom-MtLdapUserAccountControl -UserAccountControl ([int]$_.userAccountControl) } else { $null }
[PSCustomObject]@{
DistinguishedName = [string]$_.DistinguishedName; Name = [string]$_.name; SamAccountName = [string]$_.sAMAccountName; DnsHostName = [string]$_.dNSHostName
Created = $_.whenCreated; Modified = $_.whenChanged; Sid = $_.objectSid; ObjectClass = @($_.objectClass); DelegatedMsaState = $_.'msDS-DelegatedMSAState'
TrustedForDelegation = if ($null -ne $uac) { $uac.TrustedForDelegation } else { $null }
TrustedToAuthForDelegation = if ($null -ne $uac) { $uac.TrustedToAuthForDelegation } else { $null }
AllowedToDelegateTo = [string[]]@($_.'msDS-AllowedToDelegateTo' | Where-Object { $null -ne $_ })
HasResourceBasedConstrainedDelegation = $null -ne $_.'msDS-AllowedToActOnBehalfOfOtherIdentity'
}
})
}
Loading
Loading