Closed RIKIKU closed 3 years ago
Thanks for reporting. We will evaluate the behavior and back to you soon.
It seems the logic flaw in Get-AzKeyvaultSecret.
Current Get-AzKeyvaultSecret sends 2 requests to service.
So, Get-AzKeyVaultSecret is failed because the first call is failed when current secret is disabled.
We will look into it. it seems the first call is not necessary in this case.
Description
If you have a Key Vault secret with multiple versions and the "Current" version is disabled, the cmdlet Get-AzKeyVaultSecret is unable to list the versions of the secret. It throws an error message
Get-AzKeyVaultSecret: Operation returned an invalid status code 'Forbidden'
I assume this is because the cmdlet is trying to "Get" the value of the current version and is unable to and stops running in stead of carrying on to list the versions when the -IncludeVersions parameter is set. I think this is a bug because I should still be able to list the versions of the secret regardless of weather or not I can get the value of the current version.I propose that if the -IncludeVersions parameter is set, the cmdlet should ignore the "Forbidden" error on the "Get Secret" request, and only throw an error if there is an issue running the second request. Either that, or we just don't "Get Secret" in the first place and only list the versions.
If none of those options are available due to backwards compatibility, perhaps the "-Force" parameter could be used to ignore the forbidden error on the Get Secret request.
Steps to reproduce
The following script will reproduce the error 'Operation returned an invalid status code 'Forbidden''
Environment data
Module versions
Debug output
Error output