<p>By default when creating an AKS cluster a service principal is being created for that cluster.</p>
<p>Then that Service Principal can be set on the level of some other Azure Resource (VM?) in order for them to be able to establish a network connection and for them to be able to communicate (except of of course general network settings)</p>
<p>I am really not sure and can not understand when this is required and when not. If for example I have db on VM level do I need to grant the AKS service principal access to the VM to be able to communicate with it through the network or not?</p>
<p>Can someone provide me some guidance for this, and not general documentation. When this is required to be used/set on the level of those other Azure resources and when it is not?
I cannot find proper explanation for this.
Thank you</p>

<p><strong>Regarding your question about the DB</strong>, you do not need to give the service principal any access to that VM. Given that the Database runs outside of Kubernetes does not need to access that VM in any way. The database could even be in a different data center or hosted on another cloud provider entirely, applications running inside kubernetes will still be able to communicate with it as long as the traffic is allowed by firewalls etc.</p>
<p>I know you did not ask for generic documentation, but the documentation on <a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal" rel="nofollow noreferrer">Kubernetes Service Principals</a> puts it well:</p>
<blockquote>
<p>To interact with Azure APIs, an AKS cluster requires either an Azure
Active Directory (AD) service principal or a managed identity. A
service principal or managed identity is needed to dynamically create
and manage other Azure resources such as an Azure load balancer or
container registry (ACR).</p>
</blockquote>
<p>In other words, the Service principal is the identity that the Kubernetes cluster authenticates with when it interacts with other Azure resources such as:</p>
<ul>
<li><a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal#azure-container-registry" rel="nofollow noreferrer">Azure container registry</a>: The images that the containers are created from must come from somehwere. If you are storing your custom images in a private registry the cluster must be authorized to pull images from the registry. If the private registry is an Azure container registry the service principal must be authorized for those operations</li>
<li><a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal#networking" rel="nofollow noreferrer">Networking</a>: Kubernetes must be able to dynamically configure routetables and to register external IP's for services in a loadbalancer. Again, the service principal is used as identity so it must be authorized</li>
<li><a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal#storage" rel="nofollow noreferrer">Storage</a>: To access disk resources and mount them into pods</li>
<li><a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal#azure-container-instances" rel="nofollow noreferrer">Azure Container instances</a>: In case you are using the virtual kubelet to dynamically add compute resources to your cluster Kubernetes must be allow to manage containers on ACI.</li>
</ul>
<p>To <a href="https://learn.microsoft.com/en-us/azure/aks/kubernetes-service-principal#delegate-access-to-other-azure-resources" rel="nofollow noreferrer">delegate access to other Azure resources</a> you can use the azure cli to assign a role to a an assignee on a certain scope:</p>
<pre><code>az role assignment create --assignee &lt;appId&gt; --scope &lt;resourceScope&gt; --role Contributor
</code></pre>
<p>Here is <a href="https://learn.microsoft.com/en-us/azure/aks/concepts-identity#aks-cluster-identity-permissions" rel="nofollow noreferrer">a detailed list of all cluster identity permissions</a> in use</p>
