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

+1
View File
@@ -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));
}
@@ -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;
@@ -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,