Skip to content

Commit 45033bd

Browse files
author
Ankita Dutta
committed
additional changes
1 parent 422b63d commit 45033bd

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed
0 Bytes
Loading

articles/site-recovery/azure-to-azure-autoupdate.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: ankitaduttaMSFT
66
manager: rochakm
77
ms.service: site-recovery
88
ms.topic: article
9-
ms.date: 07/23/2020
9+
ms.date: 03/24/2023
1010
ms.author: ankitadutta
1111
ms.custom: engagement-fy23
1212
---
@@ -57,19 +57,21 @@ When you enable replication for a VM either starting [from the VM view](azure-to
5757

5858
To manage the extension manually, select **Off**.
5959

60+
> [!IMPORTANT]
61+
> When you choose **Allow Site Recovery to manage**, the setting is applied to all VMs in the vault.
62+
6063
1. Select **Save**.
6164

6265
:::image type="content" source="./media/azure-to-azure-autoupdate/vault-toggle.png" alt-text="Extension update settings":::
6366

64-
> [!IMPORTANT]
65-
> When you choose **Allow Site Recovery to manage**, the setting is applied to all VMs in the vault.
6667

6768
> [!NOTE]
6869
> Either option notifies you of the automation account used for managing updates. If you're using this feature in a vault for the first time, a new automation account is created by default. Alternately, you can customize the setting, and choose an existing automation account. Once defined, all subsequent actions to enable replication in the same vault will use that selected automation account. Currently, the drop-down menu will only list automation accounts that are in the same Resource Group as the vault.
6970
71+
**For a custom automation account, use the following script:**
72+
7073
> [!IMPORTANT]
71-
> The following script needs to be run in the context of an automation account.
72-
For a custom automation account, use the following script:
74+
> Run the following script in the context of an automation account. This script leverages System Assigned Managed Identities as its authentication type.
7375
7476
```azurepowershell
7577
param(
@@ -85,13 +87,13 @@ param(
8587
$SiteRecoveryRunbookName = "Modify-AutoUpdateForVaultForPatner"
8688
$TaskId = [guid]::NewGuid().ToString()
8789
$SubscriptionId = "00000000-0000-0000-0000-000000000000"
88-
$AsrApiVersion = "2018-01-10"
89-
$RunAsConnectionName = "AzureRunAsConnection"
90+
$AsrApiVersion = "2021-12-01"
9091
$ArmEndPoint = "https://management.azure.com"
9192
$AadAuthority = "https://login.windows.net/"
9293
$AadAudience = "https://management.core.windows.net/"
9394
$AzureEnvironment = "AzureCloud"
9495
$Timeout = "160"
96+
$AuthenticationType = "SystemAssignedIdentity"
9597
function Throw-TerminatingErrorMessage
9698
{
9799
Param
@@ -230,25 +232,19 @@ function Invoke-InternalWebRequest($Uri, $Headers, $Method, $Body, $ContentType,
230232
}
231233
}while($true)
232234
}
233-
function Get-Header([ref]$Header, $AadAudience, $AadAuthority, $RunAsConnectionName){
235+
function Get-Header([ref]$Header, $AadAudience){
234236
try
235237
{
236-
$RunAsConnection = Get-AutomationConnection -Name $RunAsConnectionName
237-
$TenantId = $RunAsConnection.TenantId
238-
$ApplicationId = $RunAsConnection.ApplicationId
239-
$CertificateThumbprint = $RunAsConnection.CertificateThumbprint
240-
$Path = "cert:\CurrentUser\My\{0}" -f $CertificateThumbprint
241-
$Secret = Get-ChildItem -Path $Path
242-
$ClientCredential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate(
243-
$ApplicationId,
244-
$Secret)
245-
# Trim the forward slash from the AadAuthority if it exist.
246-
$AadAuthority = $AadAuthority.TrimEnd("/")
247-
$AuthContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(
248-
"{0}/{1}" -f $AadAuthority, $TenantId )
249-
$AuthenticationResult = $authContext.AcquireToken($AadAudience, $Clientcredential)
250238
$Header.Value['Content-Type'] = 'application\json'
251-
$Header.Value['Authorization'] = $AuthenticationResult.CreateAuthorizationHeader()
239+
Write-InformationTracing ("The Authentication Type is system Assigned Identity based.")
240+
$endpoint = $env:IDENTITY_ENDPOINT
241+
$endpoint
242+
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
243+
$Headers.Add("X-IDENTITY-HEADER", $env:IDENTITY_HEADER)
244+
$Headers.Add("Metadata", "True")
245+
$authenticationResult = Invoke-RestMethod -Method Get -Headers $Headers -Uri ($endpoint +'?resource=' +$AadAudience)
246+
$accessToken = $authenticationResult.access_token
247+
$Header.Value['Authorization'] = "Bearer " + $accessToken
252248
$Header.Value["x-ms-client-request-id"] = $TaskId + "/" + (New-Guid).ToString() + "-" + (Get-Date).ToString("u")
253249
}
254250
catch
@@ -265,7 +261,7 @@ function Get-ProtectionContainerToBeModified([ref] $ContainerMappingList)
265261
Write-InformationTracing ("Get protection container mappings : {0}." -f $VaultResourceId)
266262
$ContainerMappingListUrl = $ArmEndPoint + $VaultResourceId + "/replicationProtectionContainerMappings" + "?api-version=" + $AsrApiVersion
267263
Write-InformationTracing ("Getting the bearer token and the header.")
268-
Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
264+
Get-Header ([ref]$Header) $AadAudience
269265
$Result = @()
270266
Invoke-InternalRestMethod -Uri $ContainerMappingListUrl -Headers $header -Result ([ref]$Result)
271267
$ContainerMappings = $Result[0]
@@ -321,8 +317,6 @@ $Inputs = ("Tracing inputs VaultResourceId: {0}, Timeout: {1}, AutoUpdateAction:
321317
Write-Tracing -Message $Inputs -Level Informational -DisplayMessageToUser
322318
$CloudConfig = ("Tracing cloud configuration ArmEndPoint: {0}, AadAuthority: {1}, AadAudience: {2}." -f $ArmEndPoint, $AadAuthority, $AadAudience)
323319
Write-Tracing -Message $CloudConfig -Level Informational -DisplayMessageToUser
324-
$AutomationConfig = ("Tracing automation configuration RunAsConnectionName: {0}." -f $RunAsConnectionName)
325-
Write-Tracing -Message $AutomationConfig -Level Informational -DisplayMessageToUser
326320
ValidateInput
327321
$SubscriptionId = Initialize-SubscriptionId
328322
Get-ProtectionContainerToBeModified ([ref]$ContainerMappingList)
@@ -332,6 +326,7 @@ $Input = @{
332326
"instanceType" = "A2A"
333327
"agentAutoUpdateStatus" = $AutoUpdateAction
334328
"automationAccountArmId" = $AutomationAccountArmId
329+
"automationAccountAuthenticationType" = $AuthenticationType
335330
}
336331
}
337332
}
@@ -349,7 +344,7 @@ try
349344
{
350345
try {
351346
$UpdateUrl = $ArmEndPoint + $Mapping + "?api-version=" + $AsrApiVersion
352-
Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
347+
Get-Header ([ref]$Header) $AadAudience
353348
$Result = @()
354349
Invoke-InternalWebRequest -Uri $UpdateUrl -Headers $Header -Method 'PATCH' `
355350
-Body $InputJson -ContentType "application/json" -Result ([ref]$Result)
@@ -385,7 +380,7 @@ try
385380
{
386381
try
387382
{
388-
Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
383+
Get-Header ([ref]$Header) $AadAudience
389384
$Result = Invoke-RestMethod -Uri $JobAsyncUrl -Headers $header
390385
$JobState = $Result.Status
391386
if($JobState -ieq "InProgress")
@@ -450,6 +445,7 @@ elseif($JobsCompletedSuccessList.Count -ne $ContainerMappingList.Count)
450445
Throw-TerminatingErrorMessage -Message $ErrorMessage
451446
}
452447
Write-Tracing -Level Succeeded -Message ("Modify cloud pairing completed.") -DisplayMessageToUser
448+
453449
```
454450

455451
### Manage updates manually
@@ -495,3 +491,8 @@ If you can't enable automatic updates, see the following common errors and recom
495491

496492
> [!NOTE]
497493
> After you renew the certificate, refresh the page to display the current status.
494+
495+
## Next steps
496+
497+
[Learn more](./how-to-migrate-run-as-accounts-managed-identity.md) on how to migrate the authentication type of the Automation accounts to Managed Identities.
498+

0 commit comments

Comments
 (0)