How to allow the access only for specific API from kubernetes ingress under Nginx config

Viewed 67

I have the kubernetes ingress file with some micro services are exposed fully over 'abc.example.com'

How i can achieve to allow access for only one specific API from one micro service (empl-service) while rest all other microservices are exposed fully.

Specific Api to be allowed: https://abc.example.com/empl-service/api/v1/employees/capacityReport

i am trying to append in location directive as below, but i am able to access all the API's from empl-service.

   location ~* /gateway/(api|(?!(empl)).+service)/api/v1/employees/capacityReport
    
    {          
        deny all;
        return 404 "resource not found";
    }

it will be great, if someone help me in figuring out for specific API access.

below is nginx config in kubernetes ingress file.

apiVersion: networking.k8s.io/v1beta1

kind: Ingress

metadata:

  name: xyz-platform-ingress

  namespace: di

  annotations:

    kubernetes.io/ingress.class: nginx

    nginx.ingress.kubernetes.io/ssl-redirect: "true"

    nginx.ingress.kubernetes.io/use-regex: "true"

    nginx.ingress.kubernetes.io/rewrite-target: /$1

    nginx.ingress.kubernetes.io/configuration-snippet: |

      server_tokens off;
      location ~* /.+\.html$ {
          deny all;
          return 404 "resource not found";
      }        
      location ~* (.*\/actuator.*) {
          deny all;
          return 404 "resource not found";
      } 

      location ~* /gateway/(api|(?!(empl)).+service)/api/v1/employees/capacityReport
      {          
        deny all;
        return 404 "resource not found";
      }       
      location ~* /gateway/(api|(?!(market|jdw|asd|xyz|sale)).+service).* {          
          deny all;
          return 404 "resource not found";
      }
spec:
 tls:
 - hosts:
   - abc.example.com
   secretName: tls-secret
 rules:
 - host: abc.example.com
   http:
     paths:
     - path: /gateway/?(.*)
       backend:
        serviceName: example-service
        servicePort: 8080
     
0 Answers
Related