<p>Need to understand why pods are automounting the service accounts secret.</p>
<p>If we disable the automout of service account, will this affect any operation of our application which is already have service account specified in the pod spec part, but automount of the service account is not disabled.</p>

<p>How to disable automounting of the service account is explained in the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-server" rel="nofollow noreferrer">linked documentation</a>:</p>
<blockquote>
<p>In version 1.6+, you can opt out of automounting API credentials for a
service account by setting <code>automountServiceAccountToken: false</code> on
the service account.</p>
<p>In version 1.6+, you can also opt out of automounting API credentials
for a particular pod.</p>
</blockquote>
<p>There are also some solutions suggested to mitigate the security issue:</p>
<ul>
<li><p><a href="https://github.com/kubernetes/kubernetes/issues/57601#issuecomment-353824159" rel="nofollow noreferrer">Using RBAC</a></p>
</li>
<li><p><a href="https://github.com/kubernetes/kubernetes/issues/57601#issuecomment-659304477" rel="nofollow noreferrer">Using mutating webhooks</a></p>
</li>
</ul>
<hr />
<blockquote>
<p>If we disable the automout of service account, will this affect any operation of our application which is already have service account specified in the pod spec part</p>
</blockquote>
<p>If you disable automounting of the SA secret, the Pod won't be able to access the K8s API server or do any other operation that requires authenticating as a Service Account. It's hard to tell if that would impact your workload or not, only you can tell. A web server or a worker Pod that only talks to other user-defined services might do fine without SA access, but if they want e.g. to spawn K8s Jobs from an application Pod they would need the SA.</p>
<hr />
<blockquote>
<p>But would like to understand why the secrete of the Service account getting mounted to the pods eventhough it's a security escalation.</p>
</blockquote>
<p>The point seems to be, as often in computer security, that we need to weigh convenience vs security. Automatically mounting SA secretes into a Pod makes it easy (=&gt; goes to convenience) to use K8s API. Disabling this by default is more secure but also less convenient, as you need to explicitly mark those Pods that need access to the K8s API. Whether this is too much of a burden depends very much on the workload, and there's likely no default answer that fits everyone.</p>
<hr />
<blockquote>
<p>Why was it not changed to the more secure default?</p>
</blockquote>
<p>This was answered <a href="https://github.com/kubernetes/kubernetes/issues/57601#issuecomment-494986292" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>disabling by default is not backwards compatible, so is not a
realistic option until (if) a v2 Pod API is made</p>
</blockquote>
<p>and <a href="https://github.com/kubernetes/kubernetes/issues/57601#issuecomment-522209979" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>I'm not saying that it's unreasonable, just that it's going to be a
hard pill to swallow for GA distributions of Kubernetes. I could see
this happening in the v2 pod API.</p>
</blockquote>
