Skip to content

Commit 4e9f4db

Browse files
Merge pull request #210749 from khdownie/kendownie090922-3
TSG entry for updating service principal pw
2 parents 5aeeaff + e1fbb93 commit 4e9f4db

File tree

1 file changed

+96
-1
lines changed

1 file changed

+96
-1
lines changed

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

Lines changed: 96 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,100 @@ 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. Azure Cloud Shell won't work in this scenario. For more information about installing PowerShell, see [Install Azure PowerShell on Windows with PowerShellGet](/powershell/azure/install-Az-ps).
613+
614+
To install the modules, open PowerShell with elevated privileges and run the following commands:
615+
616+
```azurepowershell
617+
Install-Module -Name Az.Storage
618+
Install-Module -Name AzureAD
619+
```
620+
621+
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.
622+
623+
```azurepowershell
624+
$tenantId = "<MyTenantId>"
625+
$subscriptionId = "<MySubscriptionId>"
626+
$resourceGroupName = "<MyResourceGroup>"
627+
$storageAccountName = "<MyStorageAccount>"
628+
```
629+
630+
3. Generate a new kerb1 key and password for the service principal.
631+
632+
```azurepowershell
633+
Connect-AzAccount -Tenant $tenantId -SubscriptionId $subscriptionId
634+
$kerbKeys = New-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName -KeyName "kerb1" -ErrorAction Stop | Select-Object -ExpandProperty Keys
635+
$kerbKey = $kerbKeys | Where-Object { $_.KeyName -eq "kerb1" } | Select-Object -ExpandProperty Value
636+
$azureAdPasswordBuffer = [System.Linq.Enumerable]::Take([System.Convert]::FromBase64String($kerbKey), 32);
637+
$password = "kk:" + [System.Convert]::ToBase64String($azureAdPasswordBuffer);
638+
```
639+
640+
4. Connect to Azure AD and retrieve the tenant information, application, and service principal.
641+
642+
```azurepowershell
643+
Connect-AzureAD
644+
$azureAdTenantDetail = Get-AzureADTenantDetail;
645+
$azureAdTenantId = $azureAdTenantDetail.ObjectId
646+
$azureAdPrimaryDomain = ($azureAdTenantDetail.VerifiedDomains | Where-Object {$_._Default -eq $true}).Name
647+
$application = Get-AzureADApplication -Filter "DisplayName eq '$($storageAccountName)'" -ErrorAction Stop;
648+
$servicePrincipal = Get-AzureADServicePrincipal -Filter "AppId eq '$($application.AppId)'"
649+
if ($servicePrincipal -eq $null) {
650+
Write-Host "Could not find service principal corresponding to application with app id $($application.AppId)"
651+
Write-Error -Message "Make sure that both service principal and application exist and are correctly configured" -ErrorAction Stop
652+
}
653+
```
654+
655+
5. Set the password for the storage account's service principal.
656+
657+
```azurepowershell
658+
$Token = ([Microsoft.Open.Azure.AD.CommonLibrary.AzureSession]::AccessTokens['AccessToken']).AccessToken;
659+
$Uri = ('https://graph.windows.net/{0}/{1}/{2}?api-version=1.6' -f $azureAdPrimaryDomain, 'servicePrincipals', $servicePrincipal.ObjectId)
660+
$json = @'
661+
{
662+
"passwordCredentials": [
663+
{
664+
"customKeyIdentifier": null,
665+
"endDate": "<STORAGEACCOUNTENDDATE>",
666+
"value": "<STORAGEACCOUNTPASSWORD>",
667+
"startDate": "<STORAGEACCOUNTSTARTDATE>"
668+
}]
669+
}
670+
'@
671+
672+
$now = [DateTime]::UtcNow
673+
$json = $json -replace "<STORAGEACCOUNTSTARTDATE>", $now.AddHours(-12).ToString("s")
674+
$json = $json -replace "<STORAGEACCOUNTENDDATE>", $now.AddMonths(6).ToString("s")
675+
$json = $json -replace "<STORAGEACCOUNTPASSWORD>", $password
676+
677+
$Headers = @{'authorization' = "Bearer $($Token)"}
678+
679+
try {
680+
Invoke-RestMethod -Uri $Uri -ContentType 'application/json' -Method Patch -Headers $Headers -Body $json
681+
Write-Host "Success: Password is set for $storageAccountName"
682+
} catch {
683+
Write-Host $_.Exception.ToString()
684+
Write-Host "StatusCode: " $_.Exception.Response.StatusCode.value
685+
Write-Host "StatusDescription: " $_.Exception.Response.StatusDescription
686+
}
687+
```
688+
689+
#### Option 2: Disable Azure AD Kerberos, delete the existing application, and reconfigure
690+
691+
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.
692+
693+
1. [Disable Azure AD Kerberos](storage-files-identity-auth-azure-active-directory-enable.md#disable-azure-ad-authentication-on-your-storage-account)
694+
1. [Delete the existing application](#cause-2-an-application-already-exists-for-the-storage-account)
695+
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)
696+
697+
Once you've reconfigured Azure AD Kerberos, the new experience will auto-create and manage the newly created application.
698+
604699
## Need help?
605700
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)