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

Add CMK support for Cosmos DB (core) #4152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9d185d4
added management key vault
Sep 9, 2024
3bab628
added cmk for vmss and storage accounts
Sep 11, 2024
dec4288
Merge branch 'main' of https://github.com/yuvalyaron/AzureTRE into 40…
yuvalyaron Nov 7, 2024
7388db5
Merge branch 'main' of https://github.com/yuvalyaron/AzureTRE into 40…
yuvalyaron Nov 11, 2024
036b90e
add default value for variables
yuvalyaron Nov 13, 2024
27212b4
add CMK for cosmos accounts
yuvalyaron Nov 14, 2024
50ec316
move tre-encryption key from mgmt to core
yuvalyaron Nov 17, 2024
df682d6
fix order of creation for encryption key
yuvalyaron Nov 17, 2024
9e66234
add cmk for the state store in mgmt
yuvalyaron Nov 17, 2024
fed7a16
add support for external KV
yuvalyaron Nov 18, 2024
7f24a23
revert CMK for cosmos - not working, need to redo this
yuvalyaron Nov 18, 2024
cd9271a
refine comments and files names
yuvalyaron Nov 19, 2024
f459a82
remove redundant space
yuvalyaron Nov 19, 2024
af53615
add space
yuvalyaron Nov 19, 2024
61d8e97
upper case in comment
yuvalyaron Nov 19, 2024
25322d7
revert cosmos tags
yuvalyaron Nov 19, 2024
e3e2d6c
Merge branch 'main' into 4002-cmk-support
yuvalyaron Nov 19, 2024
8ef0231
update changelog + core version
yuvalyaron Nov 19, 2024
70ddb6b
remove unused var
yuvalyaron Nov 19, 2024
ce953ea
remove redundant variable
yuvalyaron Nov 19, 2024
8a48a95
remove redundant variables
yuvalyaron Nov 19, 2024
b07871e
add check for enable_cmk_encryption for the key_store_id variable in tf
yuvalyaron Nov 19, 2024
0106748
bugfix: remove redundant data keyword
yuvalyaron Nov 19, 2024
18ce3fd
add enable_cmk_encryption check in module variables
yuvalyaron Nov 20, 2024
c05f752
remove redundant key_vault_id from ignore_changes for cmk
yuvalyaron Nov 21, 2024
c7f1413
remove redundant sign/verify
yuvalyaron Nov 24, 2024
26c3f79
add cmk support for cosmos db
yuvalyaron Nov 24, 2024
1666b30
update changelog + add comments
yuvalyaron Nov 24, 2024
42886ff
update core version
yuvalyaron Nov 24, 2024
dea119b
fix linting issue
yuvalyaron Nov 24, 2024
d771f6c
add null provider to providers block
yuvalyaron Nov 24, 2024
c661fdb
Merge branch 'main' of https://github.com/microsoft/AzureTRE into 414…
yuvalyaron Nov 26, 2024
e8617e4
remove duplicates that were created by merge
yuvalyaron Nov 26, 2024
56d59f5
update core version
yuvalyaron Nov 26, 2024
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ COPY ["airlock_processor/requirements.txt", "/tmp/pip-tmp/airlock_processor/"]
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt

# Install azure-cli
ARG AZURE_CLI_VERSION=2.57.0-1~bullseye
ARG AZURE_CLI_VERSION=2.67.0-1~bullseye
COPY .devcontainer/scripts/azure-cli.sh /tmp/
RUN export AZURE_CLI_VERSION=${AZURE_CLI_VERSION} \
&& /tmp/azure-cli.sh
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENHANCEMENTS:
* Update Terraform to use Azure AD authentication rather than storage account keys ([#4103](https://github.com/microsoft/AzureTRE/issues/4103))
* Update obsolete Terraform properties ([#4136](https://github.com/microsoft/AzureTRE/issues/4136))
* Update Guacamole version and dependencies ([#4140](https://github.com/microsoft/AzureTRE/issues/4140))
* Add partial (core resources only) support for customer managed keys ([#4141](https://github.com/microsoft/AzureTRE/issues/4142))
* Add partial (core resources only) support for customer managed keys ([#4141](https://github.com/microsoft/AzureTRE/issues/4142), [#4144](https://github.com/microsoft/AzureTRE/issues/4144))

BUG FIXES:
- Update KeyVault references in API to use the version so Terraform cascades the update ([#4112](https://github.com/microsoft/AzureTRE/pull/4112))
Expand Down
19 changes: 19 additions & 0 deletions core/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion core/terraform/cosmos_mongo.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,38 @@ resource "azurerm_cosmosdb_account" "mongo" {
failover_priority = 0
}

dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.encryption[0].id]
}
}

default_identity_type = var.enable_cmk_encryption ? "UserAssignedIdentity=${azurerm_user_assigned_identity.encryption[0].id}" : null

tags = local.tre_core_tags

lifecycle { ignore_changes = [tags] }
# since key_vault_key_id is created by the 'mongo_enable_cmk' null_resource, terraform forces re-creation of the resource
lifecycle { ignore_changes = [tags, key_vault_key_id] }
}

# Using the az CLI command since terraform forces a re-creation of the resource
# https://github.com/hashicorp/terraform-provider-azurerm/issues/24781
resource "null_resource" "mongo_enable_cmk" {
count = var.enable_cmk_encryption ? 1 : 0

provisioner "local-exec" {
command = "az cosmosdb update --name ${azurerm_cosmosdb_account.mongo.name} --resource-group ${azurerm_cosmosdb_account.mongo.resource_group_name} --key-uri ${data.azurerm_key_vault_key.encryption_key[0].versionless_id}"
}

depends_on = [
azurerm_cosmosdb_account.mongo,
azurerm_role_assignment.kv_encryption_key_user[0]
]
}


resource "azurerm_cosmosdb_mongo_database" "mongo" {
name = "porter"
resource_group_name = azurerm_resource_group.core.name
Expand Down
6 changes: 6 additions & 0 deletions core/terraform/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ data "azurerm_key_vault" "encryption_kv" {
resource_group_name = var.mgmt_resource_group_name
}

data "azurerm_key_vault_key" "encryption_key" {
count = var.enable_cmk_encryption ? 1 : 0
name = var.kv_encryption_key_name
key_vault_id = local.key_store_id
}

data "http" "myip" {
count = var.public_deployment_ip_address == "" ? 1 : 0
url = "https://ipecho.net/plain"
Expand Down
4 changes: 4 additions & 0 deletions core/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ terraform {
source = "Azure/azapi"
version = "~> 1.15.0"
}
null = {
source = "hashicorp/null"
version = "~> 3.2"
}
}

backend "azurerm" {}
Expand Down
28 changes: 27 additions & 1 deletion core/terraform/statestore.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ resource "azurerm_cosmosdb_account" "tre_db_account" {
}
}

dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.encryption[0].id]
}
}

default_identity_type = var.enable_cmk_encryption ? "UserAssignedIdentity=${azurerm_user_assigned_identity.encryption[0].id}" : null

consistency_policy {
consistency_level = "BoundedStaleness"
max_interval_in_seconds = 10
Expand All @@ -27,7 +37,8 @@ resource "azurerm_cosmosdb_account" "tre_db_account" {
failover_priority = 0
}

lifecycle { ignore_changes = [tags] }
# since key_vault_key_id is created by the 'tre_db_account_enable_cmk' null_resource, terraform forces re-creation of the resource
lifecycle { ignore_changes = [tags, key_vault_key_id] }
}

moved {
Expand Down Expand Up @@ -95,3 +106,18 @@ resource "azurerm_private_endpoint" "sspe" {
subresource_names = ["Sql"]
}
}

# Using the az CLI command since terraform forces a re-creation of the resource
# https://github.com/hashicorp/terraform-provider-azurerm/issues/24781
resource "null_resource" "tre_db_account_enable_cmk" {
count = var.enable_cmk_encryption ? 1 : 0

provisioner "local-exec" {
command = "az cosmosdb update --name ${azurerm_cosmosdb_account.tre_db_account.name} --resource-group ${azurerm_cosmosdb_account.tre_db_account.resource_group_name} --key-uri ${data.azurerm_key_vault_key.encryption_key[0].versionless_id}"
}

depends_on = [
azurerm_cosmosdb_account.tre_db_account,
azurerm_role_assignment.kv_encryption_key_user[0]
]
}
1 change: 0 additions & 1 deletion core/terraform/storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ resource "azurerm_storage_account" "stg" {
allow_nested_items_to_be_public = false
cross_tenant_replication_enabled = false


dynamic "identity" {
for_each = var.enable_cmk_encryption ? [1] : []
content {
Expand Down
2 changes: 1 addition & 1 deletion core/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.3"
__version__ = "0.11.4"
Loading