|
| 1 | +--- |
| 2 | +title: Azure Operator Nexus service principal rotation |
| 3 | +description: Instructions on service principal rotation lifecycle management. |
| 4 | +ms.service: azure-operator-nexus |
| 5 | +ms.custom: template-how-to |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 02/05/2024 |
| 8 | +author: sbatchu0108 |
| 9 | +ms.author: sbatchu |
| 10 | +--- |
| 11 | + |
| 12 | +# Service principal rotation on the target cluster |
| 13 | + |
| 14 | +This document provides an overview on the process of performing service principal rotation on the target cluster. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +1. The [Install Azure CLI][installation-instruction] must be installed. |
| 19 | +2. The `networkcloud` CLI extension is required. If the `networkcloud` extension isn't installed, it can be installed following the steps listed [here](https://github.com/MicrosoftDocs/azure-docs-pr/blob/main/articles/operator-nexus/howto-install-cli-extensions.md). |
| 20 | +3. Access to the Azure portal for the target cluster. |
| 21 | +4. You must be logged in to the same subscription as your target cluster via `az login` |
| 22 | +5. Target cluster must be in running and healthy state. |
| 23 | +6. Service Principal rotation should be performed prior to the configured credentials expiring. |
| 24 | +7. Service Principal should have owner privilege on the subscription of the target cluster. |
| 25 | + |
| 26 | +## Append secondary credential to the existing service principal |
| 27 | + |
| 28 | +List existing credentials info for the service principal |
| 29 | + |
| 30 | +```azurecli |
| 31 | +az ad app credential list --id "<SP Application (client) ID>" |
| 32 | +``` |
| 33 | + |
| 34 | +Append secondary credential to the service principal. Please copy the resulting generated password somewhere safe. |
| 35 | + |
| 36 | +```azurecli |
| 37 | +az ad app credential reset --id "<SP Application (client) ID>" --append --display-name "<human-readable description>" |
| 38 | +``` |
| 39 | +## Create a new service principal |
| 40 | + |
| 41 | +New service principal should have owner privilege scope on the target cluster subscription. |
| 42 | + |
| 43 | +```azurecli |
| 44 | +az ad sp create-for-rbac -n "<service principal display name>" --role owner --scopes /subscriptions/<subscription-id> |
| 45 | +``` |
| 46 | + |
| 47 | +## Rotate service principal on the target cluster |
| 48 | + |
| 49 | +Service principal can be rotated on the target cluster by supplying the new information, which can either be only secondary credential update or it could be the new service principal for the target cluster. |
| 50 | + |
| 51 | +```azurecli |
| 52 | +az networkcloud cluster update --resource-group "<resourceGroupName>" --cluster-service-principal application-id="<sp app id>" password="<cleartext password>" principal-id="<sp id>" tenant-id="<tenant id>" -n <cluster name> --subscription <subscription-id> |
| 53 | +``` |
| 54 | + |
| 55 | +## Verify new service principal update on the target cluster |
| 56 | + |
| 57 | +Cluster show will list the new service principal changes if its rotated on the target cluster. |
| 58 | + |
| 59 | +```azurecli |
| 60 | +az networkcloud cluster show --name "clusterName" --resource-group "resourceGroup" |
| 61 | +``` |
| 62 | + |
| 63 | +In the output, you can find the details under `clusterServicePrincipal` property. |
| 64 | + |
| 65 | +``` |
| 66 | +"clusterServicePrincipal": { |
| 67 | + "applicationId": "<sp application id>", |
| 68 | + "principalId": "<sp principal id>", |
| 69 | + "tenantId": "tenant id" |
| 70 | + } |
| 71 | +``` |
| 72 | + |
| 73 | +> [!NOTE] |
| 74 | +> Ensure you're using the correct service principal ID(object ID in Azure) when updating it. There are two different object IDs retrievable from Azure for the same Service Principal name, follow these steps to find the right one: |
| 75 | +> 1. Avoid retrieving the object ID from the Service Principal of type application that appears when you search for service principal on the Azure portal search bar. |
| 76 | +> 2. Instead, Search for the service principal name under "Enterprise applications" in Azure Services to find the correct object ID and use it as principal ID. |
| 77 | +
|
| 78 | +If you still have questions, [contact support](https://portal.azure.com/?#blade/Microsoft_Azure_Support/HelpAndSupportBlade). |
| 79 | +For more information about Support plans, see [Azure Support plans](https://azure.microsoft.com/support/plans/response/). |
0 commit comments