dsccommunity / dsccommunity/SqlServerDsc
SqlLogin: Add AllowRecreate parameter to enforce Sid on existing logins
@johlju is already working on this.
Since Feb 18, 2026.
- Dominant language
- PowerShell
- Stars
- 385
- Forks
- 224
- PR merge metrics
- No merged PRs in 30d
Description
Context
In PR #2453, the Sid parameter was added to the SqlLogin resource to allow setting the security identifier (SID) for newly created SQL logins. However, the SID validation logic for existing logins is being removed from Test-TargetResource to avoid infinite drift loops, since SQL Server does not support changing a login's SID after creation.
This issue tracks the work to re-add SID validation and implement login recreation functionality in a future PR.
References:
- PR: https://github.com/dsccommunity/SqlServerDsc/pull/2453
- Comment: https://github.com/dsccommunity/SqlServerDsc/pull/2453#discussion_r2805035033
- Original issue: #1470
- Requested by: @johlju
Requirements
1. Re-add SID validation to Test-TargetResource
- Check if the
Sidparameter is bound - Compare the current login's SID with the desired SID
- Return
$falseif they don't match (whenAllowRecreateis$true) - If
AllowRecreateis not set and SIDs mismatch, emit a warning but don't fail the test
2. Add login recreation logic to Set-TargetResource
- When
Sidis bound and the login exists with a different SID - Check if
AllowRecreateparameter is$true - If yes, drop the existing login and recreate it with the correct SID
- If no, emit a warning/error explaining manual intervention is required
3. Add AllowRecreate opt-in parameter
- New boolean parameter on all three functions (Get/Set/Test-TargetResource)
- Defaults to
$falsefor safety - When
$true, allows the resource to drop and recreate the login to enforce the SID - Must be explicitly set by the user to prevent accidental login deletion
Implementation Plan
Phase 1: Add AllowRecreate parameter
- Add
AllowRecreateparameter toSet-TargetResource,Test-TargetResource, andGet-TargetResource(for consistency) - Add parameter to schema MOF file (
DSC_SqlLogin.schema.mof) - Add localized strings for recreation messages
- Update comment-based help with parameter description and warnings
Phase 2: Implement Set-TargetResource logic
- In the
Presentbranch where login already exists:- After checking login existence, add SID validation block
- If
Sidis bound and login SID doesn't match:- If
AllowRecreateis$true:- Log warning about recreation
- Use
$PSCmdlet.ShouldProcessfor confirmation - Drop the existing login using
Remove-SQLServerLogin - Continue to creation logic (reuse existing creation code)
- If
AllowRecreateis$false:- Throw terminating error with clear message that SID cannot be changed without recreation
- Instruct user to set
AllowRecreate = $trueif recreation is acceptable
- If
Phase 3: Update Test-TargetResource logic
- Re-add SID comparison logic (similar to what was removed in PR #2453)
- If
Sidis bound and mismatches:- If
AllowRecreateis$true: return$false(not in desired state) - If
AllowRecreateis$false: emit warning and return$true(avoid drift loop)
- If
Phase 4: Testing and Documentation
- Add unit tests for:
- Login recreation when SID mismatches and
AllowRecreate = $true - Error thrown when SID mismatches and
AllowRecreate = $false - ShouldProcess confirmation for recreation
- Test-TargetResource behavior with/without
AllowRecreate
- Login recreation when SID mismatches and
- Add integration test for login recreation scenario
- Update resource documentation (README.md)
- Add example configuration demonstrating
AllowRecreateusage - Update CHANGELOG.md
Security Considerations
- Recreating a login will drop all associated permissions, roles, and ownerships
- The
AllowRecreateparameter must default to$falsefor safety - Documentation should clearly warn users about the implications of login recreation
- Consider logging which permissions/roles are lost during recreation (if feasible)
- Ensure
ShouldProcessis used with appropriateConfirmImpactlevel (High)
Alternative Approaches Considered
-
No recreation support: Keep current limitation, document that SID can only be set on new logins
- Simpler but less functional
- Users would need to manually drop/recreate logins
-
Automatic recreation without opt-in: Always recreate when SID mismatches
- Too dangerous, could accidentally delete production logins
-
Separate
Forceparameter: Use existing DSC patterns- Less explicit about the recreation action
AllowRecreateis more descriptive and intentional
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.