teteyi3241
teteyi3241

Reputation: 271

How to deny path in k8S ingress

I would like to block /public/configs in my k8s ingress.

My current settings doesnt work.

    - host: example.com
      http:
        paths:
          - path: /*
            pathType: ImplementationSpecific
            backend:
              service:
                name: service-myapp
                port:
                  number: 80
          - path: /public/configs
            pathType: ImplementationSpecific
            backend:
              service:
                name: service-myapp
                port:
                  number: 88 // fake port

Is there any better (easy) way?

Upvotes: 6

Views: 3103

Answers (1)

RoohAllah Godazgar
RoohAllah Godazgar

Reputation: 158

1- Create a dummy service and send it to that:

  - path: /public/configs
    pathType: ImplementationSpecific
    backend:
      service:
        name: dummy-service
        port:
          number: 80

2- use server-snippets as bellow to return 403 or any error you want:

a) for k8s nginx ingress:

  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      location ~* "^/public/configs" {
          deny all;
          return 403;
        }

b) for nginx ingress:

  annotations:
    nginx.org/server-snippet: |
      location ~* "^/public/configs" {
          deny all;
          return 403;
        }

Upvotes: 6

Related Questions