<p>I am trying to setup oauth2_proxy on kubernetes to secure one of my single page application and I am using github as the authentication provider. I found this link useful and I followed this for doing my setup.
[<a href="https://alikhil.github.io/2018/05/oauth2-proxy-for-kubernetes-services/]" rel="nofollow noreferrer">https://alikhil.github.io/2018/05/oauth2-proxy-for-kubernetes-services/]</a></p>

<p>I have created an application on github and used my DNS Name in place of the HomePageURL and CallBackURL (<a href="https://auth.example.com" rel="nofollow noreferrer">https://auth.example.com</a> replaced with <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>) because I do not have TLS secrets generated for auth.example.com. Rather I have TLS certificates generated for example.com because this domain belongs to me. I was getting error in nginx-controller that the certificate belongs to example.com and not to auth.example.com as these URLs have been used in defining the example Ingress and oauth proxy ingress and this was the basis for me to do the before mentioned chang. </p>

<p>My Ingresses looks like this</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: oauth2-proxy
  annotations:
    kubernetes.io/tls-acme: "true"
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: example.com
      http:
        paths:
          - backend:
              serviceName: oauth2-proxy
              servicePort: 4180
            path: /oauth2
  tls:
    - hosts:
        - example.com
      secretName: oauth-proxy-tls
</code></pre>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: oauth-main-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
    ingress.kubernetes.io/auth-url: https://example.com/oauth2/auth
    ingress.kubernetes.io/auth-signin: https://example/oauth2/start?rd=https://$host$request_uri$is_args$args
spec:
  rules:
    - host: example.com
      http:
        paths:
          - backend:
              serviceName: example-service
              servicePort: 80
            path: /
  tls:
    - hosts:
        - example.com
      secretName: tls-secret

</code></pre>

<p>I want that whenever I click example.com it should display page for github authentication but in my case its directly giving the response which a service should give after successful authentication. I am not being asked to provide credentials. Also, I am getting error in my ingress controller logs as <code>7 controller.go:753] Error obtaining Endpoints for Service "default/oauth2-proxy": no object matching key "default/oauth2-proxy" in local store</code>
Also, I tried replacing using nginx.ingress.kubernetes.io/auth-url: <a href="http://oauth2-proxy.oauth-proxy.svc.cluster.local:4180/oauth2/auth" rel="nofollow noreferrer">http://oauth2-proxy.oauth-proxy.svc.cluster.local:4180/oauth2/auth</a> as mentioned in the link but it did not work for me. Can some one explain why is oauth2_proxy not asking for authentication and ingress is serving the requests directly without asking for authentication?</p>

Nitesh Ratnaparkhe
<p>The annotation declared in the oauth-main-ingress yaml is incorrect.
As per the <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#external-authentication" rel="nofollow noreferrer">kubernetes/nginx-ingress documentation</a> the annotation for <strong>external auth-url</strong> should be </p>

<pre><code> nginx.ingress.kubernetes.io/auth-url: http://&lt;oauth-service-url&gt;
</code></pre>

<p>instead of </p>

<pre><code> ingress.kubernetes.io/auth-url: http://&lt;oauth-service-url&gt;
</code></pre>
