You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$existingAssignment= az role assignment list --assignee $currentUserOid--role $kvSecretsUserRoleId--scope $kvResourceId--query "[0].id"-o tsv 2>$null
150
+
$existingAssignment= az role assignment list --assignee $currentIdentityOid--role $kvSecretsUserRoleId--scope $kvResourceId--query "[0].id"-o tsv 2>$null
118
151
if (-not$existingAssignment) {
119
-
Write-Host"✓ Assigning 'Key Vault Secrets User' role to current user on Key Vault..."
120
-
$roleOutput= az role assignment create --assignee-object-id $currentUserOid--assignee-principal-type User--role $kvSecretsUserRoleId--scope $kvResourceId2>&1|Out-String
152
+
Write-Host"✓ Assigning 'Key Vault Secrets User' role to current ${identityType} on Key Vault..."
153
+
$roleOutput= az role assignment create --assignee-object-id $currentIdentityOid--assignee-principal-type $principalType--role $kvSecretsUserRoleId--scope $kvResourceId2>&1|Out-String
121
154
if ($LASTEXITCODE-ne0) {
122
155
Write-Warning"⚠ Failed to assign Key Vault Secrets User role."
123
156
Write-Warning"$roleOutput"
@@ -126,11 +159,11 @@ else {
126
159
Start-Sleep-Seconds 30
127
160
}
128
161
} else {
129
-
Write-Host"✓ Current user already has 'Key Vault Secrets User' role on Key Vault."
162
+
Write-Host"✓ Current ${identityType} already has 'Key Vault Secrets User' role on Key Vault."
130
163
}
131
164
}
132
165
} else {
133
-
Write-Warning"⚠ Could not determine current user OID. Skipping Key Vault role assignment."
166
+
Write-Warning"⚠ Could not determine current identity OID. Skipping Key Vault role assignment."
134
167
}
135
168
136
169
# Check if Key Vault public access is disabled (WAF/private networking)
@@ -235,14 +268,14 @@ else {
235
268
--start-ip-address $publicIp`
236
269
--end-ip-address $publicIp2>$null|Out-Null
237
270
238
-
# Get current user info for local Entra auth to PostgreSQL
239
-
$currentUserUpn= az ad signed-in-user show --query "userPrincipalName"-o tsv 2>$null
240
-
$currentUserOid= az ad signed-in-user show --query "id"-o tsv 2>$null
241
-
if (-not$currentUserUpn-or-not$currentUserOid) {
242
-
Write-Error"✗ Could not determine current signed-in user. Ensure you are logged in with 'az login'."
271
+
# Use previously detected identity for PostgreSQL Entra auth
272
+
if (-not$currentIdentityOid-or-not$currentIdentityDisplay) {
273
+
Write-Error"✗ Could not determine current identity. Ensure you are logged in with 'az login'."
243
274
exit1
244
275
}
245
-
Write-Host"✓ Current user: $currentUserUpn ($currentUserOid)"
276
+
$currentUserUpn=$currentIdentityDisplay
277
+
$currentUserOid=$currentIdentityOid
278
+
Write-Host"✓ Current ${identityType}: $currentUserUpn ($currentUserOid)"
246
279
247
280
# Ensure current user is a PostgreSQL Entra administrator
248
281
$existingAdmins= az postgres flexible-server $pgAdminCmd list --resource-group $ResourceGroupName--server-name $serverName--query "[].objectId"-o tsv 2>$null
@@ -254,23 +287,23 @@ else {
254
287
}
255
288
$addedPgAdmin=$false
256
289
if (-not$isAdmin) {
257
-
Write-Host"✓ Adding current user as PostgreSQL Entra administrator..."
290
+
Write-Host"✓ Adding current ${identityType} as PostgreSQL Entra administrator..."
258
291
$adminOutput= az postgres flexible-server $pgAdminCmd create `
259
292
--resource-group $ResourceGroupName`
260
293
--server-name $serverName`
261
294
--display-name $currentUserUpn`
262
295
--object-id $currentUserOid`
263
-
--type User2>&1|Out-String
296
+
--type $principalType2>&1|Out-String
264
297
if ($LASTEXITCODE-ne0) {
265
-
Write-Warning"⚠ Failed to add current user as PostgreSQL admin. Table creation may fail."
298
+
Write-Warning"⚠ Failed to add current ${identityType} as PostgreSQL admin. Table creation may fail."
266
299
Write-Warning"$adminOutput"
267
300
} else {
268
301
$addedPgAdmin=$true
269
302
Write-Host"✓ PostgreSQL admin added. Waiting 60s for propagation..."
270
303
Start-Sleep-Seconds 60
271
304
}
272
305
} else {
273
-
Write-Host"✓ Current user is already a PostgreSQL Entra administrator."
306
+
Write-Host"✓ Current ${identityType} is already a PostgreSQL Entra administrator."
0 commit comments