-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAzSK.EntraID.psm1
346 lines (308 loc) · 11.3 KB
/
AzSK.EntraID.psm1
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
Set-StrictMode -Version Latest
#. $PSScriptRoot\Framework\Listeners\ListenerHelper.ps1
. $PSScriptRoot\Framework\Framework.ps1
@("$PSScriptRoot\SVT") |
ForEach-Object {
(Get-ChildItem -Path $_ -Recurse -File -Include "*.ps1") |
ForEach-Object {
. $_.FullName
}
}
function Set-AzSKAADPolicySettings {
<#
.SYNOPSIS
This command would help to set online policy store URL.
.DESCRIPTION
This command would help to set online policy store URL.
.PARAMETER ScannerToolPath
Provide the credential scanner tool path
.PARAMETER ScannerToolName
Provide the credential scanner tool name.
.LINK
https://aka.ms/azskossdocs
#>
Param(
[Parameter(Mandatory = $false, HelpMessage = "Provide scanner tool path")]
[string]
[Alias("stp")]
$ScannerToolPath,
[Parameter(Mandatory = $false, HelpMessage = "Provide scanner tool name")]
[string]
[Alias("stn")]
$ScannerToolName
)
Begin {
[CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
[ListenerHelper]::RegisterListeners();
}
Process {
try {
$azskSettings = [ConfigurationManager]::GetLocalAzSKSettings();
if($ScannerToolPath -and $ScannerToolName)
{
$azskSettings.ScanToolPath = $ScannerToolPath
$azskSettings.ScanToolName = $ScannerToolName
}
[ConfigurationManager]::UpdateAzSKSettings($azskSettings);
[EventBase]::PublishGenericCustomMessage("Successfully configured policy settings. `nStart a fresh PS console/session to ensure any policy updates are (re-)loaded.", [MessageType]::Warning);
}
catch {
[EventBase]::PublishGenericException($_);
}
}
End {
[ListenerHelper]::UnregisterListeners();
}
}
function Set-AzSKLocalAIOrgTelemetrySettings {
<#
.SYNOPSIS
This command would help to set local control telemetry settings.
.DESCRIPTION
This command would help to set local control telemetry settings.
.PARAMETER LocalAIOrgTelemetryKey
Provide local telemetry key.
.PARAMETER EnableLocalAIOrgTelemetry
Enables local control telemetry.
.LINK
https://aka.ms/azskossdocs
#>
Param(
[Parameter(Mandatory = $true, HelpMessage = "Provide the local control telemetry key")]
[string]
[Alias("lotk")]
$LocalAIOrgTelemetryKey,
[Parameter(Mandatory = $true, HelpMessage = "Provide the flag to enable local control telemetry")]
[bool]
[Alias("elot")]
$EnableLocalAIOrgTelemetry
)
Begin {
[CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
[ListenerHelper]::RegisterListeners();
}
Process {
try {
#TODO: This should support both params as optional (we can always throw an error if neither is provided)
#TODO: That is, if a key is provided, assume bEnable=$true...else look for bEnabled and toggle telemetry.
$azskSettings = [ConfigurationManager]::GetLocalAzSKSettings();
$azskSettings.LocalControlTelemetryKey = $LocalAIOrgTelemetryKey
$azskSettings.LocalEnableControlTelemetry = $EnableLocalAIOrgTelemetry
[ConfigurationManager]::UpdateAzSKSettings($azskSettings);
[EventBase]::PublishGenericCustomMessage("Successfully set control telemetry settings");
}
catch {
[EventBase]::PublishGenericException($_);
}
}
End {
[ListenerHelper]::UnregisterListeners();
}
}
function Set-AzSKUsageTelemetryLevel {
<#
.SYNOPSIS
This command would help to set telemetry level.
.DESCRIPTION
This command would help to set telemetry level.
.PARAMETER Level
Provide the telemetry level
.LINK
https://aka.ms/azskossdocs
#>
Param(
[Parameter(Mandatory = $true, HelpMessage = "Provide the telemetry level")]
[ValidateSet("None", "Anonymous")]
[string]
[Alias("lvl")]
$Level
)
Begin {
[CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
[ListenerHelper]::RegisterListeners();
}
Process {
try {
$azskSettings = [ConfigurationManager]::GetLocalAzSKSettings();
$azskSettings.UsageTelemetryLevel = $Level
[ConfigurationManager]::UpdateAzSKSettings($azskSettings);
[EventBase]::PublishGenericCustomMessage("Successfully set usage telemetry level");
}
catch {
[EventBase]::PublishGenericException($_);
}
}
End {
[ListenerHelper]::UnregisterListeners();
}
}
function Set-AzSKMonitoringSettings
{
<#
.SYNOPSIS
This command would help in updating the Log Analytics configuration settings under the current powershell session.
.DESCRIPTION
This command will update the Log Analytics settings under the current powershell session. This also remembers the current settings and use them in the subsequent sessions.
.PARAMETER OMSWorkspaceID
Workspace ID of your Log Analytics instance. Control scan results get pushed to this instance.
.PARAMETER OMSSharedKey
Shared key of your Log Analytics instance.
.PARAMETER AltOMSWorkspaceID
Workspace ID of your alternate Log Analytics instance. Control scan results get pushed to this instance.
.PARAMETER AltOMSSharedKey
Workspace shared key of your alternate Log Analytics instance.
.PARAMETER Source
Provide the source of Log Analytics Events. (e. g. CA,CICD,SDL)
.PARAMETER Disable
Use -Disable option to clean the Log Analytics setting under the current instance.
.LINK
https://aka.ms/azskossdocs
#>
[Alias("Set-AzSKOMSSettings")]
param(
[Parameter(Mandatory = $false, HelpMessage="Workspace ID of your Log Analytics instance. Control scan results get pushed to this instance.", ParameterSetName = "Setup")]
[AllowEmptyString()]
[string]
[Alias("owid","wid","WorkspaceID")]
$OMSWorkspaceID,
[Parameter(Mandatory = $false, HelpMessage="Shared key of your Log Analytics instance.", ParameterSetName = "Setup")]
[AllowEmptyString()]
[string]
[Alias("okey","wkey","SharedKey")]
$OMSSharedKey,
[Parameter(Mandatory = $false, HelpMessage="Workspace ID of your alternate Log Analytics instance. Control scan results get pushed to this instance.", ParameterSetName = "Setup")]
[AllowEmptyString()]
[string]
[Alias("aowid","awid","AltWorkspaceID")]
$AltOMSWorkspaceID,
[Parameter(Mandatory = $false, HelpMessage="Shared key of your alternate Log Analytics instance.", ParameterSetName = "Setup")]
[AllowEmptyString()]
[string]
[Alias("aokey","awkey","AltSharedKey")]
$AltOMSSharedKey,
[Parameter(Mandatory = $false, HelpMessage="Provide the source of Log Analytics Events.(e.g. CC,CICD,SDL)", ParameterSetName = "Setup")]
[AllowEmptyString()]
[string]
[Alias("so")]
$Source,
[Parameter(Mandatory = $true, HelpMessage="Use -Disable option to clean the Log Analytics setting under the current instance.", ParameterSetName = "Disable")]
[switch]
[Alias("dsbl")]
$Disable
)
Begin
{
[CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
[ListenerHelper]::RegisterListeners();
}
Process
{
try
{
$appSettings = [ConfigurationManager]::GetLocalAzSKSettings();
if(-not $Disable)
{
if(-not [string]::IsNullOrWhiteSpace($OMSWorkspaceID) -and -not [string]::IsNullOrWhiteSpace($OMSSharedKey))
{
$appSettings.OMSWorkspaceId = $OMSWorkspaceID
$appSettings.OMSSharedKey = $OMSSharedKey
}
elseif(([string]::IsNullOrWhiteSpace($OMSWorkspaceID) -and -not [string]::IsNullOrWhiteSpace($OMSSharedKey)) `
-and (-not [string]::IsNullOrWhiteSpace($OMSWorkspaceID) -and [string]::IsNullOrWhiteSpace($OMSSharedKey)))
{
[EventBase]::PublishGenericCustomMessage("You need to send both the OMSWorkspaceId and OMSSharedKey", [MessageType]::Error);
return;
}
if(-not [string]::IsNullOrWhiteSpace($AltOMSWorkspaceID) -and -not [string]::IsNullOrWhiteSpace($AltOMSSharedKey))
{
$appSettings.AltOMSWorkspaceId = $AltOMSWorkspaceID
$appSettings.AltOMSSharedKey = $AltOMSSharedKey
}
elseif(([string]::IsNullOrWhiteSpace($AltOMSWorkspaceID) -and -not [string]::IsNullOrWhiteSpace($AltOMSSharedKey)) `
-and (-not [string]::IsNullOrWhiteSpace($AltOMSWorkspaceID) -and [string]::IsNullOrWhiteSpace($AltOMSSharedKey)))
{
[EventBase]::PublishGenericCustomMessage("You need to send both the AltOMSWorkspaceId and AltOMSSharedKey", [MessageType]::Error);
return;
}
}
else {
$appSettings.OMSWorkspaceId = ""
$appSettings.OMSSharedKey = ""
$appSettings.AltOMSWorkspaceId = ""
$appSettings.AltOMSSharedKey = ""
}
if(-not [string]::IsNullOrWhiteSpace($Source))
{
$appSettings.OMSSource = $Source
}
else
{
$appSettings.OMSSource = "SDL"
}
$appSettings.OMSType = [OMSHelper]::DefaultOMSType
[ConfigurationManager]::UpdateAzSKSettings($appSettings);
[EventBase]::PublishGenericCustomMessage([Constants]::SingleDashLine + "`r`nWe have added new queries for the Monitoring solution. These will help reflect the aggregate control pass/fail status more accurately. Please go here to get them: https://aka.ms/devopskit/omsqueries `r`n",[MessageType]::Warning);
[EventBase]::PublishGenericCustomMessage("Successfully changed policy settings");
}
catch
{
[EventBase]::PublishGenericException($_);
}
}
End
{
[ListenerHelper]::UnregisterListeners();
}
}
function Set-AzSKPrivacyNoticeResponse {
<#
.SYNOPSIS
This command would help to set user preferences for EULA and Privacy.
.DESCRIPTION
This command would help to set user preferences for EULA and Privacy.
.PARAMETER AcceptPrivacyNotice
Provide the flag to suppress the Privacy notice prompt and submit the acceptance. (Yes/No)
.LINK
https://aka.ms/azskossdocs
#>
Param
(
[Parameter(Mandatory = $true, HelpMessage = "Provide the flag to suppress the Privacy notice prompt and submit the acceptance. (Yes/No)")]
[string]
[ValidateSet("Yes", "No")]
[Alias("apn")]
$AcceptPrivacyNotice
)
Begin {
[CommandHelper]::BeginCommand($PSCmdlet.MyInvocation);
[ListenerHelper]::RegisterListeners();
}
Process {
try {
$azskSettings = [ConfigurationManager]::GetLocalAzSKSettings();
if ($AcceptPrivacyNotice -eq "yes") {
$azskSettings.PrivacyNoticeAccepted = $true
$azskSettings.UsageTelemetryLevel = "Anonymous"
}
if ($AcceptPrivacyNotice -eq "no") {
$azskSettings.PrivacyNoticeAccepted = $false
$azskSettings.UsageTelemetryLevel = "None"
}
[ConfigurationManager]::UpdateAzSKSettings($azskSettings)
[EventBase]::PublishGenericCustomMessage("Successfully updated privacy settings.");
}
catch {
[EventBase]::PublishGenericException($_);
}
}
End {
[ListenerHelper]::UnregisterListeners();
}
}
function Clear-AzSKSessionState {
Write-Host "Clearing AzSK session state..." -ForegroundColor Yellow
[ConfigOverride]::ClearConfigInstance()
Write-Host "Session state cleared." -ForegroundColor Yellow
}
. $PSScriptRoot\Framework\Helpers\AliasHelper.ps1