Skip to content

Kerberos sign-in: bind the realm to the directory entry; no UPN-only or machine-account match (BACKLOG #4846) - #3255

Open
wshallwshall wants to merge 4 commits into
mainfrom
b684-4846-kerberos-realm
Open

wshallwshall wants to merge 4 commits into
mainfrom
b684-4846-kerberos-realm

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Merge danger

Reversible: yes -- reverting the squash on main restores the previous directory lookup for Kerberos sign-in.

Blast radius: Kerberos (Windows SSO) sign-in's directory lookup: messagefoundry/auth/ldap.py, three lines at the Kerberos call in messagefoundry/auth/service.py, docs/SECURITY.md (the Kerberos realm paragraph), a changelog fragment, and tests. The password/name lookup path is unchanged, shown by controls. No store, pipeline, connection or API shape change.

Evidence

  • Before: at origin/main 353b2183fe2, the Kerberos lookup matched a forest-wide name, accepted a UPN-only match, did not bind the entry to kerberos_realm, and did not exclude computer or managed service accounts.
  • After: new tests/test_kerberos_realm_binding.py covers a forest-wide name collision both ways, a child realm, a child-only entry, UPN-only and machine-account entries, and a $ name refused before any search; controls show the password/name lookup unchanged. pytest over 18 related files: 872 passed.

Batch 684, BACKLOG #4846 (Builder E3)

Source branch b684-4846-kerberos-realm, head 7239655b6fd5781f5e3c0eaf3b2739168cb7104a. Its own PR because it changes a security control.

What changed (all items re-measured at 353b2183fe2 and still open):

  1. Lookups take kerberos_realm, and Kerberos sign-in passes it. An entry is kept only when its DN's whole trailing DC= run equals the realm, compared case-insensitively. The new _dn_realm reads the DN with the group-DN parser, now split out as _canonical_rdns; it refuses a dotted label and reads the DC OID as dc.
  2. The Kerberos filter is (&(objectCategory=person)(objectClass=user)(sAMAccountName=x)), with no UPN arm. Each entry is re-checked by _holds_name.
  3. objectCategory=person excludes computers and managed service accounts. A name ending in $ is NOT_FOUND before any search, because a trust account is a person-category user.

Scope note: three lines in messagefoundry/auth/service.py (the Kerberos call, about line 7080) pass kerberos_realm; without them the control would be unused. Batch 684's #4276 Builder also edits service.py, in a different region; whichever PR lands second may need a rebase. tests/test_ad_ambiguous_name.py wording was updated after it went red.

Open question for the owner, not decided here: keep the realm compare case-insensitive, or make it case-sensitive per RFC 4120 section 6.1. The code stays case-insensitive, as before.

Checks run: ruff check and ruff format --check; mypy linux on ldap.py and service.py, win32 on ldap.py, the tests leg on the two test files; pytest on 18 related files, 872 passed.

Not run: the full suite and mypy on the full packages. Read the full pytest, Windows and mypy tests CI legs.

Review: code-review skill at xhigh, Rounds: 2 + 1 unrepaired. The QA line and open findings are in a comment below.

… machine matches

The ticket's realm was checked against [auth].kerberos_realm and dropped,
and the directory was then asked the password sign-in's wider question.
resolve_principal and probe_principal take kerberos=True, which only the
Kerberos sign-in passes. That lookup:

- filters on objectCategory=person, objectClass=user and sAMAccountName
  only, with no userPrincipalName arm;
- answers NOT_FOUND for a name ending in $ before any search (machine
  and interdomain trust accounts);
- keeps only entries whose own sAMAccountName is the name and whose DN
  ends in the DC= RDNs of the realm's domain, up to ASCII case.

The DN parser behind canonical_group_dn is split out as _canonical_rdns
so _dn_realm reads a DN the same way. The realm is read from the
authenticator's own settings and an unset one raises LdapError.

test_ad_ambiguous_name's Windows SSO tie-break test now sets the realm
to X, the domain its entries sit under.

BACKLOG #4846
…gment

SECURITY.md's Kerberos realm paragraph says what the narrowed lookup
asks, what it refuses, and the Active Directory assumption it rests on.

BACKLOG #4846
…use early

Review round 1 on the realm binding:

- the lookup takes kerberos_realm from the caller, the same settings
  value kerberos_principal checked the ticket against, instead of the
  authenticator's own copy; an empty or malformed one raises LdapError;
- _dn_realm refuses a DC label holding a dot, escaped or not, and reads
  the domainComponent name and OID as dc;
- the $ refusal and the realm check run in probe_principal before the
  service session opens;
- one _search_user call site; docstrings, SECURITY.md and the changelog
  say what the lookup now reads, including that a ticket naming an
  implicit UPN finds nothing;
- stale Kerberos wording in test_ad_ambiguous_name is corrected.

BACKLOG #4846
…G drops

Review round 2 on the realm binding:

- _kerberos_lookup_realm checks the realm and refuses a $ name, asked
  by both probe_principal (before the session) and _lookup_by_name
  (where the filter is built), so neither guard rests on the call path;
- _checked_kerberos_realm is the one ValueError-to-LdapError mapping;
- _holds_name is the one sAMAccountName rule for the ambiguity check
  and the Kerberos narrowing;
- a dropped entry logs at DEBUG: under the global catalog it is routine;
- SECURITY.md, the changelog and the docstrings state the binding as the
  whole trailing DC= run equalling the realm, name the parser-refused
  DN case, and use the conditional for beta defects.

BACKLOG #4846
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA -- korus roles/BUILDER.md step 11 (Builder E3, BACKLOG #4846)
Level: xhigh, from the brief. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (forks a837018790fd3516f round-1255839c, a67cc9dbc458569db round-4d131a59, a3e0787a840282682 round-7771c07b; review_tag.py exit 0 each).
Rounds: 2 + 1 unrepaired. Round 1: 12 findings, 9 fixed, 3 open. Round 2: 11 findings, 8 fixed, 3 open. Round 3: 10 findings, open.

Open findings, unrepaired (the Builder reports none loosens a control):

  • The Audit handover tag checks run off the event loop under Transit (BACKLOG #3929) #3228 tie-break can no longer choose for its only production caller, Kerberos. A sealed store read still runs on each sign-in. The _stored_directory_object_id docstring and the test_windows_sso..._colliding_entry name and its "RED without Audit handover tag checks run off the event loop under Transit (BACKLOG #3929) #3228" line overstate it. Remove it or retarget it.
  • "kept 0 of N" is logged only at DEBUG. A warn-once would help with search-base misconfiguration.
  • kerberos_principal drops the realm and the service re-reads it from settings. A typed (account, realm) return would close that gap.
  • The realm is checked 3 times and the $ check runs twice. "No person needs $" overstates AD: hidden jdoe$ users exist.
  • "password sign-in unchanged" wording (that sign-in is retired), and stale "same lookup as Kerberos" prose at service.py:9582, :7429 and oidc/init.py:10.
  • create_directory_account still does the wide lookup.
  • Possible efficiency gain: scope the search base to the realm's naming context.
  • The CONFIGURATION.md kerberos_realm row should say the search base must cover the realm's DC= naming context.
  • Implicit-UPN tickets without canonicalization now fail closed; unverified against a real KDC.

@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hand-over (Manager aebf32, batch 684)

Field Value
Pull request MEFORORG/MessageFoundry 3255
Head SHA 7239655
Unread legs Every hosted CI leg; locally the full pytest suite and full-package mypy were not run. Read the full pytest, Windows and mypy tests legs.
Known defects The open round-3 findings, verbatim in the QA comment above.
Landing-order constraint none required. Batch 684's #4276 PR (not yet open) also edits messagefoundry/auth/service.py in a different region; whichever lands second may need a branch update.

Ledger ask after merge: banner for #4846, from the Builder, carried as written (the row stays PARTIAL):
PARTIAL -- engine PR 3255 builds steps 1 and 2. The Kerberos lookup keeps only person accounts (objectCategory=person, objectClass=user) whose own sAMAccountName is the ticket's name and whose DN's trailing DC= run equals kerberos_realm. There is no UPN arm, and a $ name is never looked up. Step 3, case-insensitive versus RFC 4120, is an open owner question; the code stays case-insensitive. Step 4 is owed.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hold on head 7239655.

The QA covers this head (round-7771c07b, exit 0). The lookup only narrows; nothing weakens authentication. The two fail-closed behaviour findings, the jdoe$ person account and the implicit-UPN ticket, I rule ORDINARY under decision d20261123T150929936-d70a0b. Each is a fail-closed over-refusal that passes nothing main refused, it is not on an inbound HL7 path, and every commit is reviewed. Both are queued for filing, along with the real-KDC check.

Held on one false control claim this PR made stale. The _stored_directory_object_id docstring in messagefoundry/auth/service.py (about line 7145) says the stored id "lets the lookup pick the entry the row is already bound to". On the Kerberos path, its only production caller, the tie-break can no longer choose. The same holds for tests/test_ad_ambiguous_name.py:316-319 ("RED without #3228"). Fix it one of two ways:

  • drop tie_break_object_id and its sealed read from the Kerberos call (about :7080) and retarget the test; or
  • reword the docstring and the test to say that the realm narrowing now prevents the colliding-entry lockout.

CI gate is still pending. After the fix lands, I enqueue once it is green; a text-only fix needs no new review round.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant