Repository navigation
Conversation
POST /api/admin/ldap/link-users (admin key): guids or all, dry_run, remove_local_password. A user with only a local mapping got a second, JIT-provisioned user at their first AD sign-in, and local:<name> moved to it; the original user and its roles were left behind. Linking writes ldap:<name> (and ldap:<AD spelling>) on the existing user, after checking that exactly one enabled AD account matches and no other user holds it, and syncs the profile as an AD sign-in does. Every other case is reported and left untouched; a directory error stops the run (502). The SimpleAuth password stays unless removed, now or later. The sign-in path, directoryAccountDisabled and the link path call the directory through h.ldapSearchUser / h.ldapAuthenticate so tests can stand in for AD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Per row (Link to AD), for ticked users (floating bar: Link selected to AD), for everyone (Link all to AD), and Remove SimpleAuth Password in a linked user's details. One dialog shows the dry run per user, re-runs it when the remove-password box changes, and applies exactly the previewed users in batches of 1000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
GetUser and ResolveMapping return an error matching store.ErrNotFound (errors.Is) when the user or mapping does not exist, in both backends; their messages are unchanged. Callers can now treat any other error as a store failure instead of as "absent". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Sign-in (authenticateUser): - after AD accepts the password, look the user up by ldap:<typed>, then by ldap:<AD spelling>, before provisioning anyone: a name typed in another case (JDOE for jdoe) created a second user and re-pointed the first user's mappings to it; - a JIT-provisioned user takes only mapping names nobody holds, so a first AD sign-in no longer takes an existing user's username; - a store error during the lookup fails the sign-in instead of provisioning a duplicate. Link (review fixes): - find the AD account with the sign-in's own filter (custom_filter, else username_attr), person entries only, exactly one match (auth.linkFilter, LDAPUserFinder, ErrLDAPAmbiguous), over one connection per request; - when both sides have an email and they differ, link only GUIDs listed in "confirmed" (status email_differs); results show both identities and the audit record keeps the previous profile and the AD DN; - store failures stop the run (500) instead of reading as absent or free; a request that ended stops it (503); - writes start from a fresh read of the user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Rows show the SimpleAuth user and the AD account side by side; a row with a different email in AD needs its own "Same person: link" tick. Only the latest preview's answer is shown; a stopped run's results are kept; the header checkbox leaves ticked users hidden by the search alone; apply sends batches of 100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
Log the store's GUID instead of the request's, labels instead of the request's flags and the password field, and names with line breaks removed (logSafe). gofmt on the new test file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
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.
Problem
A deployment that created its users in SimpleAuth first (a local username and a SimpleAuth password) and configured AD later cannot move those users to AD without losing their roles:
authenticateUsertries the SimpleAuth password, then AD. On AD success it finds the user by theldap:<typed name>mapping only.local:<name>. Their first AD sign-in therefore JIT-provisions a new user, andSetIdentityMappingre-pointslocal:<name>to it.I reproduced this against a Samba AD DC: the user signed in with the AD password and got a new GUID with no roles. The original user lost its
localmapping, and its password then got 401.The same split happens to any AD user who types their name in another letter case (
JDOEforjdoe). AD matches names in any case, but mapping keys are case-sensitive. JIT then re-points bothldap:andlocal:<AD spelling>away from the existing user.Change
API:
POST /api/admin/ldap/link-usersAdmin key. Takes
guids(1..1000) orall: true, plusdry_run,remove_local_passwordandconfirmed.For each user with a SimpleAuth username and no AD link:
custom_filterif set, else the username attribute. It is limited to(objectClass=person), so a group named like a user never matches. One directory connection serves the whole request.ldap:<name>on the existing user, plusldap:<AD spelling>when they differ, and syncs the profile, groups andsAMAccountNameexactly as an AD sign-in does.email_differsand nothing changes, unless the GUID is also inconfirmed. Results show both identities (display_name/emailanddirectory_display_name/directory_email). The audit record keeps the previous display name and email, plus the AD DN.not_in_directory,disabled_in_directory,conflict(withconflict_guid),ambiguous,already_linked,skipped_app_local,skipped_merged,no_local_username,not_found. It never re-points a mapping another user holds.spelling_differsflags names that AD spells differently. After linking, thesamaccountnameclaim carries AD's spelling.directory_outage_policy.remove_local_password: trueremoves it, either at link time or later: with the flag set, already-linked users that still have a password are in scope.502, a store failure500, and a request that ended early (client gone, write timeout)503. Each response includes the results so far. Store reads tell "absent" apart from "failed" through a newstore.ErrNotFound, in both backends; existing messages are unchanged.Sign-in fixes (
authenticateUser)ldap:<typed>, then byldap:<AD spelling>, before anyone is created. SoJDOEsigns in tojdoe.Console: Users page
Every action opens one dialog:
Supporting changes
auth: a sharedsignInFilter(used byLDAPAuthenticate) andlinkFilter;LDAPUserFinder(one connection, a size limit of 2, andErrLDAPAmbiguous).h.ldapAuthenticate,h.ldapSearchUser(used bydirectoryAccountDisabled) andh.ldapUserFinder.docs/API.md: the endpoint;docs/ACTIVE-DIRECTORY.md: "Moving Existing SimpleAuth Users to AD", including how to clean up duplicates made earlier;CHANGELOG.md: Unreleased.Tests
internal/handler/ldap_link_test.go(20 tests). Each fix from the independent review was first written as a failing test.JDOE/JDoe): lands on the linked user, mappings intact. Before the fix, this created a new user and stranded the linked one.allscoping;email_differswithout confirmation, linked with it, and the audit record keeps the old profile.GetUserorResolveMapping→ 500, nothing linked;internal/auth/ldap_filter_test.go: sign-in and link filters (default,uid,custom_filter, escaping).internal/store/notfound_test.go:ErrNotFoundfromGetUserandResolveMapping, messages unchanged.go vet ./...andgofmtare clean.go test -race ./...: auth, handler, migrate, store allok(Go 1.26.8)JDOE/jSmItHland on the linked users, with no new users;ahmed(different emails) are held back until confirmed, and the audit keeps the previous profile;Not in this PR (noticed while working)
GET /api/admin/usersreturns each user'spassword_hash(bcrypt) to the console.docs/ACTIVE-DIRECTORY.md"User Identity" says AD users are mapped asldap:{objectGUID}, but the code maps the username.🤖 Generated with Claude Code
https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP