forked from OneIdentity/safeguard-ps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-test-entitlement.ps1
81 lines (77 loc) · 2.45 KB
/
new-test-entitlement.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$EntitlementName,
[Parameter(Mandatory=$true)]
[string]$ApproverUserName
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $SafeguardSession)
{
throw "This script assumes you have already called Connect-Safeguard to create a session."
}
if (-not (Get-SafeguardUser $ApproverUserName))
{
throw "The $ApproverUserName user must actually exist."
}
$local:RequesterGroupId = (Invoke-SafeguardMethod Core POST UserGroups -Body @{
Name = "$EntitlementName Requesters"
}).Id
$local:ApproverGroupId = (Invoke-SafeguardMethod Core POST UserGroups -Body @{
Name = "$EntitlementName Approvers"
}).Id
Invoke-SafeguardMethod Core PUT "UserGroups/$($local:ApproverGroupId)/Members" -Body @(Get-Safeguarduser $ApproverUserName)
$local:EntitlementId = (Invoke-SafeguardMethod Core POST Roles -Body @{
Name = "$EntitlementName Test Entitlement"
}).Id
Invoke-SafeguardMethod Core PUT "Roles/$($local:EntitlementId)/Members" -Body @(@{
Id = $local:RequesterGroupId;
PrincipalKind = "Group"
})
Invoke-SafeguardMethod Core POST AccessPolicies -JsonBody "{
`"Name`": `"Basic Password`",
`"RoleId`": $local:EntitlementId,
`"AccessRequestProperties`": {
`"AccessRequestType`": `"Password`",
`"AllowSimultaneousAccess`": true
},
`"ApproverProperties`": {
`"RequireApproval`": false
}
}"
Invoke-SafeguardMethod Core POST AccessPolicies -JsonBody "{
`"Name`": `"Basic SSH`",
`"RoleId`": $local:EntitlementId,
`"AccessRequestProperties`": {
`"AccessRequestType`": `"Ssh`",
`"AllowSimultaneousAccess`": true
},
`"ApproverProperties`": {
`"RequireApproval`": true
},
`"ApproverSets`": [{
`"RequiredApprovers`": 1,
`"Approvers`": [{
`"Id`": $local:ApproverGroupId,
`"PrincipalKind`": `"Group`"
}]
}]
}"
Invoke-SafeguardMethod Core POST AccessPolicies -JsonBody "{
`"Name`": `"Basic RDP`",
`"RoleId`": $local:EntitlementId,
`"AccessRequestProperties`": {
`"AccessRequestType`": `"RemoteDesktop`",
`"AllowSimultaneousAccess`": true
},
`"ApproverProperties`": {
`"RequireApproval`": true
},
`"ApproverSets`": [{
`"RequiredApprovers`": 1,
`"Approvers`": [{
`"Id`": $local:ApproverGroupId,
`"PrincipalKind`": `"Group`"
}]
}]
}"