-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storage account's system assigned identity use CMK (#155)
- Loading branch information
1 parent
72076b9
commit e7a44b0
Showing
11 changed files
with
99 additions
and
26 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,5 @@ | ||
--- | ||
"azure_storage_account": patch | ||
--- | ||
|
||
Allowing key vault based customer managed key to be automatically created and used by the storage account's system assigned managed identity |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"container_app_job_selfhosted_runner.naming_convention": "cebed82c7742c150fbcb4c363670d8078bee27ebd7cb37a37c01cd3803670c64" | ||
"container_app_job_selfhosted_runner.naming_convention": "5b1d21788783dcf33e17a9842f9f7c874c8c5f736c82e70979eb9c8785a74ce4" | ||
} |
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,41 @@ | ||
# Create a CMK key vault key if a key is not provided | ||
# tfsec:ignore:azure-keyvault-ensure-key-expiry | ||
resource "azurerm_key_vault_key" "key" { | ||
for_each = (local.cmk_flags.kv && var.customer_managed_key.key_name == null ? toset(["kv"]) : toset([])) | ||
name = "${replace("${module.naming_convention.prefix}-st", "-", "")}-cmk-${module.naming_convention.suffix}" | ||
key_vault_id = var.customer_managed_key.key_vault_id | ||
key_type = "RSA" | ||
key_size = 4096 | ||
key_opts = ["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"] | ||
|
||
depends_on = [ | ||
azurerm_key_vault_access_policy.keys | ||
] | ||
} | ||
|
||
# Add key vault access policy if it's the supported IAM mean and the key is in the same tenant | ||
resource "azurerm_key_vault_access_policy" "keys" { | ||
for_each = (local.cmk_flags.kv && try(local.cmk_info.kv.same_subscription, false) && try(data.azurerm_key_vault.this["kv"].enable_rbac_authorization, false) == false ? toset(["kv"]) : toset([])) | ||
key_vault_id = var.customer_managed_key.key_vault_id | ||
tenant_id = data.azurerm_subscription.current.tenant_id | ||
object_id = local.cmk_info.kv.principal_id | ||
|
||
key_permissions = ["Get", "Create", "List", "Restore", "Recover", "UnwrapKey", "WrapKey", "Purge", "Encrypt", "Decrypt", "Sign", "Verify"] | ||
secret_permissions = ["Get"] | ||
} | ||
|
||
# Add role assignment if it's the supported IAM mean and the key is in the same tenant | ||
resource "azurerm_role_assignment" "keys" { | ||
for_each = (local.cmk_flags.kv && try(local.cmk_info.kv.same_subscription, false) && try(data.azurerm_key_vault.this["kv"].enable_rbac_authorization, false) == true ? toset(["kv"]) : toset([])) | ||
scope = var.customer_managed_key.key_vault_id | ||
role_definition_name = "Key Vault Crypto Service Encryption User" | ||
principal_id = local.cmk_info.kv.principal_id | ||
} | ||
|
||
resource "azurerm_storage_account_customer_managed_key" "kv" { | ||
for_each = (local.cmk_flags.kv ? toset(["kv"]) : toset([])) | ||
storage_account_id = azurerm_storage_account.this.id | ||
key_vault_id = var.customer_managed_key.key_vault_id | ||
key_name = var.customer_managed_key.key_name == null ? azurerm_key_vault_key.key["kv"].name : var.customer_managed_key.key_name | ||
user_assigned_identity_id = var.customer_managed_key.user_assigned_identity_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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"core.naming_convention": "cebed82c7742c150fbcb4c363670d8078bee27ebd7cb37a37c01cd3803670c64" | ||
"core.naming_convention": "5b1d21788783dcf33e17a9842f9f7c874c8c5f736c82e70979eb9c8785a74ce4" | ||
} |