azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

`az vm format-secret` does not work

Open sptramer opened this issue 9 years ago • 11 comments

Description

The az vm format-secret command does not work. This can be seen by trying to run one of the examples under az vm create. The command[s] run, and the error, are:

        az keyvault certificate create --vault-name vaultname -n cert1 \
          -p "$(az keyvault certificate get-default-policy)"

        secrets=$(az keyvault secret list-versions --vault-name vaultname \
          -n cert1 --query "[?attributes.enabled].id" -o tsv)

        vm_secrets=$(az vm format-secret -s "$secrets")

format-secret returns indicating that a resource group parameter is missing, although the command does not take one:

stramer@churchy [10:10] in [/mnt/c/Users/sttramer.REDMOND]
∅ ⤅  % az vm format-secret -s "$secrets"
Parameter 'resource_group_name' can not be None.
stramer@churchy [10:11] in [/mnt/c/Users/sttramer.REDMOND]
∅ ⤅ ∃ % az vm format-secret -s "$secrets" -g ResourceGroup
az: error: unrecognized arguments: -g ResourceGroup

This either indicates the example is incorrect, or the format-secret command does not work as expected.


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: apt-get

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here:

azure-cli (2.0.16)

keyvault (2.0.9)
vm (2.0.13)

OS Version: What OS and version are you using?
Answer here: WSL Linux churchy 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux Ubuntu 16.04LTS

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: zsh on WSL

sptramer avatar Sep 05 '17 17:09 sptramer

If you echo $secrets do you see valid secret URIs?

Otherwise, it sounds like the mechanism to sniff the KeyVault ID is failing. If you list the vaults in your active subscription, does the KeyVault you are trying to use appear?

tjprescott avatar Sep 05 '17 19:09 tjprescott

Yes, as far as I can tell, the URI is valid. The vault is listed in the results of az keyvault list and the requested cert is in the output of az keyvault certificate list --vault-name NAME.

sptramer avatar Sep 05 '17 23:09 sptramer

Are you using some kind of custom domain prefix that does not start with the vault name? I'm not able to repro locally yet, but I can definitely see where the sniffing logic might break down.

tjprescott avatar Sep 05 '17 23:09 tjprescott

Nope - no custom domain prefix. The key vault was created by running a garden-variety az keyvault create -n NAME -g ResourceGroup command. No external FQDN is mapped in. The URL provided to az vm format-secret was in the form https://VAULTNAME.vault.azure.net/secrets/cert1/ID_HASH

sptramer avatar Sep 05 '17 23:09 sptramer

I've gotten a partial repro. If I list the secret versions with TSV and try to use that as input I get an error on the number of segments. I'll create a PR that fixes that issue, and will hopefully fix yours (with any luck it's the same problem with a different symptom on ZSH).

tjprescott avatar Sep 07 '17 21:09 tjprescott

Hello, I am still having this issue. Is this issue fixed?

$ secret=$(az keyvault secret list-versions --vault-name WebSvrCert --name WebCert --query "[?attributes.enabled].id" --output tsv)

$ echo $secret https://websvrcert.vault.azure.net/secrets/WebCert/d79e98486c5f42a6a12c863608b3a6e8

$ vm_secret=$(az vm secret format --secret "$secret") Parameter 'resource_group_name' can not be None. Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 194, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 331, in execute six.reraise(*sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 304, in execute result = cmd(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 168, in call return super(AzCliCommand, self).call(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/knack/commands.py", line 109, in call return self.handler(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 348, in default_command_handler result = op(**command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 1429, in get_vm_format_secret 'id': _get_vault_id_from_name(cmd.cli_ctx, client, vault_name) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 1406, in _get_vault_id_from_name vault = client.get(group_name, vault_name) File "/opt/az/lib/python3.6/site-packages/azure/mgmt/keyvault/operations/vaults_operations.py", line 193, in get 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 488, in url data = self.validate(data, name, required=True, **kwargs) File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 558, in validate raise ValidationError("required", name, True) msrest.exceptions.ValidationError: Parameter 'resource_group_name' can not be None. chi@Azure:~/clouddrive$

chiyao-ms avatar Feb 18 '18 07:02 chiyao-ms

@Castermeek what version of the CLI are you running? az --version

tjprescott avatar Feb 20 '18 17:02 tjprescott

I am using 2.0.27

chi@Azure:~$ az --version azure-cli (2.0.27)

From: Travis Prescott [mailto:[email protected]] Sent: Wednesday, February 21, 2018 2:56 AM To: Azure/azure-cli [email protected] Cc: Chi Yao [email protected]; Mention [email protected] Subject: Re: [Azure/azure-cli] az vm format-secret does not work (#4379)

@Castermeekhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcastermeek&data=04%7C01%7Cchiyao%40microsoft.com%7Cc9c5dec412504daba07708d5788b2e8f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547461535470694%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=S6CdvMfn4uLYCoHl%2Fn7nR4LodJgKVBzIUsl40SMC%2BQI%3D&reserved=0 what version of the CLI are you running? az --version

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-cli%2Fissues%2F4379%23issuecomment-367062363&data=04%7C01%7Cchiyao%40microsoft.com%7Cc9c5dec412504daba07708d5788b2e8f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547461535470694%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=PdsbqqogSBb4UngE57WU5AcWJRtM8OlL5q%2BFccQ878U%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAa5ywSlTlgov0w3JqHutbO6VOByIxzVUks5tWwcngaJpZM4PNQxM&data=04%7C01%7Cchiyao%40microsoft.com%7Cc9c5dec412504daba07708d5788b2e8f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547461535470694%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=O92Nmn7TgfVLfnP4dMP%2FukfFRmcGAbPGIf9q97Qnv4o%3D&reserved=0.

chiyao-ms avatar Feb 20 '18 22:02 chiyao-ms

@Castermeek since you are experiencing this on the latest build, please open a new issue and provide the requested details so we can investigate.

tjprescott avatar Feb 20 '18 23:02 tjprescott

Hello,

Can you tell how I can rise a ticket? Thank you. -chiyao-

From: Travis Prescott [mailto:[email protected]] Sent: Wednesday, February 21, 2018 8:59 AM To: Azure/azure-cli [email protected] Cc: Chi Yao [email protected]; Mention [email protected] Subject: Re: [Azure/azure-cli] az vm format-secret does not work (#4379)

@Castermeekhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcastermeek&data=04%7C01%7Cchiyao%40microsoft.com%7C6ff27c469f244f21f94108d578bdd8e6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547679242243992%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=%2FceKmyk%2FddrrGCa6wTvYRUDobLqQQofyC2BCA%2F2vlp8%3D&reserved=0 since you are experiencing this on the latest build, please open a new issue and provide the requested details so we can investigate.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-cli%2Fissues%2F4379%23issuecomment-367164180&data=04%7C01%7Cchiyao%40microsoft.com%7C6ff27c469f244f21f94108d578bdd8e6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547679242243992%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=C%2Bvq49XrB5kEJTvVsWDmSzfMP9SUVfuR1S3unvM9wCk%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAa5ywW74jETeUerVIGDwUSt9E3Hg3je2ks5tW1wngaJpZM4PNQxM&data=04%7C01%7Cchiyao%40microsoft.com%7C6ff27c469f244f21f94108d578bdd8e6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636547679242243992%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=g5tVHCVMatcx6uvMpKXDYLHPL%2F06gnYyS7VRTAtru5w%3D&reserved=0.

chiyao-ms avatar Feb 21 '18 11:02 chiyao-ms

Submitted a new issue.

https://github.com/Azure/azure-cli/issues/5718

chiyao-ms avatar Mar 02 '18 04:03 chiyao-ms