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

az aks create fails to obtain SP credentials

Open davis-x opened this issue 7 years ago • 52 comments

Describe the bug Failed to create aks cluster using command line az aks create -n my-cluster -g test

Instead the cli fails to pull the service principal credentials

Operation failed with status: 'Bad Request'. Details: The credentials in ServicePrincipalProfile were invalid. Please see https://aka.ms/aks-sp-help for more details. (Details: adal: Refresh request failed. Status Code = '400'. Response body: {"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier 'f4b3caa9-defb-4ada-b190-e8422327afbb' was not found in the directory '599a411f-b08b-45fe-8545-623369f42d16'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: bb906908-bf98-46ad-ad5f-6262bd779100\r\nCorrelation ID: b5bb293a-d4be-43be-9a86-180b51515b4b\r\nTimestamp: 2019-06-06 18:45:03Z","error_codes":[700016],"timestamp":"2019-06-06 18:45:03Z","trace_id":"bb906908-bf98-46ad-ad5f-6262bd779100","correlation_id":"b5bb293a-d4be-43be-9a86-180b51515b4b","error_uri":"https://login.microsoftonline.com/error?code=700016"})

To Reproduce Run az aks create -n my-cluster -g test

Expected behavior A cluster is created

Environment summary

Linux-4.9.87-linuxkit-aufs-x86_64-with-debian-buster-sid
Python 3.6.5
Shell: bash

azure-cli 2.0.66

Additional context https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal#automatically-create-and-use-a-service-principal

The documentation clearly states that a principal should be created when one is not passed in.

In this case, a SP is being created, and I can see that after in the App Registrations panel, but yet the command is still failing, leaving me with a SP that appears to be useless

davis-x avatar Jun 06 '19 19:06 davis-x

I've run this command three times, and the first 2 it failed with the above error and the third time it looks like it's working. So .....

davis-x avatar Jun 06 '19 19:06 davis-x

I am witnessing this exact same behaviour. First two attempts failed but simply retrying the same command worked on 3rd attempt. Using Azure Cloud Shell with Bash.

anttipo avatar Jun 06 '19 20:06 anttipo

experiencing a similar issue which previously worked before, now we can't create a cluster bound to another tenant-id anymore. This previously worked.

See: https://github.com/MicrosoftDocs/azure-docs/issues/32883

bitsofinfo avatar Jun 07 '19 16:06 bitsofinfo

Also facing a similar error, tried deploying twice today with a two hour window between deployments, no luck.

Operation failed with status: 'Bad Request'. Details: 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: d25ed14a-ae63-4abe-aad9-80b2557c1c00\r\nCorrelation ID: acb9e202-4c50-4a1c-860c-e4822b0c4f3c\r\nTimestamp: 2019-06-11 13:42:53Z","error_codes":[7000215],"timestamp":"2019-06-11 13:42:53Z","trace_id":"d25ed14a-ae63-4abe-aad9-80b2557c1c00","correlation_id":"acb9e202-4c50-4a1c-860c-e4822b0c4f3c"})

jjgriff93 avatar Jun 11 '19 13:06 jjgriff93

Same thing here, it doesn't work, unable to create a new AKS cluster with the portal or Cli...

marchanddesable avatar Jun 11 '19 17:06 marchanddesable

@marchanddesable as a temporary workaround I manually created a service principal then passed in the details into the az aks create command, which worked

jjgriff93 avatar Jun 11 '19 18:06 jjgriff93

@jjgriff93, fyi, this workaround did not work in my case, trying more than 3 times also.

GLink avatar Jun 14 '19 11:06 GLink

I still have the same error if I try to create a AKS cluster in the portal or just by running a command like: az aks create -n my-cluster -g MyResGroup

BUT... I can create the AKS cluster with the following steps:

  1. create a service principal and get the informations az ad sp create-for-rbac --skip-assignment

It will show something like:

{ "appId": "4567876c-47d4-438b-8341-67g1a3d12rae", "displayName": "azure-cli-2019-06-15-22-24-12", "name": "http://azure-cli-2019-06-15-22-24-12", "password": "xzzg445667-efef-78888-769e-d4543567", "tenant": "fb245196-9867-4a04-rtf-4556ad3ddff6" }

  1. Autoscaler feature, only if you need the feature, aks-preview must be installed: az extension add --name aks-preview Help: https://docs.microsoft.com/en-us/azure/aks/cluster-autoscaler

  2. create a resource group: az group create --name MyResourceGrp --location westeurope

  3. create the AKS cluster:

az aks create --resource-group MyResourceGrp
--name MyClusterName -s Standard_B2s --node-count 1 --generate-ssh-keys --service-principal 4567876c-47d4-438b-8341-67g1a3d12rae --client-secret xzzg445667-efef-78888-769e-d4543567 --enable-vmss --enable-cluster-autoscaler --min-count 1 --max-count 2

marchanddesable avatar Jun 17 '19 05:06 marchanddesable

Facing the same issue here. The workaround mentioned by @jjgriff93 and @marchanddesable worked for me. Thanks!

dr0pdb avatar Jun 18 '19 05:06 dr0pdb

Seems there are two issues. This issue: #https://github.com/MicrosoftDocs/azure-docs/issues/32883 which was closed when referenced to here is actually the issue I experience, i.e setting up the aad integration for users in another tenant.

az aks create .... --aad-client-app-id $aadClientAppId This is the client id not found, but definitely exists --aad-server-app-id $aadServerAppId --aad-server-app-secret $aadServerAppSecret --aad-tenant-id $env:aadTenantId

If not same cause should be a separate issue.

GLink avatar Jun 18 '19 18:06 GLink

experiencing same @GLink worked back in early may, and no more...

bitsofinfo avatar Jun 18 '19 19:06 bitsofinfo

Me too. Experiencing the AAD Integration issue @GLink describes. Worked in the past.

pvandorp avatar Jun 19 '19 09:06 pvandorp

@jnoller, I am from Azure Data team, we have a dependency on AKS, and some users experienced this issue, it would be nice if we could get an ETA for this so that we can decide how do we proceed. Thanks!

alanrenmsft avatar Jul 25 '19 18:07 alanrenmsft

I got around this by looping and retrying the same az aks create command up to 6 times. About half the time it works.

dparker18 avatar Jul 25 '19 18:07 dparker18

Hi All - the reported issue where an AKS create command fails due to a non existent SP (even though it was created) is actually a data replication issue. As noted, if you retry the command the command will work (this happens to the portal as well).

The cause is a data replication lag between the create call for the SP, confirmation, and then replication to the requested region. This replication can take up to 4 minutes. This is also why commands that passed previously fail.

We are bringing the replication timing issue to the attention of the AD team.

jnoller avatar Jul 25 '19 20:07 jnoller

IMOP this should be mentioned somewhere in documentation or after you create the SP.

isaacrlevin avatar Aug 26 '19 21:08 isaacrlevin

We've noted this in some portal create flow docs, pointing to this troubleshooting section. Thanks for your patience while we work with the AAD team to get this propagation time improved. https://docs.microsoft.com/en-us/azure/aks/troubleshooting#im-receiving-errors-that-my-service-principal-was-not-found-when-i-try-to-create-a-new-cluster-without-passing-in-an-existing-one

jluk avatar Sep 11 '19 16:09 jluk

Could we close this now that we have a doc reference for this issue? It's a known issue captured here: https://github.com/Azure/AKS/issues/1206

Requires a fix from Azure Active Directory which should provided updates on the issue above.

jluk avatar Sep 25 '19 18:09 jluk

I also face this error when following this doc. https://docs.microsoft.com/en-us/azure/aks/windows-container-cli

This doc is not helpful because it doesn't explain what I should do to fix the issue at all. https://docs.microsoft.com/en-us/azure/aks/troubleshooting#im-receiving-errors-that-my-service-principal-was-not-found-when-i-try-to-create-a-new-cluster-without-passing-in-an-existing-one

I hope the AKS team will fix the issue by changing the az CLI command.

tanaka-takayoshi avatar Oct 22 '19 05:10 tanaka-takayoshi

For me, removing the ~/.azure/aksServicePrincipal.json file prior to deployment works very well.

  • Patriek van Dorp

From: tanaka_733 [email protected] Sent: Tuesday, October 22, 2019 7:10:15 AM To: Azure/azure-cli [email protected] Cc: Patriek van Dorp [email protected]; Comment [email protected] Subject: Re: [Azure/azure-cli] az aks create fails to obtain SP credentials (#9585)

I also face this error when following this doc. https://docs.microsoft.com/en-us/azure/aks/windows-container-clihttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Faks%2Fwindows-container-cli&data=02%7C01%7Cpatriek.van.dorp%40microsoft.com%7C7b833aaecb34411aac6708d756ae2010%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637073178184440503&sdata=V3fOW%2FHcc4nOV%2F68KedJtLLgzkRoQs6DOoUW2EP%2BaXM%3D&reserved=0

This doc is not helpful because it doesn't explain what I should do to fix the issue at all. https://docs.microsoft.com/en-us/azure/aks/troubleshooting#im-receiving-errors-that-my-service-principal-was-not-found-when-i-try-to-create-a-new-cluster-without-passing-in-an-existing-onehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Faks%2Ftroubleshooting%23im-receiving-errors-that-my-service-principal-was-not-found-when-i-try-to-create-a-new-cluster-without-passing-in-an-existing-one&data=02%7C01%7Cpatriek.van.dorp%40microsoft.com%7C7b833aaecb34411aac6708d756ae2010%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637073178184440503&sdata=Dqljum%2BcYuWLwVQGs0cEtNv9xSI3xoDcUJXKtSVefRA%3D&reserved=0

I hope the AKS team will fix the issue by changing the az CLI command.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-cli%2Fissues%2F9585%3Femail_source%3Dnotifications%26email_token%3DAALCHLT7Q77PS6CJD2LMTLTQP2DLPA5CNFSM4HVHO4BKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEB4RQWY%23issuecomment-544807003&data=02%7C01%7Cpatriek.van.dorp%40microsoft.com%7C7b833aaecb34411aac6708d756ae2010%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637073178184450496&sdata=mvxc9pckOY5tw2kebWyPKfyBpa%2BguAYhcU2VZqpBUho%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAALCHLUTSVSJM5KP2XQS3RLQP2DLPANCNFSM4HVHO4BA&data=02%7C01%7Cpatriek.van.dorp%40microsoft.com%7C7b833aaecb34411aac6708d756ae2010%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637073178184450496&sdata=QTcO0BL0mZIIUCEzwvRNKxjPPg2itrnIhOW%2F9Tm2Qak%3D&reserved=0.

pvandorp avatar Oct 22 '19 05:10 pvandorp