Kubernetes Ingress network deny some paths

ColossusMark1 picture ColossusMark1 · Aug 16, 2018 · Viewed 7.6k times · Source

I've a simple kubernetes ingress network.

I need deny the access some critical paths like /admin or etc.

My ingress network file shown as below.

 apiVersion: extensions/v1beta1
 kind: Ingress
 metadata:
 name: ingress-test
 spec:
   rules:
   - host: host.host.com
   http:
      paths:
        - path: /service-mapping
      backend:
         serviceName: /service-mapping
         servicePort: 9042

How I can deny the custom path with kubernetes ingress network, with nginx annonations or another methods .


I handle this issue with annotations shown as below .

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

     server_tokens off;
     location DANGER-PATH {
    deny all;
    return 403;
  }

spec:
  rules:
   - host: api.myhost.com
   http:
  paths:
  - backend:
      serviceName: bookapi-2
      servicePort: 8080
    path: PATH 

Answer

sedooe picture sedooe · Aug 17, 2018

You can use server-snippet annotation. This seems like exactly what you want to achieve.