You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/update-credentials.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
---
2
2
title: Update or rotate the credentials for an Azure Kubernetes Service (AKS) cluster
3
3
description: Learn how update or rotate the service principal or Microsoft Entra Application credentials for an Azure Kubernetes Service (AKS) cluster.
4
+
ms.author: schaffererin
5
+
author: schaffererin
4
6
ms.topic: article
5
7
ms.subservice: aks-security
6
8
ms.custom: devx-track-azurecli
@@ -30,23 +32,23 @@ When you want to update the credentials for an AKS cluster, you can choose to ei
30
32
31
33
### Check the expiration date of your service principal
32
34
33
-
To check the expiration date of your service principal, use the [`az ad app credential list`][az-ad-app-credential-list] command. The following example gets the service principal ID for the cluster named *myAKSCluster*in the *myResourceGroup* resource group using the [`az aks show`][az-aks-show] command. The service principal ID is set as a variable named *SP_ID*.
35
+
To check the expiration date of your service principal, use the [`az ad app credential list`][az-ad-app-credential-list] command. The following example gets the service principal ID for the `$CLUSTER_NAME`cluster in the `$RESOURCE_GROUP_NAME` resource group using the [`az aks show`][az-aks-show] command. The service principal ID is set as a variable named *SP_ID*.
34
36
35
37
```azurecli
36
-
SP_ID=$(az aks show --resource-group myResourceGroup --name myAKSCluster \
38
+
SP_ID=$(az aks show --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME \
37
39
--query servicePrincipalProfile.clientId -o tsv)
38
40
az ad app credential list --id "$SP_ID" --query "[].endDateTime" -o tsv
39
41
```
40
42
41
43
### Reset the existing service principal credentials
42
44
43
-
To update the credentials for an existing service principal, get the service principal ID of your cluster using the [`az aks show`][az-aks-show] command. The following example gets the ID for the cluster named *myAKSCluster*in the *myResourceGroup* resource group. The variable named *SP_ID* stores the service principal ID used in the next step. These commands use the Bash command language.
45
+
To update the credentials for an existing service principal, get the service principal ID of your cluster using the [`az aks show`][az-aks-show] command. The following example gets the ID for the `$CLUSTER_NAME`cluster in the `$RESOURCE_GROUP_NAME` resource group. The variable named *SP_ID* stores the service principal ID used in the next step. These commands use the Bash command language.
44
46
45
47
> [!WARNING]
46
48
> When you reset your cluster credentials on an AKS cluster that uses Azure Virtual Machine Scale Sets, a [node image upgrade][node-image-upgrade] is performed to update your nodes with the new credential information.
47
49
48
50
```azurecli-interactive
49
-
SP_ID=$(az aks show --resource-group myResourceGroup --name myAKSCluster \
51
+
SP_ID=$(az aks show --resource-group $RESOURCE_GROUP_NAME --name $CLUSTER_NAME \
50
52
--query servicePrincipalProfile.clientId -o tsv)
51
53
```
52
54
@@ -66,25 +68,25 @@ Next, you [update AKS cluster with service principal credentials][update-cluster
66
68
To create a service principal and update the AKS cluster to use the new credential, use the [`az ad sp create-for-rbac`][az-ad-sp-create] command.
67
69
68
70
```azurecli-interactive
69
-
az ad sp create-for-rbac --role Contributor --scopes /subscriptions/mySubscriptionID
71
+
az ad sp create-for-rbac --role Contributor --scopes /subscriptions/$SUBSCRIPTION_ID
70
72
```
71
73
72
74
The output is similar to the following example output. Make a note of your own `appId` and `password` to use in the next step.
Define variables for the service principal ID and client secret using your output from running the [`az ad sp create-for-rbac`][az-ad-sp-create] command. The *SP_ID* is the *appId*, and the *SP_SECRET* is your *password*.
84
86
85
87
```console
86
-
SP_ID=7d837646-b1f3-443d-874c-fd83c7c739c5
87
-
SP_SECRET=a5ce83c9-9186-426d-9183-614597c7f2f7
88
+
SP_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
89
+
SP_SECRET=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
88
90
```
89
91
90
92
Next, you [update AKS cluster with the new service principal credential][update-cluster-service-principal-credentials]. This step is necessary to update the AKS cluster with the new service principal credential.
@@ -98,8 +100,8 @@ Update the AKS cluster with your new or existing credentials by running the [`az
98
100
99
101
```azurecli-interactive
100
102
az aks update-credentials \
101
-
--resource-group myResourceGroup \
102
-
--name myAKSCluster \
103
+
--resource-group $RESOURCE_GROUP_NAME \
104
+
--name $CLUSTER_NAME \
103
105
--reset-service-principal \
104
106
--service-principal "$SP_ID" \
105
107
--client-secret "${SP_SECRET}"
@@ -113,12 +115,12 @@ You can create new Microsoft Entra server and client applications by following t
0 commit comments