Description
A managed identity lets AKS manage Azure resources without a service principal secret that you have to rotate.
Potential impact
The control plane and the kubelet need different permissions. Missing roles can break cluster operations or image pulls. Excess roles give either identity unnecessary access.
Remediation
Set the cluster’s identity to SystemAssigned or an approved UserAssigned identity. Grant the control plane and kubelet their required roles separately. When migrating from a service principal, upgrade the node pools and verify cluster operations and image pulls before retiring its credentials.
Examples
The first excerpt omits the required authentication settings. AzureRM requires a managed identity or a service principal.
Before
resource "azurerm_kubernetes_cluster" "example" {
name = "example-aks"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "exampleaks"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}
}
After
resource "azurerm_kubernetes_cluster" "example" {
name = "example-aks"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "exampleaks"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}
identity {
type = "SystemAssigned"
}
}