@@ -6,7 +6,7 @@ author: ankitaduttaMSFT
6
6
manager : rochakm
7
7
ms.service : site-recovery
8
8
ms.topic : article
9
- ms.date : 07/23/2020
9
+ ms.date : 03/24/2023
10
10
ms.author : ankitadutta
11
11
ms.custom : engagement-fy23
12
12
---
@@ -57,19 +57,21 @@ When you enable replication for a VM either starting [from the VM view](azure-to
57
57
58
58
To manage the extension manually, select ** Off** .
59
59
60
+ > [ !IMPORTANT]
61
+ > When you choose ** Allow Site Recovery to manage** , the setting is applied to all VMs in the vault.
62
+
60
63
1 . Select ** Save** .
61
64
62
65
:::image type="content" source="./media/azure-to-azure-autoupdate/vault-toggle.png" alt-text="Extension update settings":::
63
66
64
- > [ !IMPORTANT]
65
- > When you choose ** Allow Site Recovery to manage** , the setting is applied to all VMs in the vault.
66
67
67
68
> [ !NOTE]
68
69
> 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.
69
70
71
+ ** For a custom automation account, use the following script:**
72
+
70
73
> [ !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.
73
75
74
76
``` azurepowershell
75
77
param(
@@ -85,13 +87,13 @@ param(
85
87
$SiteRecoveryRunbookName = "Modify-AutoUpdateForVaultForPatner"
86
88
$TaskId = [guid]::NewGuid().ToString()
87
89
$SubscriptionId = "00000000-0000-0000-0000-000000000000"
88
- $AsrApiVersion = "2018-01-10"
89
- $RunAsConnectionName = "AzureRunAsConnection"
90
+ $AsrApiVersion = "2021-12-01"
90
91
$ArmEndPoint = "https://management.azure.com"
91
92
$AadAuthority = "https://login.windows.net/"
92
93
$AadAudience = "https://management.core.windows.net/"
93
94
$AzureEnvironment = "AzureCloud"
94
95
$Timeout = "160"
96
+ $AuthenticationType = "SystemAssignedIdentity"
95
97
function Throw-TerminatingErrorMessage
96
98
{
97
99
Param
@@ -230,25 +232,19 @@ function Invoke-InternalWebRequest($Uri, $Headers, $Method, $Body, $ContentType,
230
232
}
231
233
}while($true)
232
234
}
233
- function Get-Header([ref]$Header, $AadAudience, $AadAuthority, $RunAsConnectionName ){
235
+ function Get-Header([ref]$Header, $AadAudience){
234
236
try
235
237
{
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)
250
238
$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
252
248
$Header.Value["x-ms-client-request-id"] = $TaskId + "/" + (New-Guid).ToString() + "-" + (Get-Date).ToString("u")
253
249
}
254
250
catch
@@ -265,7 +261,7 @@ function Get-ProtectionContainerToBeModified([ref] $ContainerMappingList)
265
261
Write-InformationTracing ("Get protection container mappings : {0}." -f $VaultResourceId)
266
262
$ContainerMappingListUrl = $ArmEndPoint + $VaultResourceId + "/replicationProtectionContainerMappings" + "?api-version=" + $AsrApiVersion
267
263
Write-InformationTracing ("Getting the bearer token and the header.")
268
- Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
264
+ Get-Header ([ref]$Header) $AadAudience
269
265
$Result = @()
270
266
Invoke-InternalRestMethod -Uri $ContainerMappingListUrl -Headers $header -Result ([ref]$Result)
271
267
$ContainerMappings = $Result[0]
@@ -321,8 +317,6 @@ $Inputs = ("Tracing inputs VaultResourceId: {0}, Timeout: {1}, AutoUpdateAction:
321
317
Write-Tracing -Message $Inputs -Level Informational -DisplayMessageToUser
322
318
$CloudConfig = ("Tracing cloud configuration ArmEndPoint: {0}, AadAuthority: {1}, AadAudience: {2}." -f $ArmEndPoint, $AadAuthority, $AadAudience)
323
319
Write-Tracing -Message $CloudConfig -Level Informational -DisplayMessageToUser
324
- $AutomationConfig = ("Tracing automation configuration RunAsConnectionName: {0}." -f $RunAsConnectionName)
325
- Write-Tracing -Message $AutomationConfig -Level Informational -DisplayMessageToUser
326
320
ValidateInput
327
321
$SubscriptionId = Initialize-SubscriptionId
328
322
Get-ProtectionContainerToBeModified ([ref]$ContainerMappingList)
@@ -332,6 +326,7 @@ $Input = @{
332
326
"instanceType" = "A2A"
333
327
"agentAutoUpdateStatus" = $AutoUpdateAction
334
328
"automationAccountArmId" = $AutomationAccountArmId
329
+ "automationAccountAuthenticationType" = $AuthenticationType
335
330
}
336
331
}
337
332
}
349
344
{
350
345
try {
351
346
$UpdateUrl = $ArmEndPoint + $Mapping + "?api-version=" + $AsrApiVersion
352
- Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
347
+ Get-Header ([ref]$Header) $AadAudience
353
348
$Result = @()
354
349
Invoke-InternalWebRequest -Uri $UpdateUrl -Headers $Header -Method 'PATCH' `
355
350
-Body $InputJson -ContentType "application/json" -Result ([ref]$Result)
385
380
{
386
381
try
387
382
{
388
- Get-Header ([ref]$Header) $AadAudience $AadAuthority $RunAsConnectionName
383
+ Get-Header ([ref]$Header) $AadAudience
389
384
$Result = Invoke-RestMethod -Uri $JobAsyncUrl -Headers $header
390
385
$JobState = $Result.Status
391
386
if($JobState -ieq "InProgress")
@@ -450,6 +445,7 @@ elseif($JobsCompletedSuccessList.Count -ne $ContainerMappingList.Count)
450
445
Throw-TerminatingErrorMessage -Message $ErrorMessage
451
446
}
452
447
Write-Tracing -Level Succeeded -Message ("Modify cloud pairing completed.") -DisplayMessageToUser
448
+
453
449
```
454
450
455
451
### Manage updates manually
@@ -495,3 +491,8 @@ If you can't enable automatic updates, see the following common errors and recom
495
491
496
492
> [ !NOTE]
497
493
> 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