How to block some subpath and return 401? Request-termination + ingress

Hi,
how can we configure request termination plugin for a specified subpath of service (e.g. /api/campaign/private)? I have no idea how to use KongPlugin or KongIngress for that purpose. What is the preferred way to block subpath and return 401? Unfortunately nginx configuration snippets don’t work

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test1-kong-ingress
  annotations:
    configuration.konghq.com: "sample-customization"
spec:
  rules:
    - http:
        paths:
          - path: /api/campaign*
            backend:
              serviceName: "service-campaign"
              servicePort: 8080
          - path: /api/item*
            backend:
              serviceName: "service-item"
              servicePort: 8080

I’ve found below workauround. I’ve simply prepared 2nd ingress configuration

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test1-kong-ingress-blocked
  annotations:
    plugins.konghq.com: "block-private-endpoint"
spec:
  rules:
    - http:
        paths:
          - path: /api/campaign/private*
            backend:
              serviceName: "service-campaign"
              servicePort: 8080

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: block-private-endpoint
plugin: request-termination
config:
  status_code: 401
  message: access forbidden!

Glad you found it. This looks good.


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ