<p>I have 4 services running as 4 different deployments/pods in my kubernetes cluster, name them, <strong>A</strong>, <strong>B</strong>, <strong>C</strong> and <strong>D</strong>. 
<strong>D</strong> is providing a common service which <strong>A</strong> and <strong>B</strong> are using via rest API calls, but it behaves differently between the requests come from <strong>A</strong> and those from <strong>B</strong>. And for requests from <strong>C</strong>, <strong>D</strong> should just deny the request (not authorized).
Is there a k8s built-in way of supporting identifying/authorizing pods within the cluster?</p>

<p>My current approach is to use service account, where I created two service accounts, SA1 and SA2, which are used by <strong>A</strong> and <strong>B</strong> respectively, and my service <strong>D</strong> is registered as token reviewer. Both <strong>A</strong> and <strong>B</strong> need to read the service account token and submit it with the request to <strong>D</strong>. Through reviewing the token, <strong>D</strong> can tell if the requests are from <strong>A</strong> or <strong>B</strong>. This works, but I'm not sure if this is the best way of achieving this. Since each deployment can only use one service account, this may increase the complexity of service account management and token reviewing complexity if we get more services.</p>

<p>I went through kubernetes documents, e.g. RBAC, ABAC, node authorization and etc... but seems these are all designed for authorization of cluster API access, rather than the authorisation of services running in the cluster.</p>

<p>azure seems have a solution <a href="https://github.com/Azure/aad-pod-identity" rel="nofollow noreferrer">https://github.com/Azure/aad-pod-identity</a> which fulfills my requirement, but it also has dependencies to other deployments (Active directory), which I don't think we will have in our cluster.</p>

Ming Zhu
<p>This seems to me to be more about service-to-service security for services running on the same cluster.</p>

<p>I understand there is already a solution in place that works fine at a smaller scale but the concern is that it won't scale for more services. Also, it appears that the services are aware they run on Kubernetes inside a pod container and do something special to make authentication with service account tokens work - "...Both A and B need to read the service account token and submit it with the request to D".</p>

<p>In their answer, @coderanger mentions service mesh. If you expect the number of the services that call each other and that have to be secured to grow, a service mesh like <a href="https://istio.io/" rel="nofollow noreferrer">Istio</a> will be a good fit here. (I am not affiliated with Istio)</p>

<p>In addition to <a href="https://istio.io/docs/concepts/what-is-istio/#security" rel="nofollow noreferrer">security</a>, Istio offers a lot of features that one can pick and choose to use or not to. At large scale, it helps that the management is from a central <a href="https://istio.io/docs/concepts/what-is-istio/#architecture" rel="nofollow noreferrer">control plane</a> and, for example, with automated key &amp; certificate provisioning and rotation.</p>

<p>With Istio, the application code doesn't have to change as Istio uses sidecar container pattern to deploy a proxy in the same pod along side each of the application services containers; the lightweight proxy handles the security, traffic management, telemetry... A nice "side effect" is that developers can still develop and test these service integrations locally without worrying about security.</p>
