<p>Could anyone explain me what is the best way to add basic Auth to a kubernetes cluster deployment that is running a webapp on Google Cloud (GCP)</p>

<p>We are exposing it using: </p>

<pre><code>kubectl expose deployment testSanbox --type=LoadBalancer --port 80 --target-port 80
</code></pre>

<p>We don't need anything fancy as this is only a dev sandbox but we don't want anyone to be able to reach it.
It could be a single user/pass combo or maybe use the google credentials that we manage with IAM.</p>

<p>Sorry as you probably already noticed I'm not really experienced with kubernetes or GCP.</p>

<p>Thanks</p>

<p>If you looking for HTTP Basic Auth you can use NGINX and Ingress. Here is setup instruction <a href="https://docs.bitnami.com/kubernetes/how-to/secure-kubernetes-services-with-ingress-tls-letsencrypt/" rel="nofollow noreferrer">authentication-ingress-nginx</a>, <a href="https://banzaicloud.com/blog/ingress-auth/" rel="nofollow noreferrer">ingress-auth</a>. </p>

<p>But in context of security http authentication is not good enough secure authentication method. The problem is that, unless the process is strictly enforced throughout the entire data cycle to SSL for security, the authentication is transmitted in open on insecure lines. This lends itself to man in the middle attacks, where a user can simply capture the login data and authenticate via a copy-cat HTTP header attached to a malicious packet.</p>

<p>Here is overview in kubernetes official documentation about authorization <a href="https://kubernetes.io/docs/reference/access-authn-authz/authorization/" rel="nofollow noreferrer">authorization-kubernetes</a>.</p>

<p>If you look for better solutions use API Keys, OAuth provider such as Google, Auth0, etc. developers.google.com/identity/protocols/OAuth2WebServer AND developers.google.com/identity/protocols/OAuth2UserAgent 
There are many options for authentication and authorization.
Here are xplainations of above terms: <a href="https://nordicapis.com/3-common-methods-api-authentication-explained/" rel="nofollow noreferrer">api-authentication</a>.</p>

<p>Approach to authenticate users using Auth on GCP: <a href="https://cloud.google.com/endpoints/docs/openapi/authenticating-users-auth0" rel="nofollow noreferrer">authentication-gcp-app</a>.</p>

<p>Please let me know if it helps.</p>
