forked from aztfmod/terraform-azurerm-caf
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature: Federated credential support federated credential with service principal federated credential with managed identity
- Loading branch information
Showing
14 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module "azuread_federated_credentials" { | ||
source = "./modules/azuread/federated_credentials/" | ||
for_each = local.azuread.azuread_federated_credentials | ||
depends_on = [module.azuread_applications_v1] | ||
client_config = local.client_config | ||
settings = each.value | ||
azuread_applications = local.combined_objects_azuread_applications | ||
} | ||
|
||
output "azuread_federated_credentials" { | ||
value = module.azuread_federated_credentials | ||
} |
24 changes: 24 additions & 0 deletions
24
examples/azuread/202-azuread-application-federated-credentials/configurations.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
azuread_applications = { | ||
aks_auth_app = { | ||
application_name = "app-najeeb-sandbox-aksadmin" | ||
} | ||
} | ||
|
||
azuread_federated_credentials = { | ||
cred1 = { | ||
display_name = "app-wi-fed01" | ||
subject = "system:serviceaccount:demo:workload-identity-sa" | ||
oidc_issuer_url = "https://westeurope.oic.prod-aks.azure.com/" | ||
azuread_application = { | ||
key = "aks_auth_app" | ||
} | ||
} | ||
} | ||
|
||
azuread_service_principals = { | ||
aks_auth_app = { | ||
azuread_application = { | ||
key = "aks_auth_app" | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/managed_service_identity/101-mi-federated_credentials/configuration.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
resource_groups = { | ||
msi_region1 = { | ||
name = "security-rg1" | ||
region = "region1" | ||
} | ||
} | ||
|
||
managed_identities = { | ||
workload_system_mi = { | ||
name = "demo-mi-wi" | ||
resource_group_key = "msi_region1" | ||
} | ||
} | ||
|
||
mi_federated_credentials = { | ||
cred1 = { | ||
name = "mi-wi-demo01" | ||
subject = "system:serviceaccount:demo:workload-identity-sa" | ||
oidc_issuer_url = "https://westeurope.oic.prod-aks.azure.com/" | ||
managed_identity = { | ||
key = "workload_system_mi" | ||
} | ||
resource_group = { | ||
key = "msi_region1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module "mi_federated_credentials" { | ||
source = "./modules/security/mi_federated_credentials/" | ||
for_each = var.mi_federated_credentials | ||
depends_on = [module.managed_identities] | ||
client_config = local.client_config | ||
resource_group = local.combined_objects_resource_groups[try(each.value.resource_group.lz_key, local.client_config.landingzone_key)][try(each.value.resource_group_key, each.value.resource_group.key)] | ||
settings = each.value | ||
managed_identities = local.combined_objects_managed_identities | ||
} | ||
|
||
output "mi_federated_credentials" { | ||
value = module.mi_federated_credentials | ||
} |
8 changes: 8 additions & 0 deletions
8
modules/azuread/federated_credentials/federated_credential.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "azuread_application_federated_identity_credential" "fed_cred" { | ||
application_object_id = coalesce(try(var.settings.azuread_application.object_id, null), var.azuread_applications[try(var.settings.azuread_application.lz_key, var.client_config.landingzone_key)][var.settings.azuread_application.key].object_id) | ||
display_name = var.settings.display_name | ||
description = try(var.settings.description, null) | ||
audiences = ["api://AzureADTokenExchange"] | ||
issuer = coalesce(try(var.oidc_issuer_url, null), try(var.settings.oidc_issuer_url, null)) | ||
subject = var.settings.subject | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "credential_id" { | ||
value = azuread_application_federated_identity_credential.fed_cred.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
variable "settings" { | ||
default = {} | ||
} | ||
variable "client_config" { | ||
description = "Client configuration object (see module README.md)." | ||
} | ||
variable "azuread_applications" { | ||
default = {} | ||
} | ||
variable "oidc_issuer_url" { | ||
default = null | ||
} |
8 changes: 8 additions & 0 deletions
8
modules/security/mi_federated_credentials/federated_credential.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "azurerm_federated_identity_credential" "fed_cred" { | ||
name = var.settings.name | ||
resource_group_name = coalesce(try(var.settings.resource_group.name, null), try(var.resource_group.name, null)) | ||
audience = try(var.settings.audience, ["api://AzureADTokenExchange"]) | ||
parent_id = coalesce(try(var.settings.managed_identity.id, null), var.managed_identities[try(var.settings.managed_identity.lz_key, var.client_config.landingzone_key)][var.settings.managed_identity.key].id) | ||
subject = var.settings.subject | ||
issuer = coalesce(try(var.oidc_issuer_url, null), try(var.settings.oidc_issuer_url, null)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "id" { | ||
value = azurerm_federated_identity_credential.fed_cred.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
variable "settings" { | ||
default = {} | ||
} | ||
variable "client_config" { | ||
description = "Client configuration object (see module README.md)." | ||
} | ||
variable "resource_group" { | ||
default = {} | ||
} | ||
variable "managed_identities" { | ||
default = {} | ||
} | ||
variable "oidc_issuer_url" { | ||
default = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,3 +450,7 @@ variable "load_test" { | |
default = {} | ||
} | ||
|
||
variable "mi_federated_credentials" { | ||
default = {} | ||
} | ||
|