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

`az aks scale` gives "too many 500 error responses"

Open lprichar opened this issue 6 years ago • 9 comments

Describe the bug

Command Name az aks scale

Errors:

request failed: Error occurred in request., RetryError: HTTPSConnectionPool(host='management.azure.com', port=443): Max retries exceeded with url: /subscriptions/[subscriptionid]/resourceGroups/myresourcegroup-dev1-dynamic/providers/Microsoft.ContainerService/managedClusters/cluster-dev1?api-version=2020-03-01 (Caused by ResponseError('too many 500 error responses',))

To Reproduce:

I've tried logging on as a regular user, as a service principal, with version 2.3.1 of Azure CLI on Windows and with version 2.2 of Azure CLI in WSL. Autoscaling is false in my cluster. There is only one node pool (called default). This cluster was created through Terraform. Other az commands work fine. I have no proxy. If I add --debug nothing of immediate value pops up.

Expected Behavior

It should scale up or down just like how it works in the web UI.

Environment Summary

Windows-10-10.0.18362-SP0
Python 3.6.6
Installer: MSI

azure-cli 2.3.1

Additional Context

az aks show --resource-group my-resource-group --name my-cluster --query agentPoolProfiles

results in:

[
  {
    "availabilityZones": null,
    "count": 3,
    "enableAutoScaling": false,
    "enableNodePublicIp": null,
    "maxCount": null,
    "maxPods": 110,
    "minCount": null,
    "mode": "User",
    "name": "default",
    "nodeLabels": null,
    "nodeTaints": null,
    "orchestratorVersion": "1.15.7",
    "osDiskSizeGb": 30,
    "osType": "Linux",
    "provisioningState": "Succeeded",
    "scaleSetEvictionPolicy": null,
    "scaleSetPriority": null,
    "spotMaxPrice": null,
    "tags": null,
    "type": "AvailabilitySet",
    "vmSize": "Standard_D2_v3"
  }
]

Also, if I watch the traffic in fiddler the 500 errors look like this:

message=The credentials in ServicePrincipalProfile were invalid. Please see https://aka.ms/aks-sp-help for more details. (Details: adal: Refresh request failed. Status Code = '401'. Response body: {"error":"invalid_client","error_description":"AADSTS7000215: Invalid client secret is provided.\r\nTrace ID: 4d0fe224-1e60-4a91-91f1-399f697c0600\r\nCorrelation ID: 95b7e354-a63d-450e-8a7c-1851605a5b25\r\nTimestamp: 2020-04-07 13:51:07Z","error_codes":[7000215],"timestamp":"2020-04-07 13:51:07Z","trace_id":"4d0fe224-1e60-4a91-91f1-399f697c0600","correlation_id":"95b7e354-a63d-450e-8a7c-1851605a5b25","error_uri":"https://login.microsoftonline.com/error?code=7000215"})

The above leads me to suspect this is related to #9585, but it also sounds a bit like #12814.

lprichar avatar Apr 07 '20 18:04 lprichar

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/aks-pm.

ghost avatar Apr 07 '20 23:04 ghost

@lprichar thanks for the traces, the last fiddler error seems to point to the SP not having permission to complete the scale. could you double check the SP being used is valid, was it generated by the CLI or did you bring it yourself?

If you brought it yourself can you ensure it has all the proper access doc'd here? https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal#delegate-access-to-other-azure-resources

jluk avatar Apr 07 '20 23:04 jluk

Thanks for the super-fast response. We made the SP by hand, I believe, although that was before I joined the project. It's what Terraform runs as, and thus it created the cluster along with all our other Azure resources. I'll double check on those permissions in the morning and get back to you. But is the SP even required? That wasn't clear from the docs. I feel like it should work when I run it just with a regular az login as myself (i.e. not with --service-principal).

lprichar avatar Apr 08 '20 01:04 lprichar

The service principal being used is being given to the AKS service to create all the infra your cluster needs such as the compute/networking/storage. So, yes you will need to provide some form of auth to AKS to create a cluster for you as there is also ongoing management of those resources by AKS to keep your cluster healthy once running.

You can supply your own SP, have AKS generate an SP for you, or use the latest option which is for AKS to generate and manage a set of Managed Identities for you.

This doc explains SPs for AKS: https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal

I would suggest the last option with this MI doc for AKS: https://docs.microsoft.com/en-us/azure/aks/use-managed-identity

jluk avatar Apr 08 '20 15:04 jluk

Given that the cluster already exists I believe the MI option is out. Even if not I'd prefer not to add more credentials if possible. Ideally I'd prefer to add the requested permission to the SP if that's indeed the problem (although doesn't the 401 from fiddler indicate an authentication not authorization error?).

To address your questions and verify that I am using the correct SP (the one specified when the cluster was originally created) I did az aks list. I verified that servicePrincipalProfile.clientId in the json response (a guid starting with bae36...) matches the SP that I'm logging in with when I az login --service-principal prior to the az aks scale. I believe the fact that I can az aks list at all and see my cluster under the bae36 SP means I have a valid SP with valid credentials.

So as far as permissions, I read over the docs you provided, but none of them mentioned what specific permission is required for scaling, and none of them even sound close. I don't want to grant any more permissions to this role than is strictly necessary. Can you please provide additional guidance on what permission is required?

FYI if I az role assignment list --assignee bae36... I get:

[
  {
    "canDelegate": null,
    "id": "/subscriptions/[mysubscription]/providers/Microsoft.Authorization/roleAssignments/707...",
    "name": "707...",
    "principalId": "b91...",
    "principalName": "http://azure-cli-2019-02-14-15-13-17",
    "principalType": "ServicePrincipal",
    "roleDefinitionId": "/subscriptions/[mysubscriptionid]/providers/Microsoft.Authorization/roleDefinitions/b24...",
    "roleDefinitionName": "Contributor",
    "scope": "/subscriptions/[mysubscription]",
    "type": "Microsoft.Authorization/roleAssignments"
  }
]

Thank you so much @jluk for your guidance.

lprichar avatar Apr 08 '20 20:04 lprichar

Thanks for humoring me on all those shots in the dark from me, I think your SP is likely fine if you're able to make other az cmds successfully with the SP and audited for the access in the docs linked.

This seems to be an error returned from the service, would you mind opening a support request for someone to look at your cluster? I'm afraid I won't be able to help very much based on the error message.

jluk avatar Apr 08 '20 21:04 jluk

Done. Thanks for your help @jluk. You're welcome to close this issue now I guess, however, it might be worth considering this ticket to be an issue with how Azure CLI prints out error messages.

For instance updating Azure CLI to print out the body of the server's 500 response, at the very least when you pass --debug, if not in lue of "too many 500 error responses" would be extremely useful when diagnosing issues like this.

Up to you. Regardless, for future people that come across this thread: the trick to getting the underlying error message is typing $env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION = '1' and then opening Fiddler and setting it to decrypt SSL traffic.

lprichar avatar Apr 08 '20 22:04 lprichar

In case anyone else comes across this, I ended up solving it by upgrading to the latest terraform version and terraform azure provider (that's taking azurerm from 1.32.1 to 2.0 and terraform from 0.12.17 to 0.12.24). Then I deleted the cluster and had Terraform recreate it. Now it scales from the command line just fine. I suspect the relevant change it made is changing the type of node pool from "AvailabilitySet" to "VirtualMachineScaleSets".

lprichar avatar Apr 17 '20 14:04 lprichar

Thanks for the great discussion here! Closing this issue now.

Jen7714 avatar May 29 '20 17:05 Jen7714