fix(auth): user bind proves the bound account is the entry whose groups it returns (scadaproj#40)

BindMode=User bound as UserBindTemplate({0}) and then returned the groups of
whatever entry (UserNameAttribute={0}) found - two directory lookups that can
name two accounts (Auth-007). Reproduced live against GLAuth: mallory bound as
herself and signed in with boss's Admins group.

After the bind the service now asks RFC 4532 Who-am-I and requires the entry
to be that account (dn: -> DN match; AD u:DOMAIN\name -> sAMAccountName match).
Without a Who-am-I answer only a DN template is provable (bind DN must equal
the entry DN); anything else fails closed as GroupLookupFailed. {0} is
RFC 4514-escaped in DN templates; validator message leads with EXAMPLE\{0}.

Auth 0.4.3 -> 0.4.4 (unpublished).

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 14:46:25 -05:00
parent 5f5d684c44
commit d549a782fd
15 changed files with 530 additions and 31 deletions
@@ -45,10 +45,17 @@ public sealed record LdapOptions
/// normalised login name. Must contain <c>{0}</c> exactly once.
/// <para>
/// Prefer the down-level form <c>EXAMPLE\{0}</c>: it maps exactly to the <c>sAMAccountName</c> the
/// group search uses, so the account that binds is the account whose groups are read. A UPN
/// template (<c>{0}@example.com</c>) is only correct where every account's UPN prefix equals its
/// <c>sAMAccountName</c> — AD resolves a UPN bind against the explicit <c>userPrincipalName</c>, so
/// a mismatch can fail sign-in or bind a different account than the one whose groups are read.
/// group search uses. A UPN template (<c>{0}@example.com</c>) only signs in accounts whose UPN
/// prefix equals their <c>sAMAccountName</c> — AD resolves a UPN bind against the explicit
/// <c>userPrincipalName</c>, so it can bind a different account than the one the search finds.
/// </para>
/// <para>
/// Since 0.4.4 the service proves the entry it reads is the account that bound, and refuses the
/// sign-in (<see cref="LdapAuthFailure.GroupLookupFailed"/>) otherwise. It asks the directory
/// (RFC 4532 "Who am I?") and compares the answer with the entry's DN or, for AD's
/// <c>u:DOMAIN\name</c> answer, its <c>sAMAccountName</c>. A server without Who-am-I (e.g. GLAuth)
/// is only supported with a DN template (containing <c>=</c>), which must produce the entry's DN
/// exactly as the search reports it; <c>{0}</c> is RFC 4514-escaped in a DN template.
/// </para>
/// </summary>
public string UserBindTemplate { get; init; } = "";