Answers: <p>The thing I was looking for was <a href="https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/" rel="nofollow noreferrer">external-auth</a> in ingress-nginx. I created a simple service with nodejs which took over all the basic-auth logic. Then I used an external link to this service in k8s annotations for restricted resources.</p>
  <p>annotation snippet:</p>
  <pre><code>  annotations:
      nginx.ingress.kubernetes.io/auth-url: http://service-name.default.svc.cluster.local:3000/auth 
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-11T16:45:05.107Z
Answers: 2021-02-11T16:45:05.107Z
Answers: fourslashw
Body: <p>Currently I have a webpage which is freely accessible from certain networks an requires HTTP basic auth otherwise. This behaviour is set in the nginx config. It looks something like this:</p>
  <pre><code>geo $authentication {
      default &quot;Authentication required&quot;;
      SOME-IP &quot;off&quot;;
      SOME-NETWORK1 &quot;off&quot;;
      SOME-NETWORK2 &quot;off&quot;; 
  }
  
  ...
  auth_basic $authentication;
  ...
  </code></pre>
  <p>Now I want to move this webpage to a k8s cluster under ingress-nginx ingress controller. As I can see from the docs it has support for basic auth but provides no ways to allow access from specific ips/networks. Is there a way/another ingress controller/tool to configure said behaviour?</p>
  
Tags: <kubernetes><nginx><ingress>
Title: Disabling HTTP Basic auth for requests from specific ips in k8s ingress
UserDisplayName: fourslashw
ThreadText: # Disabling HTTP Basic auth for requests from specific ips in k8s ingress
  
  (Asked by: username_0 on 2021-02-09)
  
  Currently I have a webpage which is freely accessible from certain networks an requires HTTP basic auth otherwise. This behaviour is set in the nginx config. It looks something like this:
  
  ```
  geo $authentication {
      default "Authentication required";
      SOME-IP "off";
      SOME-NETWORK1 "off";
      SOME-NETWORK2 "off"; 
  }
  
  ...
  auth_basic $authentication;
  ...
  
  ```
  
  Now I want to move this webpage to a k8s cluster under ingress-nginx ingress controller. As I can see from the docs it has support for basic auth but provides no ways to allow access from specific ips/networks. Is there a way/another ingress controller/tool to configure said behaviour?
  
  **Tags:** kubernetes, nginx, ingress
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-02-11. Score: 1 | Accepted answer
  
  The thing I was looking for was [external-auth](https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/) in ingress-nginx. I created a simple service with nodejs which took over all the basic-auth logic. Then I used an external link to this service in k8s annotations for restricted resources.
  
  annotation snippet:
  
  ```
    annotations:
      nginx.ingress.kubernetes.io/auth-url: http://service-name.default.svc.cluster.local:3000/auth 
  
  ```
  
  
  ---
  
  