|
| 1 | +--- |
| 2 | +title: 'Configure MACsec - ExpressRoute: Azure | Microsoft Docs' |
| 3 | +description: This article helps you configure MACsec to secure the connections between your edge routers and Microsoft's edge routers. |
| 4 | +services: expressroute |
| 5 | +author: cherylmc |
| 6 | + |
| 7 | +ms.service: expressroute |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 10/07/2019 |
| 10 | +ms.author: cherylmc |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +# Configure MACsec on ExpressRoute Direct ports |
| 15 | + |
| 16 | +This article helps you configure MACsec to secure the connections between your edge routers and Microsoft's edge routers using PowerShell. |
| 17 | + |
| 18 | +## Before you begin |
| 19 | + |
| 20 | +Before you start configuration, confirm the following: |
| 21 | + |
| 22 | +* You understand [ExpressRoute Direct provisioning workflows](expressroute-erdirect-about.md). |
| 23 | +* You've created an [ExpressRoute Direct port resource](expressroute-howto-erdirect.md). |
| 24 | +* If you want to run PowerShell locally, verify that the latest version of Azure PowerShell is installed on your computer. |
| 25 | + |
| 26 | +### Working with Azure PowerShell |
| 27 | + |
| 28 | +[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)] |
| 29 | + |
| 30 | +[!INCLUDE [expressroute-cloudshell](../../includes/expressroute-cloudshell-powershell-about.md)] |
| 31 | + |
| 32 | +### Sign in and select the right subscription |
| 33 | + |
| 34 | +To start the configuration, sign in to your Azure account and select the subscription that you want to use. |
| 35 | + |
| 36 | + [!INCLUDE [sign in](../../includes/expressroute-cloud-shell-connect.md)] |
| 37 | + |
| 38 | +## 1. Create Azure Key Vault, MACsec secrets, and user identity |
| 39 | + |
| 40 | +1. Create a Key Vault instance to store MACsec secrets in a new resource group. |
| 41 | + |
| 42 | + ```azurepowershell-interactive |
| 43 | + New-AzResourceGroup -Name "your_resource_group" -Location "resource_location" |
| 44 | + $keyVault = New-AzKeyVault -Name "your_key_vault_name" -ResourceGroupName "your_resource_group" -Location "resource_location" -EnableSoftDelete |
| 45 | + ``` |
| 46 | +
|
| 47 | + If you already have a key vault or a resource group, you can reuse them. However, it is critical that you enable the [**soft-delete** feature](https://docs.microsoft.com/en-us/azure/key-vault/key-vault-ovw-soft-delete) on your existing key vault. If soft-delete is not enabled, you can use the following commands to enable it: |
| 48 | +
|
| 49 | + ```azurepowershell-interactive |
| 50 | + ($resource = Get-AzResource -ResourceId (Get-AzKeyVault -VaultName "your_existing_keyvault").ResourceId).Properties | Add-Member -MemberType "NoteProperty" -Name "enableSoftDelete" -Value "true" |
| 51 | + Set-AzResource -resourceid $resource.ResourceId -Properties $resource.Properties |
| 52 | + ``` |
| 53 | +2. Create a user identity. |
| 54 | +
|
| 55 | + ```azurepowershell-interactive |
| 56 | + $identity = New-AzUserAssignedIdentity -Name "identity_name" -Location "resource_location" -ResourceGroupName "your_resource_group" |
| 57 | + ``` |
| 58 | +
|
| 59 | + If New-AzUserAssignedIdentity is not recognized as a valid PowerShell cmdlet, install the following module (in Administrator mode) and rerun the above command. |
| 60 | +
|
| 61 | + ```azurepowershell-interactive |
| 62 | + Install-Module -Name Az.ManagedServiceIdentity |
| 63 | + ``` |
| 64 | +3. Create a connectivity association key (CAK) and a connectivity association key name (CKN) and store them in the key vault. |
| 65 | +
|
| 66 | + ```azurepowershell-interactive |
| 67 | + $CAK = ConvertTo-SecureString "your_key" -AsPlainText -Force |
| 68 | + $CKN = ConvertTo-SecureString "your_key_name" -AsPlainText -Force |
| 69 | + $MACsecCAKSecret = Set-AzKeyVaultSecret -VaultName "your_key_vault_name" -Name "CAK_name" -SecretValue $CAK |
| 70 | + $MACsecCKNSecret = Set-AzKeyVaultSecret -VaultName "your_key_vault_name" -Name "CKN_name" -SecretValue $CKN |
| 71 | + ``` |
| 72 | +4. Assign the GET permission to the user identity. |
| 73 | +
|
| 74 | + ```azurepowershell-interactive |
| 75 | + Set-AzKeyVaultAccessPolicy -VaultName "your_key_vault_name" -PermissionsToSecrets get -ObjectId $identity.PrincipalId |
| 76 | + ``` |
| 77 | +
|
| 78 | + Now this identity can get the secrets, for example CAK and CKN, from the key vault. |
| 79 | +5. Set this user identity to be used by ExpressRoute. |
| 80 | +
|
| 81 | + ```azurepowershell-interactive |
| 82 | + $erIdentity = New-AzExpressRoutePortIdentity -UserAssignedIdentityId $identity.Id |
| 83 | + ``` |
| 84 | + |
| 85 | +## 2. Configure MACsec on ExpressRoute Direct ports |
| 86 | +
|
| 87 | +### To enable MACsec |
| 88 | +
|
| 89 | +Each ExpressRoute Direct instance has two physical ports. You can choose to enable MACsec on both ports at the same time or enable MACsec on one port at a time. Doing it one port at time (by switching traffic to an active port while servicing the other port) can help minimize the interruption if your ExpressRoute Direct is already in service. |
| 90 | +
|
| 91 | +1. Set MACsec secrets and cipher and associate the user identity with the port so that the ExpressRoute management code can access the MACsec secrets if needed. |
| 92 | +
|
| 93 | + ```azurepowershell-interactive |
| 94 | + $erDirect = Get-AzExpressRoutePort -ResourceGroupName "your_resource_group" -Name "your_direct_port_name" |
| 95 | + $erDirect.Links[0]. MacSecConfig.CknSecretIdentifier = $MacSecCKNSecret.Id |
| 96 | + $erDirect.Links[0]. MacSecConfig.CakSecretIdentifier = $MacSecCAKSecret.Id |
| 97 | + $erDirect.Links[0]. MacSecConfig.Cipher = "gcm-aes-128" |
| 98 | + $erDirect.Links[1]. MacSecConfig.CknSecretIdentifier = $MacSecCKNSecret.Id |
| 99 | + $erDirect.Links[1]. MacSecConfig.CakSecretIdentifier = $MacSecCAKSecret.Id |
| 100 | + $erDirect.Links[1]. MacSecConfig.Cipher = "gcm-aes-128" |
| 101 | + $erDirect.identity = $erIdentity |
| 102 | + Set-AzExpressRoutePort -ExpressRoutePort $erDirect |
| 103 | + ``` |
| 104 | +2. (Optional) If the ports are in Administrative Down state you can run the following commands to bring up the ports. |
| 105 | +
|
| 106 | + ```azurepowershell-interactive |
| 107 | + $erDirect = Get-AzExpressRoutePort -ResourceGroupName "your_resource_group" -Name "your_direct_port_name" |
| 108 | + $erDirect.Links[0].AdminState = “Enabled” |
| 109 | + $erDirect.Links[1].AdminState = “Enabled” |
| 110 | + Set-AzExpressRoutePort -ExpressRoutePort $erDirect |
| 111 | + ``` |
| 112 | +
|
| 113 | + At this point, MACsec is enabled on the ExpressRoute Direct ports on Microsoft side. If you haven't configured it on your edge devices, you can proceed to configure them with the same MACsec secrets and cipher. |
| 114 | +
|
| 115 | +### To disable MACsec |
| 116 | +
|
| 117 | +If MACsec is no longer desired on your ExpressRoute Direct instance, you can run the following commands to disable it. |
| 118 | +
|
| 119 | +```azurepowershell-interactive |
| 120 | +$erDirect = Get-AzExpressRoutePort -ResourceGroupName "your_resource_group" -Name "your_direct_port_name" |
| 121 | +$erDirect.Links[0]. MacSecConfig.CknSecretIdentifier = $null |
| 122 | +$erDirect.Links[0]. MacSecConfig.CakSecretIdentifier = $null |
| 123 | +$erDirect.Links[1]. MacSecConfig.CknSecretIdentifier = $null |
| 124 | +$erDirect.Links[1]. MacSecConfig.CakSecretIdentifier = $null |
| 125 | +$erDirect.identity = $null |
| 126 | +Set-AzExpressRoutePort -ExpressRoutePort $erDirect |
| 127 | +``` |
| 128 | + |
| 129 | +At this point, MACsec is disabled on the ExpressRoute Direct ports on the Microsoft side. |
| 130 | + |
| 131 | +## Next steps |
| 132 | +1. [Create an ExpressRoute circuit on ExpressRoute Direct](expressroute-howto-erdirect.md) |
| 133 | +2. [Link an ExpressRoute circuit to an Azure virtual network](expressroute-howto-linkvnet-arm.md) |
| 134 | +3. [Verify ExpressRoute connectivity](expressroute-troubleshooting-expressroute-overview.md) |
0 commit comments