How to create AKS cluster in customer's account using oauth client credentials flow

Meersa 20 Reputation points
2023-08-07T07:12:21.71+00:00

We want to create AKS cluster in our customer's account via API using token obtained via client credentials oauth flow.

E.g. client.com has Azure account.

ourcompany.com wants to create AKS cluster in client.com's Azure account using API without human interaction.

How would the oauth setup look like in this case?

Thanks,

Meersa

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,456 questions
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

Accepted answer
  1. Mutaz Nassar 2,361 Reputation points Microsoft Employee
    2023-08-07T11:04:21.9466667+00:00

    Hi @Meersa,
    You can try the following:

    1. Get the token of your customer:

    TOKEN=$(az account get-access-token --query 'accessToken' -o tsv)

    1. Set the configurations of the AKS cluster, you can refer to this link for more details:
    cat << EOF > body.json
    {
    	"location": "eastus",
    	 "identity": {
        "type": "SystemAssigned"
     },
    	"properties": {
    	   "kubernetesVersion": "",
           "dnsPrefix": "dnsprefix1",
    	    "agentPoolProfiles": [
          {
            "name": "nodepool1",
            "count": 1,
            "vmSize": "Standard_DS2_v2",
            "osType": "Linux",
            "type": "VirtualMachineScaleSets",
            "mode": "System"
          }
    	 ],
    	
        "servicePrincipalProfile": {
          "clientId": "msi"
         }
    	}
    }
    EOF
    
    1. Create the AKS cluster using curl command with the generated token:
      curl -d @body.json -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" -X PUT 'https://management.azure.com/subscriptions/<subID>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ContainerService/managedClusters/<AKSClusterName>?api-version=2023-05-01'

    Note: Make sure to create the resource group.

    Hope this helps, and please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.