Skip to content

Commit 3533643

Browse files
Merge pull request KelvinTegelaar#1225 from kris6673/fix-inconsisten-TAP-generation
FIX: Unreliable TAP creation during new JIT admin user creation
2 parents 7922032 + b3df695 commit 3533643

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ExecJITAdmin.ps1

+8-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Function Invoke-ExecJITAdmin {
9292
Start-Sleep -Seconds 1
9393
}
9494

95+
#Region TAP creation
9596
if ($Request.Body.UseTAP) {
9697
try {
9798
if ($Start -gt (Get-Date)) {
@@ -102,19 +103,20 @@ Function Invoke-ExecJITAdmin {
102103
} else {
103104
$TapBody = '{}'
104105
}
105-
Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
106-
# Retry creating the TAP up to 5 times, since it can fail due to the user not being fully created yet
106+
# Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
107+
# Retry creating the TAP up to 10 times, since it can fail due to the user not being fully created yet. Sometimes it takes 2 reties, sometimes it takes 8+. Very annoying. -Bobby
107108
$Retries = 0
109+
$MAX_TAP_RETRIES = 10
108110
do {
109111
try {
110112
$TapRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($Username)/authentication/temporaryAccessPassMethods" -tenantid $TenantFilter -type POST -body $TapBody
111113
} catch {
112114
Start-Sleep -Seconds 2
113-
Write-Information 'ERROR: Failed to create TAP, retrying'
114-
Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
115+
Write-Information "ERROR: Run $Retries of $MAX_TAP_RETRIES : Failed to create TAP, retrying"
116+
# Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
115117
}
116118
$Retries++
117-
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le 5 )
119+
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le $MAX_TAP_RETRIES )
118120

119121
$TempPass = $TapRequest.temporaryAccessPass
120122
$PasswordExpiration = $TapRequest.LifetimeInMinutes
@@ -135,6 +137,7 @@ Function Invoke-ExecJITAdmin {
135137
}
136138
}
137139
}
140+
#EndRegion TAP creation
138141

139142
$Parameters = @{
140143
TenantFilter = $TenantFilter

0 commit comments

Comments
 (0)