Repository navigation
Conversation
GET /api/auth/negotiate verified the SPNEGO token, then looked the
principal up only through a "kerberos" identity mapping or by matching
the bare username against a user's display name or email. Nothing
creates kerberos mappings, and a normal AD user's display name ("John
Doe") and email (jdoe@green.org) never equal the bare sAMAccountName,
so every directory user got 401 "no user found for Kerberos principal"
-- including users who had already signed in with their AD password and
had an "ldap" mapping. Deployments worked around it by creating a
kerberos mapping per user.
/login/sso already solves this with resolveKerberosUser (ldap mapping,
LDAP lookup by sAMAccountName, JIT provisioning, AD-disable check).
resolveNegotiateUser now uses it for the API endpoint too:
1. an explicit kerberos mapping still wins, so existing mappings and
the per-user workaround keep working;
2. otherwise the directory, exactly as /login/sso;
3. the display-name/email match remains as the fallback for
deployments without a directory.
A disabled directory account returns 403 and never falls through to
the fallback match. Tokens now carry the directory groups, as they do
on /login/sso; the endpoint previously issued them with no groups.
Unit tests cover the mapping, fallback, unknown-principal and app-local
branches. The directory branch needs a live LDAP server, so it was
verified against a Samba AD DC: a password-provisioned user, a user who
never signed in (JIT) and an Arabic-named user now get tokens with
their AD groups; an AD-disabled user presenting a still-valid ticket
gets 403.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GET /api/auth/negotiatecannot map a normal Active Directory user to a SimpleAuth user. Kerberos itself succeeds (the ticket verifies against the keytab), and then the lookup fails with401 no user found for Kerberos principal: jdoe./login/ssodoes not have this problem.Why it fails
After verifying the AP-REQ, the handler looked the principal up two ways only:
kerberosidentity mapping. Nothing in SimpleAuth creates these. LDAP login and/login/ssowriteldap/localmappings.matchAutoProvisionUser, which matches when a user's display name or email equals the bare username. For a real AD account (John Doe,jdoe@green.org) that is never true.So every directory user got a 401, including users who had already signed in with their AD password and had an
ldapmapping the endpoint never consulted. Deployments have been working around this by creating akerberosmapping per user in their bootstrap scripts./login/ssoalready solves the same problem inresolveKerberosUser: it reuses theldapmapping, looks the user up in LDAP bysAMAccountName, provisions them on first sight, and checks AD-disabled state.Change
A new
resolveNegotiateUserresolves the principal in this order:kerberosmapping (full principal, then realm-less). Existing mappings and the per-user workaround keep working unchanged.resolveKerberosUser, the same code/login/ssouses.A disabled directory account comes back as
auth.ErrLDAPAccountDisabled→ 403account disabledand never falls through to step 3.Tokens from this endpoint now carry the directory groups, as
/login/ssotokens do. They were previously issued withgroups: nil.Verification
Unit tests (
negotiate_resolve_test.go): explicit mapping wins; realm-less mapping resolves; without a directory the legacy match still resolves and records a mapping; an unknown principal fails; an app-local user is never bound (M12). Fullgo test ./...is green,go vetandgofmtare clean.End to end against a Samba AD DC (
nowsci/samba-domain, realmGREEN.ORG), SimpleAuth behind nginx with LDAP on plain 389 and theHTTP/<host>keytab. Tickets come fromkinit; requests usecurl --negotiate:jdoe: signed in by password earlier, has anldapmappinggroups: [Engineering]salem: Arabic display namename: سالم المريnewhire: never signed inleaver: AD-disabled, still holding a valid service ticketThe directory branch has no unit test because it needs a live LDAP server, and the handler package has no LDAP fake. If you'd like one, I can add a scenario to
test/integration.Not changed
Two related issues in the
/login/ssofailure path showed up while testing. They are left for a separate PR to keep this one focused:redirect_uriand dropsclient_id,oidc,state,nonceand the PKCE challenge.redirect_uriwith?error=<message>but withoutstate, so OIDC clients reject the callback as a state/CSRF mismatch instead of showing the error.🤖 Generated with Claude Code