`az aks create` not working with ServicePrincipal secret stored in Keyvault
Describe the bug
I want to create an AKS cluster with the command shown below. A ServicePrincipal, which has the acrpull permission should be used to pull images from an attached ACR. This ServicePrincipal was created using az ad sp create-for-rbac with the cert being stored in a Keyvault.
It is unclear to me how I can correctly specify the ServicePrincipal's secret (the Keyvault cert/secret) in the --client-secret command line argument. I outlined steps I tried in the last section of this post.
Command Name
az aks create
Errors:
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: 4435d409-074a-4c4d-9429-efe8925e1500\r\nCorrelation ID: 51dac364-9a0c-496e-8b2d-ac0911506c1f\r\nTimestamp: 2020-04-15 10:40:05Z","error_codes":[7000215],"timestamp":"2020-04-15 10:40:05Z","trace_id":"4435d409-074a-4c4d-9429-efe8925e1500","correlation_id":"51dac364-9a0c-496e-8b2d-ac0911506c1f","error_uri":"https://login.microsoftonline.com/error?code=7000215"})
To Reproduce:
Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.
Steps:
- Create
SP1withaz ad sp create-for-rbac \ --skip-assignment \ --name {} \ --scopes $(ACR_ID) \ --role acrpull \ --create-cert \ --keyvault $(KEYVAULT_ID) \ --cert $(CERT_ID)
- Modify
$(CERT_ID)so it represents the fully qualified ID of the cert. az aks create --name {} --resource-group {} --location {} --service-principal SP1 --client-secret $(CERT_ID) --attach-acr {} --enable-cluster-autoscaler --min-count {} --max-count {} --enable-addons {} --workspace-resource-id {} --kubernetes-version {} --verbose
Expected Behavior
Should successfully create an AKS cluster with the SPs/addons enabled.
Environment Summary
macOS-10.15.3-x86_64-i386-64bit
Python 3.8.2
azure-cli 2.2.0 *
Additional Context
- The command is working when the SP is authenticated with a password.
- Tried both
/certificatesand/secretsas segments in the fully qualified ID of$(CERT_ID). - Tried passing specific certificate versions as suffix to the fully qualified ID of
$(CERT_ID). - Gave all possible Keyvault permissions through the Keyvault policies to both
SP1and the ServicePrincipal that is running theazcommands. - Enabled and disabled
Azure Virtual Machines for deploymentsetting in the Keyvault. - This has been reported in 2018 already but was unanswered: https://github.com/Azure/azure-cli/issues/8133 .
Thanks in advance.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/aks-pm.
thanks for reporting, routing to appropriate team
The --client-secret argument does not accept a keyvault certificates. You have to use a service principal with password based authentication.
Closing this issue for now as the answer as been addressed above. Feel free to reopen if this doesn't answer your question!