Skip to content

Commit 0b9e0a8

Browse files
authored
feat: (IAC-600) Add support for Microsoft Entra authentication with Kubernetes RBAC (#381)
1 parent bbda930 commit 0b9e0a8

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

docs/CONFIG-VARS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Supported configuration variables are listed in the tables below. All variables
88
- [Table of Contents](#table-of-contents)
99
- [Required Variables](#required-variables)
1010
- [Azure Authentication](#azure-authentication)
11+
- [Role Based Access Control](#role-based-access-control)
1112
- [Admin Access](#admin-access)
1213
- [Security](#security)
1314
- [Networking](#networking)
@@ -53,6 +54,20 @@ For details on how to retrieve that information, see [Azure Help Topics](./user/
5354

5455
For recommendations on how to set these variables in your environment, see [Authenticating Terraform to Access Azure](./user/TerraformAzureAuthentication.md).
5556

57+
## Role Based Access Control
58+
59+
The ability to manage RBAC for Kubernetes resources from Azure gives you the choice to manage RBAC for the cluster resources either using Azure or native Kubernetes mechanisms. For details see [Azure role-based access control](https://docs.microsoft.com/en-us/azure/aks/concepts-identity#azure-rbac-for-kubernetes-authorization).
60+
61+
Following are the possible ways to configure Authentication and Authorization in an AKS cluster:
62+
1. Authentication using local accounts with Kubernetes RBAC. This is traditionally used and current default, see details [here](https://learn.microsoft.com/en-us/azure/aks/concepts-identity#kubernetes-rbac)
63+
2. Microsoft Entra authentication with Kubernetes RBAC. See details [here](https://learn.microsoft.com/en-us/azure/aks/azure-ad-rbac)
64+
65+
| Name | Description | Type | Default |
66+
| :--- | ---: | ---: | ---: |
67+
| rbac_aad_enabled | Enables Azure Active Directory integration with Kubernetes RBAC. | bool | false |
68+
| rbac_aad_admin_group_object_ids | A list of Object IDs of Azure Active Directory Groups which should have Admin Role on the Cluster. | list(string) | null |
69+
| rbac_aad_tenant_id | (Optional) The Tenant ID used for Azure Active Directory Application. If this isn't specified the Tenant ID of the current Subscription is used.| string | |
70+
5671
## Admin Access
5772

5873
By default, the public endpoints of the Azure resources that are being created

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ module "aks" {
167167
aks_uai_id = local.aks_uai_id
168168
client_id = var.client_id
169169
client_secret = var.client_secret
170+
rbac_aad_tenant_id = var.rbac_aad_tenant_id
171+
rbac_aad_enabled = var.rbac_aad_enabled
172+
rbac_aad_admin_group_object_ids = var.rbac_aad_admin_group_object_ids
170173
aks_private_cluster = var.cluster_api_mode == "private" ? true : false
171174
depends_on = [module.vnet]
172175
}

modules/azure_aks/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ resource "azurerm_kubernetes_cluster" "aks" {
5252
}
5353
}
5454

55+
dynamic "azure_active_directory_role_based_access_control" {
56+
for_each = var.rbac_aad_enabled ? [1] : []
57+
content {
58+
managed = true
59+
tenant_id = var.rbac_aad_tenant_id
60+
admin_group_object_ids = var.rbac_aad_admin_group_object_ids
61+
azure_rbac_enabled = false
62+
}
63+
}
64+
5565
default_node_pool {
5666
name = "system"
5767
vm_size = var.aks_cluster_node_vm_size

modules/azure_aks/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
output "client_key" {
5-
value = azurerm_kubernetes_cluster.aks.kube_config[0].client_key
5+
value = var.rbac_aad_enabled ? azurerm_kubernetes_cluster.aks.kube_admin_config[0].client_key : azurerm_kubernetes_cluster.aks.kube_config[0].client_key
66
}
77

88
output "client_certificate" {
9-
value = azurerm_kubernetes_cluster.aks.kube_config[0].client_certificate
9+
value = var.rbac_aad_enabled ? azurerm_kubernetes_cluster.aks.kube_admin_config[0].client_certificate : azurerm_kubernetes_cluster.aks.kube_config[0].client_certificate
1010
}
1111

1212
output "cluster_ca_certificate" {
13-
value = azurerm_kubernetes_cluster.aks.kube_config[0].cluster_ca_certificate
13+
value = var.rbac_aad_enabled ? azurerm_kubernetes_cluster.aks.kube_admin_config[0].cluster_ca_certificate : azurerm_kubernetes_cluster.aks.kube_config[0].cluster_ca_certificate
1414
}
1515

1616
output "cluster_username" {
1717
value = azurerm_kubernetes_cluster.aks.kube_config[0].username
1818
}
1919

2020
output "cluster_password" {
21-
value = azurerm_kubernetes_cluster.aks.kube_config[0].password
21+
value = var.rbac_aad_enabled ? azurerm_kubernetes_cluster.aks.kube_admin_config[0].password : azurerm_kubernetes_cluster.aks.kube_config[0].password
2222
}
2323

2424
output "kube_config" {

modules/azure_aks/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ variable "aks_cluster_location" {
2222
default = "eastus"
2323
}
2424

25+
variable "rbac_aad_enabled" {
26+
type = bool
27+
description = "Enables Azure Active Directory integration with Kubernetes RBAC."
28+
default = false
29+
}
30+
31+
variable "rbac_aad_admin_group_object_ids" {
32+
type = list(string)
33+
description = "A list of Object IDs of Azure Active Directory Groups which should have Admin Role on the Cluster."
34+
default = null
35+
}
36+
37+
variable "rbac_aad_tenant_id" {
38+
type = string
39+
description = "(Optional) The Tenant ID used for Azure Active Directory Application. If this isn't specified the Tenant ID of the current Subscription is used."
40+
default = null
41+
}
42+
2543
variable "aks_cluster_sku_tier" {
2644
description = "The SKU Tier that should be used for this Kubernetes Cluster. Possible values are Free, Standard (which includes the Uptime SLA) and Premium. Defaults to Free"
2745
type = string

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ variable "location" {
5858
default = "eastus"
5959
}
6060

61+
## Azure AD
62+
variable "rbac_aad_enabled" {
63+
type = bool
64+
description = "Enables Azure Active Directory integration with Kubernetes RBAC."
65+
default = false
66+
}
67+
68+
variable "rbac_aad_admin_group_object_ids" {
69+
type = list(string)
70+
description = "A list of Object IDs of Azure Active Directory Groups which should have Admin Role on the Cluster."
71+
default = null
72+
}
73+
74+
variable "rbac_aad_tenant_id" {
75+
type = string
76+
description = "(Optional) The Tenant ID used for Azure Active Directory Application. If this isn't specified the Tenant ID of the current Subscription is used."
77+
default = null
78+
}
79+
6180
variable "aks_cluster_sku_tier" {
6281
description = "The SKU Tier that should be used for this Kubernetes Cluster. Possible values are Free, Standard (which includes the Uptime SLA) and Premium. Defaults to Free"
6382
type = string

0 commit comments

Comments
 (0)