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

Token created with "generate-sas" doesn't work in some vm extensions

Open jlarrow opened this issue 8 years ago • 10 comments

Describe the bug The SAS token returned by “az storage account generate-sas …” doesn’t work for “az vm extension set …” but it does work for “az storage table list …” — A SAS token generated by the portal works for both.

To Reproduce

# bash pseudo code ...
sas=$(az storage account generate-sas --account-name $storage_account --expiry 2030-12-31T23:59Z --permissions wlacu --resource-types co --services bt -o tsv)

# This works:
az storage table list --account-name $storage_account --sas-token $sas

# This doesn't work:
az vm extension set --publisher Microsoft.Azure.Diagnostics --name LinuxDiagnostic --version 3.0 --resource-group $resgrp --vm-name $vm --protected-settings ="{\"storageAccountName\": \"$storage_account\", \"storageAccountSasToken\" : \"$sas\"}" --settings $pub

Expected behavior To deploy the LinuxDiagnostic 3.0 extension using published examples.

Environment summary Using Bash script and azure-cli (2.0.45) on either SuSE SLES 12-SP3 or Ubuntu 16.04.5 LTS.

Additional context See also, PR https://github.com/Azure/azure-linux-extensions/pull/645

Possibilities: a version missmatch? (portal: sv=2017-11-09, az: sv=2018-03-28) an encoding problem? (portal: se=2031-01-01T04:59:59Z, az: se=2030-12-31T23%3A59Z) Improper handling of SAS token by Diagnostics extension?

jlarrow avatar Sep 19 '18 19:09 jlarrow

@yugangw-msft @williexu

troydai avatar Sep 20 '18 19:09 troydai

I am getting error:

Deployment failed. Correlation ID: <redacted>. VM has reported a failure when processing extension 'CustomScript'. Error message: "Enable failed: failed to get configuration: json validation error: invalid protected settings JSON: storageAccountSasToken: Additional property storageAccountSasToken is not allowed".

lukasmrtvy avatar Dec 12 '18 10:12 lukasmrtvy

@jlarrow, please can you clarify what the issue exactly is. Is the command failing or is the extension failing to properly store / send diagnostic data?

@lukasmrtvy, it seems like your issue might be slightly different, could you give some more detail. It seems you tried to set the CustomScript extension on the VM, but the command failed.

Debug output / more information would be helpful.

adewaleo avatar Dec 15 '18 00:12 adewaleo

@adewaleo I am running this:

sastoken=$(az storage account generate-sas \
  --permissions lr \
  --account-name <sa-account> \
  --services b \
  --resource-types o \
  --expiry `date -d "30 minutes" '+%Y-%m-%dT%H:%MZ'` \
  -o tsv)

az vm extension set \
  --resource-group <resource-group> \
  --vm-name <vm-name> \
  --name CustomScript \
  --publisher Microsoft.Azure.Extensions \
  --version 2.0 \
  --settings '{"fileUris": ["https://<sa-account>.blob.core.windows.net/scripts/ubuntu/install_azure_cli"], "commandToExecute": "./install_azure_cli" }' \
  --protected-settings '{"storageAccountName": "<sa-account>","storageAccountSasToken ": "${sastoken}"}'

az-cli version: 2.0.51 It works with storageAccountKey, so there is nothing wrong with script itself Thanks

lukasmrtvy avatar Dec 15 '18 08:12 lukasmrtvy

Sorry, it's been a few months and the VM I was working with has been destroyed. I did preserve the files though. I will try to re-create the issue this week (time permitting). I did preserve the files though.

I'm trying to deploy version 3.x of the Linux diagnostic extension. I've localized the problem down to the SAS token. The SAS token generated with the portal works. The SAS token generated with the az DOES NOT WORK. Here are the two keys for your reference:

badSAStoken

?se=2030-12-31T23%3A59Z&sp=wlacu&sv=2018-03-28&ss=bt&srt=co&sig=2gavsxb4n%2BsYxVM/1egmYCDxeq/iQ4rhpalCYi79S%2BQ%3D

goodSAStoken

?sv=2017-11-09&ss=bt&srt=co&sp=wlacu&se=2031-01-01T04:59:59Z&st=2018-09-18T11:28:14Z&spr=https&sig=hFqQgMEUuHnWc8ZZTjMgmAU6NIC1K5K1c6Fn%2Bp%2Bn4r8%3D

Here is my test script:

install_diag_v3

The updated quoting in the script below is in the referenced PR.

# Set your Azure VM diagnostic parameters correctly below
vm=myVM
rg=myRG
storage=mySTORAGE
pub_file=public_settings.json

# Get VM resource ID
vm_rid=$(az vm show -g $rg -n $vm --query "id" -o tsv)

# Download and edit storage account name and resource ID in public settings
wget https://raw.githubusercontent.com/Azure/azure-linux-extensions/master/Diagnostic/tests/lad_2_3_compatible_portal_pub_settings.json -O $pub_file
sed -i "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$storage#g" $pub_file
sed -i "s#__VM_RESOURCE_ID__#$vm_rid#g" $pub_file
sed -i "s#LOG_DEBUG#LOG_NOTICE#g" $pub_file

# Set protected settings (storage account SAS token)
sastoken=$(az storage account generate-sas --account-name $storage --expiry 2030-12-31T23:59Z --permissions wlacu --resource-types co --services bt -o tsv)
protected="{\"storageAccountName\": \"$storage\", \"storageAccountSasToken\": \"?$sastoken\"}"

# Finallly enable (set) the extension
az vm extension set \
        --force-update \
        --publisher Microsoft.Azure.Diagnostics \
        --name LinuxDiagnostic \
        --version '3.0' \
        --resource-group $rg \
        --vm-name $vm \
        --protected-settings "${protected}" \
        --settings $pub_file

jlarrow avatar Dec 17 '18 13:12 jlarrow

@adewaleo Tosin Adewale FTE I am running this:

sastoken=$(az storage account generate-sas \
  --permissions lr \
  --account-name <sa-account> \
  --services b \
  --resource-types o \
  --expiry `date -d "30 minutes" '+%Y-%m-%dT%H:%MZ'` \
  -o tsv)

az vm extension set \
  --resource-group <resource-group> \
  --vm-name <vm-name> \
  --name CustomScript \
  --publisher Microsoft.Azure.Extensions \
  --version 2.0 \
  --settings '{"fileUris": ["https://<sa-account>.blob.core.windows.net/scripts/ubuntu/install_azure_cli"], "commandToExecute": "./install_azure_cli" }' \
  --protected-settings '{"storageAccountName": "<sa-account>","storageAccountSasToken ": "${sastoken}"}'

az-cli version: 2.0.51 It works with storageAccountKey, so there is nothing wrong with script itself Thanks

Hello @lukasmrtvy. Thanks for following up. What error / failure do you receive when you run the command / set the extension with the storage account sas token instead of the storage account key?

adewaleo avatar Dec 17 '18 18:12 adewaleo

Thanks a lot for the information and detail, @jlarrow. Let me know if you can reproduce the issue and what error you get. I will also look into it myself.

adewaleo avatar Dec 17 '18 18:12 adewaleo

@adewaleo This is output: https://github.com/Azure/azure-cli/issues/7371#issuecomment-446530108

lukasmrtvy avatar Dec 18 '18 14:12 lukasmrtvy

@adewaleo OK, just completed a test and although the SAS tokens still look a bit different ... today either one worked as it should. So, I'm unable to duplicate the problem. The two tokens that both worked for me:

se=2030-12-31T23%3A59Z&sp=wlacu&sv=2018-03-28&ss=bt&srt=co&sig=bda6Ex%2BhM9ItYXM%2B/F4Q3piQa5OLsFoDsLW%2BOR/tWC4%3D
?sv=2018-03-28&ss=bt&srt=co&sp=wlacu&se=2030-12-31T23:59:59Z&st=2018-12-17T13:00:00Z&spr=https&sig=wjOPwWmbETTXs%2BDw%2BdNr6vUsyfHWY00QGGk%2BzzhlW18%3D

Edit: Oh, a few additional details ... Ubuntu 18.04.1 LTS azure-cli (2.0.52) operating on a VM w/same OS

jlarrow avatar Dec 18 '18 19:12 jlarrow

@jlarrow, I was also able to successfully set the linux diagnostic extension according to these instructions.

@lukasmrtvy, in this CustomScript Extension doc / article, storageAccountSasToken is not an exposed property in the config file.

I will be closing this issue.

adewaleo avatar Dec 18 '18 23:12 adewaleo