Skip to content

Commit 2bf4289

Browse files
raykaoCopilot
andcommitted
feat(infra): add Kubernetes namespaces and workload identity SA (kubernetes.tf)
argocd and aks-mcp namespaces. Workload identity service account for aks-mcp with UAMI client ID annotation. Federated credential wiring the SA to the UAMI via the cluster OIDC issuer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6530536 commit 2bf4289

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

infra/identity.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ resource "azurerm_federated_identity_credential" "gh_pr" {
4545
subject = "repo:${var.github_org}/${var.github_repo}:pull_request"
4646
}
4747

48+
resource "azurerm_federated_identity_credential" "aks_mcp_sa" {
49+
name = "aks-mcp-service-account"
50+
resource_group_name = azurerm_resource_group.main.name
51+
parent_id = azurerm_user_assigned_identity.workload.id
52+
audience = ["api://AzureADTokenExchange"]
53+
issuer = azurerm_kubernetes_cluster.main.oidc_issuer_url
54+
subject = "system:serviceaccount:aks-mcp:aks-mcp"
55+
}
56+
4857
# Contributor on the resource group (deploy AKS, ACR, etc.)
4958
resource "azurerm_role_assignment" "workload_rg_contributor" {
5059
scope = azurerm_resource_group.main.id

infra/kubernetes.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
# Kubernetes namespaces + RBAC - see task dark-factory-af1
1+
resource "kubernetes_namespace" "argocd" {
2+
metadata {
3+
name = "argocd"
4+
labels = {
5+
"app.kubernetes.io/managed-by" = "terraform"
6+
}
7+
}
8+
}
9+
10+
resource "kubernetes_namespace" "aks_mcp" {
11+
metadata {
12+
name = "aks-mcp"
13+
labels = {
14+
"app.kubernetes.io/managed-by" = "terraform"
15+
"azure.workload.identity/use" = "true"
16+
}
17+
}
18+
}
19+
20+
resource "kubernetes_service_account" "aks_mcp" {
21+
metadata {
22+
name = "aks-mcp"
23+
namespace = kubernetes_namespace.aks_mcp.metadata[0].name
24+
annotations = {
25+
"azure.workload.identity/client-id" = azurerm_user_assigned_identity.workload.client_id
26+
}
27+
labels = {
28+
"azure.workload.identity/use" = "true"
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)