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

+21 -2
View File
@@ -202,15 +202,33 @@ if ($RemoteDesktopGroupDn) {
}
$managedUsersPasswordChangeCorrected = 0
$managedUsersReversibleEncryptionCorrected = 0
$sguRoleGroupDns = @($ProfessorGroupDn, $StudentGroupDn, $AdministrativeGroupDn)
$sguRoleUserDns = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($roleGroupDn in $sguRoleGroupDns) {
foreach ($member in Get-ADGroupMember -Identity $roleGroupDn -Recursive `
-Server $LdapHost -ErrorAction Stop) {
if ($member.objectClass -eq 'user') {
[void]$sguRoleUserDns.Add($member.DistinguishedName)
}
}
}
if ($PSCmdlet.ShouldProcess($usersOuDn, 'Deny direct password changes for every managed SGU user')) {
$managedUsers = @(Get-ADUser -Filter * -SearchBase $usersOuDn -SearchScope Subtree `
-Properties CannotChangePassword -Server $LdapHost -ErrorAction Stop)
-Properties CannotChangePassword,AllowReversiblePasswordEncryption `
-Server $LdapHost -ErrorAction Stop)
foreach ($managedUser in $managedUsers) {
if (-not $managedUser.CannotChangePassword) {
Set-ADAccountControl -Identity $managedUser.DistinguishedName `
-CannotChangePassword $true -Server $LdapHost -Confirm:$false
$managedUsersPasswordChangeCorrected++
}
if ($sguRoleUserDns.Contains($managedUser.DistinguishedName) -and
-not $managedUser.AllowReversiblePasswordEncryption) {
Set-ADAccountControl -Identity $managedUser.DistinguishedName `
-AllowReversiblePasswordEncryption $true -Server $LdapHost -Confirm:$false
$managedUsersReversibleEncryptionCorrected++
}
}
}
@@ -370,4 +388,5 @@ if ($PSCmdlet.ShouldProcess($installPath, 'Install the SGU Authentication Broker
Get-Service -Name $serviceName | Select-Object Name, Status, StartType,
@{ Name = 'EventLog'; Expression = { $brokerEventLogName } },
@{ Name = 'ExistingUsersPasswordChangeDenied'; Expression = { $managedUsersPasswordChangeCorrected } }
@{ Name = 'ExistingUsersPasswordChangeDenied'; Expression = { $managedUsersPasswordChangeCorrected } },
@{ Name = 'ExistingSguRoleUsersReversibleEncryptionEnabled'; Expression = { $managedUsersReversibleEncryptionCorrected } }
+1
View File
@@ -37,6 +37,7 @@ $eventNames = @{
1303 = 'DirectoryRoleGroupMembershipAdded'
1304 = 'DirectoryPasswordChangeDenied'
1305 = 'DirectoryPhotoFailure'
1306 = 'DirectoryReversiblePasswordEncryptionEnabled'
}
# Keep these reads unfiltered. Besides making archived and current logs behave
@@ -1,12 +1,12 @@
[CmdletBinding(SupportsShouldProcess)]
param(
[string]$Version = '0.6.19',
[string]$Version = '0.6.20',
[ValidatePattern('^https://')]
[string]$ClientPackageUri = 'https://gitea.lci.ulsa.mx/alexrg/SGU-CredentialProvider/releases/download/v0.6.19/sgu-windows-client-bootstrap-0.6.19.zip',
[string]$ClientPackageUri = 'https://gitea.lci.ulsa.mx/alexrg/SGU-CredentialProvider/releases/download/v0.6.20/sgu-windows-client-bootstrap-0.6.20.zip',
[ValidatePattern('^[0-9A-Fa-f]{64}$')]
[string]$ClientPackageSha256 = 'C1FA9C92BA941003FE54E9074973CF6630E30456B186C099E731EC5F54182F24',
[string]$ClientPackageSha256 = '6F5FE0467446C695218BEDD02E7BE9E08E1437CE7287C09DE0FC4BE7C596FB60',
[string]$GpoName = 'SGU - Credential Provider update',
+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)
}