Skip to content

Commit d7296e9

Browse files
authored
Merge pull request #224244 from ankitaduttaMSFT/18/1-ASR-managedi-identities
ASR managed identities for automation accounts
2 parents c0e54c6 + 1faefb9 commit d7296e9

File tree

11 files changed

+141
-28
lines changed

11 files changed

+141
-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+
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: Migrate from a Run As account to a managed identity
3+
description: This article describes how to migrate from a Run As account to a managed identity in Azure Site Recovery.
4+
author: ankitaduttaMSFT
5+
ms.service: site-recovery
6+
ms.author: ankitadutta
7+
ms.topic: how-to
8+
ms.date: 02/23/2023
9+
---
10+
11+
# Migrate from a Run As account to Managed Identities
12+
13+
> [!IMPORTANT]
14+
> - Azure Automation Run As Account will retire on September 30, 2023 and will be replaced with Managed Identities. Before that date, you'll need to start migrating your runbooks to use managed identities. For more information, see [migrating from an existing Run As accounts to managed identity](/articles/automation/automation-managed-identity-faq.md).
15+
> - Delaying the feature has a direct impact on our support burden, as it would cause upgrades of mobility agent to fail.
16+
17+
This article shows you how to migrate your runbooks to use a Managed Identities for Azure Site Recovery. Azure Automation Accounts are used by Azure Site Recovery customers to auto-update the agents of their protected virtual machines. Site Recovery creates Azure Automation Run As Accounts when you enable replication via the IaaS VM Blade and Recovery Services Vault.
18+
19+
On Azure, managed identities eliminate the need for developers having to manage credentials by providing an identity for the Azure resource in Azure Active Directory (Azure AD) and using it to obtain Azure AD tokens.
20+
21+
## Prerequisites
22+
23+
Before you migrate from a Run As account to a managed identity, ensure that you have the appropriate roles to create a system-assigned identity for your automation account and to assign it the Contributor role in the corresponding recovery services vault.
24+
25+
## Benefits of managed identities
26+
27+
Here are some of the benefits of using managed identities:
28+
29+
- **Credentials access** - You don't need to manage credentials.
30+
- **Simplified authentication** - You can use managed identities to authenticate to any resource that supports Azure AD authentication including your own applications.
31+
- **Cost effective** - Managed identities can be used at no extra cost.
32+
- **Double encryption** - Managed identity is also used to encrypt/decrypt data and metadata using the customer-managed key stored in Azure Key Vault, providing double encryption.
33+
34+
> [!NOTE]
35+
> Managed identities for Azure resources is the new name for the service formerly known as Managed Service Identity (MSI).
36+
37+
## Migrate from an existing Run As account to a managed identity
38+
39+
### Configure managed identities
40+
41+
You can configure your managed identities through:
42+
43+
- Azure portal
44+
- Azure CLI
45+
- your Azure Resource Manager (ARM) template
46+
47+
> [!NOTE]
48+
> For more information about migration cadence and the support timeline for Run As account creation and certificate renewal, see the [frequently asked questions](../automation/automation-managed-identity-faq.md).
49+
50+
51+
### From Azure portal
52+
53+
**To migrate your Azure Automation account authentication type from a Run As to a managed identity authentication, follow these steps:**
54+
55+
1. In the [Azure portal](https://portal.azure.com), select the recovery services vault for which you want to migrate the runbooks.
56+
57+
1. On the homepage of your recovery services vault page, do the following:
58+
1. On the left pane, under **Manage**, select **Site Recovery infrastructure**.
59+
:::image type="content" source="./media/how-to-migrate-from-run-as-to-managed-identities/manage-section.png" alt-text="Screenshot of the **Site Recovery infrastructure** page.":::
60+
1. Under **For Azure virtual machines**, select **Extension update settings**.
61+
This page details the authentication type for the automation account that is being used to manage the Site Recovery extensions.
62+
63+
1. On this page, select **Migrate** to migrate the authentication type for your automation accounts to use Managed Identities.
64+
65+
:::image type="content" source="./media/how-to-migrate-from-run-as-to-managed-identities/extension-update-settings.png" alt-text="Screenshot of the Create Recovery Services vault page.":::
66+
67+
1. After the successful migration of your automation account, the authentication type for the linked account details on the **Extension update settings** page is updated.
68+
69+
When you successfully migrate from a Run As to a Managed Identities account, the following changes are reflected on the Automation Run As Accounts :
70+
71+
- System Assigned Managed Identity is enabled for the account (if not already enabled).
72+
- The **Contributor** role permission is assigned to the Recovery Services vault’s subscription.
73+
- The script that updates the mobility agent to use Managed Identity based authentication is updated.
74+
75+
76+
### Link an existing managed identity account to vault
77+
78+
To link an existing managed identity Automation account to your Recovery Services vault. Follow these steps:
79+
80+
#### Enable the managed identity for the vault
81+
82+
1. Go to the automation account that you have selected. Under **Account settings**, select **Identity**.
83+
84+
:::image type="content" source="./media/how-to-migrate-from-run-as-to-managed-identities/mi-automation-account.png" alt-text="Screenshot that shows the identity settings page.":::
85+
86+
1. Under the **System assigned**, change the **Status** to **On** and select **Save**.
87+
88+
An Object ID is generated. The vault is now registered with Azure Active
89+
Directory.
90+
:::image type="content" source="./media/hybrid-how-to-enable-replication-private-endpoints/enable-managed-identity-in-vault.png" alt-text="Screenshot that shows the system identity settings page.":::
91+
92+
1. Go back to your recovery services vault. On the left pane, select the **Access control (IAM)** option.
93+
:::image type="content" source="./media/how-to-migrate-from-run-as-to-managed-identities/add-mi-iam.png" alt-text="Screenshot that shows IAM settings page.":::
94+
1. Select **Add** > **Add role assignment** > **Contributor** to open the **Add role assignment** page.
95+
1. On the **Add role assignment** page, ensure to select **Managed identity**.
96+
1. Select the **Select members**. In the **Select managed identities** pane, do the following:
97+
1. In the **Select** field, enter the name of the managed identity automation account.
98+
1. In the **Managed identity** field, select **All system-assigned managed identities**.
99+
1. Select the **Select** option.
100+
:::image type="content" source="./media/how-to-migrate-from-run-as-to-managed-identities/select-mi.png" alt-text="Screenshot that shows select managed identity settings page.":::
101+
1. Select **Review + assign**.
102+
103+
104+
105+
## Next steps
106+
107+
Learn more about:
108+
- [Managed identities](/articles/active-directory/managed-identities-azure-resources/overview.md).
109+
- [Implementing managed identities for Microsoft Azure Resources](https://www.pluralsight.com/courses/microsoft-azure-resources-managed-identities-implementing).
110+
67.4 KB
Loading
Loading
149 KB
Loading
154 KB
Loading
197 KB
Loading
147 KB
Loading
156 KB
Loading

0 commit comments

Comments
 (0)