chore: change keyvalt set permissions on SP

This commit is contained in:
fabiohaifa 2022-02-07 16:05:28 -03:00
Родитель a9f28e3844
Коммит d9c422f89e
1 изменённых файлов: 2 добавлений и 3 удалений

Просмотреть файл

@ -23,7 +23,6 @@ Write-Host "ServicePrincipalName " $ServicePrincipalName
$context = Get-AzContext
Write-Host "Getting user and principal information..." -ForegroundColor Green
$user = Get-AzADUser -UserPrincipalName $context.Account.Id
$servicePrincipal = Get-AzADServicePrincipal -DisplayName $ServicePrincipalName
if ($servicePrincipal) {
@ -41,10 +40,10 @@ if ($servicePrincipal) {
$dbw = Get-AzDatabricksWorkspace -ResourceGroupName $ComputeResourceGroup -Name $DatabricksName
Write-Host "Adding permissions to user on Key Vault..." -ForegroundColor Green
$userPermissions = $kv.AccessPolicies | Where-Object { $_.ObjectId -eq $user.Id }
$userPermissions = $kv.AccessPolicies | Where-Object { $_.ObjectId -eq $servicePrincipal.Id }
$secretPermissions = $userPermissions.PermissionsToSecrets
if (! $secretPermissions || ! $userPermissions.PermissionsToSecrets.Contains("set")) {
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -ObjectId $user.Id -PermissionsToSecrets "set"
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -ObjectId $servicePrincipal.Id -PermissionsToSecrets "set"
}
Write-Host "Setting service principal secrets on Key Vault..." -ForegroundColor Green