Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/federated credentials #61

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions azuread_federated_credentials.tf
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
}
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"
}
}
}
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"
}
}
}
1 change: 1 addition & 0 deletions local.remote_objects.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ locals {
logic_app_standard = try(local.combined_objects_logic_app_standard, null)
machine_learning = try(local.combined_objects_machine_learning, null)
managed_identities = try(local.combined_objects_managed_identities, null)
mi_federated_credentials = try(local.combined_objects_mi_federated_credentials, null)
monitor_action_groups = try(local.combined_objects_monitor_action_groups, null)
mssql_databases = try(local.combined_objects_mssql_databases, null)
mssql_elastic_pools = try(local.combined_objects_mssql_elastic_pools, null)
Expand Down
1 change: 1 addition & 0 deletions locals.combined_objects.tf
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ locals {
combined_objects_mssql_managed_instances = merge(tomap({ (local.client_config.landingzone_key) = module.mssql_managed_instances }), try(var.remote_objects.mssql_managed_instances, {}))
combined_objects_mssql_managed_instances_secondary = merge(tomap({ (local.client_config.landingzone_key) = module.mssql_managed_instances_secondary }), try(var.remote_objects.mssql_managed_instances_secondary, {}))
combined_objects_mssql_servers = merge(tomap({ (local.client_config.landingzone_key) = module.mssql_servers }), try(var.remote_objects.mssql_servers, {}))
combined_objects_mi_federated_credentials = merge(tomap({ (local.client_config.landingzone_key) = module.mi_federated_credentials }), try(var.remote_objects.mi_federated_credentials, {}))
combined_objects_mysql_flexible_server = merge(tomap({ (local.client_config.landingzone_key) = module.mysql_flexible_server }), try(var.remote_objects.mysql_flexible_server, {}))
combined_objects_mysql_servers = merge(tomap({ (local.client_config.landingzone_key) = module.mysql_servers }), try(var.remote_objects.mysql_servers, {}))
combined_objects_nat_gateways = merge(tomap({ (local.client_config.landingzone_key) = module.nat_gateways }), try(var.remote_objects.nat_gateways, {}))
Expand Down
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ locals {
azuread_service_principal_passwords = try(var.azuread.azuread_service_principal_passwords, {})
azuread_service_principals = try(var.azuread.azuread_service_principals, {})
azuread_users = try(var.azuread.azuread_users, {})
azuread_federated_credentials = try(var.azuread.azuread_federated_credentials, {})
}

client_config = var.client_config == {} ? {
Expand Down
13 changes: 13 additions & 0 deletions mi_federated_credentials.tf
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 modules/azuread/federated_credentials/federated_credential.tf
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
}
3 changes: 3 additions & 0 deletions modules/azuread/federated_credentials/output.tf
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
}
12 changes: 12 additions & 0 deletions modules/azuread/federated_credentials/variables.tf
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
}
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))
}
3 changes: 3 additions & 0 deletions modules/security/mi_federated_credentials/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "id" {
value = azurerm_federated_identity_credential.fed_cred.id
}
16 changes: 16 additions & 0 deletions modules/security/mi_federated_credentials/variables.tf
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
}
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ variable "load_test" {
variable "cost_anomaly_alert" {
default = {}
}

variable "mi_federated_credentials" {
default = {}
}
variable "invoice_sections" {
default = {}
}
Loading