<p>I am attempting to protect a service's status page with an oauth2_proxy, using Azure AD as the external auth provider. Currently if I browse to the public url of the app (<a href="https://sub.domain.com/service/hangfire" rel="nofollow noreferrer">https://sub.domain.com/service/hangfire</a>) I got a 504 gateway timeout, where it should be directing me to authenticate.</p>

<p>I had been mostly following this guide for reference: <a href="https://msazure.club/protect-kubernetes-webapps-with-azure-active-directory-aad-authentication/" rel="nofollow noreferrer">https://msazure.club/protect-kubernetes-webapps-with-azure-active-directory-aad-authentication/</a></p>

<p>If I disable the annotations that direct the authentication, I can get to the public status page without a problem. If I browse to <a href="https://sub.domain.com/oauth2" rel="nofollow noreferrer">https://sub.domain.com/oauth2</a>, I get a prompt to authenticate with my provider, which I would expect. I am not sure where the issue lies in the ingress config but I was unable to find any similar cases to this online, stackoverflow or otherwise.</p>

<p>In this case, everything (oauth deployment, service, and ingress rules) lives in a 'dev' namespace except the actual ingress deployment, which lives in its own namespace. I don't suspect this makes a difference, but SSL termination is handled by a gateway outside the cluster.</p>

<p>oauth2 deployment:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: oauth2-proxy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: oauth2-proxy
  template:
    metadata:
      labels:
        app: oauth2-proxy
    spec:
      containers:
      - name: oauth2-proxy
        image: quay.io/pusher/oauth2_proxy:v3.2.0
        imagePullPolicy: IfNotPresent
        args:
        - --provider=azure
        - --email-domain=domain.com
        - --upstream=http://servicename
        - --http-address=0.0.0.0:4180
        - --azure-tenant=id
        - --client-id=id
        - --client-secret=number
        env:
         - name: OAUTH2_PROXY_COOKIE_SECRET
           value: secret
        ports:
         - containerPort: 4180
           protocol : TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: oauth2-proxy
  name: oauth2-proxy
spec:
  ports:
  - name: http
    port: 4180
    protocol: TCP
    targetPort: 4180
  selector:
    app: oauth2-proxy 
</code></pre>

<p>Ingress rules:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: service-ingress1
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/auth-url: https://sub.domain.com/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: https://sub.domain.com/oauth2/start?rd=$https://sub.domain.com/service/hangfire"
spec:
  rules:
  - host: sub.domain.com       
    http:
      paths:
      - path: /service/hangfire
        backend:
          serviceName: service
          servicePort: 80                    
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: service-oauth2-proxy
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: sub.domain.com      
    http:
      paths:
      - path: /oauth2
        backend:
          serviceName: oauth2-proxy
          servicePort: 4180           
</code></pre>

<p>I am getting 504 errors when I browse to the url but I do not see any errors in the ingress pods.</p>

<p>I ended up finding the resolution here: <a href="https://github.com/helm/charts/issues/5958" rel="nofollow noreferrer">https://github.com/helm/charts/issues/5958</a></p>

<p>I had to use the internal service address for the auth-url, which I had not seen mentioned anywhere else.</p>

<pre><code>nginx.ingress.kubernetes.io/auth-url: http://oauth2-proxy.development.svc.cluster.local:4180/oauth2/auth
</code></pre>
