Skip to content

Commit 96c4977

Browse files
feat: PAYMCLOUD-462 argocd now use login with entra id (#159)
* minor fix * removed password for application * added federation * save application client id to kv * minor fix * updated entra configuration for argocd * updated entra configuration for argocd * fix app client id * try azuread_service_principal_delegated_permission_grant for application * removed unused property * minor fix * entra fix for app configuration * pre-commit fixs * added ingress host and secret tls name * minor fix * pre-commit fixs
1 parent 14c4aa3 commit 96c4977

19 files changed

+260
-260
lines changed

src/0-entra/.terraform.lock.hcl

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/0-entra/00_kv.tf

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/0-entra/00_users.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/0-entra/10_argocd.tf

Lines changed: 0 additions & 118 deletions
This file was deleted.

src/0_entra/.terraform.lock.hcl

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/0_entra/00_data.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# 🔐 KV
3+
#
4+
data "azurerm_key_vault" "kv_core_ita" {
5+
name = "dvopla-d-itn-core-kv"
6+
resource_group_name = "dvopla-d-itn-sec-rg"
7+
}
8+
9+
#
10+
# Users
11+
#
12+
data "azuread_users" "argocd_application_owners" {
13+
user_principal_names = local.argocd_application_owners
14+
}
15+
16+
#
17+
# Kubernetes
18+
#
19+
data "azurerm_kubernetes_cluster" "aks" {
20+
name = local.kubernetes_cluster_name
21+
resource_group_name = local.kubernetes_cluster_resource_group_name
22+
}
23+
24+
# -----------------------------------------------------------------------------
25+
# Entra ID Data Sources
26+
# -----------------------------------------------------------------------------
27+
28+
data "azuread_service_principal" "graph" {
29+
display_name = "Microsoft Graph"
30+
}
31+
32+
# data "azurerm_client_config" "current" {}
33+
34+
data "azuread_group" "argocd_groups" {
35+
for_each = toset(var.argocd_entra_groups_allowed)
36+
display_name = each.value
37+
}

src/0_entra/10_argocd_entra.tf

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# ⚠️
2+
# ⚠️ The grant admin for pagopa.it consent step must be performed manually in the Azure Portal after applying this configuration.
3+
# ⚠️ In App > API permissions > Microsoft Graph > User.Read > Grant admin consent for pagopa.it
4+
# ⚠️
5+
6+
# -----------------------------------------------------------------------------
7+
# Application Registration & Service Principal
8+
# -----------------------------------------------------------------------------
9+
10+
resource "azuread_application" "argocd" {
11+
display_name = "${var.prefix}-${var.env}-argocd"
12+
owners = data.azuread_users.argocd_application_owners.object_ids
13+
14+
web {
15+
redirect_uris = ["https://${local.argocd_hostname}/auth/callback"]
16+
logout_url = "https://${local.argocd_hostname}/logout"
17+
}
18+
19+
# This configures the "Mobile and desktop applications" platform in Entra ID.
20+
public_client {
21+
redirect_uris = ["http://localhost:8085/auth/callback"]
22+
}
23+
24+
group_membership_claims = [
25+
"ApplicationGroup"
26+
]
27+
28+
# MODIFICATION: Explicitly define ALL required delegated permissions for the OIDC flow.
29+
required_resource_access {
30+
resource_app_id = data.azuread_service_principal.graph.client_id
31+
32+
# Permission: User.Read
33+
resource_access {
34+
# Allows the app to sign in users and read their basic profile.
35+
id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" # User.Read
36+
type = "Scope"
37+
}
38+
}
39+
40+
optional_claims {
41+
id_token {
42+
name = "groups"
43+
essential = true
44+
source = null
45+
}
46+
}
47+
}
48+
49+
resource "azuread_service_principal" "sp_argocd" {
50+
client_id = azuread_application.argocd.client_id
51+
owners = data.azuread_users.argocd_application_owners.object_ids
52+
}
53+
54+
# -----------------------------------------------------------------------------
55+
# Permissions and Consent
56+
# -----------------------------------------------------------------------------
57+
58+
# The claim_values list must now match all the permissions defined above.
59+
resource "azuread_service_principal_delegated_permission_grant" "argocd_user_read_consent" {
60+
# The Object ID of the Service Principal receiving the grant.
61+
service_principal_object_id = azuread_service_principal.sp_argocd.object_id
62+
63+
# The Object ID of the API being granted access to (Microsoft Graph).
64+
resource_service_principal_object_id = data.azuread_service_principal.graph.object_id
65+
66+
# The list of permissions (scopes) to grant. Must match what was requested.
67+
claim_values = ["User.Read"]
68+
69+
# The Object ID of the user/principal granting the consent.
70+
user_object_id = data.azurerm_client_config.current.object_id
71+
}
72+
73+
# Assigns the specified Entra ID groups to the ArgoCD Enterprise Application.
74+
# This is required because 'group_membership_claims' is set to 'ApplicationGroup'.
75+
resource "azuread_app_role_assignment" "argocd_group_assignments" {
76+
for_each = data.azuread_group.argocd_groups
77+
78+
app_role_id = "00000000-0000-0000-0000-000000000000"
79+
principal_object_id = each.value.object_id
80+
resource_object_id = azuread_service_principal.sp_argocd.object_id
81+
}
82+
83+
# -----------------------------------------------------------------------------
84+
# Workload Identity Federation
85+
# -----------------------------------------------------------------------------
86+
87+
resource "azuread_application_federated_identity_credential" "argocd" {
88+
application_id = azuread_application.argocd.id
89+
display_name = "${local.project}-argocd-server-federated-credential"
90+
description = "Federated credential for the ArgoCD server service account"
91+
audiences = ["api://AzureADTokenExchange"]
92+
issuer = data.azurerm_kubernetes_cluster.aks.oidc_issuer_url
93+
subject = "system:serviceaccount:${local.argocd_namespace}:${local.argocd_service_account_name}"
94+
}
95+
96+
# -----------------------------------------------------------------------------
97+
# Key Vault Secrets
98+
# -----------------------------------------------------------------------------
99+
100+
resource "azurerm_key_vault_secret" "argocd_entra_app_client_id" {
101+
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
102+
name = "argocd-entra-app-workload-client-id"
103+
value = azuread_application.argocd.client_id
104+
}
105+
106+
resource "azurerm_key_vault_secret" "argocd_entra_app_service_account_name" {
107+
key_vault_id = data.azurerm_key_vault.kv_core_ita.id
108+
name = "argocd-entra-app-workload-service-account-name"
109+
value = local.argocd_service_account_name
110+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ locals {
1111
"fabio.felici@pagopa.it"
1212
]
1313

14+
argocd_hostname = "argocd.internal.devopslab.pagopa.it"
15+
16+
kubernetes_cluster_name = "dvopla-d-itn-dev-aks"
17+
kubernetes_cluster_resource_group_name = "dvopla-d-itn-dev-aks-rg"
18+
19+
argocd_namespace = "argocd"
20+
argocd_service_account_name = "argocd-server"
1421
}

0 commit comments

Comments
 (0)