Skip to content

Commit

Permalink
Feat/add abac (#34)
Browse files Browse the repository at this point in the history
* Add ABAC support on role asssignment
  • Loading branch information
shanoor authored Oct 1, 2024
1 parent 58d5c24 commit 9d09485
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/standalone-scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"redis_cache/103-redis-private-endpoints",
"role_mapping/100-simple-role-mapping",
"role_mapping/101-function-app-managed-identity",
"role_mapping/103-abac",
"search_service/100-search-service-both-apikeys-and-azuread",
"search_service/101-search-service-only-api-keys",
"search_service/102-search-service-only-azuread",
Expand Down
69 changes: 69 additions & 0 deletions examples/role_mapping/103-abac/configuration.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
global_settings = {
default_region = "region1"
regions = {
region1 = "francecentral"
}
}

resource_groups = {
test = {
name = "test"
}
}

storage_accounts = {
sa1 = {
name = "ada9a3027eec"
resource_group_key = "test"
account_kind = "BlobStorage"
account_tier = "Standard"
account_replication_type = "LRS"

tags = {
environment = "dev"
team = "IT"
}

containers = {
dev = {
name = "random"
}
}
}
}

managed_identities = {
msi01 = {
name = "example-msi-rolemap-msi"
resource_group_key = "test"
}
}

role_mapping = {
built_in_role_mapping = {
storage_accounts = {
sa1 = {
"Storage Blob Data Contributor" = {
managed_identities = {
keys = [
{
key = "msi01",
condition = <<EOT
(
(
!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'} AND NOT SubOperationMatches{'Blob.List'})
)
OR
(
@Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags:Malware Scanning scan result<$key_case_sensitive$>] StringEqualsIgnoreCase 'no threats found'
)
)
EOT
}
]
},
},
}
}
}
}
5 changes: 5 additions & 0 deletions roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ resource "azurerm_role_assignment" "for" {
role_definition_id = each.value.mode == "custom_role_mapping" ? module.custom_roles[each.value.role_definition_name].role_definition_resource_id : null
role_definition_name = each.value.mode == "built_in_role_mapping" ? each.value.role_definition_name : null
scope = each.value.scope_lz_key == null ? local.services_roles[each.value.scope_resource_key][var.current_landingzone_key][each.value.scope_key_resource].id : local.services_roles[each.value.scope_resource_key][each.value.scope_lz_key][each.value.scope_key_resource].id
condition_version = try(each.value.condition, null) == null ? null : "2.0"
condition = try(each.value.condition, null)
}

resource "azurerm_role_assignment" "for_deferred" {
Expand All @@ -36,6 +38,8 @@ resource "azurerm_role_assignment" "for_deferred" {
role_definition_id = each.value.mode == "custom_role_mapping" ? module.custom_roles[each.value.role_definition_name].role_definition_resource_id : null
role_definition_name = each.value.mode == "built_in_role_mapping" ? each.value.role_definition_name : null
scope = each.value.scope_lz_key == null ? local.services_roles_deferred[each.value.scope_resource_key][var.current_landingzone_key][each.value.scope_key_resource].id : local.services_roles_deferred[each.value.scope_resource_key][each.value.scope_lz_key][each.value.scope_key_resource].id
condition_version = try(each.value.condition, null) == null ? null : "2.0"
condition = try(each.value.condition, null)
}

resource "time_sleep" "azurerm_role_assignment_for" {
Expand Down Expand Up @@ -232,6 +236,7 @@ locals {
object_id_resource_type = object_id_key
object_id_key_resource = try(object_id_key_resource.key, object_id_key_resource) # "object_id_key_resource" = "aks_admins"
object_id_lz_key = try(object_id_key_resource.lz_key, object_resources.lz_key, null)
condition = try(object_id_key_resource.condition, null)
}
]
] if role_definition_name != "lz_key"
Expand Down

0 comments on commit 9d09485

Please sign in to comment.