Conversation
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add SamAccountName and UPN derivation from IdentityKey
AD Provider: Derive SamAccountName and UPN from IdentityKey in CreateIdentity
Feb 9, 2026
blindzero
requested changes
Feb 10, 2026
Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
blindzero
approved these changes
Feb 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Active Directory provider adapter to derive AD-specific required fields during CreateIdentity, reducing workflow boilerplate while keeping the IdLE.Step.CreateIdentity contract provider-agnostic.
Changes:
- Added IdentityKey classification and derivation logic in the AD adapter to infer
SamAccountName, optionally setUserPrincipalName, and derive CN/RDN-Name. - Expanded AD provider test suite with new scenarios for derivation behavior.
- Updated AD provider reference documentation to describe the new derivation rules and examples.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/IdLE.Provider.AD/Private/New-IdleADAdapter.ps1 | Implements IdentityKey classification and derives SamAccountName/UserPrincipalName/CN Name before calling New-ADUser. |
| tests/Providers/ADIdentityProvider.Tests.ps1 | Updates fake adapter signature/behavior and adds test cases for the new derivation rules. |
| docs/reference/providers/provider-ad.md | Documents CreateIdentity derivation behavior and updates usage examples accordingly. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Owner
|
@copilot apply changes based on the comments in this thread |
- Clone $Attributes hashtable to avoid mutating caller's data - Use $effectiveAttributes for all derivation and parameter building - Simplify fake adapter to avoid duplicating production logic - Update tests to work with simplified fake adapter - All 421 tests passing Co-authored-by: blindzero <13959569+blindzero@users.noreply.github.com>
Contributor
Author
All review comments addressed:
Changes in commit 87459a6 |
blindzero
approved these changes
Feb 10, 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.
Implementation Complete: AD Provider - Derive SamAccountName and optionally UPN from IdentityKey
Summary of Changes
This PR implements smart derivation behavior in the AD Provider's
CreateIdentityoperation to improve usability for AD joiner workflows while maintaining provider-agnostic step contracts.Key Features Implemented
✅ SamAccountName Derivation
SamAccountNamefromIdentityKeywhen IdentityKey is SamAccountName-likeSamAccountNameSamAccountName✅ UserPrincipalName Auto-Set
UserPrincipalNamefromIdentityKeywhen IdentityKey is a UPNUserPrincipalName✅ CN/RDN Name Derivation
✅ Path Pass-Through
Pathattribute with no changes✅ No Hashtable Mutation
$Attributeshashtable to avoid mutating caller's data$effectiveAttributes)Files Changed
src/IdLE.Provider.AD/Private/New-IdleADAdapter.ps1 (+70 lines)
tests/Providers/ADIdentityProvider.Tests.ps1 (+240 lines)
docs/reference/providers/provider-ad.md (+88 lines)
-AllowDeleteswitch for initializationTest Results
✅ AD Provider Tests: 61/61 passing (0 failures)
✅ Full Test Suite: 421/421 passing (0 failures)
✅ Script Analyzer: 0 errors
✅ Code Review: Addressed all review comments
Backward Compatibility
Example Usage
Before (required explicit SamAccountName):
After (SamAccountName derived automatically):
UPN scenario (explicit SamAccountName required):
Original prompt
This section details on the original issue you should resolve
<issue_title>AD Provider: Derive SamAccountName and optionally UPN from IdentityKey in CreateIdentity</issue_title>
<issue_description>## Problem Statement
When using the provider-agnostic step
IdLE.Step.CreateIdentitytogether withIdLE.Provider.AD, authoring a first simple joiner workflow is unnecessarily error-prone:New-ADUserrequires-SamAccountName, but IdLE currently does not derive it fromIdentityKey. Users must duplicate the same value in bothWith.IdentityKeyandWith.Attributes.SamAccountName.IdentityKeyis provided as a UPN (user@domain) it is intuitive to treat this as the UPN, but IdLE currently does not auto-setAttributes.UserPrincipalNamewhen missing.New-ADUser -Name) should not be coupled toIdentityKey. Users want the directory object name to follow explicit values (e.g.,DisplayNameorGivenName Surname) without needing AD-specific steps.Pathmust be reliably passed through to the AD RSAT cmdlets (New-ADUser -Path ...) to avoid default-container placement (and frequent “Access is denied” due to ACL differences).Goal: Improve usability for AD joiner workflows while keeping
IdLE.Step.CreateIdentityprovider-agnostic (changes must be in the AD provider/adapter only).Proposed Solution
Implement AD-specific convenience behavior in
IdLE.Provider.AD(and/or its adapter) forCreateIdentity(IdentityKey, Attributes):1) Derive
SamAccountNamefromIdentityKey(conservative)If
Attributes.SamAccountNameis missing/empty:IdentityKeyusing the same/consistent logic as AD identity resolution (GUID vs UPN vs SamAccountName-like).IdentityKeyis SamAccountName-like:Attributes.SamAccountName = IdentityKey.IdentityKeyis a UPN (user@domain):SamAccountNameis mandatory forNew-ADUserand must be provided explicitly whenIdentityKeyis a UPN.Never override explicitly provided
Attributes.SamAccountName.2) Auto-set
UserPrincipalNamewhenIdentityKeyis a UPNIf
IdentityKeyis a UPN andAttributes.UserPrincipalNameis missing/empty:Attributes.UserPrincipalName = IdentityKey.Never override explicitly provided
Attributes.UserPrincipalName.3) Derive the AD object CN/RDN
-Nameindependently ofIdentityKeyWhen calling
New-ADUser -Name ..., determine the name with this priority order:Attributes.Name(explicit CN/RDN)Attributes.DisplayNameAttributes.GivenNameandAttributes.Surnameare present:"<GivenName> <Surname>"IdentityKey(with a warning/debug event to highlight the fallback)This ensures
Name != IdentityKeyby default in typical joiner workflows, while remaining deterministic.4) Ensure
Pathis passed through to RSATContinue to accept
Attributes.Pathand ensure it is consistently passed through toNew-ADUser -Path ...(no additional derivation required).5) Logging / events
When any derivation occurs (SamAccountName, UserPrincipalName, CN/RDN Name):
Alternatives Considered
Document-only approach (require users to always specify
SamAccountNameand manage-Namethemselves).Make
IdLE.Step.CreateIdentityAD-aware.Automatically derive SamAccountName from UPN left-part (truncate/sanitize/collision handling).
Impact
Does this affect existing workflows?
Attributes.SamAccountName,Attributes.UserPrincipalName,Attributes.Name, no behavior changes.SamAccountNamemay start working automatically whenIdentityKeyis samAccountName-like.Any backward compatibility concerns?
IdentityKeyas UPN and missingSamAccountNamewill now fail fast with a clearer, earlier error (explicitly guiding users to setSamAccountName).Additional Context
Acceptance Criteria
SamAccountName derivation
Attributes.SamAccountNameis missing/empty andIdentityKeyis samAccountName-like,SamAccountNameis set toIdentityKey.IdentityKeyis a UPN andSamAccountNameis missing/empty, creation fails fast with a clear error.*UPN convenience...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.