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