|
| 1 | +--- |
| 2 | +title: Rotate Batch account keys |
| 3 | +description: Learn how to rotate Batch account shared key credentials. |
| 4 | +ms.topic: how-to |
| 5 | +ms.date: 08/09/2024 |
| 6 | +--- |
| 7 | +# Batch account shared key credential rotation |
| 8 | + |
| 9 | +Batch accounts can be authenticated in one of two ways, either via shared key or Microsoft Entra ID. Batch accounts |
| 10 | +with shared key authentication enabled have two keys associated with them to allow for key rotation scenarios. |
| 11 | + |
| 12 | +> [!TIP] |
| 13 | +> It's highly recommended to avoid using shared key authentication with Batch accounts. The preferred authentication |
| 14 | +> mechanism is through Microsoft Entra ID. You can disable shared key authentication during account creation or you |
| 15 | +> can update allowed [Authentication Modes](/rest/api/batchmanagement/batch-account/create#authenticationmode) for an |
| 16 | +> active account. |
| 17 | +
|
| 18 | +## Batch shared key rotation procedure |
| 19 | + |
| 20 | +Azure Batch accounts have two shared keys, `primary` or `secondary`. It's important not to regenerate both |
| 21 | +keys at the same time, and instead regenerate them one at a time to avoid potential downtime. |
| 22 | + |
| 23 | +> [!WARNING] |
| 24 | +> Once a key has been regenerated, it is no longer valid and the prior key cannot be recovered for use. Ensure |
| 25 | +> that your application update process follows the recommended key rotation procedure to prevent losing access |
| 26 | +> to your Batch account. |
| 27 | +
|
| 28 | +The typical key rotation procedure is as follows: |
| 29 | + |
| 30 | +1. Normalize your application code to use either the primary or secondary key. If you're using both keys in your |
| 31 | +application simultaneously, then any rotation procedure leads to authentication errors. The following steps assume |
| 32 | +that you're using the `primary` key in your application. |
| 33 | +1. Regenerate the `secondary` key. |
| 34 | +1. Update your application code to utilize the newly regenerated `secondary` key. Deploy these changes and |
| 35 | +ensure that everything is working as expected. |
| 36 | +1. Regenerate the `primary` key. |
| 37 | +1. Optionally update your application code to use the `primary` key and deploy. This step isn't strictly |
| 38 | +necessary as long as you're tracking which key is used in your application and deployed. |
| 39 | + |
| 40 | +### Rotation in Azure portal |
| 41 | + |
| 42 | +First, sign in to the [Azure portal](https://portal.azure.com). Then, navigate to the **Keys** blade of your |
| 43 | +Batch account under **Settings**. Then select either `Regenerate primary` or `Regenerate secondary` to create a new key. |
| 44 | + |
| 45 | + :::image type="content" source="media/account-key-rotation/batch-account-key-rotation.png" alt-text="Screenshot showing key rotation."::: |
| 46 | + |
| 47 | +## See also |
| 48 | + |
| 49 | +- Learn more about [Batch accounts](accounts.md). |
| 50 | +- Learn how to authenticate with [Batch Service APIs](batch-aad-auth.md) |
| 51 | +or [Batch Management APIs](batch-aad-auth-management.md) with Microsoft Entra ID. |
0 commit comments