0

I'm trying to filter out all paths that begin with /something. While the regex seems PCRE valid by online testers, the result is 404 for all paths:

kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: myhost.com
    http:
      paths:
      - backend:
          serviceName: myservice
          servicePort: 80          
        path: /^([^something].*)

Tried to play with the regex (e.g, path: /(^[^something])(.*)), but still get 404 for all.

What am I missing?

Using v1.12.2 client with v1.14.1 server.

Kludge
  • 2,653
  • 4
  • 20
  • 42
  • can you try adding this annotation - nginx.ingress.kubernetes.io/use-regex: "true" – Tushar Mahajan Dec 04 '19 at 12:30
  • if I do that, it makes some weird certificate issues ("Your connection is not private") – Kludge Dec 04 '19 at 12:50
  • I am not sure if I understood what you want to achieve. Could you elaborate? Did you see https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#rewrite-target – PjoterS Dec 04 '19 at 15:25
  • I would like to deny all incoming requests that begin with `/something` – Kludge Dec 05 '19 at 11:31

1 Answers1

2

If you want to deny all traffic to /something you should use Nginx annotations called server-snipped. It will allow you to add custom configuration.

It would look like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: nginx-snippet
   annotations:
      nginx.ingress.kubernetes.io/configuration-snippet: |

      location /something {

           deny all;  
      }

Fimilar example can be found on Github thread.

You can also consider second option with 2 ingress objects and authentication. This was mentioned in another StackOverflow question.

In addition, you can deny access not only by location but also with specific IP. It can be obtain using annotation called whitelist-source-range.

PjoterS
  • 12,841
  • 1
  • 22
  • 54
  • Is there a way to separate paths so that it goes two two different backends? I have two react apps which i'd like to access them differently, – Denn Feb 01 '21 at 06:47