-
Notifications
You must be signed in to change notification settings - Fork 18
feat(kms): add Key Vault KMS encryption support for AKS clusters #945
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
Merged
Merged
Changes from 47 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
24415b9
feat(kms): add Key Vault KMS encryption support for AKS clusters
xinWeiWei24 8a0655a
Remove dynamic variable in plan phase
xinWeiWei24 9e88fcf
Change the default value of key_vault_network_access to Public
xinWeiWei24 516f2c2
Use UserAssigned identity type when enable KMS
xinWeiWei24 ef02196
Add Key Vault Crypto Service Encryption User role to key and key vault
xinWeiWei24 6b352f1
Remove dynamic variable in plan stage
xinWeiWei24 579a4a3
Add wrapKey and unwrapKey
xinWeiWei24 602d782
Only add role to key vault
xinWeiWei24 7d029de
Delete key role dependancy
xinWeiWei24 c6e7275
Only wrap and unwrap
xinWeiWei24 13124a0
Add Key Vault Crypto User role to key and key vault
xinWeiWei24 a7608be
fix bugs
xinWeiWei24 fdf8720
Use resource_id and add purge_soft_delete_on_destroy feature
xinWeiWei24 546b335
Export key resource_id
xinWeiWei24 d6cbc8e
Disable recover_soft_deleted_key_vaults
xinWeiWei24 180c6ab
Generate key vault name randomly
xinWeiWei24 b0c57c8
Only generate lower characters
xinWeiWei24 8833d29
Add Key Vault Crypto Service Encryption User role to key vault key
xinWeiWei24 008eedf
fix bugs
xinWeiWei24 8f8ef17
Delete Key Vault Crypto User role to key in aks
xinWeiWei24 6b01a2d
Delete Key Vault Crypto User role for key
xinWeiWei24 dc6e192
Use new-pipeline-test.yml to test
xinWeiWei24 c4f3c2e
Use new-pipeline-test.yml to test aks-cli
xinWeiWei24 cad0e79
Use nap azure-complex to test
xinWeiWei24 7ac9eac
Revert "Use nap azure-complex to test"
xinWeiWei24 83f28c3
Revert "Use new-pipeline-test.yml to test aks-cli"
xinWeiWei24 586fa12
Revert "Use new-pipeline-test.yml to test"
xinWeiWei24 ef9e546
Update the comments
xinWeiWei24 006a034
Update the comments
xinWeiWei24 fc46ff6
Update command to apply in test_aks_aad
xinWeiWei24 1a8c1ca
Update modules/terraform/azure/main.tf
xinWeiWei24 d113022
Update modules/terraform/azure/main.tf
xinWeiWei24 eb0ac1b
Update modules/terraform/azure/main.tf
xinWeiWei24 698537c
Update modules/terraform/azure/aks-cli/main.tf
xinWeiWei24 199c1fb
Delete explicit depends_on
xinWeiWei24 641beec
Update key vault random string
xinWeiWei24 30b5bb3
Require managed_identity_name to be set when KMS is enabled
xinWeiWei24 67a5ecf
Use nap azure-complex to test
xinWeiWei24 3915675
Revert "Use nap azure-complex to test"
xinWeiWei24 e2d1484
Delete version from key-vault module
xinWeiWei24 0c1291e
Make key vaults config as a list
xinWeiWei24 12445bb
Use nap azure-complex to test
xinWeiWei24 2fc1655
Fix output bug
xinWeiWei24 082d7b0
Revert "Use nap azure-complex to test"
xinWeiWei24 3f702d5
Validate kms module ouput in aks/aks-cli module instread of on the main
xinWeiWei24 7766b51
Use nap complex to test
xinWeiWei24 68a12c8
Revert "Use nap complex to test"
xinWeiWei24 de82758
Move kms configs to an object
xinWeiWei24 e1fdc8c
Add README.md in key-vault module and update azure.tfvars template to…
xinWeiWei24 db77007
Use nap complex to test
xinWeiWei24 7ecc85b
Revert "Use nap complex to test"
xinWeiWei24 d2cc732
Reduce duplicate code
xinWeiWei24 c12f197
Merge branch 'main' into xinwei/support_kms
xinWeiWei24 3022e80
Change condition
xinWeiWei24 7bd00c0
Use nap complex to test
xinWeiWei24 5c7195f
Revert "Use nap complex to test"
xinWeiWei24 6622080
key-vault: update README.md
xinWeiWei24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| data "azurerm_client_config" "current" {} | ||
|
|
||
xinWeiWei24 marked this conversation as resolved.
Show resolved
Hide resolved
xinWeiWei24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resource "random_string" "kv_suffix" { | ||
| count = var.key_vault_config != null ? 1 : 0 | ||
| length = 4 | ||
| special = false | ||
| upper = false | ||
| numeric = true | ||
| } | ||
| resource "azurerm_key_vault" "kv" { | ||
| count = var.key_vault_config != null ? 1 : 0 | ||
| name = "${lower(var.key_vault_config.name)}-${random_string.kv_suffix[0].result}" | ||
| location = var.location | ||
| resource_group_name = var.resource_group_name | ||
| tenant_id = data.azurerm_client_config.current.tenant_id | ||
| sku_name = "standard" | ||
| rbac_authorization_enabled = true | ||
|
|
||
| tags = var.tags | ||
| } | ||
|
|
||
| resource "azurerm_key_vault_key" "kms_key" { | ||
| for_each = var.key_vault_config != null ? { | ||
| for key in var.key_vault_config.keys : key.key_name => key | ||
| } : {} | ||
|
|
||
| name = each.value.key_name | ||
| key_vault_id = azurerm_key_vault.kv[0].id | ||
| key_type = "RSA" | ||
| key_size = 2048 | ||
| key_opts = ["encrypt", "decrypt", "wrapKey", "unwrapKey"] | ||
|
|
||
| depends_on = [ | ||
| azurerm_role_assignment.current_user_crypto_officer | ||
xinWeiWei24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
| } | ||
|
|
||
| # Grant current user/service principal Key Vault Crypto Officer role to create keys | ||
| resource "azurerm_role_assignment" "current_user_crypto_officer" { | ||
| count = var.key_vault_config != null ? 1 : 0 | ||
| scope = azurerm_key_vault.kv[0].id | ||
| role_definition_name = "Key Vault Crypto Officer" | ||
| principal_id = data.azurerm_client_config.current.object_id | ||
| } | ||
|
|
||
| # Grant Key Vault Contributor role for purge operations | ||
| resource "azurerm_role_assignment" "kv_contributor" { | ||
| count = var.key_vault_config != null ? 1 : 0 | ||
| scope = azurerm_key_vault.kv[0].id | ||
| role_definition_name = "Key Vault Contributor" | ||
| principal_id = data.azurerm_client_config.current.object_id | ||
| } | ||
xinWeiWei24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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 @@ | ||
| output "key_vaults" { | ||
| description = "Key Vault with all its keys and their IDs" | ||
| value = { | ||
| id = try(azurerm_key_vault.kv[0].id, null) | ||
| keys = { | ||
| for key_path, key in azurerm_key_vault_key.kms_key : | ||
| key.name => { | ||
| id = key.id | ||
| resource_id = key.resource_id | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,37 @@ | ||
| variable "resource_group_name" { | ||
| description = "Name of the resource group" | ||
| type = string | ||
| } | ||
|
|
||
| variable "location" { | ||
| description = "Azure region location" | ||
| type = string | ||
| } | ||
|
|
||
| variable "tags" { | ||
| description = "Tags to apply to resources" | ||
| type = map(string) | ||
| default = {} | ||
| } | ||
|
|
||
| variable "key_vault_config" { | ||
| description = "Key Vault configuration for AKS KMS encryption" | ||
| type = object({ | ||
| name = string # Key Vault name | ||
| keys = list(object({ | ||
| key_name = string # Encryption key name | ||
| })) | ||
| }) | ||
| default = null | ||
|
|
||
| validation { | ||
| condition = ( | ||
| var.key_vault_config == null ? true : ( | ||
| length(var.key_vault_config.name) >= 3 && | ||
| length(var.key_vault_config.name) <= 20 && | ||
| length(var.key_vault_config.keys) >= 1 | ||
| ) | ||
| ) | ||
| error_message = "Key Vault name must be 3-20 characters (total 24 after adding 4-char random suffix), and at least one key must be defined." | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.