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/certificate-rotation.md
+88-75Lines changed: 88 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,141 +8,154 @@ ms.date: 01/19/2023
8
8
9
9
# Certificate rotation in Azure Kubernetes Service (AKS)
10
10
11
-
Azure Kubernetes Service (AKS) uses certificates for authentication with many of its components. If you have a RBAC-enabled cluster built after March 2022, it's enabled with certificate auto-rotation. Periodically, you may need to rotate those certificates for security or policy reasons. For example, you may have a policy to rotate all your certificates every 90 days.
11
+
Azure Kubernetes Service (AKS) uses certificates for authentication with many of its components. RBAC-enabled clusters created after March 2022 are enabled with certificate auto-rotation. You may need to periodically rotate those certificates for security or policy reasons. For example, you may have a policy to rotate all your certificates every 90 days.
12
12
13
13
> [!NOTE]
14
-
> Certificate auto-rotation will*only* be enabled by default for RBAC enabled AKS clusters.
14
+
> Certificate auto-rotation is*only* enabled by default for RBAC enabled AKS clusters.
15
15
16
16
This article shows you how certificate rotation works in your AKS cluster.
17
17
18
18
## Before you begin
19
19
20
-
This article requires that you are running the Azure CLI version 2.0.77 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
20
+
This article requires the Azure CLI version 2.0.77 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
21
21
22
22
## AKS certificates, Certificate Authorities, and Service Accounts
23
23
24
-
AKS generates and uses the following certificates, Certificate Authorities, and Service Accounts:
24
+
AKS generates and uses the following certificates, Certificate Authorities (CA), and Service Accounts (SA):
25
25
26
-
* The AKS API server creates a Certificate Authority (CA) called the Cluster CA.
26
+
* The AKS API server creates a CA called the Cluster CA.
27
27
* The API server has a Cluster CA, which signs certificates for one-way communication from the API server to kubelets.
28
-
* Each kubelet also creates a Certificate Signing Request (CSR), which is signed by the Cluster CA, for communication from the kubelet to the API server.
28
+
* Each kubelet creates a Certificate Signing Request (CSR), which the Cluster CA signs, for communication from the kubelet to the API server.
29
29
* The API aggregator uses the Cluster CA to issue certificates for communication with other APIs. The API aggregator can also have its own CA for issuing those certificates, but it currently uses the Cluster CA.
30
-
* Each node uses a Service Account (SA) token, which is signed by the Cluster CA.
30
+
* Each node uses an SA token, which the Cluster CA signs.
31
31
* The `kubectl` client has a certificate for communicating with the AKS cluster.
32
32
33
-
Certificates mentioned above are maintained by Microsoft, except the cluster certificate, which you have to maintain.
33
+
Microsoft maintains all certificates mentioned in this section, except for the cluster certificate.
34
34
35
35
> [!NOTE]
36
-
> AKS clusters created prior to May 2019 have certificates that expire after two years. Any cluster created after May 2019 or any cluster that has its certificates rotated have Cluster CA certificates that expire after 30 years. All other AKS certificates, which use the Cluster CA for signing, will expire after two years and are automatically rotated during an AKS version upgrade which happened after 8/1/2021. To verify when your cluster was created, use `kubectl get nodes` to see the *Age* of your node pools.
37
36
>
38
-
> Additionally, you can check the expiration date of your cluster's certificate. For example, the following bash command displays the client certificate details for the *myAKSCluster* cluster in resource group *rg*:
For AKS to automatically rotate non-CA certificates, the cluster must have [TLS Bootstrapping](https://kubernetes.io/docs/reference/access-authn-authz/kubelet-tls-bootstrapping/) which has been enabled by default in all Azure regions.
60
+
### Check VMAS agent node certificate expiration date
64
61
65
-
> [!NOTE]
66
-
> If you have an existing cluster you have to upgrade that cluster to enable Certificate Auto-Rotation.
67
-
> Do not disable bootstrap to keep your auto-rotation enabled.
62
+
* Check the expiration date of the VMAS agent node certificate using the `az vm run-command invoke` command.
68
63
69
-
> [!NOTE]
70
-
> If the cluster is in a stopped state during the auto certificate rotation only the control plane certificates are rotated. In this case the nodepool should be recreated, after certificate rotation, in order to initiate the nodepool certificate rotation.
64
+
```azurecli-interactive
65
+
az vm run-command invoke -g MC_rg_myAKSCluster_region -n vm-name --command-id RunShellScript --query 'value[0].message' -otsv --scripts "openssl x509 -in /etc/kubernetes/certs/apiserver.crt -noout -enddate"
66
+
```
71
67
72
-
For any AKS clusters created or upgraded after March 2022 Azure Kubernetes Service will automatically rotate non-CA certificates on both the control plane and agent nodes within 80% of the client certificate valid time, before they expire with no downtime for the cluster.
68
+
### Check Virtual Machine Scale Set agent node certificate expiration date
73
69
74
-
### How to check whether current agent node pool is TLS Bootstrapping enabled?
70
+
* Check the expiration date of the Virtual Machine Scale Set agent node certificate using the `az vm run-command invoke` command.
75
71
76
-
To verify if TLS Bootstrapping is enabled on your cluster browse to the following paths:
* On a Linux node: */var/lib/kubelet/bootstrap-kubeconfig* or */host/var/lib/kubelet/bootstrap-kubeconfig*
79
-
* On a Windows node: *C:\k\bootstrap-config*
76
+
## Certificate Auto Rotation
80
77
81
-
To access agent nodes, see [Connect to Azure Kubernetes Service cluster nodes for maintenance or troubleshooting][aks-node-access] for more information.
78
+
For AKS to automatically rotate non-CA certificates, the cluster must have [TLS Bootstrapping](https://kubernetes.io/docs/reference/access-authn-authz/kubelet-tls-bootstrapping/), which is enabled by default in all Azure regions.
82
79
83
80
> [!NOTE]
84
-
> The file path may change as Kubernetes version evolves in the future.
81
+
>
82
+
> * If you have an existing cluster, you have to upgrade that cluster to enable Certificate Auto Rotation.
83
+
> * Don't disable Bootstrap to keep auto rotation enabled.
84
+
> * If the cluster is in a stopped state during the auto certificate rotation, only the control plane certificates are rotated. In this case, you should recreate the node pool after certificate rotation to initiate the node pool certificate rotation.
85
85
86
-
Once a region is configured, create a new cluster or upgrade an existing cluster with `az aks upgrade` to set that cluster for auto-certificate rotation. A control plane and node pool upgrade is needed to enable this feature.
86
+
For any AKS clusters created or upgraded after March 2022, Azure Kubernetes Service automatically rotates non-CA certificates on both the control plane and agent nodes within 80% of the client certificate valid time before they expire with no downtime for the cluster.
87
87
88
-
```azurecli
89
-
az aks upgrade -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME
90
-
```
88
+
### How to check whether current agent node pool is TLS Bootstrapping enabled?
91
89
92
-
### Limitation
90
+
1. Verify if your cluster has TLS Bootstrapping enabled by browsing to one to the following paths:
93
91
94
-
Certificate auto-rotation will only be enabled by default for RBAC enabled AKS clusters.
92
+
* On a Linux node: */var/lib/kubelet/bootstrap-kubeconfig* or */host/var/lib/kubelet/bootstrap-kubeconfig*
93
+
* On a Windows node: *C:\k\bootstrap-config*
94
+
95
+
For more information, see [Connect to Azure Kubernetes Service cluster nodes for maintenance or troubleshooting][aks-node-access].
96
+
97
+
> [!NOTE]
98
+
> The file path may change as Kubernetes versions evolve.
99
+
100
+
2. Once a region is configured, create a new cluster or upgrade an existing cluster to set auto rotation for the cluster certificate. You need to upgrade the control plane and node pool to enable this feature.
95
101
96
102
## Manually rotate your cluster certificates
97
103
98
104
> [!WARNING]
99
-
> Rotating your certificates using `az aks rotate-certs`will recreate all of your nodes, VM scale set and their Disks and can cause up to 30 minutes of downtime for your AKS cluster.
105
+
> Rotating your certificates using `az aks rotate-certs`recreates all of your nodes, Virtual Machine Scale Sets and Disks and can cause up to *30 minutes of downtime*for your AKS cluster.
100
106
101
-
Use [az aks get-credentials][az-aks-get-credentials]to sign in to your AKS cluster. This command also downloads and configures the `kubectl` client certificate on your local machine.
107
+
1. Connect to your cluster using the [`az aks get-credentials`][az-aks-get-credentials] command.
102
108
103
-
```azurecli
104
-
az aks get-credentials -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME
105
-
```
109
+
```azurecli-interactive
110
+
az aks get-credentials -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME
111
+
```
106
112
107
-
Use `az aks rotate-certs` to rotate all certificates, CAs, and SAs on your cluster.
113
+
2. Rotate all certificates, CAs, and SAs on your cluster using the [`az aks rotate-certs`][az-aks-rotate-certs] command.
108
114
109
-
```azurecli
110
-
az aks rotate-certs -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME
111
-
```
115
+
```azurecli-interactive
116
+
az aks rotate-certs -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME
117
+
```
112
118
113
-
> [!IMPORTANT]
114
-
> It may take up to 30 minutes for `az aks rotate-certs` to complete. If the command fails before completing, use `az aks show` to verify the status of the cluster is *Certificate Rotating*. If the cluster is in a failed state, rerun `az aks rotate-certs` to rotate your certificates again.
119
+
> [!IMPORTANT]
120
+
> It may take up to 30 minutes for `az aks rotate-certs` to complete. If the command fails before completing, use `az aks show` to verify the status of the cluster is *Certificate Rotating*. If the cluster is in a failed state, rerun `az aks rotate-certs` to rotate your certificates again.
115
121
116
-
Verify that the old certificates aren't valid by running any `kubectl` command. If you haven't updated the certificates used by `kubectl`, you'll see an error similar to the following example:
122
+
3. Verify the old certificates are no longer valid using any `kubectl` command, such as `kubectl get nodes`.
117
123
118
-
```console
119
-
kubectl get nodes
120
-
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "ca")
121
-
```
124
+
```azurecli-interactive
125
+
kubectl get nodes
126
+
```
122
127
123
-
To update the certificate used by `kubectl`, run the [az aks get-credentials][az-aks-get-credentials] command:
128
+
If you haven't updated the certificates used by `kubectl`, you see an error similar to the following example output:
124
129
125
-
```azurecli
126
-
az aks get-credentials -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME --overwrite-existing
127
-
```
130
+
```output
131
+
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "ca")
132
+
```
128
133
129
-
To verify the certificates have been updated, run the following [kubectl get][kubectl-get] command:
134
+
4. Update the certificate used by `kubectl` using the [`az aks get-credentials`][az-aks-get-credentials] command with the `--overwrite-existing` flag.
130
135
131
-
```console
132
-
kubectl get nodes
133
-
```
136
+
```azurecli-interactive
137
+
az aks get-credentials -g $RESOURCE_GROUP_NAME -n $CLUSTER_NAME --overwrite-existing
138
+
```
134
139
135
-
> [!NOTE]
136
-
> If you have any services that run on top of AKS, you might need to update their certificates.
140
+
5. Verify the certificates have been updated using the [`kubectl get`][kubectl-get] command.
141
+
142
+
```azurecli-interactive
143
+
kubectl get nodes
144
+
```
145
+
146
+
> [!NOTE]
147
+
> If you have any services that run on top of AKS, you might need to update their certificates.
137
148
138
149
## Next steps
139
150
140
-
This article showed you how to automatically rotate your cluster's certificates, CAs, and SAs. You can see [Best practices for cluster security and upgrades in Azure Kubernetes Service (AKS)][aks-best-practices-security-upgrades] for more information on AKS security best practices.
151
+
This article showed you how to automatically rotate your cluster certificates, CAs, and SAs. For more information, see [Best practices for cluster security and upgrades in Azure Kubernetes Service (AKS)][aks-best-practices-security-upgrades].
0 commit comments