<p>I have a following <code>kubectl</code> command to obtain the credentials for my Azure cluster:</p>
<pre><code>kubectl config set-credentials token --token=&quot;$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)&quot; --auth-provider=azure
</code></pre>
<p>However, this throws the following error:</p>
<pre><code>creating a new azure token source for device code authentication: client-id is empty
</code></pre>
<p>After doing some investigation, I found out that we need to supply additional information for <code>client id</code>, <code>tenant id</code>, and <code>apiserver id</code>:</p>
<pre><code>kubectl config \
  set-credentials &quot;&lt;username&gt;&quot; \
  --auth-provider=azure \
  --auth-provider-arg=environment=AzurePublicCloud \
  --auth-provider-arg=client-id=&lt;kubectl-app-id&gt; \
  --auth-provider-arg=tenant-id=&lt;tenant-id&gt; \
  --auth-provider-arg=apiserver-id=&lt;apiserver-app-id&gt;
</code></pre>
<p>How should we obtain the <code>client id</code>, <code>tenant id</code>, and <code>apiserver id</code> details?</p>

<p>Command <code>kubectl config set-credentials</code> is used to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#define-clusters-users-and-contexts" rel="nofollow noreferrer">set credentials</a> as the name implies. If you want to get some information from your cluster you have several ways to do. For example you can use Azure Portal. Everything is described <a href="https://www.inkoop.io/blog/how-to-get-azure-api-credentials/" rel="nofollow noreferrer">in this article</a>. For example to get Tenant ID you need to:</p>
<blockquote>
<ol>
<li><a href="https://portal.azure.com/" rel="nofollow noreferrer">Login into your azure account</a>.</li>
<li>Select azure active directory in the left sidebar.</li>
<li>Click properties.</li>
<li>Copy the directory ID.</li>
</ol>
</blockquote>
<p>To get Client ID:</p>
<blockquote>
<ol>
<li><a href="https://portal.azure.com/" rel="nofollow noreferrer">Login into your azure account</a>.</li>
<li>Select azure active directory in the left sidebar.</li>
<li>Click Enterprise applications.</li>
<li>Click All applications.</li>
<li>Select the application which you have created.</li>
<li>Click Properties.</li>
<li>Copy the Application ID .</li>
</ol>
</blockquote>
<p>To get Client Secret:</p>
<blockquote>
<ol>
<li><a href="https://portal.azure.com/" rel="nofollow noreferrer">Login into your azure account</a>.</li>
<li>Select azure active directory in the left sidebar.</li>
<li>Click App registrations.</li>
<li>Select the application which you have created.</li>
<li>Click on All settings.</li>
<li>Click on Keys.</li>
<li>Type Key description and select the Duration.</li>
<li>Click save.</li>
<li>Copy and store the key value. You won't be able to retrieve it after you leave this page.</li>
</ol>
</blockquote>
<p>You can also find these informations using cli based on <a href="https://learn.microsoft.com/en-us/cli/azure/ad/app/credential?view=azure-cli-latest#az_ad_app_credential_list" rel="nofollow noreferrer">oficial documentation</a>.</p>
<p>You can also find additional example for  <a href="https://learn.microsoft.com/en-us/azure/active-directory/fundamentals/active-directory-how-to-find-tenant" rel="nofollow noreferrer">Tenant ID</a> (example with Azure portal and cli options):</p>
<pre><code>az login
az account list
az account tenant list
</code></pre>
