-
Notifications
You must be signed in to change notification settings - Fork 215
identity governance: additional cmdlets for filtering entitlement mgmt policy and access packages #631
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
identity governance: additional cmdlets for filtering entitlement mgmt policy and access packages #631
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
abfbb0f
introduce select on assignment policy
markwahl-msft 007a231
Merge branch 'dev' into mwahl-em-addl2
markwahl-msft 273011e
add -NoApprovalRequiredForRequest
markwahl-msft d27ac40
introduce select- for AP and assignment
markwahl-msft b82de7c
remove select- assignment for now
markwahl-msft b8fba59
add filter on policy scope and no approval required
markwahl-msft 838c831
Merge branch 'dev' into mwahl-em-addl2
markwahl-msft 8f08bcb
Merge branch 'dev' into mwahl-em-addl2
markwahl-msft dafe03b
simplify expression
markwahl-msft 8b1e07c
Merge branch 'dev' into mwahl-em-addl2
peombwa 4547233
Merge branch 'dev' into mwahl-em-addl2
peombwa 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
123 changes: 123 additions & 0 deletions
123
...ity.Governance/Identity.Governance/custom/Select-MgEntitlementManagementAccessPackage.ps1
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,123 @@ | ||
| # ---------------------------------------------------------------------------------- | ||
| # | ||
| # Copyright Microsoft Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .Synopsis | ||
| Select matching entitlement management accessPackage | ||
| .Description | ||
| Select matching entitlement management accessPackage | ||
| .Inputs | ||
| Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackage | ||
| .Outputs | ||
| Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackage | ||
| .Notes | ||
|
|
||
| .Link | ||
| https://docs.microsoft.com/en-us/powershell/module/microsoft.graph.identity.governance/select-mgentitlementmanagementaccesspackage | ||
| #> | ||
| function Select-MgEntitlementManagementAccessPackage { | ||
| [OutputType([Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackage])] | ||
| [CmdletBinding(PositionalBinding=$false, ConfirmImpact='Medium')] | ||
| [Microsoft.Graph.PowerShell.Profile('v1.0-beta')] | ||
| param( | ||
| [Parameter (ValueFromPipeline=$true)] | ||
| [Microsoft.Graph.PowerShell.Models.MicrosoftGraphAccessPackage[]]$AccessPackage, | ||
|
|
||
| [Parameter (Mandatory = $False)] | ||
| [switch] | ||
| $PolicyWithNoApprovalRequiredForRequest, | ||
|
|
||
| [Parameter (Mandatory = $False)] | ||
| [string[]] | ||
| $PolicyWithScopeType | ||
|
|
||
| ) | ||
|
|
||
| begin { | ||
| $APWithZeroPolicies = 0 | ||
| $APWithNonZeroPolicies = 0 | ||
| $policyEvaluation = $false | ||
|
|
||
| if ($PolicyWithNoApprovalRequiredForRequest -or ($null -ne $PolicyWithScopeType -and $PolicyWithScopeType.Length -gt 0)) { | ||
| $policyEvaluation = $true | ||
| } | ||
| } | ||
|
|
||
| process { | ||
|
|
||
| $NewObj = $AccessPackage | ||
| $accessPackageId = "" | ||
| try { | ||
| $accessPackageId = $AccessPackage.Id | ||
| } catch { | ||
| write-verbose "no access package id" | ||
| return | ||
| } | ||
|
|
||
| if ($policyEvaluation) { | ||
| $inputPolicyCount = 0 | ||
| try { | ||
| if ($AccessPackage.AccessPackageAssignmentPolicies) { | ||
| $inputPolicyCount = $AccessPackage.AccessPackageAssignmentPolicies.Length | ||
|
|
||
| } | ||
| } catch { | ||
| write-verbose "no policies in $accessPackageId" | ||
| $APWithZeroPolicies++ | ||
| return | ||
| } | ||
| if ($inputPolicyCount -eq 0) { | ||
| $APWithZeroPolicies++ | ||
| return | ||
| } | ||
|
|
||
| $APWithNonZeroPolicies++ | ||
|
|
||
| $matchingPolicyCount = 0 | ||
| $matchingPolicies = @() | ||
| foreach ($p in $AccessPackage.AccessPackageAssignmentPolicies) { | ||
| $thisMatch = $null | ||
|
|
||
| $thisMatch = @(Select-MgEntitlementManagementAccessPackageAssignmentPolicy -ScopeType $PolicyWithScopeType -NoApprovalRequiredForRequest:$PolicyWithNoApprovalRequiredForRequest -Policy $p) | ||
|
|
||
| if ($null -eq $thisMatch -or $thisMatch.Length -eq 0) { | ||
| # not a match | ||
| } else { | ||
| $matchingPolicies += $thisMatch[0] | ||
| } | ||
| } | ||
| $matchingPolicyCount = $matchingPolicies.Length | ||
| if ($matchingPolicyCount -eq 0) { | ||
| write-verbose "skipping $accessPackageId as $inputPolicyCount policies has 0 matching" | ||
| return | ||
| } elseif ($inputPolicyCount -ne $matchingPolicyCount) { | ||
| write-verbose "changing $accessPackageId from $inputPolicyCount to $MatchingPolicyCount" | ||
|
|
||
| $NewObj = $AccessPackage.PSObject.Copy() | ||
| $NewObj | Add-Member -MemberType NoteProperty -Name AccessPackageAssignmentPolicies -Value $matchingPolicies -Force | ||
| } else { | ||
| write-verbose "all $inputPolicyCount policies of $accessPackageId are relevant" | ||
| } | ||
|
|
||
| } | ||
|
|
||
| write-output $NewObj | ||
| } | ||
|
|
||
| end { | ||
| if ($APWithNonZeroPolicies -eq 0 -and $ApWithZeroPolicies -gt 1 -and $policyEvaluation -eq $true) { | ||
| write-warning "no access packages had any policies to evaluate" | ||
| } | ||
| } | ||
| } | ||
120 changes: 120 additions & 0 deletions
120
...dentity.Governance/custom/Select-MgEntitlementManagementAccessPackageAssignmentPolicy.ps1
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,120 @@ | ||
| # ---------------------------------------------------------------------------------- | ||
| # | ||
| # Copyright Microsoft Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .Synopsis | ||
| Select matching entitlement management accessPackageAssignmentPolicy | ||
| .Description | ||
| Select matching entitlement management accessPackageAssignmentPolicy | ||
| .Inputs | ||
| Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackageAssignmentPolicy | ||
| .Outputs | ||
| Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackageAssignmentPolicy | ||
| .Notes | ||
|
|
||
| .Link | ||
| https://docs.microsoft.com/en-us/powershell/module/microsoft.graph.identity.governance/select-mgentitlementmanagementaccesspackageassignmentpolicy | ||
| #> | ||
| function Select-MgEntitlementManagementAccessPackageAssignmentPolicy { | ||
| [OutputType([Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAccessPackageAssignmentPolicy])] | ||
| [CmdletBinding(DefaultParameterSetName='ExplicitScope', PositionalBinding=$false, ConfirmImpact='Medium')] | ||
| [Microsoft.Graph.PowerShell.Profile('v1.0-beta')] | ||
| param( | ||
| [Parameter (ValueFromPipeline=$true)] | ||
| [Microsoft.Graph.PowerShell.Models.MicrosoftGraphAccessPackageAssignmentPolicy[]]$Policy, | ||
|
|
||
| [Parameter (Mandatory = $False)] | ||
| [switch] | ||
| $NoApprovalRequiredForRequest, | ||
|
|
||
| [Parameter (Mandatory = $False,ParameterSetName = "ExplicitScope")] | ||
| [string[]] | ||
| $ScopeType | ||
| ) | ||
|
|
||
| begin { | ||
|
|
||
| } | ||
|
|
||
| process { | ||
| $policyId = $Policy.Id | ||
| $acceptRequests = $false | ||
| $thisScopeType = "" | ||
|
|
||
| if ($Policy.RequestorSettings) { | ||
| $acceptRequests = $Policy.RequestorSettings.AcceptRequests | ||
| $thisScopeType = $Policy.RequestorSettings.ScopeType | ||
| } | ||
| $matchedScopeType = $true | ||
| if ($null -ne $ScopeType -and $ScopeType.Length -gt 0) { | ||
| $matchedScopeType = $false | ||
| foreach ($s in $ScopeType) { | ||
| if ($thisScopeType -eq $s) { | ||
| $matchedScopeType = $true | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if ($acceptRequests -and $matchedScopeType -eq $false) { | ||
| write-verbose "policy $policyId did not match scope type with $thisScopeType" | ||
| return | ||
| } | ||
|
|
||
| if ($NoApprovalRequiredForRequest -and $acceptRequests -eq $true) { | ||
| $approvalIsRequiredForRequest = $false | ||
|
|
||
| if ($Policy.RequestApprovalSettings) { | ||
| $isApprovalRequired = $Policy.RequestApprovalSettings.isApprovalRequired | ||
| $isApprovalRequiredForExtension = $Policy.RequestApprovalSettings.isApprovalRequiredForExtension | ||
|
|
||
| $isApprovalOverride = $true | ||
|
|
||
| if ($Policy.RequestApprovalSettings.ApprovalMode -eq "NoApproval") { | ||
| $isApprovalOverride = $false | ||
| } | ||
| if ($Policy.RequestApprovalSettings.ApprovalStages -eq $null -or $Policy.RequestApprovalSettings.ApprovalStages.Length -eq 0) { | ||
| $isApprovalOverride = $false | ||
| } | ||
|
|
||
| if ($isApprovalRequired -eq $true -and $isApprovalOverride -eq $true) { | ||
| $approvalIsRequiredForRequest = $true | ||
| } else { | ||
| write-verbose "policy $policyId did not require approval $isApprovalRequired $isApprovalRequiredForExtension $isApprovalOverride" | ||
| } | ||
|
|
||
| } | ||
|
|
||
| if ($approvalIsRequiredForRequest) { | ||
| write-verbose "policy $policyId requires approval" | ||
| return | ||
| } | ||
| } | ||
|
|
||
| if ($NoApprovalRequiredForRequest -and $acceptRequests -eq $false) { | ||
| # does not accept requests | ||
| write-verbose "policy $policyId does not accept requests" | ||
| return | ||
| } | ||
| if ($NoApprovalRequiredForRequest -and ($null -eq $ScopeType -or $ScopeType.Length -eq 0) -and $thisScopeType -eq "NoSubjects") { | ||
| write-verbose "policy $policyId has no subjects in scope" | ||
| return | ||
| } | ||
|
|
||
| write-output $Policy | ||
| } | ||
|
|
||
| end { | ||
|
|
||
| } | ||
| } |
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.