Rotate your Azure AD Application (App Registration) keys periodically to an Azure KeyVault.
Let's say you have some Azure AD Applications for your business applications. For in example letting users login into a web application with his or her AD account. You need an Azure AD application with a key to do that. Those keys can be rotated into an Azure KeyVault. In that way, you have more security in your business application. The business application can just retrieve the current key from the KeyVault.
Comming soon...
-
Install the rotator function in a Resource Group.
-
Get the Service Principal Object Id of the function (MSI).
#Get MSI of rotator function app Get-AzureRmADServicePrincipal -SearchString $functionAppName | Where-Object { $_.DisplayName -eq $functionAppName } $rotatorAppSpId = $(Get-AzureRmADServicePrincipal -SearchString $functionAppName | Where-Object { $_.DisplayName -eq $functionAppName }).Id
-
Create a new Azure AD Application (App Registration) in your tenant. You will get an
applicationId
and aObjectId
for this. You can see this in the portal. -
Set the rotator service principal (MSI) as owner of the application.
# Get application that needs key rotation $appObjectIdThatNeedsRotation = "PUT Application ObjectId GUID HERE" Get-AzureRmADApplication -ObjectId $appObjectIdThatNeedsRotation Get-AzureRmADApplication -ObjectId $appObjectIdThatNeedsRotation | Get-AzureRmADServicePrincipal #Add MSI as owner of the application Add-AzureADApplicationOwner -ObjectId $appObjectIdThatNeedsRotation -RefObjectId $rotatorAppSpId Get-AzureADApplicationOwner -ObjectId $appObjectIdThatNeedsRotation
-
Create a key for this application via the portal or via PowerShell with a short live span (ie 1 day). This key will be rotated so a short live span is preferred. The expired keys will be cleaned up by the rotator.
-
Store the created key in a KeyVault with the following PowerShell:
Comming soon...
-
Make sure that the rotator function has the right Access Policy on the KeyVault. You can set that with the following PowerShell:`
Write-Information "Set access policy for Application Key Rotator Function App Service Principal Id" Set-AzureRmKeyVaultAccessPolicy ` -VaultName $keyVaultName ` -ObjectId $rotatorAppSpId ` -PermissionsToSecrets Get,Set
Create a local.settings.json
file in the root of the ApplicationRotator
function.
Contents of the local.settings.json
:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TenantId": "Here the tentant id of you application",
"ClientId": "Clientid of an AD Application to run locally",
"ClientSecret": "Client secret of the above clientid to authenticate"
}
}