Add-AzVmssSecret doesnt correctly update cert list for exsisting keyvault
We have several certs added to a VMSS from keyvaultX and i want to add another cert. when i run these cmdlets $certConfig = New-AzVmssVaultCertificateConfig -CertificateUrl $certSecretID -CertificateStore "My" $vmssobj = Get-AzVmss -ResourceGroupName $resourcegroup -VMScaleSetName $VMSSName $vmssobj = Add-AzVmssSecret -VirtualMachineScaleSet $vmssobj -SourceVaultId $KeyVaultResourceID -VaultCertificate $certConfig
and look at the json there is a secrets[1] added that has my new cert, it was not added to secrets[0]. By adding the [1] i now get an error when i try to push the config back to azure
Update-AzVmss -ResourceGroupName $resourcegroup -Name $VMSSName -VirtualMachineScaleSet $vmssobj -Verbose
Update-AzVmss : List secrets contains repeated instances of /subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/dev-Operations-eus-rg/providers/Microsoft.KeyVault/vaults/KeyvaultX, which is disallowed. ErrorCode: InvalidParameter ErrorMessage: List secrets contains repeated instances of /subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/dev-Operations-eus-rg/providers/Microsoft.KeyVault/vaults/KeyVaultX, which is disallowed. ErrorTarget: sourceVault.id StatusCode: 400 ReasonPhrase: Bad Request
cmdlet should update current secrets list rather than adding a new section
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @mjconnection, @Drewm3
Hi @timpoth, this is expected behavior currently. Please see this section of the VMSS FAQ for additional information: https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-faq#when-i-run-update-azvmss-after-adding-more-than-one-certificate-from-the-same-key-vault-i-see-the-following-message
I will also check with the development team to see if they can take on a new feature for Add-AzVmssSecret to just add a new VaultCertificate to an existing Secret when an existing SourceVault is used.
Looking at the docs for the cmdlet https://docs.microsoft.com/en-us/powershell/module/az.compute/add-azvmsssecret?view=azps-2.6.0
-SourceVaultId Specifies the resource ID of the Key Vault that contains the certificates that you can add to the virtual machine. This value also acts as the key for adding multiple certificates. This means that you can use the same value for the SourceVaultId parameter when you add multiple certificates from the same Key Vault.
It reads to me like the cmdlet should be able to ‘append’ a cert to the current listing.
Further to the link you sent, it suggests the that the cert list can be up updated by updating the VMSS object $vmss.properties.osProfile.secrets[0].vaultCertificates
However I don't see 'properties' under the object, I think they want this $vmss.VirtualMachineProfile.OsProfile.Secrets[0].VaultCertificates
however that doesn't work, and you get the following error if you try to update the object that way
The property 'VaultCertificates' cannot be found on this object. Verify that the property exists and can be set.
thanks tim
Here is the example on how to add a second certificate from the same vault to the Scale Set: `$newVaultCertificate = New-AzVmssVaultCertificateConfig -CertificateUrl $secondSecretID -CertificateStore "My"
$vmssobj = Get-AzVmss -ResourceGroupName $resourcegroup -VMScaleSetName $VMSSName
$vmssobj.VirtualMachineProfile.OsProfile.Secrets[0].VaultCertificates.Add($newVaultCertificate)
Update-AzVmss -ResourceGroupName $resourcegroup -Name $VMSSName -VirtualMachineScaleSet $vmssobj`
More details here: https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-faq#how-do-i-add-a-new-vault-certificate-to-a-new-certificate-object
I was able to get that to work, thank you
@timpoth, it is great to hear that you were able to get this to work. I am going to close this issue, but I will keep working with the dev team with the suggestion update Add-AzVmssSecret to automatically do the right thing when adding a secret from a vault that is already referenced in the VMSS configuration.