@@ -8562,6 +8562,162 @@ def test_update_kms_pmk_cmk(self):
85628562 )
85638563 self .assertEqual (dec_mc_5 , ground_truth_mc_5 )
85648564
8565+ # test enable Azure Key Vault KMS with key ID
8566+ dec_6 = AKSPreviewManagedClusterUpdateDecorator (
8567+ self .cmd ,
8568+ self .client ,
8569+ {
8570+ "enable_azure_keyvault_kms" : True ,
8571+ "azure_keyvault_kms_key_id" : "https://test-keyvault.vault.azure.net/keys/test-key" ,
8572+ "azure_keyvault_kms_key_vault_resource_id" : "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.KeyVault/vaults/test-keyvault" ,
8573+ },
8574+ CUSTOM_MGMT_AKS_PREVIEW ,
8575+ )
8576+ mc_6 = self .models .ManagedCluster (location = "test_location" )
8577+ dec_6 .context .attach_mc (mc_6 )
8578+ dec_mc_6 = dec_6 .update_kms_pmk_cmk (mc_6 )
8579+
8580+ # expected security profile with Azure Key Vault KMS
8581+ ground_truth_azure_key_vault_kms_6 = self .models .AzureKeyVaultKms (
8582+ enabled = True ,
8583+ key_id = "https://test-keyvault.vault.azure.net/keys/test-key" ,
8584+ key_vault_resource_id = "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.KeyVault/vaults/test-keyvault" ,
8585+ )
8586+ ground_truth_security_profile_6 = self .models .ManagedClusterSecurityProfile (
8587+ azure_key_vault_kms = ground_truth_azure_key_vault_kms_6 ,
8588+ )
8589+ ground_truth_mc_6 = self .models .ManagedCluster (
8590+ location = "test_location" ,
8591+ security_profile = ground_truth_security_profile_6 ,
8592+ )
8593+ self .assertEqual (dec_mc_6 , ground_truth_mc_6 )
8594+
8595+ # test enable Azure Key Vault KMS on cluster with existing security profile
8596+ dec_7 = AKSPreviewManagedClusterUpdateDecorator (
8597+ self .cmd ,
8598+ self .client ,
8599+ {
8600+ "enable_azure_keyvault_kms" : True ,
8601+ "azure_keyvault_kms_key_id" : "https://test-keyvault.vault.azure.net/keys/test-key" ,
8602+ },
8603+ CUSTOM_MGMT_AKS_PREVIEW ,
8604+ )
8605+ existing_security_profile = self .models .ManagedClusterSecurityProfile ()
8606+ mc_7 = self .models .ManagedCluster (
8607+ location = "test_location" ,
8608+ security_profile = existing_security_profile ,
8609+ )
8610+ dec_7 .context .attach_mc (mc_7 )
8611+ dec_mc_7 = dec_7 .update_kms_pmk_cmk (mc_7 )
8612+
8613+ # should add to existing security profile
8614+ ground_truth_azure_key_vault_kms_7 = self .models .AzureKeyVaultKms (
8615+ enabled = True ,
8616+ key_id = "https://test-keyvault.vault.azure.net/keys/test-key" ,
8617+ key_vault_resource_id = None ,
8618+ )
8619+ ground_truth_security_profile_7 = self .models .ManagedClusterSecurityProfile (
8620+ azure_key_vault_kms = ground_truth_azure_key_vault_kms_7 ,
8621+ )
8622+ ground_truth_mc_7 = self .models .ManagedCluster (
8623+ location = "test_location" ,
8624+ security_profile = ground_truth_security_profile_7 ,
8625+ )
8626+ self .assertEqual (dec_mc_7 , ground_truth_mc_7 )
8627+
8628+ # test disable Azure Key Vault KMS
8629+ dec_8 = AKSPreviewManagedClusterUpdateDecorator (
8630+ self .cmd ,
8631+ self .client ,
8632+ {
8633+ "disable_azure_keyvault_kms" : True ,
8634+ },
8635+ CUSTOM_MGMT_AKS_PREVIEW ,
8636+ )
8637+ mc_8 = self .models .ManagedCluster (location = "test_location" )
8638+ dec_8 .context .attach_mc (mc_8 )
8639+ dec_mc_8 = dec_8 .update_kms_pmk_cmk (mc_8 )
8640+
8641+ # expected security profile with disabled Azure Key Vault KMS
8642+ ground_truth_azure_key_vault_kms_8 = self .models .AzureKeyVaultKms (enabled = False )
8643+ ground_truth_security_profile_8 = self .models .ManagedClusterSecurityProfile (
8644+ azure_key_vault_kms = ground_truth_azure_key_vault_kms_8 ,
8645+ )
8646+ ground_truth_mc_8 = self .models .ManagedCluster (
8647+ location = "test_location" ,
8648+ security_profile = ground_truth_security_profile_8 ,
8649+ )
8650+ self .assertEqual (dec_mc_8 , ground_truth_mc_8 )
8651+
8652+ # test disable Azure Key Vault KMS on cluster with existing security profile
8653+ dec_9 = AKSPreviewManagedClusterUpdateDecorator (
8654+ self .cmd ,
8655+ self .client ,
8656+ {
8657+ "disable_azure_keyvault_kms" : True ,
8658+ },
8659+ CUSTOM_MGMT_AKS_PREVIEW ,
8660+ )
8661+ existing_azure_key_vault_kms = self .models .AzureKeyVaultKms (
8662+ enabled = True ,
8663+ key_id = "https://test-keyvault.vault.azure.net/keys/test-key" ,
8664+ )
8665+ existing_security_profile = self .models .ManagedClusterSecurityProfile (
8666+ azure_key_vault_kms = existing_azure_key_vault_kms ,
8667+ )
8668+ mc_9 = self .models .ManagedCluster (
8669+ location = "test_location" ,
8670+ security_profile = existing_security_profile ,
8671+ )
8672+ dec_9 .context .attach_mc (mc_9 )
8673+ dec_mc_9 = dec_9 .update_kms_pmk_cmk (mc_9 )
8674+
8675+ # should disable existing Azure Key Vault KMS
8676+ ground_truth_azure_key_vault_kms_9 = self .models .AzureKeyVaultKms (enabled = False )
8677+ ground_truth_security_profile_9 = self .models .ManagedClusterSecurityProfile (
8678+ azure_key_vault_kms = ground_truth_azure_key_vault_kms_9 ,
8679+ )
8680+ ground_truth_mc_9 = self .models .ManagedCluster (
8681+ location = "test_location" ,
8682+ security_profile = ground_truth_security_profile_9 ,
8683+ )
8684+ self .assertEqual (dec_mc_9 , ground_truth_mc_9 )
8685+
8686+ # test combined infrastructure encryption and Azure Key Vault KMS enable
8687+ dec_10 = AKSPreviewManagedClusterUpdateDecorator (
8688+ self .cmd ,
8689+ self .client ,
8690+ {
8691+ "kms_infrastructure_encryption" : "Enabled" ,
8692+ "enable_azure_keyvault_kms" : True ,
8693+ "azure_keyvault_kms_key_id" : "https://test-keyvault.vault.azure.net/keys/test-key" ,
8694+ "azure_keyvault_kms_key_vault_resource_id" : "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.KeyVault/vaults/test-keyvault" ,
8695+ },
8696+ CUSTOM_MGMT_AKS_PREVIEW ,
8697+ )
8698+ mc_10 = self .models .ManagedCluster (location = "test_location" )
8699+ dec_10 .context .attach_mc (mc_10 )
8700+ dec_mc_10 = dec_10 .update_kms_pmk_cmk (mc_10 )
8701+
8702+ # expected security profile with both infrastructure encryption and Azure Key Vault KMS
8703+ ground_truth_kube_resource_encryption_profile_10 = self .models .KubernetesResourceObjectEncryptionProfile (
8704+ infrastructure_encryption = "Enabled"
8705+ )
8706+ ground_truth_azure_key_vault_kms_10 = self .models .AzureKeyVaultKms (
8707+ enabled = True ,
8708+ key_id = "https://test-keyvault.vault.azure.net/keys/test-key" ,
8709+ key_vault_resource_id = "/subscriptions/test-sub/resourceGroups/test-rg/providers/Microsoft.KeyVault/vaults/test-keyvault" ,
8710+ )
8711+ ground_truth_security_profile_10 = self .models .ManagedClusterSecurityProfile (
8712+ kubernetes_resource_object_encryption_profile = ground_truth_kube_resource_encryption_profile_10 ,
8713+ azure_key_vault_kms = ground_truth_azure_key_vault_kms_10 ,
8714+ )
8715+ ground_truth_mc_10 = self .models .ManagedCluster (
8716+ location = "test_location" ,
8717+ security_profile = ground_truth_security_profile_10 ,
8718+ )
8719+ self .assertEqual (dec_mc_10 , ground_truth_mc_10 )
8720+
85658721 def test_update_workload_auto_scaler_profile (self ):
85668722 # Throws exception when incorrect mc object is passed.
85678723 dec_1 = AKSPreviewManagedClusterUpdateDecorator (
0 commit comments