-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from kayasax/Approval
Approval
- Loading branch information
Showing
8 changed files
with
470 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
74 changes: 74 additions & 0 deletions
74
EasyPIM/functions/Approve-PIMAzureResourcePendingApproval.ps1
This file contains 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,74 @@ | ||
<# | ||
.Synopsis | ||
EASYPIM | ||
Powershell module to manage PIM Azure Resource Role settings with simplicity in mind | ||
Get-PIMEntraRolePolicy will return the policy rules (like require MFA on activation) of the selected rolename at the subscription level | ||
Support querrying multi roles at once | ||
.Description | ||
Get-PIMAzureResourcePendingApproval will use the Microsoft Graph APIs to retrieve the requests pending your approval | ||
.PARAMETER approvalID | ||
approval ID from get-PIMAzureResourcePendingApproval | ||
.PARAMETER justification | ||
justification for the approval | ||
.Example | ||
PS> approve-PIMAzureResourcePendingApproval -approvalID $approvalID -justification "I approve this request" | ||
Approve a pending request | ||
.Link | ||
.Notes | ||
Homepage: https://github.com/kayasax/easyPIM | ||
Author: MICHEL, Loic | ||
Changelog: | ||
Todo: | ||
* allow other scopes | ||
#> | ||
function Approve-PIMAzureResourcePendingApproval { | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
param ( | ||
|
||
[Parameter(Position = 0, Mandatory = $true,ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true)] | ||
[System.String] | ||
# Tenant ID | ||
$approvalID, | ||
|
||
[Parameter(Position = 1, Mandatory = $true)] | ||
[System.String] | ||
# justification | ||
$justification | ||
|
||
) | ||
process{ | ||
try { | ||
$script:tenantID = $tenantID | ||
|
||
Write-Verbose "approve-PIMAzureResourcePendingApproval start with parameters: approvalid => $approvalID, justification => $justification" | ||
|
||
#Get the stages: | ||
#Role Assignment Approval Steps - List - REST API (Azure Authorization) | Microsoft Learn | ||
$stages=Invoke-AzRestMethod -Uri "https://management.azure.com/$approvalID/stages?api-version=2021-01-01-preview" -Method GET | ||
|
||
$stageid=($stages.Content | convertfrom-json).value.id | ||
|
||
#approve the request | ||
#Role Assignment Approval Step - Patch - REST API (Azure Authorization) | Microsoft Learn | ||
|
||
$body='{"properties":{"justification":"'+$justification+'","reviewResult":"Approve"}}' | ||
|
||
Invoke-AzRestMethod -Uri "https://management.azure.com/$stageid/?api-version=2021-01-01-preview" -Payload $body -Method PUT | ||
return "Success, request approved" | ||
|
||
} | ||
catch { | ||
MyCatch $_ | ||
} | ||
} | ||
} |
This file contains 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,74 @@ | ||
<# | ||
.Synopsis | ||
EASYPIM | ||
Powershell module to manage PIM Azure Resource Role settings with simplicity in mind | ||
Get-PIMEntraRolePolicy will return the policy rules (like require MFA on activation) of the selected rolename at the subscription level | ||
Support querrying multi roles at once | ||
.Description | ||
Approve-PIMEntraRolePendingApprovall will use the Microsoft Graph APIs to retrieve the requests pending your approval | ||
.PARAMETER approvalID | ||
approval ID from get-PIMAzureResourcePendingApproval | ||
.PARAMETER justification | ||
justification for the approval | ||
.Example | ||
PS> approve-PIMAzureResourcePendingApproval -approvalID $approvalID -justification "I approve this request" | ||
Approve a pending request | ||
.Link | ||
.Notes | ||
Homepage: https://github.com/kayasax/easyPIM | ||
Author: MICHEL, Loic | ||
Changelog: | ||
Todo: | ||
* allow other scopes | ||
#> | ||
function Approve-PIMEntraRolePendingApproval { | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
param ( | ||
|
||
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true)] | ||
[System.String] | ||
# Approval ID | ||
$approvalID, | ||
|
||
[Parameter(Position = 1, Mandatory = $true)] | ||
[System.String] | ||
# justification | ||
$justification | ||
|
||
) | ||
process { | ||
try { | ||
#$script:tenantID = $tenantID | ||
|
||
Write-Verbose "approve-PIMEntraRolePendingApproval start with parameters: approvalid => $approvalID, justification => $justification" | ||
|
||
#Get the stages: | ||
#Role Assignment Approval Steps - List - REST API (Azure Authorization) | Microsoft Learn | ||
$stages = Invoke-graph -endpoint "roleManagement/directory/roleAssignmentApprovals/$approvalID/" -Method GET -version "beta" | ||
|
||
$stageid = $stages.id | ||
|
||
#approve the request | ||
#Role Assignment Approval Step - Patch - REST API (Azure Authorization) | Microsoft Learn | ||
|
||
$body = '{"justification":"' + $justification + '","reviewResult":"Approve"}' | ||
|
||
Invoke-graph -endpoint "roleManagement/directory/roleAssignmentApprovals/$approvalID/steps/$stageID" -body $body -version "beta" -Method PATCH | ||
return "Success, request approved" | ||
|
||
} | ||
catch { | ||
MyCatch $_ | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
EasyPIM/functions/Deny-PIMAzureResourcePendingApproval.ps1
This file contains 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,73 @@ | ||
<# | ||
.Synopsis | ||
EASYPIM | ||
Powershell module to manage PIM Azure Resource Role settings with simplicity in mind | ||
Get-PIMEntraRolePolicy will return the policy rules (like require MFA on activation) of the selected rolename at the subscription level | ||
Support querrying multi roles at once | ||
.Description | ||
Deny-PIMAzureResourcePendingApproval will deny request | ||
.PARAMETER approvalID | ||
approval ID from get-PIMAzureResourcePendingApproval | ||
.PARAMETER justification | ||
justification for the deny | ||
.Example | ||
PS> Deny-PIMAzureResourcePendingApproval -approvalID $approvalID -justification "You don't need this role" | ||
Deny a pending request | ||
.Link | ||
.Notes | ||
Homepage: https://github.com/kayasax/easyPIM | ||
Author: MICHEL, Loic | ||
Changelog: | ||
Todo: | ||
* allow other scopes | ||
#> | ||
function Deny-PIMAzureResourcePendingApproval { | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
param ( | ||
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true)] | ||
[System.String] | ||
# Tenant ID | ||
$approvalID, | ||
|
||
[Parameter(Position = 1, Mandatory = $true)] | ||
[System.String] | ||
# justification | ||
$justification | ||
|
||
) | ||
process{ | ||
try { | ||
$script:tenantID = $tenantID | ||
|
||
Write-Verbose "approve-PIMAzureResourcePendingApproval start with parameters: approvalid => $approvalID, justification => $justification" | ||
|
||
#Get the stages: | ||
#Role Assignment Approval Steps - List - REST API (Azure Authorization) | Microsoft Learn | ||
$stages = Invoke-AzRestMethod -Uri "https://management.azure.com/$approvalID/stages?api-version=2021-01-01-preview" -Method GET | ||
|
||
$stageid = ($stages.Content | convertfrom-json).value.id | ||
|
||
#approve the request | ||
#Role Assignment Approval Step - Patch - REST API (Azure Authorization) | Microsoft Learn | ||
|
||
$body = '{"properties":{"justification":"' + $justification + '","reviewResult":"Deny"}}' | ||
|
||
Invoke-AzRestMethod -Uri "https://management.azure.com/$stageid/?api-version=2021-01-01-preview" -Payload $body -Method PUT | ||
return "Success, request denied" | ||
|
||
} | ||
catch { | ||
MyCatch $_ | ||
} | ||
|
||
}} |
This file contains 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,74 @@ | ||
<# | ||
.Synopsis | ||
EASYPIM | ||
Powershell module to manage PIM Azure Resource Role settings with simplicity in mind | ||
Get-PIMEntraRolePolicy will return the policy rules (like require MFA on activation) of the selected rolename at the subscription level | ||
Support querrying multi roles at once | ||
.Description | ||
Deny-PIMEntraRolePendingApprovall will use the Microsoft Graph APIs to retrieve the requests pending your approval | ||
.PARAMETER approvalID | ||
approval ID from get-PIMAzureResourcePendingApproval | ||
.PARAMETER justification | ||
justification for the approval | ||
.Example | ||
PS> Deny-PIMAzureResourcePendingApproval -approvalID $approvalID -justification "I Deny this request" | ||
Deny a pending request | ||
.Link | ||
.Notes | ||
Homepage: https://github.com/kayasax/easyPIM | ||
Author: MICHEL, Loic | ||
Changelog: | ||
Todo: | ||
* allow other scopes | ||
#> | ||
function Deny-PIMEntraRolePendingApproval { | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
param ( | ||
|
||
[Parameter(Position = 0, Mandatory = $true,ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true)] | ||
[System.String] | ||
# Approval ID | ||
$approvalID, | ||
|
||
[Parameter(Position = 1, Mandatory = $true)] | ||
[System.String] | ||
# justification | ||
$justification | ||
|
||
) | ||
process{ | ||
try { | ||
#$script:tenantID = $tenantID | ||
|
||
Write-Verbose "Deny-PIMEntraRolePendingApproval start with parameters: approvalid => $approvalID, justification => $justification" | ||
|
||
#Get the stages: | ||
#Role Assignment Approval Steps - List - REST API (Azure Authorization) | Microsoft Learn | ||
$stages=Invoke-graph -endpoint "roleManagement/directory/roleAssignmentApprovals/$approvalID/" -Method GET -version "beta" | ||
|
||
$stageid=$stages.id | ||
|
||
#Deny the request | ||
#Role Assignment Approval Step - Patch - REST API (Azure Authorization) | Microsoft Learn | ||
|
||
$body='{"justification":"'+$justification+'","reviewResult":"Deny"}' | ||
|
||
Invoke-graph -endpoint "roleManagement/directory/roleAssignmentApprovals/$approvalID/steps/$stageID" -body $body -version "beta" -Method PATCH | ||
return "Success, request Denyd" | ||
|
||
} | ||
catch { | ||
MyCatch $_ | ||
} | ||
|
||
}} |
Oops, something went wrong.