-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor Provider.AD: Route authentication via AuthSessionBroker with convenience helpers (breaking change) #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
901e89a
Initial plan
Copilot 4279e9b
feat: Add auth session routing to EnsureAttribute step and AD provider
Copilot 50b8b61
Apply auth session routing pattern to remaining 6 provider-calling steps
Copilot 511394a
Add AuthSession parameter to all AD provider methods
Copilot f607a42
Fix adapter restoration and AuthSession propagation in AD provider
Copilot 075a4a3
Improve AuthSession parameter detection for individual methods
Copilot 0567153
feat: Add deprecation warning and update documentation
Copilot c928054
refactor: Remove -Credential parameter and all deprecated/legacy code
Copilot 980a3f9
refactor: Extract parameter detection to helper function
Copilot 14ddbfc
feat: Add New-IdleAuthSessionBroker and consolidate step logic
Copilot e1ce698
docs: Clarify credential variable sources in examples
Copilot 19da512
docs: Regenerate step reference and clarify generator usage
Copilot c08b76c
refactor: Fix thread-safety and code duplication issues
Copilot 7f48432
docs: Add New-IdleAuthSessionBroker example to provider help
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| function New-IdleAuthSessionBroker { | ||
| <# | ||
| .SYNOPSIS | ||
| Creates a simple AuthSessionBroker for use with IdLE providers. | ||
|
|
||
| .DESCRIPTION | ||
| Creates an AuthSessionBroker that routes authentication based on user-defined options. | ||
| The broker is used by steps to acquire credentials at runtime without embedding | ||
| secrets in workflows or provider construction. | ||
|
|
||
| This is a convenience function for common scenarios. For advanced scenarios | ||
| (vault integration, MFA, etc.), implement a custom broker object with an | ||
| AcquireAuthSession method. | ||
|
|
||
| .PARAMETER SessionMap | ||
| A hashtable that maps session configurations to credentials. Each key is a hashtable | ||
| representing the AuthSessionOptions pattern, and each value is the PSCredential to return. | ||
|
|
||
| Common patterns: | ||
| - @{ Role = 'Tier0' } -> $tier0Credential | ||
| - @{ Role = 'Admin' } -> $adminCredential | ||
| - @{ Domain = 'SourceAD' } -> $sourceCred | ||
| - @{ Environment = 'Production' } -> $prodCred | ||
|
|
||
| .PARAMETER DefaultCredential | ||
| Optional default credential to return when no session options are provided or | ||
| when the options don't match any entry in SessionMap. | ||
|
|
||
| .EXAMPLE | ||
| # Simple role-based broker | ||
| $broker = New-IdleAuthSessionBroker -SessionMap @{ | ||
| @{ Role = 'Tier0' } = $tier0Credential | ||
| @{ Role = 'Admin' } = $adminCredential | ||
| } -DefaultCredential $adminCredential | ||
|
|
||
| $plan = New-IdlePlan -WorkflowPath './workflow.psd1' -Request $request -Providers @{ | ||
| Identity = New-IdleADIdentityProvider | ||
| AuthSessionBroker = $broker | ||
| } | ||
|
|
||
| .EXAMPLE | ||
| # Domain-based broker for multi-forest scenarios | ||
| $broker = New-IdleAuthSessionBroker -SessionMap @{ | ||
| @{ Domain = 'SourceAD' } = $sourceCred | ||
| @{ Domain = 'TargetAD' } = $targetCred | ||
| } | ||
|
|
||
| .OUTPUTS | ||
| PSCustomObject with AcquireAuthSession method | ||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| [ValidateNotNull()] | ||
| [hashtable] $SessionMap, | ||
|
|
||
| [Parameter()] | ||
| [AllowNull()] | ||
| [PSCredential] $DefaultCredential | ||
| ) | ||
|
|
||
| $broker = [pscustomobject]@{ | ||
| PSTypeName = 'IdLE.AuthSessionBroker' | ||
| SessionMap = $SessionMap | ||
| DefaultCredential = $DefaultCredential | ||
| } | ||
|
|
||
| $broker | Add-Member -MemberType ScriptMethod -Name AcquireAuthSession -Value { | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| [ValidateNotNullOrEmpty()] | ||
| [string] $Name, | ||
|
|
||
| [Parameter()] | ||
| [AllowNull()] | ||
| [hashtable] $Options | ||
| ) | ||
|
|
||
| # If no options provided, return default | ||
| if ($null -eq $Options -or $Options.Count -eq 0) { | ||
| if ($null -ne $this.DefaultCredential) { | ||
| return $this.DefaultCredential | ||
| } | ||
| throw "No auth session options provided and no default credential configured." | ||
| } | ||
|
|
||
| # Find matching session in map | ||
| foreach ($entry in $this.SessionMap.GetEnumerator()) { | ||
| $pattern = $entry.Key | ||
| $credential = $entry.Value | ||
|
|
||
| # Check if all keys in pattern match Options | ||
| $matches = $true | ||
| foreach ($key in $pattern.Keys) { | ||
| if (-not $Options.ContainsKey($key) -or $Options[$key] -ne $pattern[$key]) { | ||
| $matches = $false | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if ($matches) { | ||
| return $credential | ||
| } | ||
| } | ||
|
|
||
| # No match found | ||
| if ($null -ne $this.DefaultCredential) { | ||
| return $this.DefaultCredential | ||
| } | ||
|
|
||
| $optionsStr = ($Options.Keys | ForEach-Object { "$_=$($Options[$_])" }) -join ', ' | ||
| throw "No matching credential found for options: $optionsStr" | ||
| } -Force | ||
|
|
||
| return $broker | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.