Skip to content

Commit cb0efc3

Browse files
committed
TSG entry for updating service principal pw
1 parent 3e46652 commit cb0efc3

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

articles/storage/files/storage-troubleshoot-windows-file-connection-problems.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Troubleshoot problems with SMB Azure file shares in Windows. See co
44
author: khdownie
55
ms.service: storage
66
ms.topic: troubleshooting
7-
ms.date: 08/26/2022
7+
ms.date: 09/09/2022
88
ms.author: kendownie
99
ms.subservice: files
1010
ms.custom: devx-track-azurepowershell
@@ -601,5 +601,102 @@ if ($null -ne $application) {
601601
}
602602
```
603603

604+
### Error - Service principal password has expired in Azure AD
605+
606+
If you've previously enabled Azure AD Kerberos authentication through manual limited preview steps, the password for the storage account's service principal is set to expire every six months. Once the password expires, users won't be able to get Kerberos tickets to the file share.
607+
608+
To mitigate this, you have two options: either rotate the service principal password in Azure AD every six months, or disable Azure AD Kerberos, delete the existing application, and reconfigure Azure AD Kerberos using the Azure portal.
609+
610+
#### Option 1: Update the service principal password using PowerShell
611+
612+
1. Install the latest Az.Storage and AzureAD modules. Use PowerShell 5.1, because currently the AzureAD module doesn't work in PowerShell 7. For more information about installing PowerShell, see [Install Azure PowerShell on Windows with PowerShellGet](/powershell/azure/install-Az-ps).
613+
614+
[!INCLUDE [azure-powershell-requirements-no-header.md](../../includes/azure-powershell-requirements-no-header.md)]
615+
616+
To install the modules, open PowerShell with elevated privileges and run the following commands:
617+
618+
```azurepowershell
619+
Install-Module -Name Az.Storage
620+
Install-Module -Name AzureAD
621+
```
622+
623+
2. Set the required variables for your tenant, subscription, storage account name, and resource group name by running the following cmdlets, replacing the values with the ones relevant to your environment.
624+
625+
```azurepowershell
626+
$tenantId = "<MyTenantId>"
627+
$subscriptionId = "<MySubscriptionId>"
628+
$resourceGroupName = "<MyResourceGroup>"
629+
$storageAccountName = "<MyStorageAccount>"
630+
```
631+
632+
3. Generate a new kerb1 key and password for the service principal.
633+
634+
```azurepowershell
635+
Connect-AzAccount -Tenant $tenantId -SubscriptionId $subscriptionId
636+
$kerbKeys = New-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName -KeyName "kerb1" -ErrorAction Stop | Select-Object -ExpandProperty Keys
637+
$kerbKey = $kerbKeys | Where-Object { $_.KeyName -eq "kerb1" } | Select-Object -ExpandProperty Value
638+
$azureAdPasswordBuffer = [System.Linq.Enumerable]::Take([System.Convert]::FromBase64String($kerbKey), 32);
639+
$password = "kk:" + [System.Convert]::ToBase64String($azureAdPasswordBuffer);
640+
```
641+
642+
4. Connect to Azure AD and retrieve the tenant information, application, and service principal.
643+
644+
```azurepowershell
645+
Connect-AzureAD
646+
$azureAdTenantDetail = Get-AzureADTenantDetail;
647+
$azureAdTenantId = $azureAdTenantDetail.ObjectId
648+
$azureAdPrimaryDomain = ($azureAdTenantDetail.VerifiedDomains | Where-Object {$_._Default -eq $true}).Name
649+
$application = Get-AzureADApplication -Filter "DisplayName eq '$($storageAccountName)'" -ErrorAction Stop;
650+
$servicePrincipal = Get-AzureADServicePrincipal -Filter "AppId eq '$($application.AppId)'"
651+
if ($servicePrincipal -eq $null) {
652+
Write-Host "Could not find service principal corresponding to application with app id $($application.AppId)"
653+
Write-Error -Message "Make sure that both service principal and application exist and are correctly configured" -ErrorAction Stop
654+
}
655+
```
656+
657+
5. Set the password for the storage account's service principal.
658+
659+
```azurepowershell
660+
$Token = ([Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']).AccessToken;
661+
$Uri = ('https://graph.windows.net/{0}/{1}/{2}?api-version=1.6' -f $azureAdPrimaryDomain, 'servicePrincipals', $servicePrincipal.ObjectId)
662+
$json = @'
663+
{
664+
"passwordCredentials": [
665+
{
666+
"customKeyIdentifier": null,
667+
"endDate": "<STORAGEACCOUNTENDDATE>",
668+
"value": "<STORAGEACCOUNTPASSWORD>",
669+
"startDate": "<STORAGEACCOUNTSTARTDATE>"
670+
}]
671+
}
672+
'@
673+
674+
$now = [DateTime]::UtcNow
675+
$json = $json -replace "<STORAGEACCOUNTSTARTDATE>", $now.AddHours(-12).ToString("s")
676+
$json = $json -replace "<STORAGEACCOUNTENDDATE>", $now.AddMonths(6).ToString("s")
677+
$json = $json -replace "<STORAGEACCOUNTPASSWORD>", $password
678+
679+
$Headers = @{'authorization' = "Bearer $($Token)"}
680+
681+
try {
682+
Invoke-RestMethod -Uri $Uri -ContentType 'application/json' -Method Patch -Headers $Headers -Body $json
683+
Write-Host "Success: Password is set for $storageAccountName"
684+
} catch {
685+
Write-Host $_.Exception.ToString()
686+
Write-Host "StatusCode: " $_.Exception.Response.StatusCode.value
687+
Write-Host "StatusDescription: " $_.Exception.Response.StatusDescription
688+
}
689+
```
690+
691+
#### Option 2: Disable Azure AD Kerberos, delete the existing application, and reconfigure
692+
693+
If you don't want to rotate the service principal password every six months, you can follow these steps. Be sure to save domain properties (domainName and domainGUID) before disabling Azure AD Kerberos, as you'll need them during reconfiguration if you want to configure directory and file-level permissions through Windows File Explorer.
694+
695+
1. [Disable Azure AD Kerberos](storage-files-identity-auth-azure-active-directory-enable.md#disable-azure-ad-authentication-on-your-storage-account)
696+
1. [Delete the existing application](#cause-2-an-application-already-exists-for-the-storage-account)
697+
1. [Reconfigure Azure AD Kerberos via the Azure portal](storage-files-identity-auth-azure-active-directory-enable.md#enable-azure-ad-kerberos-authentication-for-hybrid-user-accounts-preview)
698+
699+
Once you've reconfigured Azure AD Kerberos, the new experience will auto-create and manage the newly created application.
700+
604701
## Need help?
605702
If you still need help, [contact support](https://portal.azure.com/?#blade/Microsoft_Azure_Support/HelpAndSupportBlade) to get your problem resolved quickly.

0 commit comments

Comments
 (0)