Limit reversible password storage to SGU accounts

This commit is contained in:
alexrg committed 2026-09-29 11:35:27 -06:00
1 parent 843a1956d6
commit 80baae1b54
13 files changed
+139 -34

No files matched your search

+33 -3
View File
@@ -18,7 +18,7 @@ if ($domain.DomainMode -lt 'Windows2012Domain') {
}
# AD's default password policy must remain intact for non-SGU accounts.
# The broker validates the exact password with SGO before resetting the AD
# The broker validates the exact password with SGU before resetting the AD
# verifier. These global security groups are assigned before SetPassword.
$groups = @(
"CN=SGU-Alumnos,OU=Alumnos,OU=Usuarios-SGU,$BaseDn",
@@ -35,7 +35,7 @@ foreach ($groupDn in $groups) {
$desired = @{
Precedence = $Precedence
ComplexityEnabled = $false
ReversibleEncryptionEnabled = $false
ReversibleEncryptionEnabled = $true
MinPasswordLength = 1
PasswordHistoryCount = 0
MinPasswordAge = [TimeSpan]::Zero
@@ -51,7 +51,7 @@ $policy = Get-ADFineGrainedPasswordPolicy -Filter * -Server $DomainController |
if (-not $policy) {
if ($PSCmdlet.ShouldProcess($PolicyName, 'Create password policy limited to SGU role groups')) {
New-ADFineGrainedPasswordPolicy -Name $PolicyName @desired -Server $DomainController `
-Description 'SGO validates the exact institutional password; AD must not reject its complexity, length, history, or age.' `
-Description 'SGU validates the exact institutional password; reversible storage is enabled only for SGU role groups, and AD must not reject its complexity, length, history, or age.' `
-ProtectedFromAccidentalDeletion $true | Out-Null
}
}
@@ -80,6 +80,34 @@ foreach ($groupDn in $groups) {
}
}
# Existing SGU group members also need the per-account UAC bit before the next
# broker SetPassword call. The default domain policy stays unchanged, and users
# outside these three SGU groups are deliberately excluded.
$reversibleAccountsEnabled = 0
$usersOuDn = "OU=Usuarios-SGU,$BaseDn"
$managedUserDns = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($groupDn in $groups) {
foreach ($member in Get-ADGroupMember -Identity $groupDn -Recursive `
-Server $DomainController -ErrorAction Stop) {
if ($member.objectClass -eq 'user') {
[void]$managedUserDns.Add($member.DistinguishedName)
}
}
}
foreach ($userDn in $managedUserDns) {
$user = Get-ADUser -Identity $userDn -Properties AllowReversiblePasswordEncryption `
-Server $DomainController -ErrorAction Stop
if (-not $user.DistinguishedName.EndsWith(",$usersOuDn", [StringComparison]::OrdinalIgnoreCase)) {
continue
}
if (-not $user.AllowReversiblePasswordEncryption -and
$PSCmdlet.ShouldProcess($user.SamAccountName, 'Allow reversible password storage for SGU account')) {
Set-ADAccountControl -Identity $user.DistinguishedName `
-AllowReversiblePasswordEncryption $true -Server $DomainController -Confirm:$false
$reversibleAccountsEnabled++
}
}
$policy = Get-ADFineGrainedPasswordPolicy -Identity $PolicyName -Properties AppliesTo `
-Server $DomainController -ErrorAction Stop
if (-not $WhatIfPreference) {
@@ -99,8 +127,10 @@ if (-not $WhatIfPreference) {
Name = $policy.Name
Precedence = $policy.Precedence
ComplexityEnabled = $policy.ComplexityEnabled
ReversibleEncryptionEnabled = $policy.ReversibleEncryptionEnabled
MinPasswordLength = $policy.MinPasswordLength
PasswordHistoryCount = $policy.PasswordHistoryCount
MaxPasswordAge = $policy.MaxPasswordAge
ExistingAccountFlagsEnabled = $reversibleAccountsEnabled
Subjects = @($policy.AppliesTo)
}