<p>We have several microservices implemented in Java/Kotlin and Spring MVC, running in Tomcat docker images. These services provide public APIs which are authenticated by user's cookies/sessions. These work correctly.</p>

<p>Now, we would like to create an internal endpoint, which wouldn't be accessible either outside of GKE or via some kind of internal authentication. </p>

<p>What would be the good way to go especially for Spring MVC and GKE?</p>

<p>EDIT:</p>

<p>I would like to achieve to authenticate different endpoints on one service. For instance:</p>

<ul>
<li><code>/public/</code> - no auth</li>
<li><code>/private/</code> - user must be logged in</li>
<li><code>/internal/</code> - only other microservices can access</li>
</ul>

<p>I would prefer to implement such auth on the application level, but I am not sure what would be the best way. IP range of internal Google IPs? Some other way of securely identifying the caller?</p>

<p>Maybe my idea is bad, if so, I will be happy to change my mind.</p>

<p>Your question isn't GKE specific. It's broadly a Kubernetes question.</p>

<p>I encourage you to search Kubernetes service authentication.</p>

<p>There are many ways to do this, including rolling your own auth model. One feature that can help here is Kubernetes NetworkPolicy resource (it's like firewalls), you can learn more about it here <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/network-policies/</a> and see here for some examples: <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes" rel="nofollow noreferrer">https://github.com/ahmetb/kubernetes-network-policy-recipes</a> (Keep in mind that this is a firewall, not authentication.)</p>

<p>If you want to get this automatically, you can use Istio (<a href="https://istio.io" rel="nofollow noreferrer">https://istio.io</a>) which allows you to automatically set up mutual TLS between all your services without any code changes. Istio also gives a strong identity to each workload. You can use Istio's authentication policies to set up auth between your microservices <em>without changing your application code</em> which is really cool: <a href="https://istio.io/docs/tasks/security/authn-policy/" rel="nofollow noreferrer">https://istio.io/docs/tasks/security/authn-policy/</a></p>
