From 80baae1b549169790e947c259b027740ee2fccb7 Mon Sep 17 00:00:00 2001 From: Alejandro Rosales Date: Tue, 29 Sep 2026 11:35:27 -0600 Subject: [PATCH] Limit reversible password storage to SGU accounts --- docs/architecture.md | 13 ++++--- docs/release-0.6.19.md | 12 +++---- docs/release-0.6.20.md | 20 +++++++++++ docs/security.md | 28 +++++++++------ scripts/Deploy-AuthBroker.ps1 | 23 ++++++++++-- scripts/Get-SguBrokerLog.ps1 | 1 + ...tall-SguCredentialProviderUpdatePolicy.ps1 | 6 ++-- .../Set-SguInstitutionalPasswordPolicy.ps1 | 36 +++++++++++++++++-- src/SGU.AuthBroker/BrokerEventIds.cs | 1 + .../Services/ActiveDirectorySynchronizer.cs | 23 ++++++++++++ .../SguCredentialTile.cs | 6 ++-- tests/AuthBrokerPasswordAuthority.Tests.ps1 | 2 +- .../BrokerClientTests.cs | 2 +- 13 files changed, 139 insertions(+), 34 deletions(-) create mode 100644 docs/release-0.6.20.md diff --git a/docs/architecture.md b/docs/architecture.md index 8e15eb8..8e74202 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -68,15 +68,18 @@ that same password directly to ADSI `SetPassword`. This is an idempotent UPSERT performed on every successful sign-in, so the next sign-in after an institutional password change updates AD before Windows validates the interactive logon. If SGU explicitly rejects the credential, the provider stops without trying AD. -If SGO accepts it but AD synchronization fails, the provider reports that -failure without trying a stale AD verifier. Only a genuine broker/SGO outage +If SGU accepts it but AD synchronization fails, the provider reports that +failure without trying a stale AD verifier. Only a genuine broker/SGU outage uses the documented Windows cached-domain-credential fallback, for an existing account. A matching username pattern alone never provisions an account. The domain bootstrap creates a fine-grained password policy for the three SGU -role security groups. It allows the broker to record the exact password SGO -accepted, even when the normal domain complexity policy would reject it. It -does not relax password requirements for other domain accounts. +role security groups. It allows the broker to record the exact password SGU +accepted, including reversible storage, even when the normal domain complexity +policy would reject it. The domain default remains unchanged; per-user reversible +storage is enabled only for members of those three groups. AD rewrites an existing +password in reversible form only when the broker sets it after a successful SGU +sign-in. Do not apply the setting to unrelated domain accounts. Before an account becomes usable, the broker applies explicit deny ACEs for the Active Directory `Change Password` extended right to SELF and Everyone. Users diff --git a/docs/release-0.6.19.md b/docs/release-0.6.19.md index cd1decb..a7935eb 100644 --- a/docs/release-0.6.19.md +++ b/docs/release-0.6.19.md @@ -1,19 +1,19 @@ -# v0.6.19 — SGO password authority +# v0.6.19 — SGU password authority - Add a fine-grained Active Directory password policy scoped to the three - `SGU-*` role groups. A password accepted by SGO is stored unchanged in AD, + `SGU-*` role groups. A password accepted by SGU is stored unchanged in AD, including short passwords that the default domain complexity policy rejects. Other domain accounts keep their existing policy. - Apply and verify this policy during server bootstrap. Existing SGU accounts receive it through their role-group membership. -- Stop institutional login immediately when SGO explicitly rejects a password. - When SGO accepts it but AD synchronization fails, show a distinct error +- Stop institutional login immediately when SGU explicitly rejects a password. + When SGU accepts it but AD synchronization fails, show a distinct error instead of trying an older AD password. -- Preserve the documented cached-domain fallback only while the broker or SGO +- Preserve the documented cached-domain fallback only while the broker or SGU is genuinely unavailable. Operational validation: on the domain controller, disposable users in each of `SGU-Alumnos`, `SGU-Administrativos`, and `SGU-Docentes` accepted a three-character password and were removed after the test. The three originally reported -accounts still require a real SGO sign-in to finish AD provisioning; no student +accounts still require a real SGU sign-in to finish AD provisioning; no student password was requested or stored for testing. diff --git a/docs/release-0.6.20.md b/docs/release-0.6.20.md new file mode 100644 index 0000000..7308180 --- /dev/null +++ b/docs/release-0.6.20.md @@ -0,0 +1,20 @@ +# v0.6.20 — SGU-scoped reversible password storage + +- Enable reversible password storage only for members of the three SGU role + groups (`SGU-Alumnos`, `SGU-Administrativos`, and `SGU-Docentes`). The + domain-wide default password policy remains unchanged. +- Before synchronizing a valid Acceso SGU login, the broker enables the + per-account AD flag and then writes the exact SGU-accepted password. Existing + role-group members are repaired by server bootstrap and the password-policy + deployment script. +- Add structured broker event 1306 when the per-account setting is enabled. +- Document that reversible storage allows a privileged directory-data reader to + recover the original password, and that existing passwords are rewritten only + after their next successful SGU password synchronization. +- Correct references that called the institutional system “SGO”; the product is + SGU. + +The setting is intentionally limited to the SGU-managed role groups. Do not +apply it to unrelated domain users. Existing SGU accounts need a successful +Acceso SGU sign-in (or another authorized password reset) before their currently +stored password is rewritten using reversible encryption. diff --git a/docs/security.md b/docs/security.md index 40ce48b..08e8466 100644 --- a/docs/security.md +++ b/docs/security.md @@ -21,11 +21,19 @@ the same source list. RDP uses a separate allowlist. See - The `SGU - Institutional password authority` fine-grained AD password policy applies only to the global security groups `SGU-Alumnos`, `SGU-Administrativos`, and `SGU-Docentes`. It disables AD complexity, - history, and password age requirements and permits passwords from one - character onward so a password accepted by SGO is never altered or rejected - by AD. The default domain password policy remains unchanged. The group is - assigned before `SetPassword` for newly created users. Bootstrap reapplies - the policy via `Set-SguInstitutionalPasswordPolicy.ps1`. + history, and password age requirements, permits passwords from one character + onward, and enables reversible password storage so passwords accepted by SGU + can be recorded unchanged by AD. The default domain password policy remains + unchanged for non-SGU accounts. The broker sets the per-user reversible-storage + flag before each `SetPassword`; bootstrap repairs existing role-group members + and reapplies the policy via `Set-SguInstitutionalPasswordPolicy.ps1`. +- Reversible password storage is a significant security reduction: a domain + controller stores a decryptable password representation. A privileged attacker + or administrator who obtains the relevant directory data can recover the + original password. This is limited to accounts in the three SGU role groups; + existing password values are converted only when SGU next resets them (normally + on a successful Acceso SGU sign-in). Do not enable this for unrelated domain + accounts. - Managed `Usuarios-SGU` accounts deny the SELF and Everyone `Change Password` extended right. Only an administrator or the broker through the separate `Reset Password` right can replace the AD password. @@ -98,21 +106,21 @@ Use an enterprise CA with revocation checking in production. The provider distinguishes an SGU rejection from unavailable infrastructure: - `400`/`401`: do not create or update the account and do not submit a Windows - credential. An explicit SGO rejection is authoritative, including when an + credential. An explicit SGU rejection is authoritative, including when an older AD password still exists. -- `DIRECTORY_SYNCHRONIZATION_FAILED`: SGO accepted the password but AD did not +- `DIRECTORY_SYNCHRONIZATION_FAILED`: SGU accepted the password but AD did not record it. Show a specific error and do not attempt Windows logon against a potentially stale AD verifier. - timeout, TLS/connectivity error, `429`, or `5xx`: submit the unchanged - credential to Windows only for a genuine broker/SGO outage. Windows must still + credential to Windows only for a genuine broker/SGU outage. Windows must still validate it against AD or its cached domain verifier, so this does not grant access without a domain credential. This continuity path can accept a - last-known AD password while SGO is unreachable; decide explicitly whether + last-known AD password while SGU is unreachable; decide explicitly whether that availability trade-off is appropriate for each deployment. - usernames that do not match the institutional key format go directly to Windows and are never sent to SGU or provisioned by the broker. -Allowing an SGO-accepted three-character password also allows that short +Allowing an SGU-accepted three-character password also allows that short password at the native AD logon surface. Broker rate limiting does not protect direct AD authentication; domain network exposure and monitoring therefore remain essential. The policy cannot make a weak upstream password strong. diff --git a/scripts/Deploy-AuthBroker.ps1 b/scripts/Deploy-AuthBroker.ps1 index c3304b2..5100280 100644 --- a/scripts/Deploy-AuthBroker.ps1 +++ b/scripts/Deploy-AuthBroker.ps1 @@ -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 } } diff --git a/scripts/Get-SguBrokerLog.ps1 b/scripts/Get-SguBrokerLog.ps1 index 6a4d40d..eef407d 100644 --- a/scripts/Get-SguBrokerLog.ps1 +++ b/scripts/Get-SguBrokerLog.ps1 @@ -37,6 +37,7 @@ $eventNames = @{ 1303 = 'DirectoryRoleGroupMembershipAdded' 1304 = 'DirectoryPasswordChangeDenied' 1305 = 'DirectoryPhotoFailure' + 1306 = 'DirectoryReversiblePasswordEncryptionEnabled' } # Keep these reads unfiltered. Besides making archived and current logs behave diff --git a/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 b/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 index c1fe83e..eb97dee 100644 --- a/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 +++ b/scripts/Install-SguCredentialProviderUpdatePolicy.ps1 @@ -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', diff --git a/scripts/Set-SguInstitutionalPasswordPolicy.ps1 b/scripts/Set-SguInstitutionalPasswordPolicy.ps1 index dabc130..851a14b 100644 --- a/scripts/Set-SguInstitutionalPasswordPolicy.ps1 +++ b/scripts/Set-SguInstitutionalPasswordPolicy.ps1 @@ -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) } diff --git a/src/SGU.AuthBroker/BrokerEventIds.cs b/src/SGU.AuthBroker/BrokerEventIds.cs index b8fb28a..00e23a4 100644 --- a/src/SGU.AuthBroker/BrokerEventIds.cs +++ b/src/SGU.AuthBroker/BrokerEventIds.cs @@ -26,4 +26,5 @@ internal static class BrokerEventIds internal static readonly EventId DirectoryRoleGroupMembershipAdded = new(1303, nameof(DirectoryRoleGroupMembershipAdded)); internal static readonly EventId DirectoryPasswordChangeDenied = new(1304, nameof(DirectoryPasswordChangeDenied)); internal static readonly EventId DirectoryPhotoFailure = new(1305, nameof(DirectoryPhotoFailure)); + internal static readonly EventId DirectoryReversiblePasswordEncryptionEnabled = new(1306, nameof(DirectoryReversiblePasswordEncryptionEnabled)); } diff --git a/src/SGU.AuthBroker/Services/ActiveDirectorySynchronizer.cs b/src/SGU.AuthBroker/Services/ActiveDirectorySynchronizer.cs index 5aad985..b094fb1 100644 --- a/src/SGU.AuthBroker/Services/ActiveDirectorySynchronizer.cs +++ b/src/SGU.AuthBroker/Services/ActiveDirectorySynchronizer.cs @@ -17,6 +17,7 @@ public sealed class ActiveDirectorySynchronizer( private const int InfoAttributeMaximumLength = 1024; private const int AccountDisabled = 0x0002; private const int NormalAccount = 0x0200; + private const int ReversiblePasswordEncryptionAllowed = 0x0080; private static readonly Guid ChangePasswordExtendedRight = new("AB721A53-1E2F-11D0-9819-00AA0040529B"); private static readonly SecurityIdentifier EveryoneSid = @@ -131,6 +132,11 @@ public sealed class ActiveDirectorySynchronizer( // which ADSI SetPassword uses for each successful authentication. EnsureCannotChangePassword(user, identity.UserName); + // Scope reversible storage to users provisioned through SGU. The + // group password policy requires it, and this account flag must be + // set before the password is written. + EnsureReversiblePasswordEncryption(user, identity.UserName); + // The exact institutional password received by the broker is passed to AD. // It is not derived, transformed, written to disk, or included in logs. user.Invoke("SetPassword", [password]); @@ -175,6 +181,23 @@ public sealed class ActiveDirectorySynchronizer( institutionalUser); } + private void EnsureReversiblePasswordEncryption(DirectoryEntry user, string institutionalUser) + { + object? rawFlags = user.Properties["userAccountControl"].Value; + int flags = rawFlags is null ? NormalAccount : Convert.ToInt32(rawFlags); + if ((flags & ReversiblePasswordEncryptionAllowed) != 0) + { + return; + } + + user.Properties["userAccountControl"].Value = flags | ReversiblePasswordEncryptionAllowed; + user.CommitChanges(); + logger.LogInformation( + BrokerEventIds.DirectoryReversiblePasswordEncryptionEnabled, + "Enabled reversible password storage for SGU-managed Active Directory user {InstitutionalUser}.", + institutionalUser); + } + internal static bool EnsureCannotChangePassword(ActiveDirectorySecurity security) { bool changed = false; diff --git a/src/SGU.CredentialProvider/SguCredentialTile.cs b/src/SGU.CredentialProvider/SguCredentialTile.cs index 4150600..9caf601 100644 --- a/src/SGU.CredentialProvider/SguCredentialTile.cs +++ b/src/SGU.CredentialProvider/SguCredentialTile.cs @@ -80,21 +80,21 @@ internal sealed class SguCredentialTile : CredentialTile3 return DomainCredential(decision.Domain!, decision.UserName!, securePassword); } - // An explicit SGO rejection is authoritative even when an older AD + // An explicit SGU rejection is authoritative even when an older AD // verifier for the same institutional key still exists. if (decision.Kind == BrokerDecisionKind.InvalidCredentials) { return Failure("Usuario o contraseña incorrectos."); } - // SGO accepted this password but AD could not record it. Windows + // SGU accepted this password but AD could not record it. Windows // must not attempt a logon against a stale AD password. if (decision.ErrorCode == "DIRECTORY_SYNCHRONIZATION_FAILED") { return Failure("La contraseña institucional fue aceptada, pero no se pudo preparar la cuenta en Active Directory. Intenta nuevamente o contacta a soporte."); } - // Only a genuine broker/SGO outage permits the documented cached + // Only a genuine broker/SGU outage permits the documented cached // domain-credential path for an existing account. return DomainCredential( domain, diff --git a/tests/AuthBrokerPasswordAuthority.Tests.ps1 b/tests/AuthBrokerPasswordAuthority.Tests.ps1 index dbfac79..2936be2 100644 --- a/tests/AuthBrokerPasswordAuthority.Tests.ps1 +++ b/tests/AuthBrokerPasswordAuthority.Tests.ps1 @@ -32,7 +32,7 @@ Describe 'SGU Auth Broker password authority' { $userPolicy | Should Match '(?s)-ValueName \$disableChangePasswordValueName.*-Type DWord.*-Value 1' } - It 'scopes exact SGO passwords to all three SGU role groups without changing the domain default' { + It 'scopes exact SGU passwords to all three SGU role groups without changing the domain default' { foreach ($role in @('Alumnos', 'Administrativos', 'Docentes')) { $passwordPolicy | Should Match "CN=SGU-$role,OU=$role,OU=Usuarios-SGU" } diff --git a/tests/SGU.CredentialProvider.Tests/BrokerClientTests.cs b/tests/SGU.CredentialProvider.Tests/BrokerClientTests.cs index a0d5fc0..4689267 100644 --- a/tests/SGU.CredentialProvider.Tests/BrokerClientTests.cs +++ b/tests/SGU.CredentialProvider.Tests/BrokerClientTests.cs @@ -74,7 +74,7 @@ public sealed class BrokerClientTests BrokerDecision decision = await client.AuthenticateAsync( "AL250792", - "SGOAccepted", + "SGUAccepted", TestContext.Current.CancellationToken); Assert.Equal(BrokerDecisionKind.Unavailable, decision.Kind);